ManageSmileys.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  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. // !!! Decide: overwrite or not?
  1232. if (isset($_FILES['set_gz']) && is_uploaded_file($_FILES['set_gz']['tmp_name']) && (@ini_get('open_basedir') != '' || file_exists($_FILES['set_gz']['tmp_name'])))
  1233. $extracted = read_tgz_file($_FILES['set_gz']['tmp_name'], $boarddir . '/Smileys/' . $name);
  1234. elseif (isset($_REQUEST['set_gz']))
  1235. {
  1236. // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
  1237. if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
  1238. fatal_lang_error('not_on_simplemachines');
  1239. $extracted = read_tgz_file($_REQUEST['set_gz'], $boarddir . '/Smileys/' . $name);
  1240. }
  1241. else
  1242. redirectexit('action=admin;area=smileys');
  1243. updateSettings(array(
  1244. 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $name,
  1245. 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.'),
  1246. ));
  1247. cache_put_data('parsing_smileys', null, 480);
  1248. cache_put_data('posting_smileys', null, 480);
  1249. // !!! Add some confirmation?
  1250. redirectexit('action=admin;area=smileys');
  1251. }
  1252. /**
  1253. * A function to import new smileys from an existing directory into the database.
  1254. *
  1255. * @param string $smileyPath
  1256. */
  1257. function ImportSmileys($smileyPath)
  1258. {
  1259. global $modSettings, $smcFunc;
  1260. if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
  1261. fatal_lang_error('smiley_set_unable_to_import');
  1262. $smileys = array();
  1263. $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
  1264. while ($entry = $dir->read())
  1265. {
  1266. if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  1267. $smileys[strtolower($entry)] = $entry;
  1268. }
  1269. $dir->close();
  1270. // Exclude the smileys that are already in the database.
  1271. $request = $smcFunc['db_query']('', '
  1272. SELECT filename
  1273. FROM {db_prefix}smileys
  1274. WHERE filename IN ({array_string:smiley_list})',
  1275. array(
  1276. 'smiley_list' => $smileys,
  1277. )
  1278. );
  1279. while ($row = $smcFunc['db_fetch_assoc']($request))
  1280. if (isset($smileys[strtolower($row['filename'])]))
  1281. unset($smileys[strtolower($row['filename'])]);
  1282. $smcFunc['db_free_result']($request);
  1283. $request = $smcFunc['db_query']('', '
  1284. SELECT MAX(smiley_order)
  1285. FROM {db_prefix}smileys
  1286. WHERE hidden = {int:postform}
  1287. AND smiley_row = {int:first_row}',
  1288. array(
  1289. 'postform' => 0,
  1290. 'first_row' => 0,
  1291. )
  1292. );
  1293. list ($smiley_order) = $smcFunc['db_fetch_row']($request);
  1294. $smcFunc['db_free_result']($request);
  1295. $new_smileys = array();
  1296. foreach ($smileys as $smiley)
  1297. if (strlen($smiley) <= 48)
  1298. $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
  1299. if (!empty($new_smileys))
  1300. {
  1301. $smcFunc['db_insert']('',
  1302. '{db_prefix}smileys',
  1303. array(
  1304. 'code' => 'string-30', 'filename' => 'string-48', 'description' => 'string-80', 'smiley_row' => 'int', 'smiley_order' => 'int',
  1305. ),
  1306. $new_smileys,
  1307. array('id_smiley')
  1308. );
  1309. // Make sure the smiley codes are still in the right order.
  1310. sortSmileyTable();
  1311. cache_put_data('parsing_smileys', null, 480);
  1312. cache_put_data('posting_smileys', null, 480);
  1313. }
  1314. }
  1315. /**
  1316. * Allows to edit the message icons.
  1317. */
  1318. function EditMessageIcons()
  1319. {
  1320. global $user_info, $modSettings, $context, $settings, $txt;
  1321. global $boarddir, $smcFunc, $scripturl, $sourcedir;
  1322. // Get a list of icons.
  1323. $context['icons'] = array();
  1324. $request = $smcFunc['db_query']('', '
  1325. SELECT m.id_icon, m.title, m.filename, m.icon_order, m.id_board, b.name AS board_name
  1326. FROM {db_prefix}message_icons AS m
  1327. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1328. WHERE ({query_see_board} OR b.id_board IS NULL)',
  1329. array(
  1330. )
  1331. );
  1332. $last_icon = 0;
  1333. $trueOrder = 0;
  1334. while ($row = $smcFunc['db_fetch_assoc']($request))
  1335. {
  1336. $context['icons'][$row['id_icon']] = array(
  1337. 'id' => $row['id_icon'],
  1338. 'title' => $row['title'],
  1339. 'filename' => $row['filename'],
  1340. 'image_url' => $settings[file_exists($settings['theme_dir'] . '/images/post/' . $row['filename'] . '.gif') ? 'actual_images_url' : 'default_images_url'] . '/post/' . $row['filename'] . '.gif',
  1341. 'board_id' => $row['id_board'],
  1342. 'board' => empty($row['board_name']) ? $txt['icons_edit_icons_all_boards'] : $row['board_name'],
  1343. 'order' => $row['icon_order'],
  1344. 'true_order' => $trueOrder++,
  1345. 'after' => $last_icon,
  1346. );
  1347. $last_icon = $row['id_icon'];
  1348. }
  1349. $smcFunc['db_free_result']($request);
  1350. // Submitting a form?
  1351. if (isset($_POST[$context['session_var']]))
  1352. {
  1353. checkSession();
  1354. // Deleting icons?
  1355. if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
  1356. {
  1357. $deleteIcons = array();
  1358. foreach ($_POST['checked_icons'] as $icon)
  1359. $deleteIcons[] = (int) $icon;
  1360. // Do the actual delete!
  1361. $smcFunc['db_query']('', '
  1362. DELETE FROM {db_prefix}message_icons
  1363. WHERE id_icon IN ({array_int:icon_list})',
  1364. array(
  1365. 'icon_list' => $deleteIcons,
  1366. )
  1367. );
  1368. }
  1369. // Editing/Adding an icon?
  1370. elseif ($context['sub_action'] == 'editicon' && isset($_GET['icon']))
  1371. {
  1372. $_GET['icon'] = (int) $_GET['icon'];
  1373. // Do some preperation with the data... like check the icon exists *somewhere*
  1374. if (strpos($_POST['icon_filename'], '.gif') !== false)
  1375. $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
  1376. if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.gif'))
  1377. fatal_lang_error('icon_not_found');
  1378. // There is a 16 character limit on message icons...
  1379. elseif (strlen($_POST['icon_filename']) > 16)
  1380. fatal_lang_error('icon_name_too_long');
  1381. elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
  1382. fatal_lang_error('icon_after_itself');
  1383. // First do the sorting... if this is an edit reduce the order of everything after it by one ;)
  1384. if ($_GET['icon'] != 0)
  1385. {
  1386. $oldOrder = $context['icons'][$_GET['icon']]['true_order'];
  1387. foreach ($context['icons'] as $id => $data)
  1388. if ($data['true_order'] > $oldOrder)
  1389. $context['icons'][$id]['true_order']--;
  1390. }
  1391. // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
  1392. if (empty($_GET['icon']) && empty($context['icons']))
  1393. $_GET['icon'] = 1;
  1394. // Get the new order.
  1395. $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
  1396. // Do the same, but with the one that used to be after this icon, done to avoid conflict.
  1397. foreach ($context['icons'] as $id => $data)
  1398. if ($data['true_order'] >= $newOrder)
  1399. $context['icons'][$id]['true_order']++;
  1400. // Finally set the current icon's position!
  1401. $context['icons'][$_GET['icon']]['true_order'] = $newOrder;
  1402. // Simply replace the existing data for the other bits.
  1403. $context['icons'][$_GET['icon']]['title'] = $_POST['icon_description'];
  1404. $context['icons'][$_GET['icon']]['filename'] = $_POST['icon_filename'];
  1405. $context['icons'][$_GET['icon']]['board_id'] = (int) $_POST['icon_board'];
  1406. // Do a huge replace ;)
  1407. $iconInsert = array();
  1408. $iconInsert_new = array();
  1409. foreach ($context['icons'] as $id => $icon)
  1410. {
  1411. if ($id != 0)
  1412. {
  1413. $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
  1414. }
  1415. else
  1416. {
  1417. $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
  1418. }
  1419. }
  1420. $smcFunc['db_insert']('replace',
  1421. '{db_prefix}message_icons',
  1422. array('id_icon' => 'int', 'id_board' => 'int', 'title' => 'string-80', 'filename' => 'string-80', 'icon_order' => 'int'),
  1423. $iconInsert,
  1424. array('id_icon')
  1425. );
  1426. if (!empty($iconInsert_new))
  1427. {
  1428. $smcFunc['db_insert']('replace',
  1429. '{db_prefix}message_icons',
  1430. array('id_board' => 'int', 'title' => 'string-80', 'filename' => 'string-80', 'icon_order' => 'int'),
  1431. $iconInsert_new,
  1432. array('id_icon')
  1433. );
  1434. }
  1435. }
  1436. // Sort by order, so it is quicker :)
  1437. $smcFunc['db_query']('alter_table_icons', '
  1438. ALTER TABLE {db_prefix}message_icons
  1439. ORDER BY icon_order',
  1440. array(
  1441. 'db_error_skip' => true,
  1442. )
  1443. );
  1444. // Unless we're adding a new thing, we'll escape
  1445. if (!isset($_POST['add']))
  1446. redirectexit('action=admin;area=smileys;sa=editicons');
  1447. }
  1448. $context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
  1449. $listOptions = array(
  1450. 'id' => 'message_icon_list',
  1451. 'base_href' => $scripturl . '?action=admin;area=smileys;sa=editicons',
  1452. 'get_items' => array(
  1453. 'function' => 'list_getMessageIcons',
  1454. ),
  1455. 'no_items_label' => $txt['icons_no_entries'],
  1456. 'columns' => array(
  1457. 'icon' => array(
  1458. 'data' => array(
  1459. 'function' => create_function('$rowData', '
  1460. global $settings;
  1461. $images_url = $settings[file_exists(sprintf(\'%1$s/images/post/%2$s.gif\', $settings[\'theme_dir\'], $rowData[\'filename\'])) ? \'actual_images_url\' : \'default_images_url\'];
  1462. return sprintf(\'<img src="%1$s/post/%2$s.gif" alt="%3$s" />\', $images_url, $rowData[\'filename\'], htmlspecialchars($rowData[\'title\']));
  1463. '),
  1464. ),
  1465. 'style' => 'text-align: center;',
  1466. ),
  1467. 'filename' => array(
  1468. 'header' => array(
  1469. 'value' => $txt['smileys_filename'],
  1470. ),
  1471. 'data' => array(
  1472. 'sprintf' => array(
  1473. 'format' => '%1$s.gif',
  1474. 'params' => array(
  1475. 'filename' => true,
  1476. ),
  1477. ),
  1478. ),
  1479. ),
  1480. 'tooltip' => array(
  1481. 'header' => array(
  1482. 'value' => $txt['smileys_description'],
  1483. ),
  1484. 'data' => array(
  1485. 'db_htmlsafe' => 'title',
  1486. 'class' => 'windowbg',
  1487. ),
  1488. ),
  1489. 'board' => array(
  1490. 'header' => array(
  1491. 'value' => $txt['icons_board'],
  1492. ),
  1493. 'data' => array(
  1494. 'function' => create_function('$rowData', '
  1495. global $txt;
  1496. return empty($rowData[\'board_name\']) ? $txt[\'icons_edit_icons_all_boards\'] : $rowData[\'board_name\'];
  1497. '),
  1498. ),
  1499. ),
  1500. 'modify' => array(
  1501. 'header' => array(
  1502. 'value' => $txt['smileys_modify'],
  1503. ),
  1504. 'data' => array(
  1505. 'sprintf' => array(
  1506. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=editicon;icon=%1$s">' . $txt['smileys_modify'] . '</a>',
  1507. 'params' => array(
  1508. 'id_icon' => false,
  1509. ),
  1510. ),
  1511. 'style' => 'text-align: center',
  1512. ),
  1513. ),
  1514. 'check' => array(
  1515. 'header' => array(
  1516. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  1517. ),
  1518. 'data' => array(
  1519. 'sprintf' => array(
  1520. 'format' => '<input type="checkbox" name="checked_icons[]" value="%1$d" class="input_check" />',
  1521. 'params' => array(
  1522. 'id_icon' => false,
  1523. ),
  1524. ),
  1525. 'style' => 'text-align: center',
  1526. ),
  1527. ),
  1528. ),
  1529. 'form' => array(
  1530. 'href' => $scripturl . '?action=admin;area=smileys;sa=editicons',
  1531. ),
  1532. 'additional_rows' => array(
  1533. array(
  1534. 'position' => 'below_table_data',
  1535. '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>]',
  1536. ),
  1537. ),
  1538. );
  1539. require_once($sourcedir . '/Subs-List.php');
  1540. createList($listOptions);
  1541. // If we're adding/editing an icon we'll need a list of boards
  1542. if ($context['sub_action'] == 'editicon' || isset($_POST['add']))
  1543. {
  1544. // Force the sub_template just in case.
  1545. $context['sub_template'] = 'editicon';
  1546. $context['new_icon'] = !isset($_GET['icon']);
  1547. // Get the properties of the current icon from the icon list.
  1548. if (!$context['new_icon'])
  1549. $context['icon'] = $context['icons'][$_GET['icon']];
  1550. // Get a list of boards needed for assigning this icon to a specific board.
  1551. $boardListOptions = array(
  1552. 'use_permissions' => true,
  1553. 'selected_board' => isset($context['icon']['board_id']) ? $context['icon']['board_id'] : 0,
  1554. );
  1555. require_once($sourcedir . '/Subs-MessageIndex.php');
  1556. $context['categories'] = getBoardList($boardListOptions);
  1557. }
  1558. }
  1559. /**
  1560. * Callback function for createList().
  1561. *
  1562. * @param $start
  1563. * @param $items_per_page
  1564. * @param $sort
  1565. */
  1566. function list_getMessageIcons($start, $items_per_page, $sort)
  1567. {
  1568. global $smcFunc, $user_info;
  1569. $request = $smcFunc['db_query']('', '
  1570. SELECT m.id_icon, m.title, m.filename, m.icon_order, m.id_board, b.name AS board_name
  1571. FROM {db_prefix}message_icons AS m
  1572. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1573. WHERE ({query_see_board} OR b.id_board IS NULL)',
  1574. array(
  1575. )
  1576. );
  1577. $message_icons = array();
  1578. while ($row = $smcFunc['db_fetch_assoc']($request))
  1579. $message_icons[] = $row;
  1580. $smcFunc['db_free_result']($request);
  1581. return $message_icons;
  1582. }
  1583. /**
  1584. * This function sorts the smiley table by code length,
  1585. * it is needed as MySQL withdrew support for functions in order by.
  1586. * @todo is this ordering itself needed?
  1587. */
  1588. function sortSmileyTable()
  1589. {
  1590. global $smcFunc;
  1591. db_extend('packages');
  1592. // Add a sorting column.
  1593. $smcFunc['db_add_column']('{db_prefix}smileys', array('name' => 'temp_order', 'size' => 8, 'type' => 'mediumint', 'null' => false));
  1594. // Set the contents of this column.
  1595. $smcFunc['db_query']('set_smiley_order', '
  1596. UPDATE {db_prefix}smileys
  1597. SET temp_order = LENGTH(code)',
  1598. array(
  1599. )
  1600. );
  1601. // Order the table by this column.
  1602. $smcFunc['db_query']('alter_table_smileys', '
  1603. ALTER TABLE {db_prefix}smileys
  1604. ORDER BY temp_order DESC',
  1605. array(
  1606. 'db_error_skip' => true,
  1607. )
  1608. );
  1609. // Remove the sorting column.
  1610. $smcFunc['db_remove_column']('{db_prefix}smileys', 'temp_order');
  1611. }
  1612. ?>