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