public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / lib / classes / class.cms_config.php
100644 404 lines (343 sloc) 13.596 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* Class to hold the configuration values found in the config.php file.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsConfig extends CmsObject implements ArrayAccess
{
  var $params;
  static private $instance = NULL;
  static private $config_file_location = '';
 
  function __construct()
  {
    parent::__construct();
    $this->params = array();
  }
  
  static public function get_instance()
  {
    if (self::$instance == NULL)
    {
      self::$instance = new CmsConfig();
      self::$instance->load();
    }
    return self::$instance;
  }
  
  static public function get_config_filename()
  {
    if (self::$config_file_location == '')
    {
      $filename = dirname(CONFIG_FILE_LOCATION) . DS . 'config-' . CMS_VERSION . '.php';
      if (file_exists($filename))
      {
        self::$config_file_location = $filename;
      }
      else
      {
        self::$config_file_location = CONFIG_FILE_LOCATION;
      }
    }
    return self::$config_file_location;
  }
  
  static public function exists($key)
  {
    $config = CmsConfig::get_instance();
    return array_key_exists($key, $config->params);
  }
  
  static public function get($key)
  {
    $config = CmsConfig::get_instance();
    return $config[$key];
  }
  
  function offsetSet($key, $value)
  {
    $this->params[$key] = $value;
  }
 
  function offsetGet($key)
  {
    if (array_key_exists($key, $this->params))
    {
      return $this->params[$key];
    }
  }
 
  function offsetUnset($key)
  {
    if (array_key_exists($key, $this->params))
    {
      unset($this->params[$key]);
    }
  }
 
  function offsetExists($offset)
  {
    return array_key_exists($offset, $this->params);
  }
  
  function load($loadLocal = true, $upgrade = false)
  {
    $config = array();
 
    #Set some defaults, just in case the config file is corrupted or
    #we're coming from an upgrade
    $config['php_memory_limit'] = '';
    $config["dbms"] = "mysql";
    $config["db_hostname"] = "localhost";
    $config["db_username"] = "cms";
    $config["db_password"] = "cms";
    $config["db_name"] = "cms";
    $config["db_prefix"] = "cms_";
    $config["root_url"] = CmsRequest::get_calculated_url_base();
    $config["root_path"] = dirname(dirname(__FILE__));
    $config["query_var"] = "page";
    $config["use_bb_code"] = false;
    $config["smarty_security"] = false;
    $config["previews_path"] = TMP_CACHE_LOCATION;
    $config["uploads_path"] = cms_join_path($config["root_path"], 'uploads');
    $config["uploads_url"] = $config["root_url"] . "/uploads";
    $config["max_upload_size"] = 1000000;
    $config["debug"] = false;
    $config["assume_mod_rewrite"] = false;
    $config['internal_pretty_urls'] = true;
    $config["auto_alias_content"] = true;
    $config["image_manipulation_prog"] = "GD";
    $config["image_transform_lib_path"] = ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) ? 'C:/Program Files/VisualMagick/bin/' : '/usr/bin/ImageMagick/';
    $config["use_Indite"] = true;
    $config["image_uploads_path"] = cms_join_path($config["uploads_path"], 'images');
    $config["image_uploads_url"] = $config["root_url"] . "/uploads/images";
    $config["default_encoding"] = "";
    $config["disable_htmlarea_translation"] = false;
    $config["admin_dir"] = "admin";
    $config["persistent_db_conn"] = false;
    $config["default_upload_permission"] = '664';
    $config["page_extension"] = "";
    $config["locale"] = "";
    $config['old_stylesheet'] = true;
    $config['wiki_url'] = "http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel";
    $config['backwards_compatible'] = true;
    $config['timezone'] = 'Etc/GMT+0';
    $config['function_caching'] = true;
    $config['full_page_caching'] = false;
 
    if ($loadLocal == true)
    {
      //if (file_exists(CONFIG_FILE_LOCATION) && !cms_config_check_old_config())
      if (file_exists(self::get_config_filename()))
      {
        include(self::get_config_filename());
      }
    }
 
    #Check to see if this exists in the config.php yet
    if (!isset($config["admin_encoding"]))
    {
      #So this is our first setting of it. Is default_encoding set already?
      #If so, set admin_encoding to match (and admin encodings should behave as before)
      if (isset($config["default_encoding"]) && $config["default_encoding"])
      {
        $config['admin_encoding'] = $config['default_encoding'];
      }
      else
      {
        #Ok, so last ditch effort. Look for the encoding of the default template
        if ($upgrade == true)
        {
          $db = cms_db();
          $encoding = $db->GetOne('select encoding from '.cms_db_prefix().'templates where default_template = 1');
          if (isset($encoding) && $encoding != '')
          {
            $config["admin_encoding"] = $encoding;
          }
          else
          {
            $config["admin_encoding"] = "utf-8";
          }
        }
        else
        {
          $config["admin_encoding"] = "utf-8";
        }
      }
    }
    
    // Begin Multisite Modifications
    $subsite_config = cms_join_path($config['root_path'], 'sites', $_SERVER['HTTP_HOST'], 'config.php');
    if(file_exists($subsite_config))
    {
      include $subsite_config;
      $config['is_subsite'] = true;
    }
    // End Multisite Modifications    
 
    $this->params = $config;
 
  }
  
  function save()
  {
    $newfiledir = dirname(self::get_config_filename());
    $newfilename = self::get_config_filename();
    if (is_writable($newfilename) || is_writable($newfiledir))
    {
      $handle = fopen($newfilename, "w");
      if ($handle)
      {
        fwrite($handle, "<?php\n\n");
        fwrite($handle, $this->config_text($this->params));
        fwrite($handle, "\n?>");
        fclose($handle);
      }
    }
  }
  
  function config_text($config)
  {
    $true = 'true';
    $false = 'false';
    $result = <<<EOF
 
#CMS Made Simple Configuration File
#Please clear the cache (Site Admin->Global Settings in the admin panel)
#after making any changes to path or url related options
 
# If you are experiencing problems with php memory limit errors, then you may
# want to try enabling and/or adjusting this setting.
# Note: Your server may not allow the application to override memory limits.
\$config['php_memory_limit'] = '{$config['php_memory_limit']}';
 
#-----------------
#Database Settings
#-----------------
 
#This is your database connection information. Name of the server,
#username, password and a database with proper permissions should
#all be setup before CMS Made Simple is installed.
\$config['dbms'] = '{$config['dbms']}';
\$config['db_hostname'] = '{$config['db_hostname']}';
\$config['db_username'] = '{$config['db_username']}';
\$config['db_password'] = '{$config['db_password']}';
\$config['db_name'] = '{$config['db_name']}';  
 
#If app needs to coexist with other tables in the same db,
#put a prefix here. e.g. "cms_"
\$config['db_prefix'] = '{$config['db_prefix']}';
 
#Use persistent connections? They're generally faster, but not all hosts
#allow them.
\$config['persistent_db_conn'] = ${$config['persistent_db_conn']?'true':'false'};
 
#-------------
#Path Settings
#-------------
 
#Document root as seen from the webserver. No slash at the end
#If page is requested with https use https as root url
#e.g. http://blah.com. Only override this if you are having issues
#with the url calculation routine, which could be caused by strange
#web server configurations.
#\$config['root_url'] = '{$config['root_url']}';
 
#Path to document root. This should be the directory this file is in.
#e.g. /var/www/localhost. Only override this if PHP is for some reason
#calculating a bad path.
#\$config['root_path'] = '{$config['root_path']}';
 
#Name of the admin directory
\$config['admin_dir'] = '{$config['admin_dir']}';
 
#Where do previews get stored temporarily? It defaults to tmp/cache.
\$config['previews_path'] = '{$config['previews_path']}';
 
#Where are uploaded files put? This defaults to uploads.
\$config['uploads_path'] = '{$config['uploads_path']}';
 
#Where is the url to this uploads directory?
\$config['uploads_url'] = \$config['root_url'] . '{$config['uploads_url']}';
 
#---------------
#Upload Settings
#---------------
 
#Maxium upload size (in bytes)?
\$config['max_upload_size'] = {$config['max_upload_size']};
 
#Permissions for uploaded files. This only really needs changing if your
#host has a weird permissions scheme.
\$config['default_upload_permission'] = '{$config['default_upload_permission']}';
 
#------------------
#Usability Settings
#------------------
 
#Should smarty be tightened up a bit? This is only really necessary if you don't trust
#your users 100%.
\$config['smarty_security'] = ${$config['smarty_security']?'true':'false'};
 
#Should we use function caching? This basically means that we cache certain data that
#is repeately queried from the database. There shouldn't be many reasons to turn this
#off, but the option is there in case there are problems.
\$config['function_caching'] = ${$config['function_caching']?'true':'false'};
 
#Should we use full page caching? This basically means that the database will not even
#be touched and contents will only come from a file cache that is reset every hour. Only
#use this if you have a truly static site or in case of "slashdot" effect.
\$config['full_page_caching'] = ${$config['full_page_caching']?'true':'false'};
 
#CMSMS Debug Mode? Turn is on to get a better error when you
#see {nocache} errors.
\$config['debug'] = ${$config['debug']?'true':'false'};
 
#Automatically assign alias based on page title?
\$config['auto_alias_content'] = ${$config['auto_alias_content']?'true':'false'};
 
#------------
#URL Settings
#------------
 
#Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules
\$config['assume_mod_rewrite'] = ${$config['assume_mod_rewrite']?'true':'false'};
 
#Extension to use if you're using mod_rewrite for pretty URLs.
\$config['page_extension'] = '{$config['page_extension']}';
 
#If you don't use mod_rewrite, then would you like to use the built-in
#pretty url mechanism? This will not work with IIS and the {metadata} tag
#should be in all of your templates before enabling.
\$config['internal_pretty_urls'] = ${$config['internal_pretty_urls']?'true':'false'};
 
#If using none of the above options, what should we be using for the query string
#variable? (ex. http://www.mysite.com/index.php?page=somecontent)
\$config['query_var'] = '{$config['query_var']}';
 
#--------------
#Image Settings
#--------------
 
#Which program should be used for handling thumbnails in the image manager.
#See http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Content/Image_Manager for more
#info on what this all means
\$config['image_manipulation_prog'] = '{$config['image_manipulation_prog']}';
\$config['image_transform_lib_path'] = '{$config['image_transform_lib_path']}';
 
#Default path and URL for uploaded images in the image manager
\$config['image_uploads_path'] = '{$config['image_uploads_path']}';
\$config['image_uploads_url'] = \$config['root_url'] . '{$config['image_uploads_url']}';
 
#------------------------
#Locale/Encoding Settings
#------------------------
 
#Locale to use for various default date handling functions, etc. Leaving
#this blank will use the server's default. This might not be good if the
#site is hosted in a different country than it's intended audience.
\$config['locale'] = '{$config['locale']}';
 
#In almost all cases, default_encoding should be empty (which defaults to utf-8)
#and admin_encoding should be utf-8. If you'd like this to be different, change
#both. Keep in mind, however, that the admin interface translations are all in
#utf-8, and will be converted on the fly to match the admin_encoding. This
#could seriously slow down the admin interfaces for users.
\$config['default_encoding'] = '{$config['default_encoding']}';
\$config['admin_encoding'] = '{$config['admin_encoding']}';
 
 
#Timezone for this site.
#Check http://php.net/manual/en/timezones.php for available timezones
\$config['timezone'] = 'Etc/GMT+0';
 
 
#---------------------------------------------
#Use the old stylesheet logic? It's much slower, but it works with older
#versions of CMSMS. You'll also need this set to true if there is a module
#that uses a stylesheet callback. Leave it as false instead you really
#need it.
\$config['old_stylesheet'] = ${$config['old_stylesheet']?'true':'false'};
 
# URL of the Admin Panel section of the User Handbook
\$config['wiki_url'] = '{$config['wiki_url']}';
 
#Enable backwards compatibility mode? This basically will allow some
#modules written before 1.0 was released to work. Keep in mind that this
#will use a lot more memory and isn't guaranteed to fix the problem.
\$config['backwards_compatible'] = ${$config['backwards_compatible']?'true':'false'};
 
#Not used anymore... kept around, just in case
\$config['disable_htmlarea_translation'] = false;
\$config['use_Indite'] = true;
EOF;
    return $result;
  }
  
}
 
?>