PluginProbe
ShiftController Employee Shift Scheduling / 2.2.3
ShiftController Employee Shift Scheduling v2.2.3
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / happ / system / core / Config.php

Config.php in ShiftController Employee Shift Scheduling 2.2.3, at happ/system/core/Config.php

447 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2 /**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16 // ------------------------------------------------------------------------
17
18 /**
19 * CodeIgniter Config Class
20 *
21 * This class contains functions that enable config files to be managed
22 *
23 * @package CodeIgniter
24 * @subpackage Libraries
25 * @category Libraries
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/libraries/config.html
28 */
29 class CI_Config {
30
31 /**
32 * List of all loaded config values
33 *
34 * @var array
35 */
36 var $config = array();
37 /**
38 * List of all loaded config files
39 *
40 * @var array
41 */
42 var $is_loaded = array();
43 /**
44 * List of paths to search when trying to load a config file
45 *
46 * @var array
47 */
48 var $_config_paths = array(APPPATH);
49
50 /**
51 * Constructor
52 *
53 * Sets the $config data from the primary config.php file as a class variable
54 *
55 * @access public
56 * @param string the config file name
57 * @param boolean if configuration values should be loaded into their own section
58 * @param boolean true if errors should just return false, false if an error message should be displayed
59 * @return boolean if the file was successfully loaded or not
60 */
61 function __construct()
62 {
63 $this->config =& get_config();
64 log_message('debug', "Config Class Initialized");
65
66 // Set the base_url automatically if none was provided
67 if ($this->config['base_url'] == '')
68 {
69 if (isset($_SERVER['HTTP_HOST']))
70 {
71 $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
72 $base_url .= '://'. $_SERVER['HTTP_HOST'];
73 $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
74 }
75
76 else
77 {
78 $base_url = 'http://localhost/';
79 }
80
81 $this->set_item('base_url', $base_url);
82 }
83 }
84
85 // --------------------------------------------------------------------
86
87 /**
88 * Load Config File
89 *
90 * @access public
91 * @param string the config file name
92 * @param boolean if configuration values should be loaded into their own section
93 * @param boolean true if errors should just return false, false if an error message should be displayed
94 * @return boolean if the file was loaded correctly
95 */
96 function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
97 {
98 $file = ($file == '') ? 'config' : str_replace('.php', '', $file);
99 $found = FALSE;
100 $loaded = FALSE;
101
102 $check_locations = defined('ENVIRONMENT')
103 ? array(ENVIRONMENT.'/'.$file, $file)
104 : array($file);
105
106 $these_files = array();
107 foreach ($this->_config_paths as $path)
108 {
109 foreach ($check_locations as $location)
110 {
111 $file_path = $path.'config/'.$location.'.php';
112
113 if (in_array($file_path, $this->is_loaded, TRUE))
114 {
115 $loaded = TRUE;
116 continue 2;
117 }
118
119 if (file_exists($file_path))
120 {
121 $found = TRUE;
122 $these_files[] = $file_path;
123 // break;
124 }
125 }
126 }
127
128 if ($found === TRUE)
129 {
130 reset( $these_files );
131 foreach( $these_files as $file_path )
132 {
133 include($file_path);
134
135 if ( ! isset($config) OR ! is_array($config))
136 {
137 if ($fail_gracefully === TRUE)
138 {
139 return FALSE;
140 }
141 show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
142 }
143
144 if ($use_sections === TRUE)
145 {
146 if (! isset($this->config[$file]))
147 {
148 $this->config[$file] = array();
149 }
150
151 reset( $config );
152 foreach( $config as $k => $v )
153 {
154 if( is_array($v) )
155 {
156 reset( $v );
157 foreach( $v as $k2 => $v2 )
158 {
159 if (isset($this->config[$file][$k][$k2]))
160 {
161 foreach( $v2 as $k3 => $v3 )
162 {
163 if( isset($this->config[$file][$k][$k2][$k3]) && is_array($v3) )
164 {
165 $this->config[$file][$k][$k2][$k3] = array_merge($this->config[$file][$k][$k2][$k3], $v3);
166 }
167 else
168 {
169 $this->config[$file][$k][$k2][$k3] = $v3;
170 }
171 }
172 // $this->config[$file][$k][$k2] = array_merge($this->config[$file][$k][$k2], $v2);
173 }
174 else
175 {
176 $this->config[$file][$k][$k2] = $v2;
177 }
178 }
179 }
180 else
181 {
182 $this->config[$file][$k] = $v;
183 }
184 }
185 //$this->config[$file] = array_merge($this->config[$file], $config);
186 }
187 else
188 {
189 $this->config = array_merge($this->config, $config);
190 }
191
192 $this->is_loaded[] = $file_path;
193 unset($config);
194
195 $loaded = TRUE;
196 log_message('debug', 'Config file loaded: '.$file_path);
197 }
198 }
199
200 if ($loaded === FALSE)
201 {
202 if ($fail_gracefully === TRUE)
203 {
204 return FALSE;
205 }
206 show_error('The configuration file '.$file.'.php does not exist.');
207 }
208
209 return TRUE;
210 }
211
212 function items( $index = '' )
213 {
214 $return = array();
215 if ($index == '')
216 {
217 $keys = array_keys($this->config);
218 }
219 else
220 {
221 if ( ! isset($this->config[$index]))
222 {
223 return FALSE;
224 }
225 $keys = array_keys($this->config[$index]);
226 }
227
228 reset( $keys );
229 foreach( $keys as $k )
230 {
231 $return[ $k ] = $this->item( $k, $index );
232 }
233
234 return $return;
235 }
236
237 // --------------------------------------------------------------------
238
239 /**
240 * Fetch a config file item
241 *
242 *
243 * @access public
244 * @param string the config item name
245 * @param string the index name
246 * @param bool
247 * @return string
248 */
249 function item($item, $index = '')
250 {
251 if ($index == '')
252 {
253 if ( ! isset($this->config[$item]))
254 {
255 return FALSE;
256 }
257
258 $pref = $this->config[$item];
259 }
260 else
261 {
262 if ( ! isset($this->config[$index]))
263 {
264 return FALSE;
265 }
266
267 if ( ! isset($this->config[$index][$item]))
268 {
269 return FALSE;
270 }
271
272 $pref = $this->config[$index][$item];
273 }
274
275 return $pref;
276 }
277
278 // --------------------------------------------------------------------
279
280 /**
281 * Fetch a config file item - adds slash after item (if item is not empty)
282 *
283 * @access public
284 * @param string the config item name
285 * @param bool
286 * @return string
287 */
288 function slash_item($item)
289 {
290 if ( ! isset($this->config[$item]))
291 {
292 return FALSE;
293 }
294 if( trim($this->config[$item]) == '')
295 {
296 return '';
297 }
298
299 return rtrim($this->config[$item], '/').'/';
300 }
301
302 // --------------------------------------------------------------------
303
304 /**
305 * Site URL
306 * Returns base_url . index_page [. uri_string]
307 *
308 * @access public
309 * @param string the URI string
310 * @return string
311 */
312 function site_url($uri = '')
313 {
314 if ($uri == '')
315 {
316 return $this->slash_item('base_url').$this->item('index_page');
317 }
318
319 if ($this->item('enable_query_strings') == FALSE)
320 {
321 $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
322 return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
323 }
324 else
325 {
326 return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
327 }
328 }
329
330 // -------------------------------------------------------------
331
332 /**
333 * Base URL
334 * Returns base_url [. uri_string]
335 *
336 * @access public
337 * @param string $uri
338 * @return string
339 */
340 function base_url($uri = '')
341 {
342 return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/');
343 }
344
345 // -------------------------------------------------------------
346
347 /**
348 * Build URI string for use in Config::site_url() and Config::base_url()
349 *
350 * @access protected
351 * @param $uri
352 * @return string
353 */
354 protected function _uri_string($uri)
355 {
356 if ($this->item('enable_query_strings') == FALSE)
357 {
358 if (is_array($uri))
359 {
360 $uri = implode('/', $uri);
361 }
362 $uri = trim($uri, '/');
363 }
364 else
365 {
366 if (is_array($uri))
367 {
368 $i = 0;
369 $str = '';
370 foreach ($uri as $key => $val)
371 {
372 $prefix = ($i == 0) ? '' : '&';
373 $str .= $prefix.$key.'='.$val;
374 $i++;
375 }
376 $uri = $str;
377 }
378 }
379 return $uri;
380 }
381
382 // --------------------------------------------------------------------
383
384 /**
385 * System URL
386 *
387 * @access public
388 * @return string
389 */
390 function system_url()
391 {
392 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
393 return $this->slash_item('base_url').end($x).'/';
394 }
395
396 // --------------------------------------------------------------------
397
398 /**
399 * Set a config file item
400 *
401 * @access public
402 * @param string the config item key
403 * @param string the config item value
404 * @return void
405 */
406 function set_item($item, $value, $index = '' )
407 {
408 if ($index == '')
409 {
410 $this->config[$item] = $value;
411 }
412 else
413 {
414 $this->config[$index][$item] = $value;
415 }
416 }
417
418 // --------------------------------------------------------------------
419
420 /**
421 * Assign to Config
422 *
423 * This function is called by the front controller (CodeIgniter.php)
424 * after the Config class is instantiated. It permits config items
425 * to be assigned or overriden by variables contained in the index.php file
426 *
427 * @access private
428 * @param array
429 * @return void
430 */
431 function _assign_to_config($items = array())
432 {
433 if (is_array($items))
434 {
435 foreach ($items as $key => $val)
436 {
437 $this->set_item($key, $val);
438 }
439 }
440 }
441 }
442
443 // END CI_Config class
444
445 /* End of file Config.php */
446 /* Location: ./system/core/Config.php */
447