ManageSmileys.php 58 KB

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