ManageSettings.php 92 KB

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