| [ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #CMS - CMS Made Simple 3 #(c)2004 by Ted Kulp (wishy@users.sf.net) 4 #This project's homepage is: http://cmsmadesimple.sf.net 5 # 6 #This program is free software; you can redistribute it and/or modify 7 #it under the terms of the GNU General Public License as published by 8 #the Free Software Foundation; either version 2 of the License, or 9 #(at your option) any later version. 10 # 11 #This program is distributed in the hope that it will be useful, 12 #but WITHOUT ANY WARRANTY; without even the implied warranty of 13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 #GNU General Public License for more details. 15 #You should have received a copy of the GNU General Public License 16 #along with this program; if not, write to the Free Software 17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 # 19 #$Id: config.functions.php 3416 2006-09-09 22:58:16Z wishy $ 20 21 /** 22 * Functions relating to the config hash and config files 23 * 24 * @package CMS 25 */ 26 /** 27 * Loads the config file with defaults and then with specific values from config.php 28 * 29 * @since 0.5 30 */ 31 function cms_config_load($loadLocal = true, $upgrade = false) 32 { 33 $config = array(); 34 35 #Set some defaults, just in case the config file is corrupted or 36 #we're coming from an upgrade 37 $config["dbms"] = "mysql"; 38 $config["db_hostname"] = "localhost"; 39 $config["db_username"] = "cms"; 40 $config["db_password"] = "cms"; 41 $config["db_name"] = "cms"; 42 $config["db_prefix"] = "cms_"; 43 $config["root_url"] = "http://www.something.com"; 44 $config["root_path"] = dirname(dirname(__FILE__)); 45 $config["query_var"] = "page"; 46 $config["use_bb_code"] = false; 47 $config["use_smarty_php_tags"] = false; 48 $config["previews_path"] = $config["root_path"] . "/tmp/cache"; 49 $config["uploads_path"] = $config["root_path"] . "/uploads"; 50 $config["uploads_url"] = $config["root_url"] . "/uploads"; 51 $config["max_upload_size"] = 1000000; 52 $config["debug"] = false; 53 $config["assume_mod_rewrite"] = false; 54 $config['internal_pretty_urls'] = false; 55 $config['use_hierarchy'] = false; 56 $config["auto_alias_content"] = true; 57 $config["image_manipulation_prog"] = "GD"; 58 $config["image_transform_lib_path"] = "/usr/bin/ImageMagick/"; 59 $config["use_Indite"] = true; 60 $config["image_uploads_path"] = $config["root_path"] . "/uploads/images"; 61 $config["image_uploads_url"] = $config["root_url"] . "/uploads/images"; 62 $config["default_encoding"] = ""; 63 $config["disable_htmlarea_translation"] = false; 64 $config["admin_dir"] = "admin"; 65 $config["persistent_db_conn"] = false; 66 $config["default_upload_permission"] = '664'; 67 $config["page_extension"] = ""; 68 $config["use_adodb_lite"] = true; 69 $config["locale"] = ""; 70 $config['old_stylesheet'] = true; 71 $config['wiki_url'] = "http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel"; 72 $config['backwards_compatible'] = true; 73 74 #Don't set it yet 75 #$config["admin_encoding"] = "utf-8"; 76 77 if ($loadLocal == true) 78 { 79 //if (file_exists(CONFIG_FILE_LOCATION) && !cms_config_check_old_config()) 80 if (file_exists(CONFIG_FILE_LOCATION)) 81 { 82 include(CONFIG_FILE_LOCATION); 83 } 84 } 85 86 #Check to see if this exists in the config.php yet 87 if (!isset($config["admin_encoding"])) 88 { 89 #So this is our first setting of it. Is default_encoding set already? 90 #If so, set admin_encoding to match (and admin encodings should behave as before) 91 if (isset($config["default_encoding"]) && $config["default_encoding"]) 92 { 93 $config['admin_encoding'] = $config['default_encoding']; 94 } 95 else 96 { 97 #Ok, so last ditch effort. Look for the encoding of the default template 98 if ($upgrade == true) 99 { 100 global $gCms; 101 $db =& $gCms->GetDb(); 102 $encoding = $db->GetOne('select encoding from '.cms_db_prefix().'templates where default_template = 1'); 103 if (isset($encoding) && $encoding != '') 104 { 105 $config["admin_encoding"] = $encoding; 106 } 107 else 108 { 109 $config["admin_encoding"] = "utf-8"; 110 } 111 } 112 else 113 { 114 $config["admin_encoding"] = "utf-8"; 115 } 116 } 117 } 118 119 return $config; 120 } 121 122 function cms_config_text($config) 123 { 124 $true = 'true'; 125 $false = 'false'; 126 $result = <<<EOF 127 128 #CMS Made Simple Configuration File 129 #Please clear the cache (Site Admin->Global Settings in the admin panel) 130 #after making any changes to path or url related options 131 132 #----------------- 133 #Database Settings 134 #----------------- 135 136 #This is your database connection information. Name of the server, 137 #username, password and a database with proper permissions should 138 #all be setup before CMS Made Simple is installed. 139 \$config['dbms'] = '{$config['dbms']}'; 140 \$config['db_hostname'] = '{$config['db_hostname']}'; 141 \$config['db_username'] = '{$config['db_username']}'; 142 \$config['db_password'] = '{$config['db_password']}'; 143 \$config['db_name'] = '{$config['db_name']}'; 144 145 #If app needs to coexist with other tables in the same db, 146 #put a prefix here. e.g. "cms_" 147 \$config['db_prefix'] = '{$config['db_prefix']}'; 148 149 #Use persistent connections? They're generally faster, but not all hosts 150 #allow them. 151 \$config['persistent_db_conn'] = ${$config['persistent_db_conn']?'true':'false'}; 152 153 #Use ADODB Lite? This should be true in almost all cases. Note, slight 154 #tweaks might have to be made to date handling in a "regular" adodb 155 #install before it can be used. 156 \$config['use_adodb_lite'] = ${$config['use_adodb_lite']?'true':'false'}; 157 158 #------------- 159 #Path Settings 160 #------------- 161 162 #Document root as seen from the webserver. No slash at the end 163 #e.g. http://blah.com 164 \$config['root_url'] = '{$config['root_url']}'; 165 166 #Path to document root. This should be the directory this file is in. 167 #e.g. /var/www/localhost 168 \$config['root_path'] = '{$config['root_path']}'; 169 170 #Name of the admin directory 171 \$config['admin_dir'] = '{$config['admin_dir']}'; 172 173 #Where do previews get stored temporarily? It defaults to tmp/cache. 174 \$config['previews_path'] = '{$config['previews_path']}'; 175 176 #Where are uploaded files put? This defaults to uploads. 177 \$config['uploads_path'] = '{$config['uploads_path']}'; 178 179 #Where is the url to this uploads directory? 180 \$config['uploads_url'] = '{$config['uploads_url']}'; 181 182 #--------------- 183 #Upload Settings 184 #--------------- 185 186 #Maxium upload size (in bytes)? 187 \$config['max_upload_size'] = {$config['max_upload_size']}; 188 189 #Permissions for uploaded files. This only really needs changing if your 190 #host has a weird permissions scheme. 191 \$config['default_upload_permission'] = '{$config['default_upload_permission']}'; 192 193 #------------------ 194 #Usability Settings 195 #------------------ 196 197 #Allow smarty {php} tags? These could be dangerous if you don't trust your users. 198 \$config['use_smarty_php_tags'] = ${$config['use_smarty_php_tags']?'true':'false'}; 199 200 #CMSMS Debug Mode? Turn is on to get a better error when you 201 #see {nocache} errors. 202 \$config['debug'] = ${$config['debug']?'true':'false'}; 203 204 #Automatically assign alias based on page title? 205 \$config['auto_alias_content'] = ${$config['auto_alias_content']?'true':'false'}; 206 207 #------------ 208 #URL Settings 209 #------------ 210 211 #Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules 212 \$config['assume_mod_rewrite'] = ${$config['assume_mod_rewrite']?'true':'false'}; 213 214 #Extension to use if you're using mod_rewrite for pretty URLs. 215 \$config['page_extension'] = '{$config['page_extension']}'; 216 217 #If you don't use mod_rewrite, then would you like to use the built-in 218 #pretty url mechanism? This will not work with IIS and the {metadata} tag 219 #should be in all of your templates before enabling. 220 \$config['internal_pretty_urls'] = ${$config['internal_pretty_urls']?'true':'false'}; 221 222 #If you're using the internal pretty url mechanism or mod_rewrite, would you like to 223 #show urls in their hierarchy? (ex. http://www.mysite.com/parent/parent/childpage) 224 \$config['use_hierarchy'] = ${$config['use_hierarchy']?'true':'false'}; 225 226 #If using none of the above options, what should we be using for the query string 227 #variable? (ex. http://www.mysite.com/index.php?page=somecontent) 228 \$config['query_var'] = '{$config['query_var']}'; 229 230 #-------------- 231 #Image Settings 232 #-------------- 233 234 #Which program should be used for handling thumbnails in the image manager. 235 #See http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Content/Image_Manager for more 236 #info on what this all means 237 \$config['image_manipulation_prog'] = '{$config['image_manipulation_prog']}'; 238 \$config['image_transform_lib_path'] = '{$config['image_transform_lib_path']}'; 239 240 #Default path and URL for uploaded images in the image manager 241 \$config['image_uploads_path'] = '{$config['image_uploads_path']}'; 242 \$config['image_uploads_url'] = '{$config['image_uploads_url']}'; 243 244 #------------------------ 245 #Locale/Encoding Settings 246 #------------------------ 247 248 #Locale to use for various default date handling functions, etc. Leaving 249 #this blank will use the server's default. This might not be good if the 250 #site is hosted in a different country than it's intended audience. 251 \$config['locale'] = '{$config['locale']}'; 252 253 #In almost all cases, default_encoding should be empty (which defaults to utf-8) 254 #and admin_encoding should be utf-8. If you'd like this to be different, change 255 #both. Keep in mind, however, that the admin interface translations are all in 256 #utf-8, and will be converted on the fly to match the admin_encoding. This 257 #could seriously slow down the admin interfaces for users. 258 \$config['default_encoding'] = '{$config['default_encoding']}'; 259 \$config['admin_encoding'] = '{$config['admin_encoding']}'; 260 261 #--------------------------------------------- 262 #Use the old stylesheet logic? It's much slower, but it works with older 263 #versions of CMSMS. You'll also need this set to true if there is a module 264 #that uses a stylesheet callback. Leave it as false instead you really 265 #need it. 266 \$config['old_stylesheet'] = ${$config['old_stylesheet']?'true':'false'}; 267 268 # URL of the Admin Panel section of the User Handbook 269 \$config['wiki_url'] = '{$config['wiki_url']}'; 270 271 #Enable backwards compatibility mode? This basically will allow some 272 #modules written before 1.0 was released to work. Keep in mind that this 273 #will use a lot more memory and isn't guaranteed to fix the problem. 274 \$config['backwards_compatible'] = ${$config['backwards_compatible']?'true':'false'}; 275 276 #Not used anymore... kept around, just in case 277 \$config['disable_htmlarea_translation'] = false; 278 \$config['use_Indite'] = true; 279 EOF; 280 return $result; 281 } 282 283 /** 284 * Saves config.php 285 * 286 * Loops through the config hash given and save it's values 287 * out to the config.php in the filesystem. Files quietly 288 * if there is no access to the file; 289 * 290 * @since 0.5 291 */ 292 function cms_config_save($config) 293 { 294 $newfiledir = dirname(CONFIG_FILE_LOCATION); 295 $newfilename = CONFIG_FILE_LOCATION; 296 if (is_writable($newfilename) || is_writable($newfiledir)) 297 { 298 $handle = fopen($newfilename, "w"); 299 if ($handle) 300 { 301 fwrite($handle, "<?php\n\n"); 302 fwrite($handle, cms_config_text($config)); 303 fwrite($handle, "\n?>"); 304 fclose($handle); 305 } 306 } 307 } 308 309 /** 310 * Upgrades config.php from the old style 311 * 312 * @since 0.5 313 */ 314 function cms_config_upgrade() 315 { 316 #Get my lazy on and just do some regex magic... 317 $newfiledir = dirname(CONFIG_FILE_LOCATION); 318 $newfilename = CONFIG_FILE_LOCATION; 319 $oldconfiglines = array(); 320 if (is_writable($newfilename) || is_writable($newfiledir)) 321 { 322 $handle = fopen($newfilename, "r"); 323 if ($handle) 324 { 325 while (!feof($handle)) 326 { 327 $oldconfiglines[] = fgets($handle, 4096); 328 } 329 fclose($handle); 330 $handle = fopen($newfilename, "w"); 331 if ($handle) 332 { 333 foreach ($oldconfiglines as $oneline) 334 { 335 $newline = trim(preg_replace('/\$this-\>(\S+)/', '$config["$1"]', $oneline)); 336 if ($newline != "?>") 337 { 338 $newline .= "\n"; 339 } 340 fwrite($handle, $newline); 341 } 342 fclose($handle); 343 } 344 } 345 } 346 } 347 348 # vim:ts=4 sw=4 noet 349 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |