Common.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 function is_really_writable($file)
00043 {
00044
00045 if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
00046 {
00047 return is_writable($file);
00048 }
00049
00050
00051
00052 if (is_dir($file))
00053 {
00054 $file = rtrim($file, '/').'/'.md5(rand(1,100));
00055
00056 if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
00057 {
00058 return FALSE;
00059 }
00060
00061 fclose($fp);
00062 @chmod($file, DIR_WRITE_MODE);
00063 @unlink($file);
00064 return TRUE;
00065 }
00066 elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
00067 {
00068 return FALSE;
00069 }
00070
00071 fclose($fp);
00072 return TRUE;
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 function &load_class($class, $instantiate = TRUE)
00090 {
00091 static $objects = array();
00092
00093
00094 if (isset($objects[$class]))
00095 {
00096 return $objects[$class];
00097 }
00098
00099
00100
00101 if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
00102 {
00103 require(BASEPATH.'libraries/'.$class.EXT);
00104 require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
00105 $is_subclass = TRUE;
00106 }
00107 else
00108 {
00109 if (file_exists(APPPATH.'libraries/'.$class.EXT))
00110 {
00111 require(APPPATH.'libraries/'.$class.EXT);
00112 $is_subclass = FALSE;
00113 }
00114 else
00115 {
00116 require(BASEPATH.'libraries/'.$class.EXT);
00117 $is_subclass = FALSE;
00118 }
00119 }
00120
00121 if ($instantiate == FALSE)
00122 {
00123 $objects[$class] = TRUE;
00124 return $objects[$class];
00125 }
00126
00127 if ($is_subclass == TRUE)
00128 {
00129 $name = config_item('subclass_prefix').$class;
00130 $objects[$class] =& new $name();
00131 return $objects[$class];
00132 }
00133
00134 $name = ($class != 'Controller') ? 'CI_'.$class : $class;
00135
00136 $objects[$class] =& new $name();
00137 return $objects[$class];
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 function &get_config()
00147 {
00148 static $main_conf;
00149
00150 if ( ! isset($main_conf))
00151 {
00152 if ( ! file_exists(APPPATH.'config/config'.EXT))
00153 {
00154 exit('The configuration file config'.EXT.' does not exist.');
00155 }
00156
00157 require(APPPATH.'config/config'.EXT);
00158
00159 if ( ! isset($config) OR ! is_array($config))
00160 {
00161 exit('Your config file does not appear to be formatted correctly.');
00162 }
00163
00164 $main_conf[0] =& $config;
00165 }
00166 return $main_conf[0];
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 function config_item($item)
00176 {
00177 static $config_item = array();
00178
00179 if ( ! isset($config_item[$item]))
00180 {
00181 $config =& get_config();
00182
00183 if ( ! isset($config[$item]))
00184 {
00185 return FALSE;
00186 }
00187 $config_item[$item] = $config[$item];
00188 }
00189
00190 return $config_item[$item];
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 function show_error($message)
00207 {
00208 $error =& load_class('Exceptions');
00209 echo $error->show_error('An Error Was Encountered', $message);
00210 exit;
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 function show_404($page = '')
00225 {
00226 $error =& load_class('Exceptions');
00227 $error->show_404($page);
00228 exit;
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 function log_message($level = 'error', $message, $php_error = FALSE)
00242 {
00243 static $LOG;
00244
00245 $config =& get_config();
00246 if ($config['log_threshold'] == 0)
00247 {
00248 return;
00249 }
00250
00251 $LOG =& load_class('Log');
00252 $LOG->write_log($level, $message, $php_error);
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 function _exception_handler($severity, $message, $filepath, $line)
00270 {
00271
00272
00273
00274
00275
00276
00277
00278 if ($severity == E_STRICT)
00279 {
00280 return;
00281 }
00282
00283 $error =& load_class('Exceptions');
00284
00285
00286
00287
00288
00289 if (($severity & error_reporting()) == $severity)
00290 {
00291 $error->show_php_error($severity, $message, $filepath, $line);
00292 }
00293
00294
00295 $config =& get_config();
00296 if ($config['log_threshold'] == 0)
00297 {
00298 return;
00299 }
00300
00301 $error->log_exception($severity, $message, $filepath, $line);
00302 }
00303
00304
00305
00306
00307