ManageSmileys.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  1. <?php
  2. /**
  3. * This file takes care of all administration of smileys.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2011 Simple Machines
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. /**
  17. * This is the dispatcher of smileys administration.
  18. */
  19. function ManageSmileys()
  20. {
  21. global $context, $txt, $scripturl, $modSettings;
  22. isAllowedTo('manage_smileys');
  23. loadLanguage('ManageSmileys');
  24. loadTemplate('ManageSmileys');
  25. $subActions = array(
  26. 'addsmiley' => 'AddSmiley',
  27. 'editicon' => 'EditMessageIcons',
  28. 'editicons' => 'EditMessageIcons',
  29. 'editsets' => 'EditSmileySets',
  30. 'editsmileys' => 'EditSmileys',
  31. 'import' => 'EditSmileySets',
  32. 'modifyset' => 'EditSmileySets',
  33. 'modifysmiley' => 'EditSmileys',
  34. 'setorder' => 'EditSmileyOrder',
  35. 'settings' => 'EditSmileySettings',
  36. 'install' => 'InstallSmileySet'
  37. );
  38. call_integration_hook('integrate_manage_smileys', array(&$subActions));
  39. // Default the sub-action to 'edit smiley settings'.
  40. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'editsets';
  41. $context['page_title'] = $txt['smileys_manage'];
  42. $context['sub_action'] = $_REQUEST['sa'];
  43. $context['sub_template'] = $context['sub_action'];
  44. // Load up all the tabs...
  45. $context[$context['admin_menu_name']]['tab_data'] = array(
  46. 'title' => $txt['smileys_manage'],
  47. 'help' => 'smileys',
  48. 'description' => $txt['smiley_settings_explain'],
  49. 'tabs' => array(
  50. 'editsets' => array(
  51. 'description' => $txt['smiley_editsets_explain'],
  52. ),
  53. 'addsmiley' => array(
  54. 'description' => $txt['smiley_addsmiley_explain'],
  55. ),
  56. 'editsmileys' => array(
  57. 'description' => $txt['smiley_editsmileys_explain'],
  58. ),
  59. 'setorder' => array(
  60. 'description' => $txt['smiley_setorder_explain'],
  61. ),
  62. 'editicons' => array(
  63. 'description' => $txt['icons_edit_icons_explain'],
  64. ),
  65. 'settings' => array(
  66. 'description' => $txt['smiley_settings_explain'],
  67. ),
  68. ),
  69. );
  70. // Some settings may not be enabled, disallow these from the tabs as appropriate.
  71. if (empty($modSettings['messageIcons_enable']))
  72. $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
  73. if (empty($modSettings['smiley_enable']))
  74. {
  75. $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
  76. $context[$context['admin_menu_name']]['tab_data']['tabs']['editsmileys']['disabled'] = true;
  77. $context[$context['admin_menu_name']]['tab_data']['tabs']['setorder']['disabled'] = true;
  78. }
  79. // Call the right function for this sub-acton.
  80. $subActions[$_REQUEST['sa']]();
  81. }
  82. /**
  83. * Allows to modify smileys settings.
  84. *
  85. * @param bool $return_config = false
  86. */
  87. function EditSmileySettings($return_config = false)
  88. {
  89. global $modSettings, $context, $settings, $txt, $boarddir, $sourcedir, $scripturl;
  90. // The directories...
  91. $context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];
  92. $context['smileys_dir_found'] = is_dir($context['smileys_dir']);
  93. // Get the names of the smiley sets.
  94. $smiley_sets = explode(',', $modSettings['smiley_sets_known']);
  95. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  96. $smiley_context = array();
  97. foreach ($smiley_sets as $i => $set)
  98. $smiley_context[$set] = $set_names[$i];
  99. // All the settings for the page...
  100. $config_vars = array(
  101. array('title', 'settings'),
  102. // Inline permissions.
  103. array('permissions', 'manage_smileys'),
  104. '',
  105. array('select', 'smiley_sets_default', $smiley_context),
  106. array('check', 'smiley_sets_enable'),
  107. array('check', 'smiley_enable', 'subtext' => $txt['smileys_enable_note']),
  108. array('text', 'smileys_url'),
  109. array('text', 'smileys_dir', 'invalid' => !$context['smileys_dir_found']),
  110. '',
  111. // Message icons.
  112. array('check', 'messageIcons_enable', 'subtext' => $txt['setting_messageIcons_enable_note']),
  113. );
  114. call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
  115. if ($return_config)
  116. return $config_vars;
  117. // Setup the basics of the settings template.
  118. require_once($sourcedir . '/ManageServer.php');
  119. $context['sub_template'] = 'show_settings';
  120. // Finish up the form...
  121. $context['post_url'] = $scripturl . '?action=admin;area=smileys;save;sa=settings';
  122. $context['permissions_excluded'] = array(-1);
  123. // Saving the settings?
  124. if (isset($_GET['save']))
  125. {
  126. checkSession();
  127. // Validate the smiley set name.
  128. $_POST['smiley_sets_default'] = empty($smiley_context[$_POST['smiley_sets_default']]) ? 'default' : $_POST['smiley_sets_default'];
  129. // Make sure that the smileys are in the right order after enabling them.
  130. if (isset($_POST['smiley_enable']))
  131. sortSmileyTable();
  132. call_integration_hook('integrate_save_smiley_settings');
  133. saveDBSettings($config_vars);
  134. cache_put_data('parsing_smileys', null, 480);
  135. cache_put_data('posting_smileys', null, 480);
  136. redirectexit('action=admin;area=smileys;sa=settings');
  137. }
  138. prepareDBSettingContext($config_vars);
  139. }
  140. /**
  141. * List, add, remove, modify smileys sets.
  142. */
  143. function EditSmileySets()
  144. {
  145. global $modSettings, $context, $settings, $txt, $boarddir;
  146. global $smcFunc, $scripturl, $sourcedir;
  147. // Set the right tab to be selected.
  148. $context[$context['admin_menu_name']]['current_subsection'] = 'editsets';
  149. // They must've been submitted a form.
  150. if (isset($_POST[$context['session_var']]))
  151. {
  152. checkSession();
  153. validateToken('admin-mss', 'request');
  154. // Delete selected smiley sets.
  155. if (!empty($_POST['delete']) && !empty($_POST['smiley_set']))
  156. {
  157. $set_paths = explode(',', $modSettings['smiley_sets_known']);
  158. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  159. foreach ($_POST['smiley_set'] as $id => $val)
  160. if (isset($set_paths[$id], $set_names[$id]) && !empty($id))
  161. unset($set_paths[$id], $set_names[$id]);
  162. updateSettings(array(
  163. 'smiley_sets_known' => implode(',', $set_paths),
  164. 'smiley_sets_names' => implode("\n", $set_names),
  165. 'smiley_sets_default' => in_array($modSettings['smiley_sets_default'], $set_paths) ? $modSettings['smiley_sets_default'] : $set_paths[0],
  166. ));
  167. cache_put_data('parsing_smileys', null, 480);
  168. cache_put_data('posting_smileys', null, 480);
  169. }
  170. // Add a new smiley set.
  171. elseif (!empty($_POST['add']))
  172. $context['sub_action'] = 'modifyset';
  173. // Create or modify a smiley set.
  174. elseif (isset($_POST['set']))
  175. {
  176. $set_paths = explode(',', $modSettings['smiley_sets_known']);
  177. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  178. // Create a new smiley set.
  179. if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
  180. {
  181. if (in_array($_POST['smiley_sets_path'], $set_paths))
  182. fatal_lang_error('smiley_set_already_exists');
  183. updateSettings(array(
  184. 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
  185. 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $_POST['smiley_sets_name'],
  186. 'smiley_sets_default' => empty($_POST['smiley_sets_default']) ? $modSettings['smiley_sets_default'] : $_POST['smiley_sets_path'],
  187. ));
  188. }
  189. // Modify an existing smiley set.
  190. else
  191. {
  192. // Make sure the smiley set exists.
  193. if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
  194. fatal_lang_error('smiley_set_not_found');
  195. // Make sure the path is not yet used by another smileyset.
  196. if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
  197. fatal_lang_error('smiley_set_path_already_used');
  198. $set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
  199. $set_names[$_POST['set']] = $_POST['smiley_sets_name'];
  200. updateSettings(array(
  201. 'smiley_sets_known' => implode(',', $set_paths),
  202. 'smiley_sets_names' => implode("\n", $set_names),
  203. 'smiley_sets_default' => empty($_POST['smiley_sets_default']) ? $modSettings['smiley_sets_default'] : $_POST['smiley_sets_path']
  204. ));
  205. }
  206. // The user might have checked to also import smileys.
  207. if (!empty($_POST['smiley_sets_import']))
  208. ImportSmileys($_POST['smiley_sets_path']);
  209. cache_put_data('parsing_smileys', null, 480);
  210. cache_put_data('posting_smileys', null, 480);
  211. }
  212. }
  213. // Load all available smileysets...
  214. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  215. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  216. foreach ($context['smiley_sets'] as $i => $set)
  217. $context['smiley_sets'][$i] = array(
  218. 'id' => $i,
  219. 'path' => htmlspecialchars($set),
  220. 'name' => htmlspecialchars($set_names[$i]),
  221. 'selected' => $set == $modSettings['smiley_sets_default']
  222. );
  223. // Importing any smileys from an existing set?
  224. if ($context['sub_action'] == 'import')
  225. {
  226. checkSession('get');
  227. validateToken('admin-mss', 'request');
  228. $_GET['set'] = (int) $_GET['set'];
  229. // Sanity check - then import.
  230. if (isset($context['smiley_sets'][$_GET['set']]))
  231. ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
  232. // Force the process to continue.
  233. $context['sub_action'] = 'modifyset';
  234. $context['sub_template'] = 'modifyset';
  235. }
  236. // If we're modifying or adding a smileyset, some context info needs to be set.
  237. if ($context['sub_action'] == 'modifyset')
  238. {
  239. $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
  240. if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
  241. $context['current_set'] = array(
  242. 'id' => '-1',
  243. 'path' => '',
  244. 'name' => '',
  245. 'selected' => false,
  246. 'is_new' => true,
  247. );
  248. else
  249. {
  250. $context['current_set'] = &$context['smiley_sets'][$_GET['set']];
  251. $context['current_set']['is_new'] = false;
  252. // Calculate whether there are any smileys in the directory that can be imported.
  253. if (!empty($modSettings['smiley_enable']) && !empty($modSettings['smileys_dir']) && is_dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']))
  254. {
  255. $smileys = array();
  256. $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']);
  257. while ($entry = $dir->read())
  258. {
  259. if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  260. $smileys[strtolower($entry)] = $entry;
  261. }
  262. $dir->close();
  263. // Exclude the smileys that are already in the database.
  264. $request = $smcFunc['db_query']('', '
  265. SELECT filename
  266. FROM {db_prefix}smileys
  267. WHERE filename IN ({array_string:smiley_list})',
  268. array(
  269. 'smiley_list' => $smileys,
  270. )
  271. );
  272. while ($row = $smcFunc['db_fetch_assoc']($request))
  273. if (isset($smileys[strtolower($row['filename'])]))
  274. unset($smileys[strtolower($row['filename'])]);
  275. $smcFunc['db_free_result']($request);
  276. $context['current_set']['can_import'] = count($smileys);
  277. // Setup this string to look nice.
  278. $txt['smiley_set_import_multiple'] = sprintf($txt['smiley_set_import_multiple'], $context['current_set']['can_import']);
  279. }
  280. }
  281. // Retrieve all potential smiley set directories.
  282. $context['smiley_set_dirs'] = array();
  283. if (!empty($modSettings['smileys_dir']) && is_dir($modSettings['smileys_dir']))
  284. {
  285. $dir = dir($modSettings['smileys_dir']);
  286. while ($entry = $dir->read())
  287. {
  288. if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
  289. $context['smiley_set_dirs'][] = array(
  290. 'id' => $entry,
  291. 'path' => $modSettings['smileys_dir'] . '/' . $entry,
  292. 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
  293. 'current' => $entry == $context['current_set']['path'],
  294. );
  295. }
  296. $dir->close();
  297. }
  298. }
  299. // This is our save haven.
  300. createToken('admin-mss', 'request');
  301. $listOptions = array(
  302. 'id' => 'smiley_set_list',
  303. 'base_href' => $scripturl . '?action=admin;area=smileys;sa=editsets',
  304. 'default_sort_col' => 'default',
  305. 'get_items' => array(
  306. 'function' => 'list_getSmileySets',
  307. ),
  308. 'get_count' => array(
  309. 'function' => 'list_getNumSmileySets',
  310. ),
  311. 'columns' => array(
  312. 'default' => array(
  313. 'header' => array(
  314. 'value' => $txt['smiley_sets_default'],
  315. ),
  316. 'data' => array(
  317. 'function' => create_function('$rowData', '
  318. return $rowData[\'selected\'] ? \'<strong>*</strong>\' : \'\';
  319. '),
  320. 'style' => 'text-align: center;',
  321. ),
  322. 'sort' => array(
  323. 'default' => 'selected DESC',
  324. ),
  325. ),
  326. 'name' => array(
  327. 'header' => array(
  328. 'value' => $txt['smiley_sets_name'],
  329. ),
  330. 'data' => array(
  331. 'db_htmlsafe' => 'name',
  332. 'class' => 'windowbg',
  333. ),
  334. 'sort' => array(
  335. 'default' => 'name',
  336. 'reverse' => 'name DESC',
  337. ),
  338. ),
  339. 'url' => array(
  340. 'header' => array(
  341. 'value' => $txt['smiley_sets_url'],
  342. ),
  343. 'data' => array(
  344. 'sprintf' => array(
  345. 'format' => $modSettings['smileys_url'] . '/<strong>%1$s</strong>/...',
  346. 'params' => array(
  347. 'path' => true,
  348. ),
  349. ),
  350. 'class' => 'windowbg',
  351. ),
  352. 'sort' => array(
  353. 'default' => 'path',
  354. 'reverse' => 'path DESC',
  355. ),
  356. ),
  357. 'modify' => array(
  358. 'header' => array(
  359. 'value' => $txt['smiley_set_modify'],
  360. ),
  361. 'data' => array(
  362. 'sprintf' => array(
  363. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifyset;set=%1$d">' . $txt['smiley_set_modify'] . '</a>',
  364. 'params' => array(
  365. 'id' => true,
  366. ),
  367. ),
  368. 'style' => 'text-align: center;',
  369. ),
  370. ),
  371. 'check' => array(
  372. 'header' => array(
  373. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  374. ),
  375. 'data' => array(
  376. 'function' => create_function('$rowData', '
  377. return $rowData[\'id\'] == 0 ? \'\' : sprintf(\'<input type="checkbox" name="smiley_set[%1$d]" class="input_check" />\', $rowData[\'id\']);
  378. '),
  379. 'style' => 'text-align: center',
  380. ),
  381. ),
  382. ),
  383. 'form' => array(
  384. 'href' => $scripturl . '?action=admin;area=smileys;sa=editsets',
  385. 'token' => 'admin-mss',
  386. ),
  387. 'additional_rows' => array(
  388. array(
  389. 'position' => 'below_table_data',
  390. 'value' => '[<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifyset' . '">' . $txt['smiley_sets_add'] . '</a>] <input type="submit" name="delete" value="' . $txt['smiley_sets_delete'] . '" onclick="return confirm(\'' . $txt['smiley_sets_confirm'] . '\');" class="button_submit" />',
  391. ),
  392. ),
  393. );
  394. require_once($sourcedir . '/Subs-List.php');
  395. createList($listOptions);
  396. }
  397. /**
  398. * Callback function for createList().
  399. * @todo to be moved to Subs-Smileys?
  400. *
  401. * @param $start
  402. * @param $items_per_page
  403. * @param $sort
  404. */
  405. function list_getSmileySets($start, $items_per_page, $sort)
  406. {
  407. global $modSettings;
  408. $known_sets = explode(',', $modSettings['smiley_sets_known']);
  409. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  410. $cols = array(
  411. 'id' => array(),
  412. 'selected' => array(),
  413. 'path' => array(),
  414. 'name' => array(),
  415. );
  416. foreach ($known_sets as $i => $set)
  417. {
  418. $cols['id'][] = $i;
  419. $cols['selected'][] = $i;
  420. $cols['path'][] = $set;
  421. $cols['name'][] = $set_names[$i];
  422. }
  423. $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
  424. if (substr($sort, 0, 4) === 'name')
  425. array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
  426. elseif (substr($sort, 0, 4) === 'path')
  427. array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
  428. else
  429. array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
  430. $smiley_sets = array();
  431. foreach ($cols['id'] as $i => $id)
  432. $smiley_sets[] = array(
  433. 'id' => $id,
  434. 'path' => $cols['path'][$i],
  435. 'name' => $cols['name'][$i],
  436. 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
  437. );
  438. return $smiley_sets;
  439. }
  440. /**
  441. * Callback function for createList().
  442. * @todo to be moved to Subs-Smileys?
  443. */
  444. function list_getNumSmileySets()
  445. {
  446. global $modSettings;
  447. return count(explode(',', $modSettings['smiley_sets_known']));
  448. }
  449. /**
  450. * Add a smiley, that's right.
  451. */
  452. function AddSmiley()
  453. {
  454. global $modSettings, $context, $settings, $txt, $boarddir, $smcFunc;
  455. // Get a list of all known smiley sets.
  456. $context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];
  457. $context['smileys_dir_found'] = is_dir($context['smileys_dir']);
  458. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  459. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  460. foreach ($context['smiley_sets'] as $i => $set)
  461. $context['smiley_sets'][$i] = array(
  462. 'id' => $i,
  463. 'path' => htmlspecialchars($set),
  464. 'name' => htmlspecialchars($set_names[$i]),
  465. 'selected' => $set == $modSettings['smiley_sets_default']
  466. );
  467. // Submitting a form?
  468. if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
  469. {
  470. checkSession();
  471. // Some useful arrays... types we allow - and ports we don't!
  472. $allowedTypes = array('jpeg', 'jpg', 'gif', 'png', 'bmp');
  473. $disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
  474. $_POST['smiley_code'] = htmltrim__recursive($_POST['smiley_code']);
  475. $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
  476. $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
  477. // Make sure some code was entered.
  478. if (empty($_POST['smiley_code']))
  479. fatal_lang_error('smiley_has_no_code');
  480. // Check whether the new code has duplicates. It should be unique.
  481. $request = $smcFunc['db_query']('', '
  482. SELECT id_smiley
  483. FROM {db_prefix}smileys
  484. WHERE code = {raw:mysql_binary_statement} {string:smiley_code}',
  485. array(
  486. 'mysql_binary_statement' => $smcFunc['db_title'] == 'MySQL' ? 'BINARY' : '',
  487. 'smiley_code' => $_POST['smiley_code'],
  488. )
  489. );
  490. if ($smcFunc['db_num_rows']($request) > 0)
  491. fatal_lang_error('smiley_not_unique');
  492. $smcFunc['db_free_result']($request);
  493. // If we are uploading - check all the smiley sets are writable!
  494. if ($_POST['method'] != 'existing')
  495. {
  496. $writeErrors = array();
  497. foreach ($context['smiley_sets'] as $set)
  498. {
  499. if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
  500. $writeErrors[] = $set['path'];
  501. }
  502. if (!empty($writeErrors))
  503. fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
  504. }
  505. // Uploading just one smiley for all of them?
  506. if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
  507. {
  508. if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
  509. fatal_lang_error('smileys_upload_error');
  510. // Sorry, no spaces, dots, or anything else but letters allowed.
  511. $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
  512. // We only allow image files - it's THAT simple - no messing around here...
  513. if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
  514. fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
  515. // We only need the filename...
  516. $destName = basename($_FILES['uploadSmiley']['name']);
  517. // Make sure they aren't trying to upload a nasty file - for their own good here!
  518. if (in_array(strtolower($destName), $disabledFiles))
  519. fatal_lang_error('smileys_upload_error_illegal');
  520. // Check if the file already exists... and if not move it to EVERY smiley set directory.
  521. $i = 0;
  522. // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
  523. while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
  524. $i++;
  525. // Okay, we're going to put the smiley right here, since it's not there yet!
  526. if (isset($context['smiley_sets'][$i]['path']))
  527. {
  528. $smileyLocation = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
  529. move_uploaded_file($_FILES['uploadSmiley']['tmp_name'], $smileyLocation);
  530. @chmod($smileyLocation, 0644);
  531. // Now, we want to move it from there to all the other sets.
  532. for ($n = count($context['smiley_sets']); $i < $n; $i++)
  533. {
  534. $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
  535. // The file is already there! Don't overwrite it!
  536. if (file_exists($currentPath))
  537. continue;
  538. // Okay, so copy the first one we made to here.
  539. copy($smileyLocation, $currentPath);
  540. @chmod($currentPath, 0644);
  541. }
  542. }
  543. // Finally make sure it's saved correctly!
  544. $_POST['smiley_filename'] = $destName;
  545. }
  546. // What about uploading several files?
  547. elseif ($_POST['method'] != 'existing')
  548. {
  549. $newName = '';
  550. foreach ($_FILES as $name => $data)
  551. {
  552. if ($_FILES[$name]['name'] == '')
  553. fatal_lang_error('smileys_upload_error_blank');
  554. if (empty($newName))
  555. $newName = basename($_FILES[$name]['name']);
  556. elseif (basename($_FILES[$name]['name']) != $newName)
  557. fatal_lang_error('smileys_upload_error_name');
  558. }
  559. foreach ($context['smiley_sets'] as $i => $set)
  560. {
  561. $set['name'] = un_htmlspecialchars($set['name']);
  562. $set['path'] = un_htmlspecialchars($set['path']);
  563. if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
  564. continue;
  565. // Got one...
  566. if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
  567. fatal_lang_error('smileys_upload_error');
  568. // Sorry, no spaces, dots, or anything else but letters allowed.
  569. $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
  570. // We only allow image files - it's THAT simple - no messing around here...
  571. if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
  572. fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
  573. // We only need the filename...
  574. $destName = basename($_FILES['individual_' . $set['name']]['name']);
  575. // Make sure they aren't trying to upload a nasty file - for their own good here!
  576. if (in_array(strtolower($destName), $disabledFiles))
  577. fatal_lang_error('smileys_upload_error_illegal');
  578. // If the file exists - ignore it.
  579. $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
  580. if (file_exists($smileyLocation))
  581. continue;
  582. // Finally - move the image!
  583. move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
  584. @chmod($smileyLocation, 0644);
  585. // Should always be saved correctly!
  586. $_POST['smiley_filename'] = $destName;
  587. }
  588. }
  589. // Also make sure a filename was given.
  590. if (empty($_POST['smiley_filename']))
  591. fatal_lang_error('smiley_has_no_filename');
  592. // Find the position on the right.
  593. $smiley_order = '0';
  594. if ($_POST['smiley_location'] != 1)
  595. {
  596. $request = $smcFunc['db_query']('', '
  597. SELECT MAX(smiley_order) + 1
  598. FROM {db_prefix}smileys
  599. WHERE hidden = {int:smiley_location}
  600. AND smiley_row = {int:first_row}',
  601. array(
  602. 'smiley_location' => $_POST['smiley_location'],
  603. 'first_row' => 0,
  604. )
  605. );
  606. list ($smiley_order) = $smcFunc['db_fetch_row']($request);
  607. $smcFunc['db_free_result']($request);
  608. if (empty($smiley_order))
  609. $smiley_order = '0';
  610. }
  611. $smcFunc['db_insert']('',
  612. '{db_prefix}smileys',
  613. array(
  614. 'code' => 'string-30', 'filename' => 'string-48', 'description' => 'string-80', 'hidden' => 'int', 'smiley_order' => 'int',
  615. ),
  616. array(
  617. $_POST['smiley_code'], $_POST['smiley_filename'], $_POST['smiley_description'], $_POST['smiley_location'], $smiley_order,
  618. ),
  619. array('id_smiley')
  620. );
  621. cache_put_data('parsing_smileys', null, 480);
  622. cache_put_data('posting_smileys', null, 480);
  623. // No errors? Out of here!
  624. redirectexit('action=admin;area=smileys;sa=editsmileys');
  625. }
  626. $context['selected_set'] = $modSettings['smiley_sets_default'];
  627. // Get all possible filenames for the smileys.
  628. $context['filenames'] = array();
  629. if ($context['smileys_dir_found'])
  630. {
  631. foreach ($context['smiley_sets'] as $smiley_set)
  632. {
  633. if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
  634. continue;
  635. $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
  636. while ($entry = $dir->read())
  637. {
  638. if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  639. $context['filenames'][strtolower($entry)] = array(
  640. 'id' => htmlspecialchars($entry),
  641. 'selected' => false,
  642. );
  643. }
  644. $dir->close();
  645. }
  646. ksort($context['filenames']);
  647. }
  648. // Create a new smiley from scratch.
  649. $context['filenames'] = array_values($context['filenames']);
  650. $context['current_smiley'] = array(
  651. 'id' => 0,
  652. 'code' => '',
  653. 'filename' => $context['filenames'][0]['id'],
  654. 'description' => $txt['smileys_default_description'],
  655. 'location' => 0,
  656. 'is_new' => true,
  657. );
  658. }
  659. /**
  660. * Add, remove, edit smileys.
  661. */
  662. function EditSmileys()
  663. {
  664. global $modSettings, $context, $settings, $txt, $boarddir;
  665. global $smcFunc, $scripturl, $sourcedir;
  666. // Force the correct tab to be displayed.
  667. $context[$context['admin_menu_name']]['current_subsection'] = 'editsmileys';
  668. // Submitting a form?
  669. if (isset($_POST[$context['session_var']]))
  670. {
  671. checkSession();
  672. // Changing the selected smileys?
  673. if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
  674. {
  675. foreach ($_POST['checked_smileys'] as $id => $smiley_id)
  676. $_POST['checked_smileys'][$id] = (int) $smiley_id;
  677. if ($_POST['smiley_action'] == 'delete')
  678. $smcFunc['db_query']('', '
  679. DELETE FROM {db_prefix}smileys
  680. WHERE id_smiley IN ({array_int:checked_smileys})',
  681. array(
  682. 'checked_smileys' => $_POST['checked_smileys'],
  683. )
  684. );
  685. // Changing the status of the smiley?
  686. else
  687. {
  688. // Check it's a valid type.
  689. $displayTypes = array(
  690. 'post' => 0,
  691. 'hidden' => 1,
  692. 'popup' => 2
  693. );
  694. if (isset($displayTypes[$_POST['smiley_action']]))
  695. $smcFunc['db_query']('', '
  696. UPDATE {db_prefix}smileys
  697. SET hidden = {int:display_type}
  698. WHERE id_smiley IN ({array_int:checked_smileys})',
  699. array(
  700. 'checked_smileys' => $_POST['checked_smileys'],
  701. 'display_type' => $displayTypes[$_POST['smiley_action']],
  702. )
  703. );
  704. }
  705. }
  706. // Create/modify a smiley.
  707. elseif (isset($_POST['smiley']))
  708. {
  709. // Is it a delete?
  710. if (!empty($_POST['deletesmiley']))
  711. {
  712. $smcFunc['db_query']('', '
  713. DELETE FROM {db_prefix}smileys
  714. WHERE id_smiley = {int:current_smiley}',
  715. array(
  716. 'current_smiley' => $_POST['smiley'],
  717. )
  718. );
  719. }
  720. // Otherwise an edit.
  721. else
  722. {
  723. $_POST['smiley'] = (int) $_POST['smiley'];
  724. $_POST['smiley_code'] = htmltrim__recursive($_POST['smiley_code']);
  725. $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
  726. $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
  727. // Make sure some code was entered.
  728. if (empty($_POST['smiley_code']))
  729. fatal_lang_error('smiley_has_no_code');
  730. // Also make sure a filename was given.
  731. if (empty($_POST['smiley_filename']))
  732. fatal_lang_error('smiley_has_no_filename');
  733. // Check whether the new code has duplicates. It should be unique.
  734. $request = $smcFunc['db_query']('', '
  735. SELECT id_smiley
  736. FROM {db_prefix}smileys
  737. WHERE code = {raw:mysql_binary_type} {string:smiley_code}' . (empty($_POST['smiley']) ? '' : '
  738. AND id_smiley != {int:current_smiley}'),
  739. array(
  740. 'current_smiley' => $_POST['smiley'],
  741. 'mysql_binary_type' => $smcFunc['db_title'] == 'MySQL' ? 'BINARY' : '',
  742. 'smiley_code' => $_POST['smiley_code'],
  743. )
  744. );
  745. if ($smcFunc['db_num_rows']($request) > 0)
  746. fatal_lang_error('smiley_not_unique');
  747. $smcFunc['db_free_result']($request);
  748. $smcFunc['db_query']('', '
  749. UPDATE {db_prefix}smileys
  750. SET
  751. code = {string:smiley_code},
  752. filename = {string:smiley_filename},
  753. description = {string:smiley_description},
  754. hidden = {int:smiley_location}
  755. WHERE id_smiley = {int:current_smiley}',
  756. array(
  757. 'smiley_location' => $_POST['smiley_location'],
  758. 'current_smiley' => $_POST['smiley'],
  759. 'smiley_code' => $_POST['smiley_code'],
  760. 'smiley_filename' => $_POST['smiley_filename'],
  761. 'smiley_description' => $_POST['smiley_description'],
  762. )
  763. );
  764. }
  765. // Sort all smiley codes for more accurate parsing (longest code first).
  766. sortSmileyTable();
  767. }
  768. cache_put_data('parsing_smileys', null, 480);
  769. cache_put_data('posting_smileys', null, 480);
  770. }
  771. // Load all known smiley sets.
  772. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  773. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  774. foreach ($context['smiley_sets'] as $i => $set)
  775. $context['smiley_sets'][$i] = array(
  776. 'id' => $i,
  777. 'path' => htmlspecialchars($set),
  778. 'name' => htmlspecialchars($set_names[$i]),
  779. 'selected' => $set == $modSettings['smiley_sets_default']
  780. );
  781. // Prepare overview of all (custom) smileys.
  782. if ($context['sub_action'] == 'editsmileys')
  783. {
  784. // Determine the language specific sort order of smiley locations.
  785. $smiley_locations = array(
  786. $txt['smileys_location_form'],
  787. $txt['smileys_location_hidden'],
  788. $txt['smileys_location_popup'],
  789. );
  790. asort($smiley_locations);
  791. // Create a list of options for selecting smiley sets.
  792. $smileyset_option_list = '
  793. <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
  794. foreach ($context['smiley_sets'] as $smiley_set)
  795. $smileyset_option_list .= '
  796. <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected="selected"' : '') . '>' . $smiley_set['name'] . '</option>';
  797. $smileyset_option_list .= '
  798. </select>';
  799. $listOptions = array(
  800. 'id' => 'smiley_list',
  801. 'items_per_page' => 40,
  802. 'base_href' => $scripturl . '?action=admin;area=smileys;sa=editsmileys',
  803. 'default_sort_col' => 'filename',
  804. 'get_items' => array(
  805. 'function' => 'list_getSmileys',
  806. ),
  807. 'get_count' => array(
  808. 'function' => 'list_getNumSmileys',
  809. ),
  810. 'no_items_label' => $txt['smileys_no_entries'],
  811. 'columns' => array(
  812. 'picture' => array(
  813. 'data' => array(
  814. 'sprintf' => array(
  815. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifysmiley;smiley=%1$d"><img src="' . $modSettings['smileys_url'] . '/' . $modSettings['smiley_sets_default'] . '/%2$s" alt="%3$s" style="padding: 2px;" id="smiley%1$d" /><input type="hidden" name="smileys[%1$d][filename]" value="%2$s" /></a>',
  816. 'params' => array(
  817. 'id_smiley' => false,
  818. 'filename' => true,
  819. 'description' => true,
  820. ),
  821. ),
  822. 'style' => 'text-align: center;',
  823. ),
  824. ),
  825. 'code' => array(
  826. 'header' => array(
  827. 'value' => $txt['smileys_code'],
  828. ),
  829. 'data' => array(
  830. 'db_htmlsafe' => 'code',
  831. ),
  832. 'sort' => array(
  833. 'default' => 'code',
  834. 'reverse' => 'code DESC',
  835. ),
  836. ),
  837. 'filename' => array(
  838. 'header' => array(
  839. 'value' => $txt['smileys_filename'],
  840. ),
  841. 'data' => array(
  842. 'db_htmlsafe' => 'filename',
  843. 'class' => 'windowbg',
  844. ),
  845. 'sort' => array(
  846. 'default' => 'filename',
  847. 'reverse' => 'filename DESC',
  848. ),
  849. ),
  850. 'location' => array(
  851. 'header' => array(
  852. 'value' => $txt['smileys_location'],
  853. ),
  854. 'data' => array(
  855. 'function' => create_function('$rowData', '
  856. global $txt;
  857. if (empty($rowData[\'hidden\']))
  858. return $txt[\'smileys_location_form\'];
  859. elseif ($rowData[\'hidden\'] == 1)
  860. return $txt[\'smileys_location_hidden\'];
  861. else
  862. return $txt[\'smileys_location_popup\'];
  863. '),
  864. 'class' => 'windowbg',
  865. ),
  866. 'sort' => array(
  867. 'default' => 'FIND_IN_SET(hidden, \'' . implode(',', array_keys($smiley_locations)) . '\')',
  868. 'reverse' => 'FIND_IN_SET(hidden, \'' . implode(',', array_keys($smiley_locations)) . '\') DESC',
  869. ),
  870. ),
  871. 'tooltip' => array(
  872. 'header' => array(
  873. 'value' => $txt['smileys_description'],
  874. ),
  875. 'data' => array(
  876. 'function' => create_function('$rowData', empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']) ? '
  877. return htmlspecialchars($rowData[\'description\']);
  878. ' : '
  879. global $context, $txt, $modSettings;
  880. // Check if there are smileys missing in some sets.
  881. $missing_sets = array();
  882. foreach ($context[\'smiley_sets\'] as $smiley_set)
  883. if (!file_exists(sprintf(\'%1$s/%2$s/%3$s\', $modSettings[\'smileys_dir\'], $smiley_set[\'path\'], $rowData[\'filename\'])))
  884. $missing_sets[] = $smiley_set[\'path\'];
  885. $description = htmlspecialchars($rowData[\'description\']);
  886. if (!empty($missing_sets))
  887. $description .= sprintf(\'<br /><span class="smalltext"><strong>%1$s:</strong> %2$s</span>\', $txt[\'smileys_not_found_in_set\'], implode(\', \', $missing_sets));
  888. return $description;
  889. '),
  890. 'class' => 'windowbg',
  891. ),
  892. 'sort' => array(
  893. 'default' => 'description',
  894. 'reverse' => 'description DESC',
  895. ),
  896. ),
  897. 'modify' => array(
  898. 'header' => array(
  899. 'value' => $txt['smileys_modify'],
  900. ),
  901. 'data' => array(
  902. 'sprintf' => array(
  903. 'format' => '<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifysmiley;smiley=%1$d">' . $txt['smileys_modify'] . '</a>',
  904. 'params' => array(
  905. 'id_smiley' => false,
  906. ),
  907. ),
  908. 'style' => 'text-align: center;',
  909. ),
  910. ),
  911. 'check' => array(
  912. 'header' => array(
  913. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  914. ),
  915. 'data' => array(
  916. 'sprintf' => array(
  917. 'format' => '<input type="checkbox" name="checked_smileys[]" value="%1$d" class="input_check" />',
  918. 'params' => array(
  919. 'id_smiley' => false,
  920. ),
  921. ),
  922. 'style' => 'text-align: center',
  923. ),
  924. ),
  925. ),
  926. 'form' => array(
  927. 'href' => $scripturl . '?action=admin;area=smileys;sa=editsmileys',
  928. 'name' => 'smileyForm',
  929. ),
  930. 'additional_rows' => array(
  931. array(
  932. 'position' => 'above_column_headers',
  933. 'value' => $smileyset_option_list,
  934. 'style' => 'text-align: right;',
  935. ),
  936. array(
  937. 'position' => 'below_table_data',
  938. 'value' => '
  939. <select name="smiley_action" onchange="makeChanges(this.value);">
  940. <option value="-1">' . $txt['smileys_with_selected'] . ':</option>
  941. <option value="-1">--------------</option>
  942. <option value="hidden">' . $txt['smileys_make_hidden'] . '</option>
  943. <option value="post">' . $txt['smileys_show_on_post'] . '</option>
  944. <option value="popup">' . $txt['smileys_show_on_popup'] . '</option>
  945. <option value="delete">' . $txt['smileys_remove'] . '</option>
  946. </select>
  947. <noscript><input type="submit" name="perform_action" value="' . $txt['go'] . '" class="button_submit" /></noscript>',
  948. 'style' => 'text-align: right;',
  949. ),
  950. ),
  951. 'javascript' => '
  952. function makeChanges(action)
  953. {
  954. if (action == \'-1\')
  955. return false;
  956. else if (action == \'delete\')
  957. {
  958. if (confirm(\'' . $txt['smileys_confirm'] . '\'))
  959. document.forms.smileyForm.submit();
  960. }
  961. else
  962. document.forms.smileyForm.submit();
  963. return true;
  964. }
  965. function changeSet(newSet)
  966. {
  967. var currentImage, i, knownSmileys = [];
  968. if (knownSmileys.length == 0)
  969. {
  970. for (var i = 0, n = document.images.length; i < n; i++)
  971. if (document.images[i].id.substr(0, 6) == \'smiley\')
  972. knownSmileys[knownSmileys.length] = document.images[i].id.substr(6);
  973. }
  974. for (i = 0; i < knownSmileys.length; i++)
  975. {
  976. currentImage = document.getElementById("smiley" + knownSmileys[i]);
  977. currentImage.src = "' . $modSettings['smileys_url'] . '/" + newSet + "/" + document.forms.smileyForm["smileys[" + knownSmileys[i] + "][filename]"].value;
  978. }
  979. }',
  980. );
  981. require_once($sourcedir . '/Subs-List.php');
  982. createList($listOptions);
  983. // The list is the only thing to show, so make it the main template.
  984. $context['default_list'] = 'smiley_list';
  985. $context['sub_template'] = 'show_list';
  986. }
  987. // Modifying smileys.
  988. elseif ($context['sub_action'] == 'modifysmiley')
  989. {
  990. // Get a list of all known smiley sets.
  991. $context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];
  992. $context['smileys_dir_found'] = is_dir($context['smileys_dir']);
  993. $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
  994. $set_names = explode("\n", $modSettings['smiley_sets_names']);
  995. foreach ($context['smiley_sets'] as $i => $set)
  996. $context['smiley_sets'][$i] = array(
  997. 'id' => $i,
  998. 'path' => htmlspecialchars($set),
  999. 'name' => htmlspecialchars($set_names[$i]),
  1000. 'selected' => $set == $modSettings['smiley_sets_default']
  1001. );
  1002. $context['selected_set'] = $modSettings['smiley_sets_default'];
  1003. // Get all possible filenames for the smileys.
  1004. $context['filenames'] = array();
  1005. if ($context['smileys_dir_found'])
  1006. {
  1007. foreach ($context['smiley_sets'] as $smiley_set)
  1008. {
  1009. if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
  1010. continue;
  1011. $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
  1012. while ($entry = $dir->read())
  1013. {
  1014. if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
  1015. $context['filenames'][strtolower($entry)] = array(
  1016. 'id' => htmlspecialchars($entry),
  1017. 'selected' => false,
  1018. );
  1019. }
  1020. $dir->close();
  1021. }
  1022. ksort($context['filenames']);
  1023. }
  1024. $request = $smcFunc['db_query']('', '
  1025. SELECT id_smiley AS id, code, filename, description, hidden AS location, 0 AS is_new
  1026. FROM {db_prefix}smileys
  1027. WHERE id_smiley = {int:current_smiley}',
  1028. array(
  1029. 'current_smiley' => (int) $_REQUEST['smiley'],
  1030. )
  1031. );
  1032. if ($smcFunc['db_num_rows']($request) != 1)
  1033. fatal_lang_error('smiley_not_found');
  1034. $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
  1035. $smcFunc['db_free_result']($request);
  1036. $context['current_smiley']['code'] = htmlspecialchars($context['current_smiley']['code']);
  1037. $context['current_smiley']['filename'] = htmlspecialchars($context['current_smiley']['filename']);
  1038. $context['current_smiley']['description'] = htmlspecialchars($context['current_smiley']['description']);
  1039. if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
  1040. $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
  1041. }
  1042. }
  1043. /**
  1044. * Callback function for createList().
  1045. *
  1046. * @param unknown_type $start
  1047. * @param unknown_type $items_per_page
  1048. * @param unknown_type $sort
  1049. */
  1050. function list_getSmileys($start, $items_per_page, $sort)
  1051. {
  1052. global $smcFunc;
  1053. $request = $smcFunc['db_query']('', '
  1054. SELECT id_smiley, code, filename, description, smiley_row, smiley_order, hidden
  1055. FROM {db_prefix}smileys
  1056. ORDER BY ' . $sort,
  1057. array(
  1058. )
  1059. );
  1060. $smileys = array();
  1061. while ($row = $smcFunc['db_fetch_assoc']($request))
  1062. $smileys[] = $row;
  1063. $smcFunc['db_free_result']($request);
  1064. return $smileys;
  1065. }
  1066. /**
  1067. * Callback function for createList().
  1068. */
  1069. function list_getNumSmileys()
  1070. {
  1071. global $smcFunc;
  1072. $request = $smcFunc['db_query']('', '
  1073. SELECT COUNT(*)
  1074. FROM {db_prefix}smileys',
  1075. array(
  1076. )
  1077. );
  1078. list($numSmileys) = $smcFunc['db_fetch_row'];
  1079. $smcFunc['db_free_result']($request);
  1080. return $numSmileys;
  1081. }
  1082. /**
  1083. * Allows to edit smileys order.
  1084. */
  1085. function EditSmileyOrder()
  1086. {
  1087. global $modSettings, $context, $settings, $txt, $boarddir, $smcFunc;
  1088. // Move smileys to another position.
  1089. if (isset($_REQUEST['reorder']))
  1090. {
  1091. checkSession('get');
  1092. $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
  1093. $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
  1094. if (empty($_GET['source']))
  1095. fatal_lang_error('smiley_not_found');
  1096. if (!empty($_GET['after']))
  1097. {
  1098. $_GET['after'] = (int) $_GET['after'];
  1099. $request = $smcFunc['db_query']('', '
  1100. SELECT smiley_row, smiley_order, hidden
  1101. FROM {db_prefix}smileys
  1102. WHERE hidden = {int:location}
  1103. AND id_smiley = {int:after_smiley}',
  1104. array(
  1105. 'location' => $_GET['location'],
  1106. 'after_smiley' => $_GET['after'],
  1107. )
  1108. );
  1109. if ($smcFunc['db_num_rows']($request) != 1)
  1110. fatal_lang_error('smiley_not_found');
  1111. list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
  1112. $smcFunc['db_free_result']($request);
  1113. }
  1114. else
  1115. {
  1116. $smiley_row = (int) $_GET['row'];
  1117. $smiley_order = -1;
  1118. $smileyLocation = (int) $_GET['location'];
  1119. }
  1120. $smcFunc['db_query']('', '
  1121. UPDATE {db_prefix}smileys
  1122. SET smiley_order = smiley_order + 1
  1123. WHERE hidden = {int:new_location}
  1124. AND smiley_row = {int:smiley_row}
  1125. AND smiley_order > {int:smiley_order}',
  1126. array(
  1127. 'new_location' => $_GET['location'],
  1128. 'smiley_row' => $smiley_row,
  1129. 'smiley_order' => $smiley_order,
  1130. )
  1131. );
  1132. $smcFunc['db_query']('', '
  1133. UPDATE {db_prefix}smileys
  1134. SET
  1135. smiley_order = {int:smiley_order} + 1,
  1136. smiley_row = {int:smiley_row},
  1137. hidden = {int:new_location}
  1138. WHERE id_smiley = {int:current_smiley}',
  1139. array(
  1140. 'smiley_order' => $smiley_order,
  1141. 'smiley_row' => $smiley_row,
  1142. 'new_location' => $smileyLocation,
  1143. 'current_smiley' => $_GET['source'],
  1144. )
  1145. );
  1146. cache_put_data('parsing_smileys', null, 480);
  1147. cache_put_data('posting_smileys', null, 480);
  1148. }
  1149. $request = $smcFunc['db_query']('', '
  1150. SELECT id_smiley, code, filename, description, smiley_row, smiley_order, hidden
  1151. FROM {db_prefix}smileys
  1152. WHERE hidden != {int:popup}
  1153. ORDER BY smiley_order, smiley_row',
  1154. array(
  1155. 'popup' => 1,
  1156. )
  1157. );
  1158. $context['smileys'] = array(
  1159. 'postform' => array(
  1160. 'rows' => array(),
  1161. ),
  1162. 'popup' => array(
  1163. 'rows' => array(),
  1164. ),
  1165. );
  1166. while ($row = $smcFunc['db_fetch_assoc']($request))
  1167. {
  1168. $location = empty($row['hidden']) ? 'postform' : 'popup';
  1169. $context['smileys'][$location]['rows'][$row['smiley_row']][] = array(
  1170. 'id' => $row['id_smiley'],
  1171. 'code' => htmlspecialchars($row['code']),
  1172. 'filename' => htmlspecialchars($row['filename']),
  1173. 'description' => htmlspecialchars($row['description']),
  1174. 'row' => $row['smiley_row'],
  1175. 'order' => $row['smiley_order'],
  1176. 'selected' => !empty($_REQUEST['move']) && $_REQUEST['move'] == $row['id_smiley'],
  1177. );
  1178. }
  1179. $smcFunc['db_free_result']($request);
  1180. $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
  1181. // Make sure all rows are sequential.
  1182. foreach (array_keys($context['smileys']) as $location)
  1183. $context['smileys'][$location] = array(
  1184. 'id' => $location,
  1185. 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
  1186. 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
  1187. 'last_row' => count($context['smileys'][$location]['rows']),
  1188. 'rows' => array_values($context['smileys'][$location]['rows']),
  1189. );
  1190. // Check & fix smileys that are not ordered properly in the database.
  1191. foreach (array_keys($context['smileys']) as $location)
  1192. {
  1193. foreach ($context['smileys'][$location]['rows'] as $id => $smiley_row)
  1194. {
  1195. // Fix empty rows if any.
  1196. if ($id != $smiley_row[0]['row'])
  1197. {
  1198. $smcFunc['db_query']('', '
  1199. UPDATE {db_prefix}smileys
  1200. SET smiley_row = {int:new_row}
  1201. WHERE smiley_row = {int:current_row}
  1202. AND hidden = {int:location}',
  1203. array(
  1204. 'new_row' => $id,
  1205. 'current_row' => $smiley_row[0]['row'],
  1206. 'location' => $location == 'postform' ? '0' : '2',
  1207. )
  1208. );
  1209. // Only change the first row value of the first smiley (we don't need the others :P).
  1210. $context['smileys'][$location]['rows'][$id][0]['row'] = $id;
  1211. }
  1212. // Make sure the smiley order is always sequential.
  1213. foreach ($smiley_row as $order_id => $smiley)
  1214. if ($order_id != $smiley['order'])
  1215. $smcFunc['db_query']('', '
  1216. UPDATE {db_prefix}smileys
  1217. SET smiley_order = {int:new_order}
  1218. WHERE id_smiley = {int:current_smiley}',
  1219. array(
  1220. 'new_order' => $order_id,
  1221. 'current_smiley' => $smiley['id'],
  1222. )
  1223. );
  1224. }
  1225. }
  1226. cache_put_data('parsing_smileys', null, 480);
  1227. cache_put_data('posting_smileys', null, 480);
  1228. }
  1229. /**
  1230. * Install a smiley set.
  1231. */
  1232. function InstallSmileySet()
  1233. {
  1234. global $sourcedir, $boarddir, $modSettings, $smcFunc;
  1235. isAllowedTo('manage_smileys');
  1236. checkSession('request');
  1237. require_once($sourcedir . '/Subs-Package.php');
  1238. $name = strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.');
  1239. $name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
  1240. //@todo Decide: overwrite or not?
  1241. if (isset($_FILES['set_gz']) && is_uploaded_file($_FILES['set_gz']['tmp_name']) && (ini_get('open_basedir') != '' || file_exists($_FILES['set_gz']['tmp_name'])))
  1242. $extracted = read_tgz_file($_FILES['set_gz']['tmp_name'], $boarddir . '/Smileys/' . $name);
  1243. elseif (isset($_REQUEST['set_gz']))
  1244. {
  1245. // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
  1246. if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
  1247. fatal_lang_error('not_on_simplemachines');
  1248. $extracted = read_tgz_file($_REQUEST['set_gz'], $boarddir . '/Smileys/' . $name);
  1249. }
  1250. else
  1251. redirectexit('action=admin;area=smileys');
  1252. updateSettings(array(
  1253. 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $name,
  1254. 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.'),
  1255. ));
  1256. cache_put_data('parsing_smileys', null, 480);
  1257. cache_put_data('posting_smileys', null, 480);
  1258. // @todo Add some confirmation?
  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' => '[<a href="' . $scripturl . '?action=admin;area=smileys;sa=editicon">' . $txt['icons_add_new'] . '</a>] <input type="submit" name="delete" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit" />',
  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. ?>