ManageSettings.php 87 KB

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