ManageSettings.php 83 KB

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