ManageSettings.php 86 KB

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