ManageSettings.php 91 KB

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