ManageSmileys.php 58 KB

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