ManageSmileys.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. <?php
  2. /**
  3. * This file takes care of all administration of smileys.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2011 Simple Machines
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. /**
  17. * This is the dispatcher of smileys administration.
  18. */
  19. function ManageSmileys()
  20. {
  21. global $context, $txt, $scripturl, $modSettings;
  22. isAllowedTo('manage_smileys');
  23. loadLanguage('ManageSmileys');
  24. loadTemplate('ManageSmileys');
  25. $subActions = array(
  26. 'addsmiley' => 'AddSmiley',
  27. 'editicon' => 'EditMessageIcons',
  28. 'editicons' => 'EditMessageIcons',
  29. 'editsets' => 'EditSmileySets',
  30. 'editsmileys' => 'EditSmileys',
  31. 'import' => 'EditSmileySets',
  32. 'modifyset' => 'EditSmileySets',
  33. 'modifysmiley' => 'EditSmileys',
  34. 'setorder' => 'EditSmileyOrder',
  35. 'settings' => 'EditSmileySettings',
  36. 'install' => 'InstallSmileySet'
  37. );
  38. call_integration_hook('integrate_manage_smileys', array(&$subActions));
  39. // If customized smileys is disabled don't show the setting page
  40. if (empty($modSettings['smiley_enable']))
  41. {
  42. unset($subActions['addsmiley']);
  43. unset($subActions['editsmileys']);
  44. unset($subActions['setorder']);
  45. unset($subActions['modifysmiley']);
  46. }
  47. if (empty($modSettings['messageIcons_enable']))
  48. {
  49. unset($subActions['editicon']);
  50. unset($subActions['editicons']);
  51. }
  52. // Default the sub-action to 'edit smiley settings'.
  53. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'editsets';
  54. $context['page_title'] = $txt['smileys_manage'];
  55. $context['sub_action'] = $_REQUEST['sa'];
  56. $context['sub_template'] = $context['sub_action'];
  57. // Load up all the tabs...
  58. $context[$context['admin_menu_name']]['tab_data'] = array(
  59. 'title' => $txt['smileys_manage'],
  60. 'help' => 'smileys',
  61. 'description' => $txt['smiley_settings_explain'],
  62. 'tabs' => array(
  63. 'editsets' => array(
  64. 'description' => $txt['smiley_editsets_explain'],
  65. ),
  66. 'addsmiley' => array(
  67. 'description' => $txt['smiley_addsmiley_explain'],
  68. ),
  69. 'editsmileys' => array(
  70. 'description' => $txt['smiley_editsmileys_explain'],
  71. ),
  72. 'setorder' => array(
  73. 'description' => $txt['smiley_setorder_explain'],
  74. ),
  75. 'editicons' => array(
  76. 'description' => $txt['icons_edit_icons_explain'],
  77. ),
  78. 'settings' => array(
  79. 'description' => $txt['smiley_settings_explain'],
  80. ),
  81. ),
  82. );
  83. // Some settings may not be enabled, disallow these from the tabs as appropriate.
  84. if (empty($modSettings['messageIcons_enable']))
  85. $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
  86. if (empty($modSettings['smiley_enable']))
  87. {
  88. $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
  89. $context[$context['admin_menu_name']]['tab_data']['tabs']['editsmileys']['disabled'] = true;
  90. $context[$context['admin_menu_name']]['tab_data']['tabs']['setorder']['disabled'] = true;
  91. }
  92. // Call the right function for this sub-acton.
  93. $subActions[$_REQUEST['sa']]();
  94. }
  95. /**
  96. * Allows to modify smileys settings.
  97. *
  98. * @param bool $return_config = false
  99. */
  100. function EditSmileySettings($return_config = false)
  101. {
  102. global $modSettings, $context, $settings, $txt, $boarddir, $sourcedir, $scripturl;
  103. // The directories...
  104. $context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];
  105. $context['smileys_dir_found'] = is_dir($context['smileys_dir']);
  106. // Get the names of the smiley sets.
  107. $smiley_sets = explode(',', $modSettings['smiley_sets_known']);
  108. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  109. $smiley_context = array();
  110. foreach ($smiley_sets as $i => $set)
  111. $smiley_context[$set] = $set_names[$i];
  112. // All the settings for the page...
  113. $config_vars = array(
  114. array('title', 'settings'),
  115. // Inline permissions.
  116. array('permissions', 'manage_smileys'),
  117. '',
  118. array('select', 'smiley_sets_default', $smiley_context),
  119. array('check', 'smiley_sets_enable'),
  120. array('check', 'smiley_enable', 'subtext' => $txt['smileys_enable_note']),
  121. array('text', 'smileys_url'),
  122. array('text', 'smileys_dir', 'invalid' => !$context['smileys_dir_found']),
  123. '',
  124. // Message icons.
  125. array('check', 'messageIcons_enable', 'subtext' => $txt['setting_messageIcons_enable_note']),
  126. );
  127. call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
  128. if ($return_config)
  129. return $config_vars;
  130. // Setup the basics of the settings template.
  131. require_once($sourcedir . '/ManageServer.php');
  132. $context['sub_template'] = 'show_settings';
  133. // Finish up the form...
  134. $context['post_url'] = $scripturl . '?action=admin;area=smileys;save;sa=settings';
  135. $context['permissions_excluded'] = array(-1);
  136. // Saving the settings?
  137. if (isset($_GET['save']))
  138. {
  139. checkSession();
  140. // Validate the smiley set name.
  141. $_POST['smiley_sets_default'] = empty($smiley_context[$_POST['smiley_sets_default']]) ? 'default' : $_POST['smiley_sets_default'];
  142. // Make sure that the smileys are in the right order after enabling them.
  143. if (isset($_POST['smiley_enable']))
  144. sortSmileyTable();
  145. call_integration_hook('integrate_save_smiley_settings');
  146. saveDBSettings($config_vars);
  147. cache_put_data('parsing_smileys', null, 480);
  148. cache_put_data('posting_smileys', null, 480);
  149. redirectexit('action=admin;area=smileys;sa=settings');
  150. }
  151. // We need this for the in-line permissions
  152. createToken('admin-mp');
  153. prepareDBSettingContext($config_vars);
  154. }
  155. /**
  156. * List, add, remove, modify smileys sets.
  157. */
  158. function EditSmileySets()
  159. {
  160. global $modSettings, $context, $settings, $txt, $boarddir;
  161. global $smcFunc, $scripturl, $sourcedir;
  162. // Set the right tab to be selected.
  163. $context[$context['admin_menu_name']]['current_subsection'] = 'editsets';
  164. // They must've been submitted a form.
  165. if (isset($_POST[$context['session_var']]))
  166. {
  167. checkSession();
  168. validateToken('admin-mss', 'request');
  169. // Delete selected smiley sets.
  170. if (!empty($_POST['delete']) && !empty($_POST['smiley_set']))
  171. {
  172. $set_paths = explode(',', $modSettings['smiley_sets_known']);
  173. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  174. foreach ($_POST['smiley_set'] as $id => $val)
  175. {
  176. if (isset($set_paths[$id], $set_names[$id]) && !empty($id))
  177. unset($set_paths[$id], $set_names[$id]);
  178. }
  179. updateSettings(array(
  180. 'smiley_sets_known' => implode(',', $set_paths),
  181. 'smiley_sets_names' => implode("\n", $set_names),
  182. 'smiley_sets_default' => in_array($modSettings['smiley_sets_default'], $set_paths) ? $modSettings['smiley_sets_default'] : $set_paths[0],
  183. ));
  184. }
  185. // Add a new smiley set.
  186. elseif (!empty($_POST['add']))
  187. $context['sub_action'] = 'modifyset';
  188. // Create or modify a smiley set.
  189. elseif (isset($_POST['set']))
  190. {
  191. $set_paths = explode(',', $modSettings['smiley_sets_known']);
  192. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  193. // Create a new smiley set.
  194. if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
  195. {
  196. if (in_array($_POST['smiley_sets_path'], $set_paths))
  197. fatal_lang_error('smiley_set_already_exists');
  198. updateSettings(array(
  199. 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
  200. 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $_POST['smiley_sets_name'],
  201. 'smiley_sets_default' => empty($_POST['smiley_sets_default']) ? $modSettings['smiley_sets_default'] : $_POST['smiley_sets_path'],
  202. ));
  203. }
  204. // Modify an existing smiley set.
  205. else
  206. {
  207. // Make sure the smiley set exists.
  208. if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
  209. fatal_lang_error('smiley_set_not_found');
  210. // Make sure the path is not yet used by another smileyset.
  211. if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
  212. fatal_lang_error('smiley_set_path_already_used');
  213. $set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
  214. $set_names[$_POST['set']] = $_POST['smiley_sets_name'];
  215. updateSettings(array(
  216. 'smiley_sets_known' => implode(',', $set_paths),
  217. 'smiley_sets_names' => implode("\n", $set_names),
  218. 'smiley_sets_default' => empty($_POST['smiley_sets_default']) ? $modSettings['smiley_sets_default'] : $_POST['smiley_sets_path']
  219. ));
  220. }
  221. // The user might have checked to also import smileys.
  222. if (!empty($_POST['smiley_sets_import']))
  223. ImportSmileys($_POST['smiley_sets_path']);
  224. }
  225. cache_put_data('parsing_smileys', null, 480);
  226. cache_put_data('posting_smileys', null, 480);
  227. }
  228. // Load all available smileysets...
  229. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  230. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  231. foreach ($context['smiley_sets'] as $i => $set)
  232. $context['smiley_sets'][$i] = array(
  233. 'id' => $i,
  234. 'path' => htmlspecialchars($set),
  235. 'name' => htmlspecialchars($set_names[$i]),
  236. 'selected' => $set == $modSettings['smiley_sets_default']
  237. );
  238. // Importing any smileys from an existing set?
  239. if ($context['sub_action'] == 'import')
  240. {
  241. checkSession('get');
  242. validateToken('admin-mss', 'request');
  243. $_GET['set'] = (int) $_GET['set'];
  244. // Sanity check - then import.
  245. if (isset($context['smiley_sets'][$_GET['set']]))
  246. ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
  247. // Force the process to continue.
  248. $context['sub_action'] = 'modifyset';
  249. $context['sub_template'] = 'modifyset';
  250. }
  251. // If we're modifying or adding a smileyset, some context info needs to be set.
  252. if ($context['sub_action'] == 'modifyset')
  253. {
  254. $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
  255. if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
  256. $context['current_set'] = array(
  257. 'id' => '-1',
  258. 'path' => '',
  259. 'name' => '',
  260. 'selected' => false,
  261. 'is_new' => true,
  262. );
  263. else
  264. {
  265. $context['current_set'] = &$context['smiley_sets'][$_GET['set']];
  266. $context['current_set']['is_new'] = false;
  267. // Calculate whether there are any smileys in the directory that can be imported.
  268. if (!empty($modSettings['smiley_enable']) && !empty($modSettings['smileys_dir']) && is_dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']))
  269. {
  270. $smileys = array();
  271. $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']);
  272. while ($entry = $dir->read())
  273. {
  274. if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  275. $smileys[strtolower($entry)] = $entry;
  276. }
  277. $dir->close();
  278. // Exclude the smileys that are already in the database.
  279. $request = $smcFunc['db_query']('', '
  280. SELECT filename
  281. FROM {db_prefix}smileys
  282. WHERE filename IN ({array_string:smiley_list})',
  283. array(
  284. 'smiley_list' => $smileys,
  285. )
  286. );
  287. while ($row = $smcFunc['db_fetch_assoc']($request))
  288. if (isset($smileys[strtolower($row['filename'])]))
  289. unset($smileys[strtolower($row['filename'])]);
  290. $smcFunc['db_free_result']($request);
  291. $context['current_set']['can_import'] = count($smileys);
  292. // Setup this string to look nice.
  293. $txt['smiley_set_import_multiple'] = sprintf($txt['smiley_set_import_multiple'], $context['current_set']['can_import']);
  294. }
  295. }
  296. // Retrieve all potential smiley set directories.
  297. $context['smiley_set_dirs'] = array();
  298. if (!empty($modSettings['smileys_dir']) && is_dir($modSettings['smileys_dir']))
  299. {
  300. $dir = dir($modSettings['smileys_dir']);
  301. while ($entry = $dir->read())
  302. {
  303. if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
  304. $context['smiley_set_dirs'][] = array(
  305. 'id' => $entry,
  306. 'path' => $modSettings['smileys_dir'] . '/' . $entry,
  307. 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
  308. 'current' => $entry == $context['current_set']['path'],
  309. );
  310. }
  311. $dir->close();
  312. }
  313. }
  314. // This is our save haven.
  315. createToken('admin-mss', 'request');
  316. $listOptions = array(
  317. 'id' => 'smiley_set_list',
  318. 'title' => $txt['smiley_sets'],
  319. 'no_items_label' => $txt['smiley_sets_none'],
  320. 'base_href' => $scripturl . '?action=admin;area=smileys;sa=editsets',
  321. 'default_sort_col' => 'default',
  322. 'get_items' => array(
  323. 'function' => 'list_getSmileySets',
  324. ),
  325. 'get_count' => array(
  326. 'function' => 'list_getNumSmileySets',
  327. ),
  328. 'columns' => array(
  329. 'default' => array(
  330. 'header' => array(
  331. 'value' => $txt['smiley_sets_default'],
  332. ),
  333. 'data' => array(
  334. 'function' => create_function('$rowData', '
  335. return $rowData[\'selected\'] ? \'<strong>*</strong>\' : \'\';
  336. '),
  337. 'style' => 'text-align: center;',
  338. ),
  339. 'sort' => array(
  340. 'default' => 'selected DESC',
  341. ),
  342. ),
  343. 'name' => array(
  344. 'header' => array(
  345. 'value' => $txt['smiley_sets_name'],
  346. ),
  347. 'data' => array(
  348. 'db_htmlsafe' => 'name',
  349. ),
  350. 'sort' => array(
  351. 'default' => 'name',
  352. 'reverse' => 'name DESC',
  353. ),
  354. ),
  355. 'url' => array(
  356. 'header' => array(
  357. 'value' => $txt['smiley_sets_url'],
  358. ),
  359. 'data' => array(
  360. 'sprintf' => array(
  361. 'format' => $modSettings['smileys_url'] . '/<strong>%1$s</strong>/...',
  362. 'params' => array(
  363. 'path' => true,
  364. ),
  365. ),
  366. ),
  367. 'sort' => array(
  368. 'default' => 'path',
  369. 'reverse' => 'path DESC',
  370. ),
  371. ),
  372. 'modify' => array(
  373. 'header' => array(
  374. 'value' => $txt['smiley_set_modify'],
  375. ),
  376. 'data' => array(
  377. 'sprintf' => array(
  378. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifyset;set=%1$d">' . $txt['smiley_set_modify'] . '</a>',
  379. 'params' => array(
  380. 'id' => true,
  381. ),
  382. ),
  383. 'style' => 'text-align: center;',
  384. ),
  385. ),
  386. 'check' => array(
  387. 'header' => array(
  388. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  389. ),
  390. 'data' => array(
  391. 'function' => create_function('$rowData', '
  392. return $rowData[\'id\'] == 0 ? \'\' : sprintf(\'<input type="checkbox" name="smiley_set[%1$d]" class="input_check" />\', $rowData[\'id\']);
  393. '),
  394. 'style' => 'text-align: center',
  395. ),
  396. ),
  397. ),
  398. 'form' => array(
  399. 'href' => $scripturl . '?action=admin;area=smileys;sa=editsets',
  400. 'token' => 'admin-mss',
  401. ),
  402. 'additional_rows' => array(
  403. array(
  404. 'position' => 'below_table_data',
  405. 'value' => '<input type="submit" name="delete" value="' . $txt['smiley_sets_delete'] . '" onclick="return confirm(\'' . $txt['smiley_sets_confirm'] . '\');" class="button_submit" /> <a class="button_link" href="' . $scripturl . '?action=admin;area=smileys;sa=modifyset' . '">' . $txt['smiley_sets_add'] . '</a> ',
  406. ),
  407. ),
  408. );
  409. require_once($sourcedir . '/Subs-List.php');
  410. createList($listOptions);
  411. }
  412. /**
  413. * Callback function for createList().
  414. * @todo to be moved to Subs-Smileys?
  415. *
  416. * @param $start
  417. * @param $items_per_page
  418. * @param $sort
  419. */
  420. function list_getSmileySets($start, $items_per_page, $sort)
  421. {
  422. global $modSettings;
  423. $known_sets = explode(',', $modSettings['smiley_sets_known']);
  424. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  425. $cols = array(
  426. 'id' => array(),
  427. 'selected' => array(),
  428. 'path' => array(),
  429. 'name' => array(),
  430. );
  431. foreach ($known_sets as $i => $set)
  432. {
  433. $cols['id'][] = $i;
  434. $cols['selected'][] = $i;
  435. $cols['path'][] = $set;
  436. $cols['name'][] = $set_names[$i];
  437. }
  438. $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
  439. if (substr($sort, 0, 4) === 'name')
  440. array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
  441. elseif (substr($sort, 0, 4) === 'path')
  442. array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
  443. else
  444. array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
  445. $smiley_sets = array();
  446. foreach ($cols['id'] as $i => $id)
  447. $smiley_sets[] = array(
  448. 'id' => $id,
  449. 'path' => $cols['path'][$i],
  450. 'name' => $cols['name'][$i],
  451. 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
  452. );
  453. return $smiley_sets;
  454. }
  455. /**
  456. * Callback function for createList().
  457. * @todo to be moved to Subs-Smileys?
  458. */
  459. function list_getNumSmileySets()
  460. {
  461. global $modSettings;
  462. return count(explode(',', $modSettings['smiley_sets_known']));
  463. }
  464. /**
  465. * Add a smiley, that's right.
  466. */
  467. function AddSmiley()
  468. {
  469. global $modSettings, $context, $settings, $txt, $boarddir, $smcFunc;
  470. // Get a list of all known smiley sets.
  471. $context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];
  472. $context['smileys_dir_found'] = is_dir($context['smileys_dir']);
  473. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  474. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  475. foreach ($context['smiley_sets'] as $i => $set)
  476. $context['smiley_sets'][$i] = array(
  477. 'id' => $i,
  478. 'path' => htmlspecialchars($set),
  479. 'name' => htmlspecialchars($set_names[$i]),
  480. 'selected' => $set == $modSettings['smiley_sets_default']
  481. );
  482. // Submitting a form?
  483. if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
  484. {
  485. checkSession();
  486. // Some useful arrays... types we allow - and ports we don't!
  487. $allowedTypes = array('jpeg', 'jpg', 'gif', 'png', 'bmp');
  488. $disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
  489. $_POST['smiley_code'] = htmltrim__recursive($_POST['smiley_code']);
  490. $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
  491. $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
  492. // Make sure some code was entered.
  493. if (empty($_POST['smiley_code']))
  494. fatal_lang_error('smiley_has_no_code');
  495. // Check whether the new code has duplicates. It should be unique.
  496. $request = $smcFunc['db_query']('', '
  497. SELECT id_smiley
  498. FROM {db_prefix}smileys
  499. WHERE code = {raw:mysql_binary_statement} {string:smiley_code}',
  500. array(
  501. 'mysql_binary_statement' => $smcFunc['db_title'] == 'MySQL' ? 'BINARY' : '',
  502. 'smiley_code' => $_POST['smiley_code'],
  503. )
  504. );
  505. if ($smcFunc['db_num_rows']($request) > 0)
  506. fatal_lang_error('smiley_not_unique');
  507. $smcFunc['db_free_result']($request);
  508. // If we are uploading - check all the smiley sets are writable!
  509. if ($_POST['method'] != 'existing')
  510. {
  511. $writeErrors = array();
  512. foreach ($context['smiley_sets'] as $set)
  513. {
  514. if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
  515. $writeErrors[] = $set['path'];
  516. }
  517. if (!empty($writeErrors))
  518. fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
  519. }
  520. // Uploading just one smiley for all of them?
  521. if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
  522. {
  523. if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
  524. fatal_lang_error('smileys_upload_error');
  525. // Sorry, no spaces, dots, or anything else but letters allowed.
  526. $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
  527. // We only allow image files - it's THAT simple - no messing around here...
  528. if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
  529. fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
  530. // We only need the filename...
  531. $destName = basename($_FILES['uploadSmiley']['name']);
  532. // Make sure they aren't trying to upload a nasty file - for their own good here!
  533. if (in_array(strtolower($destName), $disabledFiles))
  534. fatal_lang_error('smileys_upload_error_illegal');
  535. // Check if the file already exists... and if not move it to EVERY smiley set directory.
  536. $i = 0;
  537. // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
  538. while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
  539. $i++;
  540. // Okay, we're going to put the smiley right here, since it's not there yet!
  541. if (isset($context['smiley_sets'][$i]['path']))
  542. {
  543. $smileyLocation = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
  544. move_uploaded_file($_FILES['uploadSmiley']['tmp_name'], $smileyLocation);
  545. @chmod($smileyLocation, 0644);
  546. // Now, we want to move it from there to all the other sets.
  547. for ($n = count($context['smiley_sets']); $i < $n; $i++)
  548. {
  549. $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
  550. // The file is already there! Don't overwrite it!
  551. if (file_exists($currentPath))
  552. continue;
  553. // Okay, so copy the first one we made to here.
  554. copy($smileyLocation, $currentPath);
  555. @chmod($currentPath, 0644);
  556. }
  557. }
  558. // Finally make sure it's saved correctly!
  559. $_POST['smiley_filename'] = $destName;
  560. }
  561. // What about uploading several files?
  562. elseif ($_POST['method'] != 'existing')
  563. {
  564. $newName = '';
  565. foreach ($_FILES as $name => $data)
  566. {
  567. if ($_FILES[$name]['name'] == '')
  568. fatal_lang_error('smileys_upload_error_blank');
  569. if (empty($newName))
  570. $newName = basename($_FILES[$name]['name']);
  571. elseif (basename($_FILES[$name]['name']) != $newName)
  572. fatal_lang_error('smileys_upload_error_name');
  573. }
  574. foreach ($context['smiley_sets'] as $i => $set)
  575. {
  576. $set['name'] = un_htmlspecialchars($set['name']);
  577. $set['path'] = un_htmlspecialchars($set['path']);
  578. if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
  579. continue;
  580. // Got one...
  581. if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
  582. fatal_lang_error('smileys_upload_error');
  583. // Sorry, no spaces, dots, or anything else but letters allowed.
  584. $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
  585. // We only allow image files - it's THAT simple - no messing around here...
  586. if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
  587. fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
  588. // We only need the filename...
  589. $destName = basename($_FILES['individual_' . $set['name']]['name']);
  590. // Make sure they aren't trying to upload a nasty file - for their own good here!
  591. if (in_array(strtolower($destName), $disabledFiles))
  592. fatal_lang_error('smileys_upload_error_illegal');
  593. // If the file exists - ignore it.
  594. $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
  595. if (file_exists($smileyLocation))
  596. continue;
  597. // Finally - move the image!
  598. move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
  599. @chmod($smileyLocation, 0644);
  600. // Should always be saved correctly!
  601. $_POST['smiley_filename'] = $destName;
  602. }
  603. }
  604. // Also make sure a filename was given.
  605. if (empty($_POST['smiley_filename']))
  606. fatal_lang_error('smiley_has_no_filename');
  607. // Find the position on the right.
  608. $smiley_order = '0';
  609. if ($_POST['smiley_location'] != 1)
  610. {
  611. $request = $smcFunc['db_query']('', '
  612. SELECT MAX(smiley_order) + 1
  613. FROM {db_prefix}smileys
  614. WHERE hidden = {int:smiley_location}
  615. AND smiley_row = {int:first_row}',
  616. array(
  617. 'smiley_location' => $_POST['smiley_location'],
  618. 'first_row' => 0,
  619. )
  620. );
  621. list ($smiley_order) = $smcFunc['db_fetch_row']($request);
  622. $smcFunc['db_free_result']($request);
  623. if (empty($smiley_order))
  624. $smiley_order = '0';
  625. }
  626. $smcFunc['db_insert']('',
  627. '{db_prefix}smileys',
  628. array(
  629. 'code' => 'string-30', 'filename' => 'string-48', 'description' => 'string-80', 'hidden' => 'int', 'smiley_order' => 'int',
  630. ),
  631. array(
  632. $_POST['smiley_code'], $_POST['smiley_filename'], $_POST['smiley_description'], $_POST['smiley_location'], $smiley_order,
  633. ),
  634. array('id_smiley')
  635. );
  636. cache_put_data('parsing_smileys', null, 480);
  637. cache_put_data('posting_smileys', null, 480);
  638. // No errors? Out of here!
  639. redirectexit('action=admin;area=smileys;sa=editsmileys');
  640. }
  641. $context['selected_set'] = $modSettings['smiley_sets_default'];
  642. // Get all possible filenames for the smileys.
  643. $context['filenames'] = array();
  644. if ($context['smileys_dir_found'])
  645. {
  646. foreach ($context['smiley_sets'] as $smiley_set)
  647. {
  648. if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
  649. continue;
  650. $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
  651. while ($entry = $dir->read())
  652. {
  653. if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  654. $context['filenames'][strtolower($entry)] = array(
  655. 'id' => htmlspecialchars($entry),
  656. 'selected' => false,
  657. );
  658. }
  659. $dir->close();
  660. }
  661. ksort($context['filenames']);
  662. }
  663. // Create a new smiley from scratch.
  664. $context['filenames'] = array_values($context['filenames']);
  665. $context['current_smiley'] = array(
  666. 'id' => 0,
  667. 'code' => '',
  668. 'filename' => $context['filenames'][0]['id'],
  669. 'description' => $txt['smileys_default_description'],
  670. 'location' => 0,
  671. 'is_new' => true,
  672. );
  673. }
  674. /**
  675. * Add, remove, edit smileys.
  676. */
  677. function EditSmileys()
  678. {
  679. global $modSettings, $context, $settings, $txt, $boarddir;
  680. global $smcFunc, $scripturl, $sourcedir;
  681. // Force the correct tab to be displayed.
  682. $context[$context['admin_menu_name']]['current_subsection'] = 'editsmileys';
  683. // Submitting a form?
  684. if (isset($_POST[$context['session_var']]))
  685. {
  686. checkSession();
  687. // Changing the selected smileys?
  688. if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
  689. {
  690. foreach ($_POST['checked_smileys'] as $id => $smiley_id)
  691. $_POST['checked_smileys'][$id] = (int) $smiley_id;
  692. if ($_POST['smiley_action'] == 'delete')
  693. $smcFunc['db_query']('', '
  694. DELETE FROM {db_prefix}smileys
  695. WHERE id_smiley IN ({array_int:checked_smileys})',
  696. array(
  697. 'checked_smileys' => $_POST['checked_smileys'],
  698. )
  699. );
  700. // Changing the status of the smiley?
  701. else
  702. {
  703. // Check it's a valid type.
  704. $displayTypes = array(
  705. 'post' => 0,
  706. 'hidden' => 1,
  707. 'popup' => 2
  708. );
  709. if (isset($displayTypes[$_POST['smiley_action']]))
  710. $smcFunc['db_query']('', '
  711. UPDATE {db_prefix}smileys
  712. SET hidden = {int:display_type}
  713. WHERE id_smiley IN ({array_int:checked_smileys})',
  714. array(
  715. 'checked_smileys' => $_POST['checked_smileys'],
  716. 'display_type' => $displayTypes[$_POST['smiley_action']],
  717. )
  718. );
  719. }
  720. }
  721. // Create/modify a smiley.
  722. elseif (isset($_POST['smiley']))
  723. {
  724. // Is it a delete?
  725. if (!empty($_POST['deletesmiley']))
  726. {
  727. $smcFunc['db_query']('', '
  728. DELETE FROM {db_prefix}smileys
  729. WHERE id_smiley = {int:current_smiley}',
  730. array(
  731. 'current_smiley' => $_POST['smiley'],
  732. )
  733. );
  734. }
  735. // Otherwise an edit.
  736. else
  737. {
  738. $_POST['smiley'] = (int) $_POST['smiley'];
  739. $_POST['smiley_code'] = htmltrim__recursive($_POST['smiley_code']);
  740. $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
  741. $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
  742. // Make sure some code was entered.
  743. if (empty($_POST['smiley_code']))
  744. fatal_lang_error('smiley_has_no_code');
  745. // Also make sure a filename was given.
  746. if (empty($_POST['smiley_filename']))
  747. fatal_lang_error('smiley_has_no_filename');
  748. // Check whether the new code has duplicates. It should be unique.
  749. $request = $smcFunc['db_query']('', '
  750. SELECT id_smiley
  751. FROM {db_prefix}smileys
  752. WHERE code = {raw:mysql_binary_type} {string:smiley_code}' . (empty($_POST['smiley']) ? '' : '
  753. AND id_smiley != {int:current_smiley}'),
  754. array(
  755. 'current_smiley' => $_POST['smiley'],
  756. 'mysql_binary_type' => $smcFunc['db_title'] == 'MySQL' ? 'BINARY' : '',
  757. 'smiley_code' => $_POST['smiley_code'],
  758. )
  759. );
  760. if ($smcFunc['db_num_rows']($request) > 0)
  761. fatal_lang_error('smiley_not_unique');
  762. $smcFunc['db_free_result']($request);
  763. $smcFunc['db_query']('', '
  764. UPDATE {db_prefix}smileys
  765. SET
  766. code = {string:smiley_code},
  767. filename = {string:smiley_filename},
  768. description = {string:smiley_description},
  769. hidden = {int:smiley_location}
  770. WHERE id_smiley = {int:current_smiley}',
  771. array(
  772. 'smiley_location' => $_POST['smiley_location'],
  773. 'current_smiley' => $_POST['smiley'],
  774. 'smiley_code' => $_POST['smiley_code'],
  775. 'smiley_filename' => $_POST['smiley_filename'],
  776. 'smiley_description' => $_POST['smiley_description'],
  777. )
  778. );
  779. }
  780. // Sort all smiley codes for more accurate parsing (longest code first).
  781. sortSmileyTable();
  782. }
  783. cache_put_data('parsing_smileys', null, 480);
  784. cache_put_data('posting_smileys', null, 480);
  785. }
  786. // Load all known smiley sets.
  787. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  788. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  789. foreach ($context['smiley_sets'] as $i => $set)
  790. $context['smiley_sets'][$i] = array(
  791. 'id' => $i,
  792. 'path' => htmlspecialchars($set),
  793. 'name' => htmlspecialchars($set_names[$i]),
  794. 'selected' => $set == $modSettings['smiley_sets_default']
  795. );
  796. // Prepare overview of all (custom) smileys.
  797. if ($context['sub_action'] == 'editsmileys')
  798. {
  799. // Determine the language specific sort order of smiley locations.
  800. $smiley_locations = array(
  801. $txt['smileys_location_form'],
  802. $txt['smileys_location_hidden'],
  803. $txt['smileys_location_popup'],
  804. );
  805. asort($smiley_locations);
  806. // Create a list of options for selecting smiley sets.
  807. $smileyset_option_list = '
  808. <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
  809. foreach ($context['smiley_sets'] as $smiley_set)
  810. $smileyset_option_list .= '
  811. <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected="selected"' : '') . '>' . $smiley_set['name'] . '</option>';
  812. $smileyset_option_list .= '
  813. </select>';
  814. $listOptions = array(
  815. 'id' => 'smiley_list',
  816. 'title' => $txt['smileys_edit'],
  817. 'items_per_page' => 40,
  818. 'base_href' => $scripturl . '?action=admin;area=smileys;sa=editsmileys',
  819. 'default_sort_col' => 'filename',
  820. 'get_items' => array(
  821. 'function' => 'list_getSmileys',
  822. ),
  823. 'get_count' => array(
  824. 'function' => 'list_getNumSmileys',
  825. ),
  826. 'no_items_label' => $txt['smileys_no_entries'],
  827. 'columns' => array(
  828. 'picture' => array(
  829. 'data' => array(
  830. 'sprintf' => array(
  831. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifysmiley;smiley=%1$d"><img src="' . $modSettings['smileys_url'] . '/' . $modSettings['smiley_sets_default'] . '/%2$s" alt="%3$s" style="padding: 2px;" id="smiley%1$d" /><input type="hidden" name="smileys[%1$d][filename]" value="%2$s" /></a>',
  832. 'params' => array(
  833. 'id_smiley' => false,
  834. 'filename' => true,
  835. 'description' => true,
  836. ),
  837. ),
  838. 'style' => 'text-align: center;',
  839. ),
  840. ),
  841. 'code' => array(
  842. 'header' => array(
  843. 'value' => $txt['smileys_code'],
  844. ),
  845. 'data' => array(
  846. 'db_htmlsafe' => 'code',
  847. ),
  848. 'sort' => array(
  849. 'default' => 'code',
  850. 'reverse' => 'code DESC',
  851. ),
  852. ),
  853. 'filename' => array(
  854. 'header' => array(
  855. 'value' => $txt['smileys_filename'],
  856. ),
  857. 'data' => array(
  858. 'db_htmlsafe' => 'filename',
  859. ),
  860. 'sort' => array(
  861. 'default' => 'filename',
  862. 'reverse' => 'filename DESC',
  863. ),
  864. ),
  865. 'location' => array(
  866. 'header' => array(
  867. 'value' => $txt['smileys_location'],
  868. ),
  869. 'data' => array(
  870. 'function' => create_function('$rowData', '
  871. global $txt;
  872. if (empty($rowData[\'hidden\']))
  873. return $txt[\'smileys_location_form\'];
  874. elseif ($rowData[\'hidden\'] == 1)
  875. return $txt[\'smileys_location_hidden\'];
  876. else
  877. return $txt[\'smileys_location_popup\'];
  878. '),
  879. ),
  880. 'sort' => array(
  881. 'default' => 'FIND_IN_SET(hidden, \'' . implode(',', array_keys($smiley_locations)) . '\')',
  882. 'reverse' => 'FIND_IN_SET(hidden, \'' . implode(',', array_keys($smiley_locations)) . '\') DESC',
  883. ),
  884. ),
  885. 'tooltip' => array(
  886. 'header' => array(
  887. 'value' => $txt['smileys_description'],
  888. ),
  889. 'data' => array(
  890. 'function' => create_function('$rowData', empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']) ? '
  891. return htmlspecialchars($rowData[\'description\']);
  892. ' : '
  893. global $context, $txt, $modSettings;
  894. // Check if there are smileys missing in some sets.
  895. $missing_sets = array();
  896. foreach ($context[\'smiley_sets\'] as $smiley_set)
  897. if (!file_exists(sprintf(\'%1$s/%2$s/%3$s\', $modSettings[\'smileys_dir\'], $smiley_set[\'path\'], $rowData[\'filename\'])))
  898. $missing_sets[] = $smiley_set[\'path\'];
  899. $description = htmlspecialchars($rowData[\'description\']);
  900. if (!empty($missing_sets))
  901. $description .= sprintf(\'<br /><span class="smalltext"><strong>%1$s:</strong> %2$s</span>\', $txt[\'smileys_not_found_in_set\'], implode(\', \', $missing_sets));
  902. return $description;
  903. '),
  904. ),
  905. 'sort' => array(
  906. 'default' => 'description',
  907. 'reverse' => 'description DESC',
  908. ),
  909. ),
  910. 'modify' => array(
  911. 'header' => array(
  912. 'value' => $txt['smileys_modify'],
  913. ),
  914. 'data' => array(
  915. 'sprintf' => array(
  916. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifysmiley;smiley=%1$d">' . $txt['smileys_modify'] . '</a>',
  917. 'params' => array(
  918. 'id_smiley' => false,
  919. ),
  920. ),
  921. 'style' => 'text-align: center;',
  922. ),
  923. ),
  924. 'check' => array(
  925. 'header' => array(
  926. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  927. ),
  928. 'data' => array(
  929. 'sprintf' => array(
  930. 'format' => '<input type="checkbox" name="checked_smileys[]" value="%1$d" class="input_check" />',
  931. 'params' => array(
  932. 'id_smiley' => false,
  933. ),
  934. ),
  935. 'style' => 'text-align: center',
  936. ),
  937. ),
  938. ),
  939. 'form' => array(
  940. 'href' => $scripturl . '?action=admin;area=smileys;sa=editsmileys',
  941. 'name' => 'smileyForm',
  942. ),
  943. 'additional_rows' => array(
  944. array(
  945. 'position' => 'above_column_headers',
  946. 'value' => $smileyset_option_list,
  947. 'style' => 'text-align: right;',
  948. ),
  949. array(
  950. 'position' => 'below_table_data',
  951. 'value' => '
  952. <select name="smiley_action" onchange="makeChanges(this.value);">
  953. <option value="-1">' . $txt['smileys_with_selected'] . ':</option>
  954. <option value="-1">--------------</option>
  955. <option value="hidden">' . $txt['smileys_make_hidden'] . '</option>
  956. <option value="post">' . $txt['smileys_show_on_post'] . '</option>
  957. <option value="popup">' . $txt['smileys_show_on_popup'] . '</option>
  958. <option value="delete">' . $txt['smileys_remove'] . '</option>
  959. </select>
  960. <noscript><input type="submit" name="perform_action" value="' . $txt['go'] . '" class="button_submit" /></noscript>',
  961. 'style' => 'text-align: right;',
  962. ),
  963. ),
  964. 'javascript' => '
  965. function makeChanges(action)
  966. {
  967. if (action == \'-1\')
  968. return false;
  969. else if (action == \'delete\')
  970. {
  971. if (confirm(\'' . $txt['smileys_confirm'] . '\'))
  972. document.forms.smileyForm.submit();
  973. }
  974. else
  975. document.forms.smileyForm.submit();
  976. return true;
  977. }
  978. function changeSet(newSet)
  979. {
  980. var currentImage, i, knownSmileys = [];
  981. if (knownSmileys.length == 0)
  982. {
  983. for (var i = 0, n = document.images.length; i < n; i++)
  984. if (document.images[i].id.substr(0, 6) == \'smiley\')
  985. knownSmileys[knownSmileys.length] = document.images[i].id.substr(6);
  986. }
  987. for (i = 0; i < knownSmileys.length; i++)
  988. {
  989. currentImage = document.getElementById("smiley" + knownSmileys[i]);
  990. currentImage.src = "' . $modSettings['smileys_url'] . '/" + newSet + "/" + document.forms.smileyForm["smileys[" + knownSmileys[i] + "][filename]"].value;
  991. }
  992. }',
  993. );
  994. require_once($sourcedir . '/Subs-List.php');
  995. createList($listOptions);
  996. // The list is the only thing to show, so make it the main template.
  997. $context['default_list'] = 'smiley_list';
  998. $context['sub_template'] = 'show_list';
  999. }
  1000. // Modifying smileys.
  1001. elseif ($context['sub_action'] == 'modifysmiley')
  1002. {
  1003. // Get a list of all known smiley sets.
  1004. $context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];
  1005. $context['smileys_dir_found'] = is_dir($context['smileys_dir']);
  1006. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  1007. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  1008. foreach ($context['smiley_sets'] as $i => $set)
  1009. $context['smiley_sets'][$i] = array(
  1010. 'id' => $i,
  1011. 'path' => htmlspecialchars($set),
  1012. 'name' => htmlspecialchars($set_names[$i]),
  1013. 'selected' => $set == $modSettings['smiley_sets_default']
  1014. );
  1015. $context['selected_set'] = $modSettings['smiley_sets_default'];
  1016. // Get all possible filenames for the smileys.
  1017. $context['filenames'] = array();
  1018. if ($context['smileys_dir_found'])
  1019. {
  1020. foreach ($context['smiley_sets'] as $smiley_set)
  1021. {
  1022. if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
  1023. continue;
  1024. $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
  1025. while ($entry = $dir->read())
  1026. {
  1027. if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  1028. $context['filenames'][strtolower($entry)] = array(
  1029. 'id' => htmlspecialchars($entry),
  1030. 'selected' => false,
  1031. );
  1032. }
  1033. $dir->close();
  1034. }
  1035. ksort($context['filenames']);
  1036. }
  1037. $request = $smcFunc['db_query']('', '
  1038. SELECT id_smiley AS id, code, filename, description, hidden AS location, 0 AS is_new
  1039. FROM {db_prefix}smileys
  1040. WHERE id_smiley = {int:current_smiley}',
  1041. array(
  1042. 'current_smiley' => (int) $_REQUEST['smiley'],
  1043. )
  1044. );
  1045. if ($smcFunc['db_num_rows']($request) != 1)
  1046. fatal_lang_error('smiley_not_found');
  1047. $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
  1048. $smcFunc['db_free_result']($request);
  1049. $context['current_smiley']['code'] = htmlspecialchars($context['current_smiley']['code']);
  1050. $context['current_smiley']['filename'] = htmlspecialchars($context['current_smiley']['filename']);
  1051. $context['current_smiley']['description'] = htmlspecialchars($context['current_smiley']['description']);
  1052. if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
  1053. $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
  1054. }
  1055. }
  1056. /**
  1057. * Callback function for createList().
  1058. *
  1059. * @param unknown_type $start
  1060. * @param unknown_type $items_per_page
  1061. * @param unknown_type $sort
  1062. */
  1063. function list_getSmileys($start, $items_per_page, $sort)
  1064. {
  1065. global $smcFunc;
  1066. $request = $smcFunc['db_query']('', '
  1067. SELECT id_smiley, code, filename, description, smiley_row, smiley_order, hidden
  1068. FROM {db_prefix}smileys
  1069. ORDER BY ' . $sort,
  1070. array(
  1071. )
  1072. );
  1073. $smileys = array();
  1074. while ($row = $smcFunc['db_fetch_assoc']($request))
  1075. $smileys[] = $row;
  1076. $smcFunc['db_free_result']($request);
  1077. return $smileys;
  1078. }
  1079. /**
  1080. * Callback function for createList().
  1081. */
  1082. function list_getNumSmileys()
  1083. {
  1084. global $smcFunc;
  1085. $request = $smcFunc['db_query']('', '
  1086. SELECT COUNT(*)
  1087. FROM {db_prefix}smileys',
  1088. array(
  1089. )
  1090. );
  1091. list($numSmileys) = $smcFunc['db_fetch_row'];
  1092. $smcFunc['db_free_result']($request);
  1093. return $numSmileys;
  1094. }
  1095. /**
  1096. * Allows to edit smileys order.
  1097. */
  1098. function EditSmileyOrder()
  1099. {
  1100. global $modSettings, $context, $settings, $txt, $boarddir, $smcFunc;
  1101. // Move smileys to another position.
  1102. if (isset($_REQUEST['reorder']))
  1103. {
  1104. checkSession('get');
  1105. $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
  1106. $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
  1107. if (empty($_GET['source']))
  1108. fatal_lang_error('smiley_not_found');
  1109. if (!empty($_GET['after']))
  1110. {
  1111. $_GET['after'] = (int) $_GET['after'];
  1112. $request = $smcFunc['db_query']('', '
  1113. SELECT smiley_row, smiley_order, hidden
  1114. FROM {db_prefix}smileys
  1115. WHERE hidden = {int:location}
  1116. AND id_smiley = {int:after_smiley}',
  1117. array(
  1118. 'location' => $_GET['location'],
  1119. 'after_smiley' => $_GET['after'],
  1120. )
  1121. );
  1122. if ($smcFunc['db_num_rows']($request) != 1)
  1123. fatal_lang_error('smiley_not_found');
  1124. list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
  1125. $smcFunc['db_free_result']($request);
  1126. }
  1127. else
  1128. {
  1129. $smiley_row = (int) $_GET['row'];
  1130. $smiley_order = -1;
  1131. $smileyLocation = (int) $_GET['location'];
  1132. }
  1133. $smcFunc['db_query']('', '
  1134. UPDATE {db_prefix}smileys
  1135. SET smiley_order = smiley_order + 1
  1136. WHERE hidden = {int:new_location}
  1137. AND smiley_row = {int:smiley_row}
  1138. AND smiley_order > {int:smiley_order}',
  1139. array(
  1140. 'new_location' => $_GET['location'],
  1141. 'smiley_row' => $smiley_row,
  1142. 'smiley_order' => $smiley_order,
  1143. )
  1144. );
  1145. $smcFunc['db_query']('', '
  1146. UPDATE {db_prefix}smileys
  1147. SET
  1148. smiley_order = {int:smiley_order} + 1,
  1149. smiley_row = {int:smiley_row},
  1150. hidden = {int:new_location}
  1151. WHERE id_smiley = {int:current_smiley}',
  1152. array(
  1153. 'smiley_order' => $smiley_order,
  1154. 'smiley_row' => $smiley_row,
  1155. 'new_location' => $smileyLocation,
  1156. 'current_smiley' => $_GET['source'],
  1157. )
  1158. );
  1159. cache_put_data('parsing_smileys', null, 480);
  1160. cache_put_data('posting_smileys', null, 480);
  1161. }
  1162. $request = $smcFunc['db_query']('', '
  1163. SELECT id_smiley, code, filename, description, smiley_row, smiley_order, hidden
  1164. FROM {db_prefix}smileys
  1165. WHERE hidden != {int:popup}
  1166. ORDER BY smiley_order, smiley_row',
  1167. array(
  1168. 'popup' => 1,
  1169. )
  1170. );
  1171. $context['smileys'] = array(
  1172. 'postform' => array(
  1173. 'rows' => array(),
  1174. ),
  1175. 'popup' => array(
  1176. 'rows' => array(),
  1177. ),
  1178. );
  1179. while ($row = $smcFunc['db_fetch_assoc']($request))
  1180. {
  1181. $location = empty($row['hidden']) ? 'postform' : 'popup';
  1182. $context['smileys'][$location]['rows'][$row['smiley_row']][] = array(
  1183. 'id' => $row['id_smiley'],
  1184. 'code' => htmlspecialchars($row['code']),
  1185. 'filename' => htmlspecialchars($row['filename']),
  1186. 'description' => htmlspecialchars($row['description']),
  1187. 'row' => $row['smiley_row'],
  1188. 'order' => $row['smiley_order'],
  1189. 'selected' => !empty($_REQUEST['move']) && $_REQUEST['move'] == $row['id_smiley'],
  1190. );
  1191. }
  1192. $smcFunc['db_free_result']($request);
  1193. $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
  1194. // Make sure all rows are sequential.
  1195. foreach (array_keys($context['smileys']) as $location)
  1196. $context['smileys'][$location] = array(
  1197. 'id' => $location,
  1198. 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
  1199. 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
  1200. 'last_row' => count($context['smileys'][$location]['rows']),
  1201. 'rows' => array_values($context['smileys'][$location]['rows']),
  1202. );
  1203. // Check & fix smileys that are not ordered properly in the database.
  1204. foreach (array_keys($context['smileys']) as $location)
  1205. {
  1206. foreach ($context['smileys'][$location]['rows'] as $id => $smiley_row)
  1207. {
  1208. // Fix empty rows if any.
  1209. if ($id != $smiley_row[0]['row'])
  1210. {
  1211. $smcFunc['db_query']('', '
  1212. UPDATE {db_prefix}smileys
  1213. SET smiley_row = {int:new_row}
  1214. WHERE smiley_row = {int:current_row}
  1215. AND hidden = {int:location}',
  1216. array(
  1217. 'new_row' => $id,
  1218. 'current_row' => $smiley_row[0]['row'],
  1219. 'location' => $location == 'postform' ? '0' : '2',
  1220. )
  1221. );
  1222. // Only change the first row value of the first smiley (we don't need the others :P).
  1223. $context['smileys'][$location]['rows'][$id][0]['row'] = $id;
  1224. }
  1225. // Make sure the smiley order is always sequential.
  1226. foreach ($smiley_row as $order_id => $smiley)
  1227. if ($order_id != $smiley['order'])
  1228. $smcFunc['db_query']('', '
  1229. UPDATE {db_prefix}smileys
  1230. SET smiley_order = {int:new_order}
  1231. WHERE id_smiley = {int:current_smiley}',
  1232. array(
  1233. 'new_order' => $order_id,
  1234. 'current_smiley' => $smiley['id'],
  1235. )
  1236. );
  1237. }
  1238. }
  1239. cache_put_data('parsing_smileys', null, 480);
  1240. cache_put_data('posting_smileys', null, 480);
  1241. }
  1242. /**
  1243. * Install a smiley set.
  1244. */
  1245. function InstallSmileySet()
  1246. {
  1247. global $sourcedir, $boarddir, $modSettings, $smcFunc;
  1248. isAllowedTo('manage_smileys');
  1249. checkSession('request');
  1250. require_once($sourcedir . '/Subs-Package.php');
  1251. $name = strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.');
  1252. $name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
  1253. //@todo Decide: overwrite or not?
  1254. if (isset($_FILES['set_gz']) && is_uploaded_file($_FILES['set_gz']['tmp_name']) && (ini_get('open_basedir') != '' || file_exists($_FILES['set_gz']['tmp_name'])))
  1255. $extracted = read_tgz_file($_FILES['set_gz']['tmp_name'], $boarddir . '/Smileys/' . $name);
  1256. elseif (isset($_REQUEST['set_gz']))
  1257. {
  1258. // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
  1259. if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
  1260. fatal_lang_error('not_on_simplemachines');
  1261. $extracted = read_tgz_file($_REQUEST['set_gz'], $boarddir . '/Smileys/' . $name);
  1262. }
  1263. else
  1264. redirectexit('action=admin;area=smileys');
  1265. updateSettings(array(
  1266. 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $name,
  1267. 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.'),
  1268. ));
  1269. cache_put_data('parsing_smileys', null, 480);
  1270. cache_put_data('posting_smileys', null, 480);
  1271. // @todo Add some confirmation?
  1272. redirectexit('action=admin;area=smileys');
  1273. }
  1274. /**
  1275. * A function to import new smileys from an existing directory into the database.
  1276. *
  1277. * @param string $smileyPath
  1278. */
  1279. function ImportSmileys($smileyPath)
  1280. {
  1281. global $modSettings, $smcFunc;
  1282. if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
  1283. fatal_lang_error('smiley_set_unable_to_import');
  1284. $smileys = array();
  1285. $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
  1286. while ($entry = $dir->read())
  1287. {
  1288. if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  1289. $smileys[strtolower($entry)] = $entry;
  1290. }
  1291. $dir->close();
  1292. // Exclude the smileys that are already in the database.
  1293. $request = $smcFunc['db_query']('', '
  1294. SELECT filename
  1295. FROM {db_prefix}smileys
  1296. WHERE filename IN ({array_string:smiley_list})',
  1297. array(
  1298. 'smiley_list' => $smileys,
  1299. )
  1300. );
  1301. while ($row = $smcFunc['db_fetch_assoc']($request))
  1302. if (isset($smileys[strtolower($row['filename'])]))
  1303. unset($smileys[strtolower($row['filename'])]);
  1304. $smcFunc['db_free_result']($request);
  1305. $request = $smcFunc['db_query']('', '
  1306. SELECT MAX(smiley_order)
  1307. FROM {db_prefix}smileys
  1308. WHERE hidden = {int:postform}
  1309. AND smiley_row = {int:first_row}',
  1310. array(
  1311. 'postform' => 0,
  1312. 'first_row' => 0,
  1313. )
  1314. );
  1315. list ($smiley_order) = $smcFunc['db_fetch_row']($request);
  1316. $smcFunc['db_free_result']($request);
  1317. $new_smileys = array();
  1318. foreach ($smileys as $smiley)
  1319. if (strlen($smiley) <= 48)
  1320. $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
  1321. if (!empty($new_smileys))
  1322. {
  1323. $smcFunc['db_insert']('',
  1324. '{db_prefix}smileys',
  1325. array(
  1326. 'code' => 'string-30', 'filename' => 'string-48', 'description' => 'string-80', 'smiley_row' => 'int', 'smiley_order' => 'int',
  1327. ),
  1328. $new_smileys,
  1329. array('id_smiley')
  1330. );
  1331. // Make sure the smiley codes are still in the right order.
  1332. sortSmileyTable();
  1333. cache_put_data('parsing_smileys', null, 480);
  1334. cache_put_data('posting_smileys', null, 480);
  1335. }
  1336. }
  1337. /**
  1338. * Allows to edit the message icons.
  1339. */
  1340. function EditMessageIcons()
  1341. {
  1342. global $user_info, $modSettings, $context, $settings, $txt;
  1343. global $boarddir, $smcFunc, $scripturl, $sourcedir;
  1344. // Get a list of icons.
  1345. $context['icons'] = array();
  1346. $request = $smcFunc['db_query']('', '
  1347. SELECT m.id_icon, m.title, m.filename, m.icon_order, m.id_board, b.name AS board_name
  1348. FROM {db_prefix}message_icons AS m
  1349. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1350. WHERE ({query_see_board} OR b.id_board IS NULL)',
  1351. array(
  1352. )
  1353. );
  1354. $last_icon = 0;
  1355. $trueOrder = 0;
  1356. while ($row = $smcFunc['db_fetch_assoc']($request))
  1357. {
  1358. $context['icons'][$row['id_icon']] = array(
  1359. 'id' => $row['id_icon'],
  1360. 'title' => $row['title'],
  1361. 'filename' => $row['filename'],
  1362. 'image_url' => $settings[file_exists($settings['theme_dir'] . '/images/post/' . $row['filename'] . '.png') ? 'actual_images_url' : 'default_images_url'] . '/post/' . $row['filename'] . '.png',
  1363. 'board_id' => $row['id_board'],
  1364. 'board' => empty($row['board_name']) ? $txt['icons_edit_icons_all_boards'] : $row['board_name'],
  1365. 'order' => $row['icon_order'],
  1366. 'true_order' => $trueOrder++,
  1367. 'after' => $last_icon,
  1368. );
  1369. $last_icon = $row['id_icon'];
  1370. }
  1371. $smcFunc['db_free_result']($request);
  1372. // Submitting a form?
  1373. if (isset($_POST[$context['session_var']]))
  1374. {
  1375. checkSession();
  1376. // Deleting icons?
  1377. if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
  1378. {
  1379. $deleteIcons = array();
  1380. foreach ($_POST['checked_icons'] as $icon)
  1381. $deleteIcons[] = (int) $icon;
  1382. // Do the actual delete!
  1383. $smcFunc['db_query']('', '
  1384. DELETE FROM {db_prefix}message_icons
  1385. WHERE id_icon IN ({array_int:icon_list})',
  1386. array(
  1387. 'icon_list' => $deleteIcons,
  1388. )
  1389. );
  1390. }
  1391. // Editing/Adding an icon?
  1392. elseif ($context['sub_action'] == 'editicon' && isset($_GET['icon']))
  1393. {
  1394. $_GET['icon'] = (int) $_GET['icon'];
  1395. // Do some preperation with the data... like check the icon exists *somewhere*
  1396. if (strpos($_POST['icon_filename'], '.gif') !== false)
  1397. $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
  1398. if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.gif'))
  1399. fatal_lang_error('icon_not_found');
  1400. // There is a 16 character limit on message icons...
  1401. elseif (strlen($_POST['icon_filename']) > 16)
  1402. fatal_lang_error('icon_name_too_long');
  1403. elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
  1404. fatal_lang_error('icon_after_itself');
  1405. // First do the sorting... if this is an edit reduce the order of everything after it by one ;)
  1406. if ($_GET['icon'] != 0)
  1407. {
  1408. $oldOrder = $context['icons'][$_GET['icon']]['true_order'];
  1409. foreach ($context['icons'] as $id => $data)
  1410. if ($data['true_order'] > $oldOrder)
  1411. $context['icons'][$id]['true_order']--;
  1412. }
  1413. // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
  1414. if (empty($_GET['icon']) && empty($context['icons']))
  1415. $_GET['icon'] = 1;
  1416. // Get the new order.
  1417. $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
  1418. // Do the same, but with the one that used to be after this icon, done to avoid conflict.
  1419. foreach ($context['icons'] as $id => $data)
  1420. if ($data['true_order'] >= $newOrder)
  1421. $context['icons'][$id]['true_order']++;
  1422. // Finally set the current icon's position!
  1423. $context['icons'][$_GET['icon']]['true_order'] = $newOrder;
  1424. // Simply replace the existing data for the other bits.
  1425. $context['icons'][$_GET['icon']]['title'] = $_POST['icon_description'];
  1426. $context['icons'][$_GET['icon']]['filename'] = $_POST['icon_filename'];
  1427. $context['icons'][$_GET['icon']]['board_id'] = (int) $_POST['icon_board'];
  1428. // Do a huge replace ;)
  1429. $iconInsert = array();
  1430. $iconInsert_new = array();
  1431. foreach ($context['icons'] as $id => $icon)
  1432. {
  1433. if ($id != 0)
  1434. {
  1435. $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
  1436. }
  1437. else
  1438. {
  1439. $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
  1440. }
  1441. }
  1442. $smcFunc['db_insert']('replace',
  1443. '{db_prefix}message_icons',
  1444. array('id_icon' => 'int', 'id_board' => 'int', 'title' => 'string-80', 'filename' => 'string-80', 'icon_order' => 'int'),
  1445. $iconInsert,
  1446. array('id_icon')
  1447. );
  1448. if (!empty($iconInsert_new))
  1449. {
  1450. $smcFunc['db_insert']('replace',
  1451. '{db_prefix}message_icons',
  1452. array('id_board' => 'int', 'title' => 'string-80', 'filename' => 'string-80', 'icon_order' => 'int'),
  1453. $iconInsert_new,
  1454. array('id_icon')
  1455. );
  1456. }
  1457. }
  1458. // Sort by order, so it is quicker :)
  1459. $smcFunc['db_query']('alter_table_icons', '
  1460. ALTER TABLE {db_prefix}message_icons
  1461. ORDER BY icon_order',
  1462. array(
  1463. 'db_error_skip' => true,
  1464. )
  1465. );
  1466. // Unless we're adding a new thing, we'll escape
  1467. if (!isset($_POST['add']))
  1468. redirectexit('action=admin;area=smileys;sa=editicons');
  1469. }
  1470. $context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
  1471. $listOptions = array(
  1472. 'id' => 'message_icon_list',
  1473. 'title' => $txt['icons_edit_message_icons'],
  1474. 'base_href' => $scripturl . '?action=admin;area=smileys;sa=editicons',
  1475. 'get_items' => array(
  1476. 'function' => 'list_getMessageIcons',
  1477. ),
  1478. 'no_items_label' => $txt['icons_no_entries'],
  1479. 'columns' => array(
  1480. 'icon' => array(
  1481. 'data' => array(
  1482. 'function' => create_function('$rowData', '
  1483. global $settings;
  1484. $images_url = $settings[file_exists(sprintf(\'%1$s/images/post/%2$s.png\', $settings[\'theme_dir\'], $rowData[\'filename\'])) ? \'actual_images_url\' : \'default_images_url\'];
  1485. return sprintf(\'<img src="%1$s/post/%2$s.png" alt="%3$s" />\', $images_url, $rowData[\'filename\'], htmlspecialchars($rowData[\'title\']));
  1486. '),
  1487. ),
  1488. 'style' => 'text-align: center;',
  1489. ),
  1490. 'filename' => array(
  1491. 'header' => array(
  1492. 'value' => $txt['smileys_filename'],
  1493. ),
  1494. 'data' => array(
  1495. 'sprintf' => array(
  1496. 'format' => '%1$s.png',
  1497. 'params' => array(
  1498. 'filename' => true,
  1499. ),
  1500. ),
  1501. ),
  1502. ),
  1503. 'tooltip' => array(
  1504. 'header' => array(
  1505. 'value' => $txt['smileys_description'],
  1506. ),
  1507. 'data' => array(
  1508. 'db_htmlsafe' => 'title',
  1509. ),
  1510. ),
  1511. 'board' => array(
  1512. 'header' => array(
  1513. 'value' => $txt['icons_board'],
  1514. ),
  1515. 'data' => array(
  1516. 'function' => create_function('$rowData', '
  1517. global $txt;
  1518. return empty($rowData[\'board_name\']) ? $txt[\'icons_edit_icons_all_boards\'] : $rowData[\'board_name\'];
  1519. '),
  1520. ),
  1521. ),
  1522. 'modify' => array(
  1523. 'header' => array(
  1524. 'value' => $txt['smileys_modify'],
  1525. ),
  1526. 'data' => array(
  1527. 'sprintf' => array(
  1528. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=editicon;icon=%1$s">' . $txt['smileys_modify'] . '</a>',
  1529. 'params' => array(
  1530. 'id_icon' => false,
  1531. ),
  1532. ),
  1533. 'style' => 'text-align: center',
  1534. ),
  1535. ),
  1536. 'check' => array(
  1537. 'header' => array(
  1538. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  1539. ),
  1540. 'data' => array(
  1541. 'sprintf' => array(
  1542. 'format' => '<input type="checkbox" name="checked_icons[]" value="%1$d" class="input_check" />',
  1543. 'params' => array(
  1544. 'id_icon' => false,
  1545. ),
  1546. ),
  1547. 'style' => 'text-align: center',
  1548. ),
  1549. ),
  1550. ),
  1551. 'form' => array(
  1552. 'href' => $scripturl . '?action=admin;area=smileys;sa=editicons',
  1553. ),
  1554. 'additional_rows' => array(
  1555. array(
  1556. 'position' => 'below_table_data',
  1557. 'value' => '<input type="submit" name="delete" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit" /> <a class="button_link" href="' . $scripturl . '?action=admin;area=smileys;sa=editicon">' . $txt['icons_add_new'] . '</a>',
  1558. ),
  1559. ),
  1560. );
  1561. require_once($sourcedir . '/Subs-List.php');
  1562. createList($listOptions);
  1563. // If we're adding/editing an icon we'll need a list of boards
  1564. if ($context['sub_action'] == 'editicon' || isset($_POST['add']))
  1565. {
  1566. // Force the sub_template just in case.
  1567. $context['sub_template'] = 'editicon';
  1568. $context['new_icon'] = !isset($_GET['icon']);
  1569. // Get the properties of the current icon from the icon list.
  1570. if (!$context['new_icon'])
  1571. $context['icon'] = $context['icons'][$_GET['icon']];
  1572. // Get a list of boards needed for assigning this icon to a specific board.
  1573. $boardListOptions = array(
  1574. 'use_permissions' => true,
  1575. 'selected_board' => isset($context['icon']['board_id']) ? $context['icon']['board_id'] : 0,
  1576. );
  1577. require_once($sourcedir . '/Subs-MessageIndex.php');
  1578. $context['categories'] = getBoardList($boardListOptions);
  1579. }
  1580. }
  1581. /**
  1582. * Callback function for createList().
  1583. *
  1584. * @param $start
  1585. * @param $items_per_page
  1586. * @param $sort
  1587. */
  1588. function list_getMessageIcons($start, $items_per_page, $sort)
  1589. {
  1590. global $smcFunc, $user_info;
  1591. $request = $smcFunc['db_query']('', '
  1592. SELECT m.id_icon, m.title, m.filename, m.icon_order, m.id_board, b.name AS board_name
  1593. FROM {db_prefix}message_icons AS m
  1594. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1595. WHERE ({query_see_board} OR b.id_board IS NULL)',
  1596. array(
  1597. )
  1598. );
  1599. $message_icons = array();
  1600. while ($row = $smcFunc['db_fetch_assoc']($request))
  1601. $message_icons[] = $row;
  1602. $smcFunc['db_free_result']($request);
  1603. return $message_icons;
  1604. }
  1605. /**
  1606. * This function sorts the smiley table by code length,
  1607. * it is needed as MySQL withdrew support for functions in order by.
  1608. * @todo is this ordering itself needed?
  1609. */
  1610. function sortSmileyTable()
  1611. {
  1612. global $smcFunc;
  1613. db_extend('packages');
  1614. // Add a sorting column.
  1615. $smcFunc['db_add_column']('{db_prefix}smileys', array('name' => 'temp_order', 'size' => 8, 'type' => 'mediumint', 'null' => false));
  1616. // Set the contents of this column.
  1617. $smcFunc['db_query']('set_smiley_order', '
  1618. UPDATE {db_prefix}smileys
  1619. SET temp_order = LENGTH(code)',
  1620. array(
  1621. )
  1622. );
  1623. // Order the table by this column.
  1624. $smcFunc['db_query']('alter_table_smileys', '
  1625. ALTER TABLE {db_prefix}smileys
  1626. ORDER BY temp_order DESC',
  1627. array(
  1628. 'db_error_skip' => true,
  1629. )
  1630. );
  1631. // Remove the sorting column.
  1632. $smcFunc['db_remove_column']('{db_prefix}smileys', 'temp_order');
  1633. }
  1634. ?>