ManageSettings.php 83 KB

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