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