1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
21 * Loads the base classes and executes the request.
23 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Common Functions
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/
30 // ------------------------------------------------------------------------
33 * Tests for file writability
35 * is_writable() returns TRUE on Windows servers when you really can't write to
36 * the file, based on the read-only attribute. is_writable() is also unreliable
37 * on Unix servers if safe_mode is on.
42 function is_really_writable($file)
44 // If we're on a Unix server with safe_mode off we call is_writable
45 if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
47 return is_writable($file);
50 // For windows servers and safe_mode "on" installations we'll actually
51 // write a file then read it. Bah...
54 $file = rtrim($file, '/').'/'.md5(rand(1,100));
56 if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
62 @chmod($file, DIR_WRITE_MODE);
66 elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
75 // ------------------------------------------------------------------------
80 * This function acts as a singleton. If the requested class does not
81 * exist it is instantiated and set to a static variable. If it has
82 * previously been instantiated the variable is returned.
85 * @param string the class name being requested
86 * @param bool optional flag that lets classes get loaded but not instantiated
89 function &load_class($class, $instantiate = TRUE)
91 static $objects = array();
93 // Does the class exist? If so, we're done...
94 if (isset($objects[$class]))
96 return $objects[$class];
99 // If the requested class does not exist in the application/libraries
100 // folder we'll load the native class from the system/libraries folder.
101 if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
103 require(BASEPATH.'libraries/'.$class.EXT);
104 require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
109 if (file_exists(APPPATH.'libraries/'.$class.EXT))
111 require(APPPATH.'libraries/'.$class.EXT);
112 $is_subclass = FALSE;
116 require(BASEPATH.'libraries/'.$class.EXT);
117 $is_subclass = FALSE;
121 if ($instantiate == FALSE)
123 $objects[$class] = TRUE;
124 return $objects[$class];
127 if ($is_subclass == TRUE)
129 $name = config_item('subclass_prefix').$class;
130 $objects[$class] =& new $name();
131 return $objects[$class];
134 $name = ($class != 'Controller') ? 'CI_'.$class : $class;
136 $objects[$class] =& new $name();
137 return $objects[$class];
141 * Loads the main config.php file
146 function &get_config()
150 if ( ! isset($main_conf))
152 if ( ! file_exists(APPPATH.'config/config'.EXT))
154 exit('The configuration file config'.EXT.' does not exist.');
157 require(APPPATH.'config/config'.EXT);
159 if ( ! isset($config) OR ! is_array($config))
161 exit('Your config file does not appear to be formatted correctly.');
164 $main_conf[0] =& $config;
166 return $main_conf[0];
175 function config_item($item)
177 static $config_item = array();
179 if ( ! isset($config_item[$item]))
181 $config =& get_config();
183 if ( ! isset($config[$item]))
187 $config_item[$item] = $config[$item];
190 return $config_item[$item];
197 * This function lets us invoke the exception class and
198 * display errors using the standard error template located
199 * in application/errors/errors.php
200 * This function will send the error page directly to the
206 function show_error($message)
208 $error =& load_class('Exceptions');
209 echo $error->show_error('An Error Was Encountered', $message);
217 * This function is similar to the show_error() function above
218 * However, instead of the standard error template it displays
224 function show_404($page = '')
226 $error =& load_class('Exceptions');
227 $error->show_404($page);
233 * Error Logging Interface
235 * We use this as a simple mechanism to access the logging
236 * class and send messages to be logged.
241 function log_message($level = 'error', $message, $php_error = FALSE)
245 $config =& get_config();
246 if ($config['log_threshold'] == 0)
251 $LOG =& load_class('Log');
252 $LOG->write_log($level, $message, $php_error);
258 * This is the custom exception handler that is declaired at the top
259 * of Codeigniter.php. The main reason we use this is permit
260 * PHP errors to be logged in our own log files since we may
261 * not have access to server logs. Since this function
262 * effectively intercepts PHP errors, however, we also need
263 * to display errors based on the current error_reporting level.
264 * We do that with the use of a PHP error template.
269 function _exception_handler($severity, $message, $filepath, $line)
271 // We don't bother with "strict" notices since they will fill up
272 // the log file with information that isn't normally very
273 // helpful. For example, if you are running PHP 5 and you
274 // use version 4 style class functions (without prefixes
275 // like "public", "private", etc.) you'll get notices telling
276 // you that these have been deprecated.
278 if ($severity == E_STRICT)
283 $error =& load_class('Exceptions');
285 // Should we display the error?
286 // We'll get the current error_reporting level and add its bits
287 // with the severity bits to find out.
289 if (($severity & error_reporting()) == $severity)
291 $error->show_php_error($severity, $message, $filepath, $line);
294 // Should we log the error? No? We're done...
295 $config =& get_config();
296 if ($config['log_threshold'] == 0)
301 $error->log_exception($severity, $message, $filepath, $line);
306 /* End of file Common.php */
307 /* Location: ./system/codeigniter/Common.php */