ManageSmileys.php 58 KB

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