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