ManageSettings.php 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  1. <?php
  2. /**
  3. * This file is here to make it easier for installed mods to have
  4. * settings and options.
  5. *
  6. * Simple Machines Forum (SMF)
  7. *
  8. * @package SMF
  9. * @author Simple Machines http://www.simplemachines.org
  10. * @copyright 2011 Simple Machines
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version 2.1 Alpha 1
  14. */
  15. if (!defined('SMF'))
  16. die('Hacking attempt...');
  17. /**
  18. * This just avoids some repetition.
  19. *
  20. * @param array $subActions = array()
  21. * @param string $defaultAction = ''
  22. */
  23. function loadGeneralSettingParameters($subActions = array(), $defaultAction = '')
  24. {
  25. global $context, $txt, $sourcedir;
  26. // You need to be an admin to edit settings!
  27. isAllowedTo('admin_forum');
  28. loadLanguage('Help');
  29. loadLanguage('ManageSettings');
  30. // Will need the utility functions from here.
  31. require_once($sourcedir . '/ManageServer.php');
  32. $context['sub_template'] = 'show_settings';
  33. // By default do the basic settings.
  34. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($defaultAction) ? $defaultAction : array_pop($temp = array_keys($subActions)));
  35. $context['sub_action'] = $_REQUEST['sa'];
  36. }
  37. /**
  38. * This function passes control through to the relevant tab.
  39. */
  40. function ModifyFeatureSettings()
  41. {
  42. global $context, $txt, $scripturl, $modSettings, $settings;
  43. $context['page_title'] = $txt['modSettings_title'];
  44. $subActions = array(
  45. 'basic' => 'ModifyBasicSettings',
  46. 'layout' => 'ModifyLayoutSettings',
  47. 'karma' => 'ModifyKarmaSettings',
  48. 'sig' => 'ModifySignatureSettings',
  49. 'profile' => 'ShowCustomProfiles',
  50. 'profileedit' => 'EditCustomProfiles',
  51. );
  52. call_integration_hook('integrate_modify_features', array(&$subActions));
  53. // If Advanced Profile Fields are disabled don't show the setting page
  54. if (!in_array('cp', $context['admin_features']))
  55. unset($subActions['profile']);
  56. // Same for Karma
  57. if (!in_array('k', $context['admin_features']))
  58. unset($subActions['karma']);
  59. loadGeneralSettingParameters($subActions, 'basic');
  60. // Load up all the tabs...
  61. $context[$context['admin_menu_name']]['tab_data'] = array(
  62. 'title' => $txt['modSettings_title'],
  63. 'help' => 'featuresettings',
  64. 'description' => sprintf($txt['modSettings_desc'], $settings['theme_id'], $context['session_id'], $context['session_var']),
  65. 'tabs' => array(
  66. 'basic' => array(
  67. ),
  68. 'layout' => array(
  69. ),
  70. 'karma' => array(
  71. ),
  72. 'sig' => array(
  73. 'description' => $txt['signature_settings_desc'],
  74. ),
  75. 'profile' => array(
  76. 'description' => $txt['custom_profile_desc'],
  77. ),
  78. ),
  79. );
  80. // Call the right function for this sub-acton.
  81. $subActions[$_REQUEST['sa']]();
  82. }
  83. /**
  84. * This function passes control through to the relevant security tab.
  85. */
  86. function ModifySecuritySettings()
  87. {
  88. global $context, $txt, $scripturl, $modSettings, $settings;
  89. $context['page_title'] = $txt['admin_security_moderation'];
  90. $subActions = array(
  91. 'general' => 'ModifyGeneralSecuritySettings',
  92. 'spam' => 'ModifySpamSettings',
  93. 'moderation' => 'ModifyModerationSettings',
  94. );
  95. call_integration_hook('integrate_modify_security', array(&$subActions));
  96. // If Warning System is disabled don't show the setting page
  97. if (!in_array('w', $context['admin_features']))
  98. unset($subActions['moderation']);
  99. loadGeneralSettingParameters($subActions, 'general');
  100. // Load up all the tabs...
  101. $context[$context['admin_menu_name']]['tab_data'] = array(
  102. 'title' => $txt['admin_security_moderation'],
  103. 'help' => 'securitysettings',
  104. 'description' => $txt['security_settings_desc'],
  105. 'tabs' => array(
  106. 'general' => array(
  107. ),
  108. 'spam' => array(
  109. 'description' => $txt['antispam_Settings_desc'] ,
  110. ),
  111. 'moderation' => array(
  112. ),
  113. ),
  114. );
  115. // Call the right function for this sub-acton.
  116. $subActions[$_REQUEST['sa']]();
  117. }
  118. /**
  119. * This my friend, is for all the mod authors out there.
  120. */
  121. function ModifyModSettings()
  122. {
  123. global $context, $txt, $scripturl, $modSettings, $settings;
  124. $context['page_title'] = $txt['admin_modifications'];
  125. $subActions = array(
  126. 'hooks' => 'list_integration_hooks',
  127. 'general' => 'ModifyGeneralModSettings',
  128. // Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
  129. );
  130. // Make it easier for mods to add new areas.
  131. call_integration_hook('integrate_modify_modifications', array(&$subActions));
  132. loadGeneralSettingParameters($subActions, $context['hooks_exist'] ? 'hooks' : 'general');
  133. // Load up all the tabs...
  134. $context[$context['admin_menu_name']]['tab_data'] = array(
  135. 'title' => $txt['admin_modifications'],
  136. 'help' => 'modsettings',
  137. 'description' => $txt['modification_settings_desc'],
  138. 'tabs' => array(
  139. 'hooks' => array(
  140. ),
  141. 'general' => array(
  142. ),
  143. ),
  144. );
  145. // Call the right function for this sub-acton.
  146. $subActions[$_REQUEST['sa']]();
  147. }
  148. /**
  149. * This is an overall control panel enabling/disabling lots of SMF's key feature components.
  150. *
  151. * @param $return_config
  152. */
  153. function ModifyCoreFeatures($return_config = false)
  154. {
  155. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  156. /* This is an array of all the features that can be enabled/disabled - each option can have the following:
  157. title - Text title of this item (If standard string does not exist).
  158. desc - Description of this feature (If standard string does not exist).
  159. settings - Array of settings to change (For each name => value) on enable - reverse is done for disable. If > 1 will not change value if set.
  160. setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature.
  161. save_callback - Function called on save, takes state as parameter.
  162. */
  163. $core_features = array(
  164. // cd = calendar.
  165. 'cd' => array(
  166. 'url' => 'action=admin;area=managecalendar',
  167. 'settings' => array(
  168. 'cal_enabled' => 1,
  169. ),
  170. ),
  171. // cp = custom profile fields.
  172. 'cp' => array(
  173. 'url' => 'action=admin;area=featuresettings;sa=profile',
  174. 'save_callback' => create_function('$value', '
  175. global $smcFunc;
  176. if (!$value)
  177. {
  178. $smcFunc[\'db_query\'](\'\', \'
  179. UPDATE {db_prefix}custom_fields
  180. SET active = 0\');
  181. }
  182. '),
  183. 'setting_callback' => create_function('$value', '
  184. if (!$value)
  185. return array(
  186. \'disabled_profile_fields\' => \'\',
  187. \'registration_fields\' => \'\',
  188. \'displayFields\' => \'\',
  189. );
  190. else
  191. return array();
  192. '),
  193. ),
  194. // k = karma.
  195. 'k' => array(
  196. 'url' => 'action=admin;area=featuresettings;sa=karma',
  197. 'settings' => array(
  198. 'karmaMode' => 2,
  199. ),
  200. ),
  201. // ml = moderation log.
  202. 'ml' => array(
  203. 'url' => 'action=admin;area=logs;sa=modlog',
  204. 'settings' => array(
  205. 'modlog_enabled' => 1,
  206. ),
  207. ),
  208. // pm = post moderation.
  209. 'pm' => array(
  210. 'url' => 'action=admin;area=permissions;sa=postmod',
  211. 'setting_callback' => create_function('$value', '
  212. global $sourcedir;
  213. // Cant use warning post moderation if disabled!
  214. if (!$value)
  215. {
  216. require_once($sourcedir . \'/PostModeration.php\');
  217. approveAllData();
  218. return array(\'warning_moderate\' => 0);
  219. }
  220. else
  221. return array();
  222. '),
  223. ),
  224. // ps = Paid Subscriptions.
  225. 'ps' => array(
  226. 'url' => 'action=admin;area=paidsubscribe',
  227. 'settings' => array(
  228. 'paid_enabled' => 1,
  229. ),
  230. 'setting_callback' => create_function('$value', '
  231. global $smcFunc, $sourcedir;
  232. // Set the correct disabled value for scheduled task.
  233. $smcFunc[\'db_query\'](\'\', \'
  234. UPDATE {db_prefix}scheduled_tasks
  235. SET disabled = {int:disabled}
  236. WHERE task = {string:task}\',
  237. array(
  238. \'disabled\' => $value ? 0 : 1,
  239. \'task\' => \'paid_subscriptions\',
  240. )
  241. );
  242. // Should we calculate next trigger?
  243. if ($value)
  244. {
  245. require_once($sourcedir . \'/ScheduledTasks.php\');
  246. CalculateNextTrigger(\'paid_subscriptions\');
  247. }
  248. '),
  249. ),
  250. // rg = report generator.
  251. 'rg' => array(
  252. 'url' => 'action=admin;area=reports',
  253. ),
  254. // w = warning.
  255. 'w' => array(
  256. 'url' => 'action=admin;area=securitysettings;sa=moderation',
  257. 'setting_callback' => create_function('$value', '
  258. global $modSettings;
  259. list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']);
  260. $warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\'];
  261. if (!$value)
  262. {
  263. $returnSettings = array(
  264. \'warning_watch\' => 0,
  265. \'warning_moderate\' => 0,
  266. \'warning_mute\' => 0,
  267. );
  268. }
  269. elseif (empty($modSettings[\'warning_enable\']) && $value)
  270. {
  271. $returnSettings = array(
  272. \'warning_watch\' => 10,
  273. \'warning_moderate\' => 35,
  274. \'warning_mute\' => 60,
  275. );
  276. }
  277. else
  278. $returnSettings = array();
  279. $returnSettings[\'warning_settings\'] = $warning_settings;
  280. return $returnSettings;
  281. '),
  282. ),
  283. // Search engines
  284. 'sp' => array(
  285. 'url' => 'action=admin;area=sengines',
  286. 'settings' => array(
  287. 'spider_mode' => 1,
  288. ),
  289. 'setting_callback' => create_function('$value', '
  290. // Turn off the spider group if disabling.
  291. if (!$value)
  292. return array(\'spider_group\' => 0, \'show_spider_online\' => 0);
  293. '),
  294. 'on_save' => create_function('', '
  295. global $sourcedir, $modSettings;
  296. require_once($sourcedir . \'/ManageSearchEngines.php\');
  297. recacheSpiderNames();
  298. '),
  299. ),
  300. );
  301. // Anyone who would like to add a core feature?
  302. call_integration_hook('integrate_core_features', array(&$core_features));
  303. // Are we getting info for the help section.
  304. if ($return_config)
  305. {
  306. $return_data = array();
  307. foreach ($core_features as $id => $data)
  308. $return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]);
  309. return $return_data;
  310. }
  311. loadGeneralSettingParameters();
  312. // Are we saving?
  313. if (isset($_POST['save']))
  314. {
  315. checkSession();
  316. if (isset($_GET['xml']))
  317. {
  318. $tokenValidation = validateToken('admin-core', 'post', false);
  319. if (empty($tokenValidation))
  320. return 'token_verify_fail';
  321. }
  322. else
  323. validateToken('admin-core');
  324. $setting_changes = array('admin_features' => array());
  325. // Cycle each feature and change things as required!
  326. foreach ($core_features as $id => $feature)
  327. {
  328. // Enabled?
  329. if (!empty($_POST['feature_' . $id]))
  330. $setting_changes['admin_features'][] = $id;
  331. // Setting values to change?
  332. if (isset($feature['settings']))
  333. {
  334. foreach ($feature['settings'] as $key => $value)
  335. {
  336. if (empty($_POST['feature_' . $id]) || (!empty($_POST['feature_' . $id]) && ($value < 2 || empty($modSettings[$key]))))
  337. $setting_changes[$key] = !empty($_POST['feature_' . $id]) ? $value : !$value;
  338. }
  339. }
  340. // Is there a call back for settings?
  341. if (isset($feature['setting_callback']))
  342. {
  343. $returned_settings = $feature['setting_callback'](!empty($_POST['feature_' . $id]));
  344. if (!empty($returned_settings))
  345. $setting_changes = array_merge($setting_changes, $returned_settings);
  346. }
  347. // Standard save callback?
  348. if (isset($feature['on_save']))
  349. $feature['on_save']();
  350. }
  351. // Make sure this one setting is a string!
  352. $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']);
  353. // Make any setting changes!
  354. updateSettings($setting_changes);
  355. // This is needed to let menus appear if cache > 2
  356. clean_cache('data');
  357. // Any post save things?
  358. foreach ($core_features as $id => $feature)
  359. {
  360. // Standard save callback?
  361. if (isset($feature['save_callback']))
  362. $feature['save_callback'](!empty($_POST['feature_' . $id]));
  363. }
  364. if (!isset($_REQUEST['xml']))
  365. redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']);
  366. }
  367. // Put them in context.
  368. $context['features'] = array();
  369. foreach ($core_features as $id => $feature)
  370. $context['features'][$id] = array(
  371. 'title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id],
  372. 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'],
  373. 'enabled' => in_array($id, $context['admin_features']),
  374. 'state' => in_array($id, $context['admin_features']) ? 'on' : 'off',
  375. 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '',
  376. 'image' => (file_exists($settings['theme_dir'] . '/images/admin/feature_' . $id . '.png') ? $settings['images_url'] : $settings['default_images_url']) . '/admin/feature_' . $id . '.png',
  377. );
  378. // Are they a new user?
  379. $context['is_new_install'] = !isset($modSettings['admin_features']);
  380. $context['force_disable_tabs'] = $context['is_new_install'];
  381. // Don't show them this twice!
  382. if ($context['is_new_install'])
  383. updateSettings(array('admin_features' => ''));
  384. // sub_template is already generic_xml and the token is created somewhere else
  385. if (isset($_REQUEST['xml']))
  386. return;
  387. $context['sub_template'] = 'core_features';
  388. $context['page_title'] = $txt['core_settings_title'];
  389. // We love our tokens.
  390. createToken('admin-core');
  391. }
  392. /**
  393. *
  394. * @param $return_config
  395. */
  396. function ModifyBasicSettings($return_config = false)
  397. {
  398. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  399. $config_vars = array(
  400. // Big Options... polls, sticky, bbc....
  401. array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])),
  402. '',
  403. // Basic stuff, titles, flash, permissions...
  404. array('check', 'allow_guestAccess'),
  405. array('check', 'enable_buddylist'),
  406. array('check', 'allow_editDisplayName'),
  407. array('check', 'allow_hideOnline'),
  408. array('check', 'titlesEnable'),
  409. array('text', 'default_personal_text', 'subtext' => $txt['default_personal_text_note']),
  410. '',
  411. // Jquery source
  412. array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'])),
  413. '',
  414. // SEO stuff
  415. array('check', 'queryless_urls', 'subtext' => '<strong>' . $txt['queryless_urls_note'] . '</strong>'),
  416. array('text', 'meta_keywords', 'subtext' => $txt['meta_keywords_note'], 'size' => 50),
  417. '',
  418. // Number formatting, timezones.
  419. array('text', 'time_format'),
  420. array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']),
  421. 'default_timezone' => array('select', 'default_timezone', array()),
  422. '',
  423. // Who's online?
  424. array('check', 'who_enabled'),
  425. array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
  426. '',
  427. // Statistics.
  428. array('check', 'trackStats'),
  429. array('check', 'hitStats'),
  430. '',
  431. // Option-ish things... miscellaneous sorta.
  432. array('check', 'allow_disableAnnounce'),
  433. array('check', 'disallow_sendBody'),
  434. );
  435. // Get all the time zones.
  436. if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
  437. {
  438. $all_zones = timezone_identifiers_list();
  439. // Make sure we set the value to the same as the printed value.
  440. foreach ($all_zones as $zone)
  441. $config_vars['default_timezone'][2][$zone] = $zone;
  442. }
  443. else
  444. unset($config_vars['default_timezone']);
  445. call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
  446. if ($return_config)
  447. return $config_vars;
  448. // Saving?
  449. if (isset($_GET['save']))
  450. {
  451. checkSession();
  452. // Prevent absurd boundaries here - make it a day tops.
  453. if (isset($_POST['lastActive']))
  454. $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
  455. call_integration_hook('integrate_save_basic_settings');
  456. saveDBSettings($config_vars);
  457. writeLog();
  458. redirectexit('action=admin;area=featuresettings;sa=basic');
  459. }
  460. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
  461. $context['settings_title'] = $txt['mods_cat_features'];
  462. prepareDBSettingContext($config_vars);
  463. }
  464. /**
  465. * Settings really associated with general security aspects.
  466. *
  467. * @param $return_config
  468. */
  469. function ModifyGeneralSecuritySettings($return_config = false)
  470. {
  471. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  472. $config_vars = array(
  473. array('check', 'guest_hideContacts'),
  474. array('check', 'make_email_viewable'),
  475. '',
  476. array('int', 'failed_login_threshold'),
  477. array('int', 'loginHistoryDays'),
  478. '',
  479. array('check', 'enableErrorLogging'),
  480. array('check', 'enableErrorQueryLogging'),
  481. '',
  482. array('check', 'securityDisable'),
  483. array('check', 'securityDisable_moderate'),
  484. '',
  485. // Reactive on email, and approve on delete
  486. array('check', 'send_validation_onChange'),
  487. array('check', 'approveAccountDeletion'),
  488. '',
  489. // Password strength.
  490. array('select', 'password_strength', array($txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high'])),
  491. '',
  492. // Reporting of personal messages?
  493. array('check', 'enableReportPM'),
  494. );
  495. call_integration_hook('integrate_general_security_settings', array(&$config_vars));
  496. if ($return_config)
  497. return $config_vars;
  498. // Saving?
  499. if (isset($_GET['save']))
  500. {
  501. checkSession();
  502. saveDBSettings($config_vars);
  503. call_integration_hook('integrate_save_general_security_settings');
  504. writeLog();
  505. redirectexit('action=admin;area=securitysettings;sa=general');
  506. }
  507. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=general';
  508. $context['settings_title'] = $txt['mods_cat_security_general'];
  509. prepareDBSettingContext($config_vars);
  510. }
  511. /**
  512. *
  513. * @param $return_config
  514. */
  515. function ModifyLayoutSettings($return_config = false)
  516. {
  517. global $txt, $scripturl, $context, $settings, $sc;
  518. $config_vars = array(
  519. // Pagination stuff.
  520. array('check', 'compactTopicPagesEnable'),
  521. array('int', 'compactTopicPagesContiguous', null, $txt['contiguous_page_display'] . '<div class="smalltext">' . str_replace(' ', '&nbsp;', '"3" ' . $txt['to_display'] . ': <strong>1 ... 4 [5] 6 ... 9</strong>') . '<br />' . str_replace(' ', '&nbsp;', '"5" ' . $txt['to_display'] . ': <strong>1 ... 3 4 [5] 6 7 ... 9</strong>') . '</div>'),
  522. array('int', 'defaultMaxMembers'),
  523. '',
  524. // Stuff that just is everywhere - today, search, online, etc.
  525. array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])),
  526. array('check', 'topbottomEnable'),
  527. array('check', 'onlineEnable'),
  528. array('check', 'enableVBStyleLogin'),
  529. '',
  530. // Automagic image resizing.
  531. array('int', 'max_image_width'),
  532. array('int', 'max_image_height'),
  533. '',
  534. // This is like debugging sorta.
  535. array('check', 'timeLoadPageEnable'),
  536. );
  537. call_integration_hook('integrate_layout_settings', array(&$config_vars));
  538. if ($return_config)
  539. return $config_vars;
  540. // Saving?
  541. if (isset($_GET['save']))
  542. {
  543. checkSession();
  544. call_integration_hook('integrate_save_layout_settings');
  545. saveDBSettings($config_vars);
  546. writeLog();
  547. redirectexit('action=admin;area=featuresettings;sa=layout');
  548. }
  549. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
  550. $context['settings_title'] = $txt['mods_cat_layout'];
  551. prepareDBSettingContext($config_vars);
  552. }
  553. /**
  554. *
  555. * @param $return_config
  556. */
  557. function ModifyKarmaSettings($return_config = false)
  558. {
  559. global $txt, $scripturl, $context, $settings, $sc;
  560. $config_vars = array(
  561. // Karma - On or off?
  562. array('select', 'karmaMode', explode('|', $txt['karma_options'])),
  563. '',
  564. // Who can do it.... and who is restricted by time limits?
  565. array('int', 'karmaMinPosts', 6, 'postinput' => strtolower($txt['posts'])),
  566. array('float', 'karmaWaitTime', 6, 'postinput' => $txt['hours']),
  567. array('check', 'karmaTimeRestrictAdmins'),
  568. '',
  569. // What does it look like? [smite]?
  570. array('text', 'karmaLabel'),
  571. array('text', 'karmaApplaudLabel'),
  572. array('text', 'karmaSmiteLabel'),
  573. );
  574. call_integration_hook('integrate_karma_settings', array(&$config_vars));
  575. if ($return_config)
  576. return $config_vars;
  577. // Saving?
  578. if (isset($_GET['save']))
  579. {
  580. checkSession();
  581. call_integration_hook('integrate_save_karma_settings');
  582. saveDBSettings($config_vars);
  583. redirectexit('action=admin;area=featuresettings;sa=karma');
  584. }
  585. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=karma';
  586. $context['settings_title'] = $txt['karma'];
  587. prepareDBSettingContext($config_vars);
  588. }
  589. /**
  590. * Moderation type settings - although there are fewer than we have you believe ;)
  591. *
  592. * @param bool $return_config = false
  593. */
  594. function ModifyModerationSettings($return_config = false)
  595. {
  596. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  597. $config_vars = array(
  598. // Warning system?
  599. array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'], 'help' => 'warning_enable'),
  600. 'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note']),
  601. array('int', 'warning_mute', 'subtext' => $txt['setting_warning_mute_note']),
  602. 'rem1' => array('int', 'user_limit', 'subtext' => $txt['setting_user_limit_note']),
  603. 'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note']),
  604. array('select', 'warning_show', 'subtext' => $txt['setting_warning_show_note'], array($txt['setting_warning_show_mods'], $txt['setting_warning_show_user'], $txt['setting_warning_show_all'])),
  605. );
  606. call_integration_hook('integrate_moderation_settings', array(&$config_vars));
  607. if ($return_config)
  608. return $config_vars;
  609. // Cannot use moderation if post moderation is not enabled.
  610. if (!$modSettings['postmod_active'])
  611. unset($config_vars['moderate']);
  612. // Saving?
  613. if (isset($_GET['save']))
  614. {
  615. checkSession();
  616. // Make sure these don't have an effect.
  617. if (substr($modSettings['warning_settings'], 0, 1) != 1)
  618. {
  619. $_POST['warning_watch'] = 0;
  620. $_POST['warning_moderate'] = 0;
  621. $_POST['warning_mute'] = 0;
  622. }
  623. else
  624. {
  625. $_POST['warning_watch'] = min($_POST['warning_watch'], 100);
  626. $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
  627. $_POST['warning_mute'] = min($_POST['warning_mute'], 100);
  628. }
  629. // Fix the warning setting array!
  630. $_POST['warning_settings'] = '1,' . min(100, (int) $_POST['user_limit']) . ',' . min(100, (int) $_POST['warning_decrement']);
  631. $save_vars = $config_vars;
  632. $save_vars[] = array('text', 'warning_settings');
  633. unset($save_vars['rem1'], $save_vars['rem2']);
  634. call_integration_hook('integrate_save_karma_settings', array(&$save_vars));
  635. saveDBSettings($save_vars);
  636. redirectexit('action=admin;area=securitysettings;sa=moderation');
  637. }
  638. // We actually store lots of these together - for efficiency.
  639. list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
  640. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=moderation';
  641. $context['settings_title'] = $txt['moderation_settings'];
  642. prepareDBSettingContext($config_vars);
  643. }
  644. /**
  645. * Let's try keep the spam to a minimum ah Thantos?
  646. * @param bool $return_config = false
  647. */
  648. function ModifySpamSettings($return_config = false)
  649. {
  650. global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc;
  651. // Generate a sample registration image.
  652. $context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
  653. $context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
  654. $config_vars = array(
  655. array('check', 'reg_verification'),
  656. array('check', 'search_enable_captcha'),
  657. // This, my friend, is a cheat :p
  658. 'guest_verify' => array('check', 'guests_require_captcha', 'subtext' => $txt['setting_guests_require_captcha_desc']),
  659. array('int', 'posts_require_captcha', 'subtext' => $txt['posts_require_captcha_desc'], 'onchange' => 'if (this.value > 0){ document.getElementById(\'guests_require_captcha\').checked = true; document.getElementById(\'guests_require_captcha\').disabled = true;} else {document.getElementById(\'guests_require_captcha\').disabled = false;}'),
  660. array('check', 'guests_report_require_captcha'),
  661. '',
  662. // PM Settings
  663. 'pm1' => array('int', 'max_pm_recipients', 'subtext' => $txt['max_pm_recipients_note']),
  664. 'pm2' => array('int', 'pm_posts_verification', 'subtext' => $txt['pm_posts_verification_note']),
  665. 'pm3' => array('int', 'pm_posts_per_hour', 'subtext' => $txt['pm_posts_per_hour_note']),
  666. // Visual verification.
  667. array('title', 'configure_verification_means'),
  668. array('desc', 'configure_verification_means_desc'),
  669. 'vv' => array('select', 'visual_verification_type', array($txt['setting_image_verification_off'], $txt['setting_image_verification_vsimple'], $txt['setting_image_verification_simple'], $txt['setting_image_verification_medium'], $txt['setting_image_verification_high'], $txt['setting_image_verification_extreme']), 'subtext'=> $txt['setting_visual_verification_type_desc'], 'onchange' => $context['use_graphic_library'] ? 'refreshImages();' : ''),
  670. // Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say.
  671. array('title', 'setup_verification_questions'),
  672. array('desc', 'setup_verification_questions_desc'),
  673. array('int', 'qa_verification_number', 'subtext' => $txt['setting_qa_verification_number_desc']),
  674. array('callback', 'question_answer_list'),
  675. );
  676. call_integration_hook('integrate_spam_settings', array(&$config_vars));
  677. if ($return_config)
  678. return $config_vars;
  679. // Load any question and answers!
  680. $context['question_answers'] = array();
  681. $request = $smcFunc['db_query']('', '
  682. SELECT id_comment, body AS question, recipient_name AS answer
  683. FROM {db_prefix}log_comments
  684. WHERE comment_type = {string:ver_test}',
  685. array(
  686. 'ver_test' => 'ver_test',
  687. )
  688. );
  689. while ($row = $smcFunc['db_fetch_assoc']($request))
  690. {
  691. $context['question_answers'][$row['id_comment']] = array(
  692. 'id' => $row['id_comment'],
  693. 'question' => $row['question'],
  694. 'answer' => $row['answer'],
  695. );
  696. }
  697. $smcFunc['db_free_result']($request);
  698. // Saving?
  699. if (isset($_GET['save']))
  700. {
  701. checkSession();
  702. // Fix PM settings.
  703. $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
  704. // Hack in guest requiring verification!
  705. if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
  706. $_POST['posts_require_captcha'] = -1;
  707. $save_vars = $config_vars;
  708. unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
  709. $save_vars[] = array('text', 'pm_spam_settings');
  710. // Handle verification questions.
  711. $questionInserts = array();
  712. $count_questions = 0;
  713. foreach ($_POST['question'] as $id => $question)
  714. {
  715. $question = trim($smcFunc['htmlspecialchars']($question, ENT_COMPAT, $context['character_set']));
  716. $answer = trim($smcFunc['strtolower']($smcFunc['htmlspecialchars']($_POST['answer'][$id], ENT_COMPAT, $context['character_set'])));
  717. // Already existed?
  718. if (isset($context['question_answers'][$id]))
  719. {
  720. $count_questions++;
  721. // Changed?
  722. if ($context['question_answers'][$id]['question'] != $question || $context['question_answers'][$id]['answer'] != $answer)
  723. {
  724. if ($question == '' || $answer == '')
  725. {
  726. $smcFunc['db_query']('', '
  727. DELETE FROM {db_prefix}log_comments
  728. WHERE comment_type = {string:ver_test}
  729. AND id_comment = {int:id}',
  730. array(
  731. 'id' => $id,
  732. 'ver_test' => 'ver_test',
  733. )
  734. );
  735. $count_questions--;
  736. }
  737. else
  738. $request = $smcFunc['db_query']('', '
  739. UPDATE {db_prefix}log_comments
  740. SET body = {string:question}, recipient_name = {string:answer}
  741. WHERE comment_type = {string:ver_test}
  742. AND id_comment = {int:id}',
  743. array(
  744. 'id' => $id,
  745. 'ver_test' => 'ver_test',
  746. 'question' => $question,
  747. 'answer' => $answer,
  748. )
  749. );
  750. }
  751. }
  752. // It's so shiney and new!
  753. elseif ($question != '' && $answer != '')
  754. {
  755. $questionInserts[] = array(
  756. 'comment_type' => 'ver_test',
  757. 'body' => $question,
  758. 'recipient_name' => $answer,
  759. );
  760. }
  761. }
  762. // Any questions to insert?
  763. if (!empty($questionInserts))
  764. {
  765. $smcFunc['db_insert']('',
  766. '{db_prefix}log_comments',
  767. array('comment_type' => 'string', 'body' => 'string-65535', 'recipient_name' => 'string-80'),
  768. $questionInserts,
  769. array('id_comment')
  770. );
  771. $count_questions++;
  772. }
  773. if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
  774. $_POST['qa_verification_number'] = $count_questions;
  775. call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
  776. // Now save.
  777. saveDBSettings($save_vars);
  778. cache_put_data('verificationQuestionIds', null, 300);
  779. redirectexit('action=admin;area=securitysettings;sa=spam');
  780. }
  781. $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
  782. $_SESSION['visual_verification_code'] = '';
  783. for ($i = 0; $i < 6; $i++)
  784. $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
  785. // Some javascript for CAPTCHA.
  786. $context['settings_post_javascript'] = '';
  787. if ($context['use_graphic_library'])
  788. $context['settings_post_javascript'] .= '
  789. function refreshImages()
  790. {
  791. var imageType = document.getElementById(\'visual_verification_type\').value;
  792. document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
  793. }';
  794. // Show the image itself, or text saying we can't.
  795. if ($context['use_graphic_library'])
  796. $config_vars['vv']['postinput'] = '<br /><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image" /><br />';
  797. else
  798. $config_vars['vv']['postinput'] = '<br /><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
  799. // Hack for PM spam settings.
  800. list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
  801. // Hack for guests requiring verification.
  802. $modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']);
  803. $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
  804. // Some minor javascript for the guest post setting.
  805. if ($modSettings['posts_require_captcha'])
  806. $context['settings_post_javascript'] .= '
  807. document.getElementById(\'guests_require_captcha\').disabled = true;';
  808. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=spam';
  809. $context['settings_title'] = $txt['antispam_Settings'];
  810. prepareDBSettingContext($config_vars);
  811. }
  812. /**
  813. * You'll never guess what this function does...
  814. *
  815. * @param $return_config
  816. */
  817. function ModifySignatureSettings($return_config = false)
  818. {
  819. global $context, $txt, $modSettings, $sig_start, $smcFunc, $helptxt, $scripturl;
  820. $config_vars = array(
  821. // Are signatures even enabled?
  822. array('check', 'signature_enable'),
  823. '',
  824. // Tweaking settings!
  825. array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
  826. array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
  827. array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
  828. array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
  829. array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
  830. '',
  831. // Image settings.
  832. array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
  833. array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
  834. array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
  835. '',
  836. array('bbc', 'signature_bbc'),
  837. );
  838. call_integration_hook('integrate_signature_settings', array(&$config_vars));
  839. if ($return_config)
  840. return $config_vars;
  841. // Setup the template.
  842. $context['page_title'] = $txt['signature_settings'];
  843. $context['sub_template'] = 'show_settings';
  844. // Disable the max smileys option if we don't allow smileys at all!
  845. $context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;';
  846. // Load all the signature settings.
  847. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  848. $sig_limits = explode(',', $sig_limits);
  849. $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
  850. // Applying to ALL signatures?!!
  851. if (isset($_GET['apply']))
  852. {
  853. // Security!
  854. checkSession('get');
  855. $sig_start = time();
  856. // This is horrid - but I suppose some people will want the option to do it.
  857. $_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
  858. $done = false;
  859. $request = $smcFunc['db_query']('', '
  860. SELECT MAX(id_member)
  861. FROM {db_prefix}members',
  862. array(
  863. )
  864. );
  865. list ($context['max_member']) = $smcFunc['db_fetch_row']($request);
  866. $smcFunc['db_free_result']($request);
  867. while (!$done)
  868. {
  869. $changes = array();
  870. $request = $smcFunc['db_query']('', '
  871. SELECT id_member, signature
  872. FROM {db_prefix}members
  873. WHERE id_member BETWEEN ' . $_GET['step'] . ' AND ' . $_GET['step'] . ' + 49
  874. AND id_group != {int:admin_group}
  875. AND FIND_IN_SET({int:admin_group}, additional_groups) = 0',
  876. array(
  877. 'admin_group' => 1,
  878. )
  879. );
  880. while ($row = $smcFunc['db_fetch_assoc']($request))
  881. {
  882. // Apply all the rules we can realistically do.
  883. $sig = strtr($row['signature'], array('<br />' => "\n"));
  884. // Max characters...
  885. if (!empty($sig_limits[1]))
  886. $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
  887. // Max lines...
  888. if (!empty($sig_limits[2]))
  889. {
  890. $count = 0;
  891. for ($i = 0; $i < strlen($sig); $i++)
  892. {
  893. if ($sig[$i] == "\n")
  894. {
  895. $count++;
  896. if ($count >= $sig_limits[2])
  897. $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
  898. }
  899. }
  900. }
  901. if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2]))
  902. {
  903. foreach ($matches[1] as $ind => $size)
  904. {
  905. $limit_broke = 0;
  906. // Attempt to allow all sizes of abuse, so to speak.
  907. if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
  908. $limit_broke = $sig_limits[7] . 'px';
  909. elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
  910. $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
  911. elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
  912. $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
  913. elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
  914. $limit_broke = 'large';
  915. if ($limit_broke)
  916. $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
  917. }
  918. }
  919. // Stupid images - this is stupidly, stupidly challenging.
  920. if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6])))
  921. {
  922. $replaces = array();
  923. $img_count = 0;
  924. // Get all BBC tags...
  925. preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br />)*([^<">]+?)(?:<br />)*\[/img\]~i', $sig, $matches);
  926. // ... and all HTML ones.
  927. preg_match_all('~&lt;img\s+src=(?:&quot;)?((?:http://|ftp://|https://|ftps://).+?)(?:&quot;)?(?:\s+alt=(?:&quot;)?(.*?)(?:&quot;)?)?(?:\s?/)?&gt;~i', $sig, $matches2, PREG_PATTERN_ORDER);
  928. // And stick the HTML in the BBC.
  929. if (!empty($matches2))
  930. {
  931. foreach ($matches2[0] as $ind => $dummy)
  932. {
  933. $matches[0][] = $matches2[0][$ind];
  934. $matches[1][] = '';
  935. $matches[2][] = '';
  936. $matches[3][] = '';
  937. $matches[4][] = '';
  938. $matches[5][] = '';
  939. $matches[6][] = '';
  940. $matches[7][] = $matches2[1][$ind];
  941. }
  942. }
  943. // Try to find all the images!
  944. if (!empty($matches))
  945. {
  946. $image_count_holder = array();
  947. foreach ($matches[0] as $key => $image)
  948. {
  949. $width = -1; $height = -1;
  950. $img_count++;
  951. // Too many images?
  952. if (!empty($sig_limits[3]) && $img_count > $sig_limits[3])
  953. {
  954. // If we've already had this before we only want to remove the excess.
  955. if (isset($image_count_holder[$image]))
  956. {
  957. $img_offset = -1;
  958. $rep_img_count = 0;
  959. while ($img_offset !== false)
  960. {
  961. $img_offset = strpos($sig, $image, $img_offset + 1);
  962. $rep_img_count++;
  963. if ($rep_img_count > $image_count_holder[$image])
  964. {
  965. // Only replace the excess.
  966. $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
  967. // Stop looping.
  968. $img_offset = false;
  969. }
  970. }
  971. }
  972. else
  973. $replaces[$image] = '';
  974. continue;
  975. }
  976. // Does it have predefined restraints? Width first.
  977. if ($matches[6][$key])
  978. $matches[2][$key] = $matches[6][$key];
  979. if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
  980. {
  981. $width = $sig_limits[5];
  982. $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
  983. }
  984. elseif ($matches[2][$key])
  985. $width = $matches[2][$key];
  986. // ... and height.
  987. if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
  988. {
  989. $height = $sig_limits[6];
  990. if ($width != -1)
  991. $width = $width * ($height / $matches[4][$key]);
  992. }
  993. elseif ($matches[4][$key])
  994. $height = $matches[4][$key];
  995. // If the dimensions are still not fixed - we need to check the actual image.
  996. if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
  997. {
  998. $sizes = url_image_size($matches[7][$key]);
  999. if (is_array($sizes))
  1000. {
  1001. // Too wide?
  1002. if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
  1003. {
  1004. $width = $sig_limits[5];
  1005. $sizes[1] = $sizes[1] * ($width / $sizes[0]);
  1006. }
  1007. // Too high?
  1008. if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
  1009. {
  1010. $height = $sig_limits[6];
  1011. if ($width == -1)
  1012. $width = $sizes[0];
  1013. $width = $width * ($height / $sizes[1]);
  1014. }
  1015. elseif ($width != -1)
  1016. $height = $sizes[1];
  1017. }
  1018. }
  1019. // Did we come up with some changes? If so remake the string.
  1020. if ($width != -1 || $height != -1)
  1021. {
  1022. $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
  1023. }
  1024. // Record that we got one.
  1025. $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
  1026. }
  1027. if (!empty($replaces))
  1028. $sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
  1029. }
  1030. }
  1031. // Try to fix disabled tags.
  1032. if (!empty($disabledTags))
  1033. {
  1034. $sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig);
  1035. $sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig);
  1036. }
  1037. $sig = strtr($sig, array("\n" => '<br />'));
  1038. call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
  1039. if ($sig != $row['signature'])
  1040. $changes[$row['id_member']] = $sig;
  1041. }
  1042. if ($smcFunc['db_num_rows']($request) == 0)
  1043. $done = true;
  1044. $smcFunc['db_free_result']($request);
  1045. // Do we need to delete what we have?
  1046. if (!empty($changes))
  1047. {
  1048. foreach ($changes as $id => $sig)
  1049. $smcFunc['db_query']('', '
  1050. UPDATE {db_prefix}members
  1051. SET signature = {string:signature}
  1052. WHERE id_member = {int:id_member}',
  1053. array(
  1054. 'id_member' => $id,
  1055. 'signature' => $sig,
  1056. )
  1057. );
  1058. }
  1059. $_GET['step'] += 50;
  1060. if (!$done)
  1061. pauseSignatureApplySettings();
  1062. }
  1063. }
  1064. $context['signature_settings'] = array(
  1065. 'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
  1066. 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
  1067. 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
  1068. 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
  1069. 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
  1070. 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
  1071. 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
  1072. 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
  1073. 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
  1074. );
  1075. // Temporarily make each setting a modSetting!
  1076. foreach ($context['signature_settings'] as $key => $value)
  1077. $modSettings['signature_' . $key] = $value;
  1078. // Make sure we check the right tags!
  1079. $modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
  1080. // Saving?
  1081. if (isset($_GET['save']))
  1082. {
  1083. checkSession();
  1084. // Clean up the tag stuff!
  1085. $bbcTags = array();
  1086. foreach (parse_bbc(false) as $tag)
  1087. $bbcTags[] = $tag['tag'];
  1088. if (!isset($_POST['signature_bbc_enabledTags']))
  1089. $_POST['signature_bbc_enabledTags'] = array();
  1090. elseif (!is_array($_POST['signature_bbc_enabledTags']))
  1091. $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
  1092. $sig_limits = array();
  1093. foreach ($context['signature_settings'] as $key => $value)
  1094. {
  1095. if ($key == 'allow_smileys')
  1096. continue;
  1097. elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
  1098. $sig_limits[] = -1;
  1099. else
  1100. $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
  1101. }
  1102. call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
  1103. $_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags']));
  1104. // Even though we have practically no settings let's keep the convention going!
  1105. $save_vars = array();
  1106. $save_vars[] = array('text', 'signature_settings');
  1107. saveDBSettings($save_vars);
  1108. redirectexit('action=admin;area=featuresettings;sa=sig');
  1109. }
  1110. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
  1111. $context['settings_title'] = $txt['signature_settings'];
  1112. $context['settings_message'] = '<p class="centertext">' . sprintf($txt['signature_settings_warning'], $context['session_id'], $context['session_var']) . '</p>';
  1113. prepareDBSettingContext($config_vars);
  1114. }
  1115. /**
  1116. * Just pause the signature applying thing.
  1117. */
  1118. function pauseSignatureApplySettings()
  1119. {
  1120. global $context, $txt, $sig_start;
  1121. // Try get more time...
  1122. @set_time_limit(600);
  1123. if (function_exists('apache_reset_timeout'))
  1124. @apache_reset_timeout();
  1125. // Have we exhausted all the time we allowed?
  1126. if (time() - array_sum(explode(' ', $sig_start)) < 3)
  1127. return;
  1128. $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
  1129. $context['page_title'] = $txt['not_done_title'];
  1130. $context['continue_post_data'] = '';
  1131. $context['continue_countdown'] = '2';
  1132. $context['sub_template'] = 'not_done';
  1133. // Specific stuff to not break this template!
  1134. $context[$context['admin_menu_name']]['current_subsection'] = 'sig';
  1135. // Get the right percent.
  1136. $context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100);
  1137. // Never more than 100%!
  1138. $context['continue_percent'] = min($context['continue_percent'], 100);
  1139. obExit();
  1140. }
  1141. /**
  1142. * Show all the custom profile fields available to the user.
  1143. */
  1144. function ShowCustomProfiles()
  1145. {
  1146. global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
  1147. global $modSettings, $sourcedir;
  1148. $context['page_title'] = $txt['custom_profile_title'];
  1149. $context['sub_template'] = 'show_custom_profile';
  1150. // What about standard fields they can tweak?
  1151. $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website', 'posts', 'warning_status');
  1152. // What fields can't you put on the registration page?
  1153. $context['fields_no_registration'] = array('posts', 'warning_status');
  1154. // Are we saving any standard field changes?
  1155. if (isset($_POST['save']))
  1156. {
  1157. checkSession();
  1158. validateToken('admin-scp');
  1159. // Do the active ones first.
  1160. $disable_fields = array_flip($standard_fields);
  1161. if (!empty($_POST['active']))
  1162. {
  1163. foreach ($_POST['active'] as $value)
  1164. if (isset($disable_fields[$value]))
  1165. unset($disable_fields[$value]);
  1166. }
  1167. // What we have left!
  1168. $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
  1169. // Things we want to show on registration?
  1170. $reg_fields = array();
  1171. if (!empty($_POST['reg']))
  1172. {
  1173. foreach ($_POST['reg'] as $value)
  1174. if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
  1175. $reg_fields[] = $value;
  1176. }
  1177. // What we have left!
  1178. $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
  1179. if (!empty($changes))
  1180. updateSettings($changes);
  1181. }
  1182. createToken('admin-scp');
  1183. require_once($sourcedir . '/Subs-List.php');
  1184. $listOptions = array(
  1185. 'id' => 'standard_profile_fields',
  1186. 'title' => $txt['standard_profile_title'],
  1187. 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1188. 'get_items' => array(
  1189. 'function' => 'list_getProfileFields',
  1190. 'params' => array(
  1191. true,
  1192. ),
  1193. ),
  1194. 'columns' => array(
  1195. 'field' => array(
  1196. 'header' => array(
  1197. 'value' => $txt['standard_profile_field'],
  1198. 'style' => 'text-align: left;',
  1199. ),
  1200. 'data' => array(
  1201. 'db' => 'label',
  1202. 'style' => 'width: 60%;',
  1203. ),
  1204. ),
  1205. 'active' => array(
  1206. 'header' => array(
  1207. 'value' => $txt['custom_edit_active'],
  1208. ),
  1209. 'data' => array(
  1210. 'function' => create_function('$rowData', '
  1211. $isChecked = $rowData[\'disabled\'] ? \'\' : \' checked="checked"\';
  1212. $onClickHandler = $rowData[\'can_show_register\'] ? sprintf(\'onclick="document.getElementById(\\\'reg_%1$s\\\').disabled = !this.checked;"\', $rowData[\'id\']) : \'\';
  1213. return sprintf(\'<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" class="input_check"%2$s%3$s />\', $rowData[\'id\'], $isChecked, $onClickHandler);
  1214. '),
  1215. 'style' => 'width: 20%; text-align: center;',
  1216. ),
  1217. ),
  1218. 'show_on_registration' => array(
  1219. 'header' => array(
  1220. 'value' => $txt['custom_edit_registration'],
  1221. ),
  1222. 'data' => array(
  1223. 'function' => create_function('$rowData', '
  1224. $isChecked = $rowData[\'on_register\'] && !$rowData[\'disabled\'] ? \' checked="checked"\' : \'\';
  1225. $isDisabled = $rowData[\'can_show_register\'] ? \'\' : \' disabled="disabled"\';
  1226. return sprintf(\'<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" class="input_check"%2$s%3$s />\', $rowData[\'id\'], $isChecked, $isDisabled);
  1227. '),
  1228. 'style' => 'width: 20%; text-align: center;',
  1229. ),
  1230. ),
  1231. ),
  1232. 'form' => array(
  1233. 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1234. 'name' => 'standardProfileFields',
  1235. 'token' => 'admin-scp',
  1236. ),
  1237. 'additional_rows' => array(
  1238. array(
  1239. 'position' => 'below_table_data',
  1240. 'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />',
  1241. 'style' => 'text-align: right;',
  1242. ),
  1243. ),
  1244. );
  1245. createList($listOptions);
  1246. $listOptions = array(
  1247. 'id' => 'custom_profile_fields',
  1248. 'title' => $txt['custom_profile_title'],
  1249. 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1250. 'default_sort_col' => 'field_name',
  1251. 'no_items_label' => $txt['custom_profile_none'],
  1252. 'items_per_page' => 25,
  1253. 'get_items' => array(
  1254. 'function' => 'list_getProfileFields',
  1255. 'params' => array(
  1256. false,
  1257. ),
  1258. ),
  1259. 'get_count' => array(
  1260. 'function' => 'list_getProfileFieldSize',
  1261. ),
  1262. 'columns' => array(
  1263. 'field_name' => array(
  1264. 'header' => array(
  1265. 'value' => $txt['custom_profile_fieldname'],
  1266. 'style' => 'text-align: left;',
  1267. ),
  1268. 'data' => array(
  1269. 'function' => create_function('$rowData', '
  1270. global $scripturl;
  1271. return sprintf(\'<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>\', $scripturl, $rowData[\'id_field\'], $rowData[\'field_name\'], $rowData[\'field_desc\']);
  1272. '),
  1273. 'style' => 'width: 62%;',
  1274. ),
  1275. 'sort' => array(
  1276. 'default' => 'field_name',
  1277. 'reverse' => 'field_name DESC',
  1278. ),
  1279. ),
  1280. 'field_type' => array(
  1281. 'header' => array(
  1282. 'value' => $txt['custom_profile_fieldtype'],
  1283. 'style' => 'text-align: left;',
  1284. ),
  1285. 'data' => array(
  1286. 'function' => create_function('$rowData', '
  1287. global $txt;
  1288. $textKey = sprintf(\'custom_profile_type_%1$s\', $rowData[\'field_type\']);
  1289. return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
  1290. '),
  1291. 'style' => 'width: 15%;',
  1292. ),
  1293. 'sort' => array(
  1294. 'default' => 'field_type',
  1295. 'reverse' => 'field_type DESC',
  1296. ),
  1297. ),
  1298. 'active' => array(
  1299. 'header' => array(
  1300. 'value' => $txt['custom_profile_active'],
  1301. ),
  1302. 'data' => array(
  1303. 'function' => create_function('$rowData', '
  1304. global $txt;
  1305. return $rowData[\'active\'] ? $txt[\'yes\'] : $txt[\'no\'];
  1306. '),
  1307. 'style' => 'width: 8%; text-align: center;',
  1308. ),
  1309. 'sort' => array(
  1310. 'default' => 'active DESC',
  1311. 'reverse' => 'active',
  1312. ),
  1313. ),
  1314. 'placement' => array(
  1315. 'header' => array(
  1316. 'value' => $txt['custom_profile_placement'],
  1317. ),
  1318. 'data' => array(
  1319. 'function' => create_function('$rowData', '
  1320. global $txt;
  1321. return $txt[\'custom_profile_placement_\' . (empty($rowData[\'placement\']) ? \'standard\' : ($rowData[\'placement\'] == 1 ? \'withicons\' : \'abovesignature\'))];
  1322. '),
  1323. 'style' => 'width: 8%; text-align: center;',
  1324. ),
  1325. 'sort' => array(
  1326. 'default' => 'placement DESC',
  1327. 'reverse' => 'placement',
  1328. ),
  1329. ),
  1330. 'show_on_registration' => array(
  1331. 'header' => array(
  1332. 'value' => $txt['modify'],
  1333. ),
  1334. 'data' => array(
  1335. 'sprintf' => array(
  1336. 'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
  1337. 'params' => array(
  1338. 'id_field' => false,
  1339. ),
  1340. ),
  1341. 'style' => 'width: 15%; text-align: center;',
  1342. ),
  1343. ),
  1344. ),
  1345. 'form' => array(
  1346. 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
  1347. 'name' => 'customProfileFields',
  1348. ),
  1349. 'additional_rows' => array(
  1350. array(
  1351. 'position' => 'below_table_data',
  1352. 'value' => '<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="button_submit" />',
  1353. 'style' => 'text-align: right;',
  1354. ),
  1355. ),
  1356. );
  1357. createList($listOptions);
  1358. }
  1359. /**
  1360. * Callback for createList().
  1361. *
  1362. * @param $start
  1363. * @param $items_per_page
  1364. * @param $sort
  1365. * @param $standardFields
  1366. */
  1367. function list_getProfileFields($start, $items_per_page, $sort, $standardFields)
  1368. {
  1369. global $txt, $modSettings, $smcFunc;
  1370. $list = array();
  1371. if ($standardFields)
  1372. {
  1373. $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website', 'posts', 'warning_status');
  1374. $fields_no_registration = array('posts', 'warning_status');
  1375. $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
  1376. $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
  1377. foreach ($standard_fields as $field)
  1378. $list[] = array(
  1379. 'id' => $field,
  1380. 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
  1381. 'disabled' => in_array($field, $disabled_fields),
  1382. 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
  1383. 'can_show_register' => !in_array($field, $fields_no_registration),
  1384. );
  1385. }
  1386. else
  1387. {
  1388. // Load all the fields.
  1389. $request = $smcFunc['db_query']('', '
  1390. SELECT id_field, col_name, field_name, field_desc, field_type, active, placement
  1391. FROM {db_prefix}custom_fields
  1392. ORDER BY {raw:sort}
  1393. LIMIT {int:start}, {int:items_per_page}',
  1394. array(
  1395. 'sort' => $sort,
  1396. 'start' => $start,
  1397. 'items_per_page' => $items_per_page,
  1398. )
  1399. );
  1400. while ($row = $smcFunc['db_fetch_assoc']($request))
  1401. $list[] = $row;
  1402. $smcFunc['db_free_result']($request);
  1403. }
  1404. return $list;
  1405. }
  1406. /**
  1407. * Callback for createList().
  1408. */
  1409. function list_getProfileFieldSize()
  1410. {
  1411. global $smcFunc;
  1412. $request = $smcFunc['db_query']('', '
  1413. SELECT COUNT(*)
  1414. FROM {db_prefix}custom_fields',
  1415. array(
  1416. )
  1417. );
  1418. list ($numProfileFields) = $smcFunc['db_fetch_row']($request);
  1419. $smcFunc['db_free_result']($request);
  1420. return $numProfileFields;
  1421. }
  1422. /**
  1423. * Edit some profile fields?
  1424. */
  1425. function EditCustomProfiles()
  1426. {
  1427. global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
  1428. // Sort out the context!
  1429. $context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0;
  1430. $context[$context['admin_menu_name']]['current_subsection'] = 'profile';
  1431. $context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
  1432. $context['sub_template'] = 'edit_profile_field';
  1433. // Load the profile language for section names.
  1434. loadLanguage('Profile');
  1435. if ($context['fid'])
  1436. {
  1437. $request = $smcFunc['db_query']('', '
  1438. SELECT
  1439. id_field, col_name, field_name, field_desc, field_type, field_length, field_options,
  1440. show_reg, show_display, show_profile, private, active, default_value, can_search,
  1441. bbc, mask, enclose, placement
  1442. FROM {db_prefix}custom_fields
  1443. WHERE id_field = {int:current_field}',
  1444. array(
  1445. 'current_field' => $context['fid'],
  1446. )
  1447. );
  1448. $context['field'] = array();
  1449. while ($row = $smcFunc['db_fetch_assoc']($request))
  1450. {
  1451. if ($row['field_type'] == 'textarea')
  1452. @list ($rows, $cols) = @explode(',', $row['default_value']);
  1453. else
  1454. {
  1455. $rows = 3;
  1456. $cols = 30;
  1457. }
  1458. $context['field'] = array(
  1459. 'name' => $row['field_name'],
  1460. 'desc' => $row['field_desc'],
  1461. 'colname' => $row['col_name'],
  1462. 'profile_area' => $row['show_profile'],
  1463. 'reg' => $row['show_reg'],
  1464. 'display' => $row['show_display'],
  1465. 'type' => $row['field_type'],
  1466. 'max_length' => $row['field_length'],
  1467. 'rows' => $rows,
  1468. 'cols' => $cols,
  1469. 'bbc' => $row['bbc'] ? true : false,
  1470. 'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false,
  1471. 'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '',
  1472. 'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''),
  1473. 'active' => $row['active'],
  1474. 'private' => $row['private'],
  1475. 'can_search' => $row['can_search'],
  1476. 'mask' => $row['mask'],
  1477. 'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '',
  1478. 'enclose' => $row['enclose'],
  1479. 'placement' => $row['placement'],
  1480. );
  1481. }
  1482. $smcFunc['db_free_result']($request);
  1483. }
  1484. // Setup the default values as needed.
  1485. if (empty($context['field']))
  1486. $context['field'] = array(
  1487. 'name' => '',
  1488. 'colname' => '???',
  1489. 'desc' => '',
  1490. 'profile_area' => 'forumprofile',
  1491. 'reg' => false,
  1492. 'display' => false,
  1493. 'type' => 'text',
  1494. 'max_length' => 255,
  1495. 'rows' => 4,
  1496. 'cols' => 30,
  1497. 'bbc' => false,
  1498. 'default_check' => false,
  1499. 'default_select' => '',
  1500. 'options' => array('', '', ''),
  1501. 'active' => true,
  1502. 'private' => false,
  1503. 'can_search' => false,
  1504. 'mask' => 'nohtml',
  1505. 'regex' => '',
  1506. 'enclose' => '',
  1507. 'placement' => 0,
  1508. );
  1509. // Are we saving?
  1510. if (isset($_POST['save']))
  1511. {
  1512. checkSession();
  1513. validateToken('admin-ecp');
  1514. // Everyone needs a name - even the (bracket) unknown...
  1515. if (trim($_POST['field_name']) == '')
  1516. redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
  1517. // Regex you say? Do a very basic test to see if the pattern is valid
  1518. if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
  1519. redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
  1520. $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
  1521. $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
  1522. // Checkboxes...
  1523. $show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0;
  1524. $show_display = isset($_POST['display']) ? 1 : 0;
  1525. $bbc = isset($_POST['bbc']) ? 1 : 0;
  1526. $show_profile = $_POST['profile_area'];
  1527. $active = isset($_POST['active']) ? 1 : 0;
  1528. $private = isset($_POST['private']) ? (int) $_POST['private'] : 0;
  1529. $can_search = isset($_POST['can_search']) ? 1 : 0;
  1530. // Some masking stuff...
  1531. $mask = isset($_POST['mask']) ? $_POST['mask'] : '';
  1532. if ($mask == 'regex' && isset($_POST['regex']))
  1533. $mask .= $_POST['regex'];
  1534. $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
  1535. $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
  1536. $placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0;
  1537. // Select options?
  1538. $field_options = '';
  1539. $newOptions = array();
  1540. $default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : '';
  1541. if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio'))
  1542. {
  1543. foreach ($_POST['select_option'] as $k => $v)
  1544. {
  1545. // Clean, clean, clean...
  1546. $v = $smcFunc['htmlspecialchars']($v);
  1547. $v = strtr($v, array(',' => ''));
  1548. // Nada, zip, etc...
  1549. if (trim($v) == '')
  1550. continue;
  1551. // Otherwise, save it boy.
  1552. $field_options .= $v . ',';
  1553. // This is just for working out what happened with old options...
  1554. $newOptions[$k] = $v;
  1555. // Is it default?
  1556. if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
  1557. $default = $v;
  1558. }
  1559. $field_options = substr($field_options, 0, -1);
  1560. }
  1561. // Text area has default has dimensions
  1562. if ($_POST['field_type'] == 'textarea')
  1563. $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
  1564. // Come up with the unique name?
  1565. if (empty($context['fid']))
  1566. {
  1567. $colname = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6);
  1568. preg_match('~([\w\d_-]+)~', $colname, $matches);
  1569. // If there is nothing to the name, then let's start out own - for foreign languages etc.
  1570. if (isset($matches[1]))
  1571. $colname = $initial_colname = 'cust_' . strtolower($matches[1]);
  1572. else
  1573. $colname = $initial_colname = 'cust_' . mt_rand(1, 999);
  1574. // Make sure this is unique.
  1575. // @todo This may not be the most efficient way to do this.
  1576. $unique = false;
  1577. for ($i = 0; !$unique && $i < 9; $i ++)
  1578. {
  1579. $request = $smcFunc['db_query']('', '
  1580. SELECT id_field
  1581. FROM {db_prefix}custom_fields
  1582. WHERE col_name = {string:current_column}',
  1583. array(
  1584. 'current_column' => $colname,
  1585. )
  1586. );
  1587. if ($smcFunc['db_num_rows']($request) == 0)
  1588. $unique = true;
  1589. else
  1590. $colname = $initial_colname . $i;
  1591. $smcFunc['db_free_result']($request);
  1592. }
  1593. // Still not a unique colum name? Leave it up to the user, then.
  1594. if (!$unique)
  1595. fatal_lang_error('custom_option_not_unique');
  1596. }
  1597. // Work out what to do with the user data otherwise...
  1598. else
  1599. {
  1600. // Anything going to check or select is pointless keeping - as is anything coming from check!
  1601. if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check')
  1602. || (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
  1603. || ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check'))
  1604. {
  1605. $smcFunc['db_query']('', '
  1606. DELETE FROM {db_prefix}themes
  1607. WHERE variable = {string:current_column}
  1608. AND id_member > {int:no_member}',
  1609. array(
  1610. 'no_member' => 0,
  1611. 'current_column' => $context['field']['colname'],
  1612. )
  1613. );
  1614. }
  1615. // Otherwise - if the select is edited may need to adjust!
  1616. elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')
  1617. {
  1618. $optionChanges = array();
  1619. $takenKeys = array();
  1620. // Work out what's changed!
  1621. foreach ($context['field']['options'] as $k => $option)
  1622. {
  1623. if (trim($option) == '')
  1624. continue;
  1625. // Still exists?
  1626. if (in_array($option, $newOptions))
  1627. {
  1628. $takenKeys[] = $k;
  1629. continue;
  1630. }
  1631. }
  1632. // Finally - have we renamed it - or is it really gone?
  1633. foreach ($optionChanges as $k => $option)
  1634. {
  1635. // Just been renamed?
  1636. if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
  1637. $smcFunc['db_query']('', '
  1638. UPDATE {db_prefix}themes
  1639. SET value = {string:new_value}
  1640. WHERE variable = {string:current_column}
  1641. AND value = {string:old_value}
  1642. AND id_member > {int:no_member}',
  1643. array(
  1644. 'no_member' => 0,
  1645. 'new_value' => $newOptions[$k],
  1646. 'current_column' => $context['field']['colname'],
  1647. 'old_value' => $option,
  1648. )
  1649. );
  1650. }
  1651. }
  1652. // @todo Maybe we should adjust based on new text length limits?
  1653. }
  1654. // Do the insertion/updates.
  1655. if ($context['fid'])
  1656. {
  1657. $smcFunc['db_query']('', '
  1658. UPDATE {db_prefix}custom_fields
  1659. SET
  1660. field_name = {string:field_name}, field_desc = {string:field_desc},
  1661. field_type = {string:field_type}, field_length = {int:field_length},
  1662. field_options = {string:field_options}, show_reg = {int:show_reg},
  1663. show_display = {int:show_display}, show_profile = {string:show_profile},
  1664. private = {int:private}, active = {int:active}, default_value = {string:default_value},
  1665. can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask},
  1666. enclose = {string:enclose}, placement = {int:placement}
  1667. WHERE id_field = {int:current_field}',
  1668. array(
  1669. 'field_length' => $field_length,
  1670. 'show_reg' => $show_reg,
  1671. 'show_display' => $show_display,
  1672. 'private' => $private,
  1673. 'active' => $active,
  1674. 'can_search' => $can_search,
  1675. 'bbc' => $bbc,
  1676. 'current_field' => $context['fid'],
  1677. 'field_name' => $_POST['field_name'],
  1678. 'field_desc' => $_POST['field_desc'],
  1679. 'field_type' => $_POST['field_type'],
  1680. 'field_options' => $field_options,
  1681. 'show_profile' => $show_profile,
  1682. 'default_value' => $default,
  1683. 'mask' => $mask,
  1684. 'enclose' => $enclose,
  1685. 'placement' => $placement,
  1686. )
  1687. );
  1688. // Just clean up any old selects - these are a pain!
  1689. if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
  1690. $smcFunc['db_query']('', '
  1691. DELETE FROM {db_prefix}themes
  1692. WHERE variable = {string:current_column}
  1693. AND value NOT IN ({array_string:new_option_values})
  1694. AND id_member > {int:no_member}',
  1695. array(
  1696. 'no_member' => 0,
  1697. 'new_option_values' => $newOptions,
  1698. 'current_column' => $context['field']['colname'],
  1699. )
  1700. );
  1701. }
  1702. else
  1703. {
  1704. $smcFunc['db_insert']('',
  1705. '{db_prefix}custom_fields',
  1706. array(
  1707. 'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string',
  1708. 'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string',
  1709. 'show_reg' => 'int', 'show_display' => 'int', 'show_profile' => 'string',
  1710. 'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int',
  1711. 'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int',
  1712. ),
  1713. array(
  1714. $colname, $_POST['field_name'], $_POST['field_desc'],
  1715. $_POST['field_type'], $field_length, $field_options,
  1716. $show_reg, $show_display, $show_profile,
  1717. $private, $active, $default, $can_search,
  1718. $bbc, $mask, $enclose, $placement,
  1719. ),
  1720. array('id_field')
  1721. );
  1722. }
  1723. // As there's currently no option to priorize certain fields over others, let's order them alphabetically.
  1724. $smcFunc['db_query']('alter_table_boards', '
  1725. ALTER TABLE {db_prefix}custom_fields
  1726. ORDER BY field_name',
  1727. array(
  1728. 'db_error_skip' => true,
  1729. )
  1730. );
  1731. }
  1732. // Deleting?
  1733. elseif (isset($_POST['delete']) && $context['field']['colname'])
  1734. {
  1735. checkSession();
  1736. validateToken('admin-ecp');
  1737. // Delete the user data first.
  1738. $smcFunc['db_query']('', '
  1739. DELETE FROM {db_prefix}themes
  1740. WHERE variable = {string:current_column}
  1741. AND id_member > {int:no_member}',
  1742. array(
  1743. 'no_member' => 0,
  1744. 'current_column' => $context['field']['colname'],
  1745. )
  1746. );
  1747. // Finally - the field itself is gone!
  1748. $smcFunc['db_query']('', '
  1749. DELETE FROM {db_prefix}custom_fields
  1750. WHERE id_field = {int:current_field}',
  1751. array(
  1752. 'current_field' => $context['fid'],
  1753. )
  1754. );
  1755. }
  1756. // Rebuild display cache etc.
  1757. if (isset($_POST['delete']) || isset($_POST['save']))
  1758. {
  1759. checkSession();
  1760. $request = $smcFunc['db_query']('', '
  1761. SELECT col_name, field_name, field_type, bbc, enclose, placement
  1762. FROM {db_prefix}custom_fields
  1763. WHERE show_display = {int:is_displayed}
  1764. AND active = {int:active}
  1765. AND private != {int:not_owner_only}
  1766. AND private != {int:not_admin_only}',
  1767. array(
  1768. 'is_displayed' => 1,
  1769. 'active' => 1,
  1770. 'not_owner_only' => 2,
  1771. 'not_admin_only' => 3,
  1772. )
  1773. );
  1774. $fields = array();
  1775. while ($row = $smcFunc['db_fetch_assoc']($request))
  1776. {
  1777. $fields[] = array(
  1778. 'colname' => strtr($row['col_name'], array('|' => '', ';' => '')),
  1779. 'title' => strtr($row['field_name'], array('|' => '', ';' => '')),
  1780. 'type' => $row['field_type'],
  1781. 'bbc' => $row['bbc'] ? '1' : '0',
  1782. 'placement' => !empty($row['placement']) ? $row['placement'] : '0',
  1783. 'enclose' => !empty($row['enclose']) ? $row['enclose'] : '',
  1784. );
  1785. }
  1786. $smcFunc['db_free_result']($request);
  1787. updateSettings(array('displayFields' => serialize($fields)));
  1788. redirectexit('action=admin;area=featuresettings;sa=profile');
  1789. }
  1790. createToken('admin-ecp');
  1791. }
  1792. /**
  1793. * Allow to edit the settings on the pruning screen.
  1794. * @param $return_config
  1795. */
  1796. function ModifyPruningSettings($return_config = false)
  1797. {
  1798. global $txt, $scripturl, $sourcedir, $context, $settings, $sc, $modSettings;
  1799. // Make sure we understand what's going on.
  1800. loadLanguage('ManageSettings');
  1801. $context['page_title'] = $txt['pruning_title'];
  1802. $config_vars = array(
  1803. // Even do the pruning?
  1804. // The array indexes are there so we can remove/change them before saving.
  1805. 'pruningOptions' => array('check', 'pruningOptions'),
  1806. '',
  1807. // Various logs that could be pruned.
  1808. array('int', 'pruneErrorLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Error log.
  1809. array('int', 'pruneModLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Moderation log.
  1810. array('int', 'pruneBanLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Ban hit log.
  1811. array('int', 'pruneReportLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Report to moderator log.
  1812. array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
  1813. array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
  1814. // If you add any additional logs make sure to add them after this point. Additionally, make sure you add them to the weekly scheduled task.
  1815. // Mod Developers: Do NOT use the pruningOptions master variable for this as SMF Core may overwrite your setting in the future!
  1816. );
  1817. call_integration_hook('integrate_prune_settings', array(&$config_vars));
  1818. if ($return_config)
  1819. return $config_vars;
  1820. // We'll need this in a bit.
  1821. require_once($sourcedir . '/ManageServer.php');
  1822. // Saving?
  1823. if (isset($_GET['save']))
  1824. {
  1825. checkSession();
  1826. $savevar = array(
  1827. array('text', 'pruningOptions')
  1828. );
  1829. if (!empty($_POST['pruningOptions']))
  1830. {
  1831. $vals = array();
  1832. foreach ($config_vars as $index => $dummy)
  1833. {
  1834. if (!is_array($dummy) || $index == 'pruningOptions')
  1835. continue;
  1836. $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
  1837. }
  1838. $_POST['pruningOptions'] = implode(',', $vals);
  1839. }
  1840. else
  1841. $_POST['pruningOptions'] = '';
  1842. saveDBSettings($savevar);
  1843. redirectexit('action=admin;area=logs;sa=pruning');
  1844. }
  1845. $context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=pruning';
  1846. $context['settings_title'] = $txt['pruning_title'];
  1847. $context['sub_template'] = 'show_settings';
  1848. // Get the actual values
  1849. if (!empty($modSettings['pruningOptions']))
  1850. @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
  1851. else
  1852. $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
  1853. prepareDBSettingContext($config_vars);
  1854. }
  1855. /**
  1856. * If you have a general mod setting to add stick it here.
  1857. *
  1858. * @param $return_config
  1859. */
  1860. function ModifyGeneralModSettings($return_config = false)
  1861. {
  1862. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  1863. $config_vars = array(
  1864. // Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
  1865. );
  1866. // Make it even easier to add new settings.
  1867. call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
  1868. if ($return_config)
  1869. return $config_vars;
  1870. $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
  1871. $context['settings_title'] = $txt['mods_cat_modifications_misc'];
  1872. // No removing this line you, dirty unwashed mod authors. :p
  1873. if (empty($config_vars))
  1874. {
  1875. $context['settings_save_dont_show'] = true;
  1876. $context['settings_message'] = '<div class="centertext">' . $txt['modification_no_misc_settings'] . '</div>';
  1877. return prepareDBSettingContext($config_vars);
  1878. }
  1879. // Saving?
  1880. if (isset($_GET['save']))
  1881. {
  1882. checkSession();
  1883. $save_vars = $config_vars;
  1884. call_integration_hook('integrate_save_general_mod_settings', array(&$save_vars));
  1885. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
  1886. saveDBSettings($save_vars);
  1887. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
  1888. redirectexit('action=admin;area=modsettings;sa=general');
  1889. }
  1890. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: RED INK IS FOR TEACHERS AND THOSE WHO LIKE PAIN!
  1891. prepareDBSettingContext($config_vars);
  1892. }
  1893. function list_integration_hooks()
  1894. {
  1895. global $sourcedir, $scripturl, $context, $txt, $modSettings, $settings;
  1896. $context['filter'] = '';
  1897. $presentHooks = get_integration_hooks();
  1898. if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($presentHooks)))
  1899. $context['filter'] = ';filter=' . $_GET['filter'];
  1900. if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function']))
  1901. {
  1902. checkSession('request');
  1903. validateToken('admin-hook', 'request');
  1904. if ($_REQUEST['do'] == 'remove')
  1905. remove_integration_function($_REQUEST['hook'], $_REQUEST['function']);
  1906. elseif ($_REQUEST['do'] == 'disable')
  1907. {
  1908. remove_integration_function($_REQUEST['hook'], $_REQUEST['function']);
  1909. // It's a hack I know...but I'm way too lazy!!!
  1910. add_integration_function($_REQUEST['hook'], $_REQUEST['function'] . ']');
  1911. }
  1912. elseif ($_REQUEST['do'] == 'enable')
  1913. {
  1914. remove_integration_function($_REQUEST['hook'], $_REQUEST['function'] . ']');
  1915. // It's a hack I know...but I'm way too lazy!!!
  1916. add_integration_function($_REQUEST['hook'], $_REQUEST['function']);
  1917. }
  1918. redirectexit('action=admin;area=modsettings;sa=hooks' . $context['filter']);
  1919. }
  1920. createToken('admin-hook', 'request');
  1921. $list_options = array(
  1922. 'id' => 'list_integration_hooks',
  1923. 'title' => $txt['hooks_title_list'],
  1924. 'items_per_page' => 20,
  1925. 'base_href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  1926. 'default_sort_col' => 'hook_name',
  1927. 'get_items' => array(
  1928. 'function' => 'get_integration_hooks_data',
  1929. ),
  1930. 'get_count' => array(
  1931. 'function' => 'get_integration_hooks_count',
  1932. ),
  1933. 'no_items_label' => $txt['hooks_no_hooks'],
  1934. 'columns' => array(
  1935. 'hook_name' => array(
  1936. 'header' => array(
  1937. 'value' => $txt['hooks_field_hook_name'],
  1938. ),
  1939. 'data' => array(
  1940. 'db' => 'hook_name',
  1941. ),
  1942. 'sort' => array(
  1943. 'default' => 'hook_name',
  1944. 'reverse' => 'hook_name DESC',
  1945. ),
  1946. ),
  1947. 'function_name' => array(
  1948. 'header' => array(
  1949. 'value' => $txt['hooks_field_function_name'],
  1950. ),
  1951. 'data' => array(
  1952. 'db' => 'function_name',
  1953. ),
  1954. 'sort' => array(
  1955. 'default' => 'function_name',
  1956. 'reverse' => 'function_name DESC',
  1957. ),
  1958. ),
  1959. 'file_name' => array(
  1960. 'header' => array(
  1961. 'value' => $txt['hooks_field_file_name'],
  1962. ),
  1963. 'data' => array(
  1964. 'db' => 'file_name',
  1965. ),
  1966. 'sort' => array(
  1967. 'default' => 'file_name',
  1968. 'reverse' => 'file_name DESC',
  1969. ),
  1970. ),
  1971. 'status' => array(
  1972. 'header' => array(
  1973. 'value' => $txt['hooks_field_hook_exists'],
  1974. 'style' => 'width:3%',
  1975. ),
  1976. 'data' => array(
  1977. 'function' => create_function('$data', '
  1978. global $txt, $settings, $scripturl, $context;
  1979. $change_status = array(\'before\' => \'\', \'after\' => \'\');
  1980. if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\')
  1981. {
  1982. $change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'function_name\'] . $context[\'filter\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\';
  1983. $change_status[\'after\'] = \'</a>\';
  1984. }
  1985. return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\'];
  1986. '),
  1987. 'class' => 'centertext',
  1988. ),
  1989. 'sort' => array(
  1990. 'default' => 'status',
  1991. 'reverse' => 'status DESC',
  1992. ),
  1993. ),
  1994. 'check' => array(
  1995. 'header' => array(
  1996. 'value' => $txt['hooks_button_remove'],
  1997. 'style' => 'width:3%',
  1998. ),
  1999. 'data' => array(
  2000. 'function' => create_function('$data', '
  2001. global $txt, $settings, $scripturl, $context;
  2002. if (!$data[\'hook_exists\'])
  2003. return \'
  2004. <a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'function_name\'] . $context[\'filter\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">
  2005. <img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" />
  2006. </a>\';
  2007. '),
  2008. 'class' => 'centertext',
  2009. ),
  2010. ),
  2011. ),
  2012. 'form' => array(
  2013. 'href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  2014. 'name' => 'list_integration_hooks',
  2015. ),
  2016. 'additional_rows' => array(
  2017. array(
  2018. 'position' => 'after_title',
  2019. 'value' => $txt['hooks_disable_instructions'] . '<br />
  2020. ' . $txt['hooks_disable_legend'] . ':
  2021. <ul style="list-style: none;">
  2022. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . '</li>
  2023. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . '</li>
  2024. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . '</li>
  2025. </ul>'
  2026. ),
  2027. ),
  2028. );
  2029. require_once($sourcedir . '/Subs-List.php');
  2030. createList($list_options);
  2031. $context['page_title'] = $txt['hooks_title_list'];
  2032. $context['sub_template'] = 'show_list';
  2033. $context['default_list'] = 'list_integration_hooks';
  2034. }
  2035. function get_files_recursive($dir_path)
  2036. {
  2037. $files = array();
  2038. if ($dh = opendir($dir_path))
  2039. {
  2040. while (($file = readdir($dh)) !== false)
  2041. {
  2042. if ($file != '.' && $file != '..')
  2043. {
  2044. if (is_dir($dir_path . '/' . $file))
  2045. $files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
  2046. else
  2047. $files[] = array('dir' => $dir_path, 'name' => $file);
  2048. }
  2049. }
  2050. }
  2051. closedir($dh);
  2052. return $files;
  2053. }
  2054. function get_integration_hooks_data($start, $per_page, $sort)
  2055. {
  2056. global $boarddir, $sourcedir, $settings, $txt, $context, $scripturl;
  2057. $hooks = $temp_hooks = get_integration_hooks();
  2058. $hooks_data = $temp_data = $hook_status = array();
  2059. $files = get_files_recursive($sourcedir);
  2060. if (!empty($files))
  2061. {
  2062. foreach ($files as $file)
  2063. {
  2064. if (is_file($file['dir'] . '/' . $file['name']) && substr($file['name'], -4) === '.php')
  2065. {
  2066. $fp = fopen($file['dir'] . '/' . $file['name'], 'rb');
  2067. $fc = fread($fp, filesize($file['dir'] . '/' . $file['name']));
  2068. fclose($fp);
  2069. foreach ($temp_hooks as $hook => $functions)
  2070. {
  2071. foreach ($functions as $function_o)
  2072. {
  2073. $function = str_replace(']', '', $function_o);
  2074. if (substr($hook, -8) === '_include')
  2075. {
  2076. $hook_status[$hook][$function]['exists'] = file_exists(strtr(trim($function), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])));
  2077. // I need to know if there is at least one function called in this file.
  2078. $temp_data['include'][basename($function)] = array('hook' => $hook, 'function' => $function);
  2079. unset($temp_hooks[$hook][$function_o]);
  2080. }
  2081. // @TODO replace with a preg_match? (the difference is the space before the open parentheses
  2082. elseif (strpos($fc, 'function ' . trim($function) . '(') !== false || strpos($fc, 'function ' . trim($function) . ' (') !== false)
  2083. {
  2084. $hook_status[$hook][$function]['exists'] = true;
  2085. $hook_status[$hook][$function]['in_file'] = $file['name'];
  2086. // I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
  2087. $temp_data['function'][$file['name']][] = $function_o;
  2088. unset($temp_hooks[$hook][$function_o]);
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. $sort_types = array(
  2096. 'hook_name' => array('hook', SORT_ASC),
  2097. 'hook_name DESC' => array('hook', SORT_DESC),
  2098. 'function_name' => array('function', SORT_ASC),
  2099. 'function_name DESC' => array('function', SORT_DESC),
  2100. 'file_name' => array('file_name', SORT_ASC),
  2101. 'file_name DESC' => array('file_name', SORT_DESC),
  2102. 'status' => array('status', SORT_ASC),
  2103. 'status DESC' => array('status', SORT_DESC),
  2104. );
  2105. $sort_options = $sort_types[$sort];
  2106. $sort = array();
  2107. $context['hooks_filters'] = '';
  2108. $hooks_filters = array();
  2109. foreach ($hooks as $hook => $functions)
  2110. {
  2111. $hooks_filters[] = '<option onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks;filter=' . $hook . '\';">' . $hook . '</option>';
  2112. foreach ($functions as $function)
  2113. {
  2114. $enabled = strstr($function, ']') === false;
  2115. $function = str_replace(']', '', $function);
  2116. // This is a not an include and the function is included in a certain file (if not it doesn't exists so don't care)
  2117. if (substr($hook, -8) !== '_include' && isset($hook_status[$hook][$function]['in_file']))
  2118. {
  2119. $current_hook = isset($temp_data['include'][$hook_status[$hook][$function]['in_file']]) ? $temp_data['include'][$hook_status[$hook][$function]['in_file']] : '';
  2120. $enabled = false;
  2121. // Checking all the functions within this particular file
  2122. // if any of them is enable then the file *must* be included and the integrate_*_include hook cannot be disabled
  2123. foreach ($temp_data['function'][$hook_status[$hook][$function]['in_file']] as $func)
  2124. $enabled = $enabled || strstr($func, ']') !== false;
  2125. if (!$enabled && !empty($current_hook))
  2126. $hook_status[$current_hook['hook']][$current_hook['function']]['enabled'] = true;
  2127. }
  2128. }
  2129. }
  2130. if (!empty($hooks_filters))
  2131. $context['hooks_filters'] = '<select style="margin-left:15px;">' . '<option>---</option><option onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks\';">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>';
  2132. $temp_data = array();
  2133. $id = 0;
  2134. foreach ($hooks as $hook => $functions)
  2135. {
  2136. if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
  2137. {
  2138. foreach ($functions as $function)
  2139. {
  2140. $enabled = strstr($function, ']') === false;
  2141. $function = str_replace(']', '', $function);
  2142. $hook_exists = !empty($hook_status[$hook][$function]['exists']);
  2143. $file_name = isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ((substr($hook, -8) === '_include') ? 'zzzzzzzzz' : 'zzzzzzzza');
  2144. $status = $hook_exists ? ($enabled ? 'a' : 'b') : 'c';
  2145. $sort[] = $$sort_options[0];
  2146. $temp_data[] = array(
  2147. 'id' => 'hookid_' . $id++,
  2148. 'hook_name' => $hook,
  2149. 'function_name' => $function,
  2150. 'file_name' => (isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ''),
  2151. 'hook_exists' => $hook_exists,
  2152. 'status' => $hook_exists ? ($enabled ? 'allow' : 'moderate') : 'deny',
  2153. 'img_text' => $txt['hooks_' . ($hook_exists ? ($enabled ? 'active' : 'disabled') : 'missing')],
  2154. 'enabled' => $enabled,
  2155. 'can_be_disabled' => !isset($hook_status[$hook][$function]['enabled']),
  2156. );
  2157. }
  2158. }
  2159. }
  2160. array_multisort($sort, $sort_options[1], $temp_data);
  2161. $counter = 0;
  2162. $start++;
  2163. foreach ($temp_data as $data)
  2164. {
  2165. if (++$counter < $start)
  2166. continue;
  2167. elseif ($counter == $start + $per_page)
  2168. break;
  2169. $hooks_data[] = $data;
  2170. }
  2171. return $hooks_data;
  2172. }
  2173. function get_integration_hooks_count()
  2174. {
  2175. global $context;
  2176. $hooks = get_integration_hooks();
  2177. $hooks_count = 0;
  2178. $context['filter'] = false;
  2179. if (isset($_GET['filter']))
  2180. $context['filter'] = $_GET['filter'];
  2181. foreach ($hooks as $hook => $functions)
  2182. {
  2183. if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
  2184. $hooks_count += count($functions);
  2185. }
  2186. return $hooks_count;
  2187. }
  2188. function get_integration_hooks()
  2189. {
  2190. global $modSettings;
  2191. static $integration_hooks;
  2192. if (!isset($integration_hooks))
  2193. {
  2194. $integration_hooks = array();
  2195. foreach ($modSettings as $key => $value)
  2196. {
  2197. if (!empty($value) && substr($key, 0, 10) === 'integrate_')
  2198. $integration_hooks[$key] = explode(',', $value);
  2199. }
  2200. }
  2201. return $integration_hooks;
  2202. }
  2203. ?>