ManageSettings.php 83 KB

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