ManageSettings.php 83 KB

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