ManageSmileys.php 59 KB

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