ManageSettings.php 92 KB

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