ManageSettings.php 86 KB

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