ManageSmileys.php 58 KB

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