PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/setup/prefs.php

https://gitlab.com/ElvisAns/tiki
PHP | 345 lines | 224 code | 61 blank | 60 comment | 27 complexity | 31637eb3940967dc7ac0cf751097ce88 MD5 | raw file
  1. <?php
  2. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id$
  7. // RULE1: $prefs does not contain serialized values. Only the database contains serialized values.
  8. // RULE2: put array('') in default prefs for serialized values
  9. //this script may only be included - so its better to die if called directly.
  10. if (basename($_SERVER['SCRIPT_NAME']) == basename(__FILE__)) {
  11. header("location: index.php");
  12. exit;
  13. }
  14. //
  15. // This section is being phased out. Please use the instructions at https://dev.tiki.org/Create+a+new+preference instead.
  16. //
  17. // Prefs for which we want to use the site value (they will be prefixed with 'site_')
  18. // ( this is also used in tikilib, not only when reloading prefs )
  19. global $user_overrider_prefs, $prefs;
  20. $user_overrider_prefs = [
  21. 'language',
  22. 'language_admin',
  23. 'userbreadCrumb',
  24. 'tikiIndex',
  25. 'wikiHomePage',
  26. 'default_calendars',
  27. 'metatag_robots',
  28. 'theme',
  29. 'theme_option',
  30. ];
  31. initialize_prefs();
  32. function get_default_prefs()
  33. {
  34. static $prefs;
  35. if (is_array($prefs)) {
  36. return $prefs;
  37. }
  38. global $tikipath;
  39. $cachelib = TikiLib::lib('cache');
  40. if ($prefs = $cachelib->getSerialized('tiki_default_preferences_cache')) {
  41. return $prefs;
  42. }
  43. $prefslib = TikiLib::lib('prefs');
  44. $prefs = $prefslib->getDefaults();
  45. $prefs = array_merge(
  46. $prefs,
  47. [
  48. // tiki and version
  49. 'tiki_release' => '0',
  50. 'tiki_needs_upgrade' => 'n',
  51. 'tiki_version_last_check' => 0,
  52. 'groups_are_emulated' => 'n',
  53. // wiki
  54. 'backlinks_name_len' => '0',
  55. 'feature_wiki_notepad' => 'n',
  56. 'feature_wiki_feedback_polls' => [],
  57. 'mailin_respond_email' => 'y',
  58. 'mailin_autocheck' => 'n',
  59. 'mailin_autocheckFreq' => '0',
  60. 'mailin_autocheckLast' => 0,
  61. 'wiki_bot_bar' => 'n',
  62. 'wiki_left_column' => 'y',
  63. 'wiki_right_column' => 'y',
  64. 'wiki_top_bar' => 'y',
  65. 'feature_wiki_watch_structure' => 'n',
  66. 'wiki_validate_plugin' => 'y',
  67. 'wiki_pagealias_tokens' => 'alias',
  68. // File galleries
  69. // Root galleries fake preferences. These are automatically overridden by schema upgrade scripts
  70. // for installations that pre-date the existence of these root galleries.
  71. 'fgal_root_id' => 1, // Ancestor of "default" type galleries. For old installs, overriden by 20090811_filegals_container_tiki.sql
  72. 'fgal_root_user_id' => 2, // Ancestor of "user" type galleries (feature_use_fgal_for_user_files). For old installs,
  73. // overriden by 20101126_fgal_add_gallerie_user_tiki.php
  74. 'fgal_root_wiki_attachments_id' => 3, // Ancestor of wiki "attachments" type galleries (feature_use_fgal_for_wiki_attachments).
  75. // For old installs, overriden by 20101210_fgal_add_wiki_attachments_tiki.php
  76. //can probably be removed - doesn't seem to be set or used anywhere
  77. 'fgal_show_checked' => 'y',
  78. // articles
  79. 'cms_bot_bar' => 'y',
  80. 'cms_left_column' => 'y',
  81. 'cms_right_column' => 'y',
  82. 'cms_top_bar' => 'n',
  83. 'cms_last_viewed_month' => '0',
  84. // trackers
  85. 'trackerCreatorGroupName' => ' ',
  86. // user
  87. 'userlevels' => function_exists('tra') ? ['1' => tra('Simple'),'2' => tra('Advanced')] : ['1' => 'Simple','2' => 'Advanced'],
  88. 'userbreadCrumb' => 4,
  89. 'feature_community_friends_permission' => 'n',
  90. 'feature_community_friends_permission_dep' => '2',
  91. 'lowercase_username' => 'n',
  92. 'users_prefs_country' => '',
  93. 'users_prefs_email_is_public' => 'n',
  94. 'users_prefs_homePage' => '',
  95. 'users_prefs_lat' => '0',
  96. 'users_prefs_lon' => '0',
  97. 'users_prefs_mytiki_articles' => 'y',
  98. 'users_prefs_realName' => '',
  99. 'users_prefs_gender' => '',
  100. 'users_prefs_mailCurrentAccount' => '0',
  101. // freetags
  102. 'freetags_cloud_colors' => '',
  103. // feed
  104. 'max_rss_mapfiles' => 10,
  105. 'rss_mapfiles' => 'n',
  106. 'title_rss_mapfiles' => '',
  107. // auth
  108. 'min_user_length' => 1,
  109. 'auth_pear' => 'tiki',
  110. 'auth_ldap_url' => '',
  111. 'auth_pear_host' => 'localhost',
  112. 'auth_pear_port' => '389',
  113. 'auth_ldap_groupnameatr' => '',
  114. 'auth_ldap_groupdescatr' => '',
  115. 'auth_ldap_syncuserattr' => 'uid',
  116. 'auth_ldap_syncgroupattr' => 'cn',
  117. 'auth_phpbb_dbport' => '',
  118. 'auth_phpbb_dbtype' => 'mysql',
  119. 'login_url' => 'tiki-login.php',
  120. 'login_scr' => 'tiki-login_scr.php',
  121. 'register_url' => 'tiki-register.php',
  122. 'error_url' => 'tiki-error.php',
  123. // intertiki
  124. 'interlist' => [],
  125. 'known_hosts' => [],
  126. // categories
  127. 'category_i18n_unsynced' => [],
  128. // look and feel
  129. 'feature_sitenav' => 'n',
  130. 'sitenav' => '{tr}Navigation : {/tr}<a href="tiki-contact.php" accesskey="10" title="">{tr}Contact Us{/tr}</a>',
  131. // toolbars
  132. // comma delimited items, / delimited rows and | denotes items right justified in toolbar (in reverse order)
  133. // full list in lib/toolbars/toolbarslib.php Toolbar::getList()
  134. // cannot contain spaces, commas, forward-slash or pipe chars within tool names
  135. 'toolbar_global' => '
  136. bold, italic, underline, strike, sub, sup,-, color, -, tikiimage, tikilink, link, unlink, anchor, -,
  137. undo, redo, -, find, replace, -, removeformat, specialchar, smiley | help, switcheditor, autosave, admintoolbar /
  138. format, templates, cut, copy, paste, pastetext, pasteword, -, h1, h2, h3, left, center, -,
  139. blockquote, list, numlist, -, pagebreak, rule, -, table, pastlink, -, source, showblocks, screencapture | fullscreen /
  140. style, fontname, fontsize, outdent, indent /
  141. ',
  142. 'toolbar_global_comments' => '
  143. bold, italic, underline, strike , - , link, smiley | help
  144. ',
  145. 'toolbar_sheet' => 'addrow, addrowbefore, addrowmulti, deleterow,-, addcolumn, addcolumnbefore, addcolumnmulti, deletecolumn,-,
  146. sheetgetrange, sheetrefresh, -, sheetfind | sheetclose, sheetsave, help/
  147. bold, italic, underline, strike, center, -, color, bgcolor, -, tikilink, nonparsed | fullscreen /',
  148. // unsorted features
  149. 'anonCanEdit' => 'n',
  150. 'feature_contribution_display_in_comment' => 'y',
  151. 'feature_contribution_mandatory' => 'n',
  152. 'feature_contribution_mandatory_blog' => 'n',
  153. 'feature_contribution_mandatory_comment' => 'n',
  154. 'feature_contribution_mandatory_forum' => 'n',
  155. 'feature_debugger_console' => 'n',
  156. 'feature_events' => 'n',
  157. 'feature_projects' => 'n',
  158. 'feature_ranking' => 'n',
  159. 'feature_top_banner' => 'n',
  160. 'minical_reminders' => 0,
  161. 'php_docroot' => 'http://php.net/',
  162. 'shoutbox_autolink' => 'n',
  163. 'show_comzone' => 'n',
  164. 'use_proxy' => 'n',
  165. 'webserverauth' => 'n',
  166. 'feature_intertiki_imported_groups' => '',
  167. 'feature_contributor_wiki' => '',
  168. 'https_login_required' => '',
  169. 'replimaster' => '',
  170. 'javascript_enabled' => 'n',
  171. // SefUrl
  172. 'feature_sefurl_paths' => [''], //empty string needed to keep preference from setting unexpectedly
  173. 'feature_sefurl_routes' => 'n',
  174. 'feature_lastup' => 'y',
  175. 'terminology_profile_installed' => 'n',
  176. // Web Monetization
  177. 'webmonetization_payment_pointer' => '',
  178. 'webmonetization_default_paywall_text' => '',
  179. // Error Tracking
  180. 'error_tracking_enabled_php' => 'n', //empty string needed to keep preference from setting unexpectedly
  181. 'error_tracking_enabled_js' => 'n', //empty string needed to keep preference from setting unexpectedly
  182. 'error_tracking_dsn' => '',
  183. ]
  184. );
  185. if (! empty($prefs['tmpDir']) && $prefs['tmpDir'] == sys_get_temp_dir() && is_dir($tikipath.'temp')) {
  186. // Use Tiki-based temp dir by default instead of system temp dir
  187. $prefs['tmpDir'] = $tikipath.'temp';
  188. }
  189. // Special default values
  190. $_SESSION['tmpDir'] = $prefs['tmpDir'];
  191. $prefs['feature_lastup'] = 'y';
  192. // Be sure we have a default value for user prefs
  193. foreach ($prefs as $p => $v) {
  194. if (substr($p, 0, 12) == 'users_prefs_') {
  195. $prefs[substr($p, 12)] = $v;
  196. }
  197. }
  198. $cachelib->cacheItem("tiki_default_preferences_cache", serialize($prefs));
  199. return $prefs;
  200. }
  201. function initialize_prefs($force = false)
  202. {
  203. global $prefs, $user_overrider_prefs, $in_installer, $section, $systemConfiguration;
  204. if (! $force && (defined('TIKI_IN_INSTALLER') || defined('TIKI_IN_TEST'))) {
  205. $prefs = get_default_prefs();
  206. return;
  207. }
  208. $cachelib = TikiLib::lib('cache');
  209. if ($cachelib->isCached('global_preferences')) {
  210. $prefs = $cachelib->getSerialized('global_preferences');
  211. // note there is a small chance in high concurrency environments that cache file may be cleared
  212. // in the interim leading to blank $prefs
  213. }
  214. if (empty($prefs) || ! $cachelib->isCached('global_preferences')) {
  215. $defaults = get_default_prefs();
  216. // Find which preferences need to be serialized/unserialized, based on the default
  217. // values (those with arrays as values) and preferences with special serializations
  218. $serializedPreferences = [];
  219. $prefslib = TikiLib::lib('prefs');
  220. foreach ($defaults as $preference => $value) {
  221. if (is_array($value) || in_array($preference, ['category_defaults', 'memcache_servers'])) {
  222. $serializedPreferences[] = $preference;
  223. }
  224. }
  225. $tikilib = TikiLib::lib("tiki");
  226. if (method_exists($tikilib, "getModifiedPreferences")) {
  227. $modified = TikiLib::lib("tiki")->getModifiedPreferences();
  228. } else {
  229. $modified = [];
  230. }
  231. // Unserialize serialized preferences
  232. foreach ($serializedPreferences as $serializedPreference) {
  233. if (! empty($modified[$serializedPreference]) && ! is_array($modified[$serializedPreference])) {
  234. $unserialized = @unserialize($modified[$serializedPreference]);
  235. if ($unserialized === false) {
  236. Feedback::error(tr('Preference %0 failed to unserialize. Value was "%1"', $serializedPreference, $modified[$serializedPreference]));
  237. } else {
  238. $modified[$serializedPreference] = $unserialized;
  239. }
  240. }
  241. }
  242. // Keep some useful sites values available before overriding with user prefs
  243. // (they could be used in templates, so we need to set them even for Anonymous)
  244. foreach ($user_overrider_prefs as $uop) {
  245. if (isset($modified[$uop])) {
  246. $modified['site_' . $uop] = $modified[$uop];
  247. } elseif (isset($defaults[$uop])) {
  248. $modified['site_' . $uop] = $defaults[$uop];
  249. }
  250. }
  251. $prefs = $modified + $defaults;
  252. $cachelib->cacheItem('global_preferences', serialize($prefs));
  253. }
  254. // Override preferences with system-configured preferences.
  255. $system = $systemConfiguration->preference->toArray();
  256. // Also include the site_ versions
  257. foreach ($user_overrider_prefs as $uop) {
  258. if (isset($system[$uop])) {
  259. $system['site_' . $uop] = $system[$uop];
  260. }
  261. }
  262. $prefs = array_merge($prefs, $system);
  263. if (! defined('TIKI_PREFS_DEFINED')) {
  264. define('TIKI_PREFS_DEFINED', 1);
  265. }
  266. }
  267. /**
  268. * Detect the engine used in the current schema.
  269. * Assumes that all tables use the same table engine
  270. * @return string identifying the current engine, or an empty string if not installed
  271. */
  272. function getCurrentEngine()
  273. {
  274. return TikiLib::lib("tiki")->getCurrentEngine();
  275. }
  276. /**
  277. * Determine if MySQL fulltext search is supported by the current DB engine
  278. * Assumes that all tables use the same table engine
  279. * @return true if it is supported, otherwise false
  280. */
  281. function isMySQLFulltextSearchSupported()
  282. {
  283. return TikiLib::lib("tiki")->isMySQLFulltextSearchSupported();
  284. }