ManageSettings.php 88 KB

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