ManageSmileys.php 57 KB

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