| 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | class CI_Loader { |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | var $_ci_ob_level; |
|---|
| 33 | var $_ci_view_path = ''; |
|---|
| 34 | var $_ci_is_php5 = FALSE; |
|---|
| 35 | var $_ci_is_instance = FALSE; |
|---|
| 36 | var $_ci_cached_vars = array(); |
|---|
| 37 | var $_ci_classes = array(); |
|---|
| 38 | var $_ci_models = array(); |
|---|
| 39 | var $_ci_helpers = array(); |
|---|
| 40 | var $_ci_plugins = array(); |
|---|
| 41 | var $_ci_scripts = array(); |
|---|
| 42 | var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | function CI_Loader() |
|---|
| 53 | { |
|---|
| 54 | $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; |
|---|
| 55 | $this->_ci_view_path = APPPATH.'views/'; |
|---|
| 56 | $this->_ci_ob_level = ob_get_level(); |
|---|
| 57 | |
|---|
| 58 | log_message('debug', "Loader Class Initialized"); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | function library($library = '', $params = NULL) |
|---|
| 75 | { |
|---|
| 76 | if ($library == '') |
|---|
| 77 | { |
|---|
| 78 | return FALSE; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | if (is_array($library)) |
|---|
| 82 | { |
|---|
| 83 | foreach ($library as $class) |
|---|
| 84 | { |
|---|
| 85 | $this->_ci_load_class($class, $params); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | else |
|---|
| 89 | { |
|---|
| 90 | $this->_ci_load_class($library, $params); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | $this->_ci_assign_to_models(); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | function model($model, $name = '', $db_conn = FALSE) |
|---|
| 109 | { |
|---|
| 110 | if (is_array($model)) |
|---|
| 111 | { |
|---|
| 112 | foreach($model as $babe) |
|---|
| 113 | { |
|---|
| 114 | $this->model($babe); |
|---|
| 115 | } |
|---|
| 116 | return; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | if ($model == '') |
|---|
| 120 | { |
|---|
| 121 | return; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | if (strpos($model, '/') === FALSE) |
|---|
| 126 | { |
|---|
| 127 | $path = ''; |
|---|
| 128 | } |
|---|
| 129 | else |
|---|
| 130 | { |
|---|
| 131 | $x = explode('/', $model); |
|---|
| 132 | $model = end($x); |
|---|
| 133 | unset($x[count($x)-1]); |
|---|
| 134 | $path = implode('/', $x).'/'; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | if ($name == '') |
|---|
| 138 | { |
|---|
| 139 | $name = $model; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | if (in_array($name, $this->_ci_models, TRUE)) |
|---|
| 143 | { |
|---|
| 144 | return; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | $CI =& get_instance(); |
|---|
| 148 | if (isset($CI->$name)) |
|---|
| 149 | { |
|---|
| 150 | show_error('The model name you are loading is the name of a resource that is already being used: '.$name); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | $model = strtolower($model); |
|---|
| 154 | |
|---|
| 155 | if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) |
|---|
| 156 | { |
|---|
| 157 | show_error('Unable to locate the model you have specified: '.$model); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | if ($db_conn !== FALSE AND ! class_exists('CI_DB')) |
|---|
| 161 | { |
|---|
| 162 | if ($db_conn === TRUE) |
|---|
| 163 | $db_conn = ''; |
|---|
| 164 | |
|---|
| 165 | $CI->load->database($db_conn, FALSE, TRUE); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | if ( ! class_exists('Model')) |
|---|
| 169 | { |
|---|
| 170 | load_class('Model', FALSE); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | require_once(APPPATH.'models/'.$path.$model.EXT); |
|---|
| 174 | |
|---|
| 175 | $model = ucfirst($model); |
|---|
| 176 | |
|---|
| 177 | $CI->$name = new $model(); |
|---|
| 178 | $CI->$name->_assign_libraries(); |
|---|
| 179 | |
|---|
| 180 | $this->_ci_models[] = $name; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | function database($params = '', $return = FALSE, $active_record = FALSE) |
|---|
| 195 | { |
|---|
| 196 | |
|---|
| 197 | $CI =& get_instance(); |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE AND isset($CI->db) AND is_object($CI->db)) |
|---|
| 201 | { |
|---|
| 202 | return FALSE; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | require_once(BASEPATH.'database/DB'.EXT); |
|---|
| 206 | |
|---|
| 207 | if ($return === TRUE) |
|---|
| 208 | { |
|---|
| 209 | return DB($params, $active_record); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | $CI->db = ''; |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | $CI->db =& DB($params, $active_record); |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | $this->_ci_assign_to_models(); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | function dbutil() |
|---|
| 232 | { |
|---|
| 233 | if ( ! class_exists('CI_DB')) |
|---|
| 234 | { |
|---|
| 235 | $this->database(); |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | $CI =& get_instance(); |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | $CI->load->dbforge(); |
|---|
| 243 | |
|---|
| 244 | require_once(BASEPATH.'database/DB_utility'.EXT); |
|---|
| 245 | require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); |
|---|
| 246 | $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; |
|---|
| 247 | |
|---|
| 248 | $CI->dbutil =& new $class(); |
|---|
| 249 | |
|---|
| 250 | $CI->load->_ci_assign_to_models(); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | function dbforge() |
|---|
| 262 | { |
|---|
| 263 | if ( ! class_exists('CI_DB')) |
|---|
| 264 | { |
|---|
| 265 | $this->database(); |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | $CI =& get_instance(); |
|---|
| 269 | |
|---|
| 270 | require_once(BASEPATH.'database/DB_forge'.EXT); |
|---|
| 271 | require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); |
|---|
| 272 | $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; |
|---|
| 273 | |
|---|
| 274 | $CI->dbforge = new $class(); |
|---|
| 275 | |
|---|
| 276 | $CI->load->_ci_assign_to_models(); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | function view($view, $vars = array(), $return = FALSE) |
|---|
| 299 | { |
|---|
| 300 | return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | function file($path, $return = FALSE) |
|---|
| 316 | { |
|---|
| 317 | return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | function vars($vars = array()) |
|---|
| 333 | { |
|---|
| 334 | $vars = $this->_ci_object_to_array($vars); |
|---|
| 335 | |
|---|
| 336 | if (is_array($vars) AND count($vars) > 0) |
|---|
| 337 | { |
|---|
| 338 | foreach ($vars as $key => $val) |
|---|
| 339 | { |
|---|
| 340 | $this->_ci_cached_vars[$key] = $val; |
|---|
| 341 | } |
|---|
| 342 | } |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | function helper($helpers = array()) |
|---|
| 357 | { |
|---|
| 358 | if ( ! is_array($helpers)) |
|---|
| 359 | { |
|---|
| 360 | $helpers = array($helpers); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | foreach ($helpers as $helper) |
|---|
| 364 | { |
|---|
| 365 | $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); |
|---|
| 366 | |
|---|
| 367 | if (isset($this->_ci_helpers[$helper])) |
|---|
| 368 | { |
|---|
| 369 | continue; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | if (file_exists($ext_helper)) |
|---|
| 376 | { |
|---|
| 377 | $base_helper = BASEPATH.'helpers/'.$helper.EXT; |
|---|
| 378 | |
|---|
| 379 | if ( ! file_exists($base_helper)) |
|---|
| 380 | { |
|---|
| 381 | show_error('Unable to load the requested file: helpers/'.$helper.EXT); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | include_once($ext_helper); |
|---|
| 385 | include_once($base_helper); |
|---|
| 386 | } |
|---|
| 387 | elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) |
|---|
| 388 | { |
|---|
| 389 | include_once(APPPATH.'helpers/'.$helper.EXT); |
|---|
| 390 | } |
|---|
| 391 | else |
|---|
| 392 | { |
|---|
| 393 | if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) |
|---|
| 394 | { |
|---|
| 395 | include_once(BASEPATH.'helpers/'.$helper.EXT); |
|---|
| 396 | } |
|---|
| 397 | else |
|---|
| 398 | { |
|---|
| 399 | show_error('Unable to load the requested file: helpers/'.$helper.EXT); |
|---|
| 400 | } |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | $this->_ci_helpers[$helper] = TRUE; |
|---|
| 404 | |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | function helpers($helpers = array()) |
|---|
| 423 | { |
|---|
| 424 | $this->helper($helpers); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | function plugin($plugins = array()) |
|---|
| 439 | { |
|---|
| 440 | if ( ! is_array($plugins)) |
|---|
| 441 | { |
|---|
| 442 | $plugins = array($plugins); |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | foreach ($plugins as $plugin) |
|---|
| 446 | { |
|---|
| 447 | $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); |
|---|
| 448 | |
|---|
| 449 | if (isset($this->_ci_plugins[$plugin])) |
|---|
| 450 | { |
|---|
| 451 | continue; |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) |
|---|
| 455 | { |
|---|
| 456 | include_once(APPPATH.'plugins/'.$plugin.EXT); |
|---|
| 457 | } |
|---|
| 458 | else |
|---|
| 459 | { |
|---|
| 460 | if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) |
|---|
| 461 | { |
|---|
| 462 | include_once(BASEPATH.'plugins/'.$plugin.EXT); |
|---|
| 463 | } |
|---|
| 464 | else |
|---|
| 465 | { |
|---|
| 466 | show_error('Unable to load the requested file: plugins/'.$plugin.EXT); |
|---|
| 467 | } |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | $this->_ci_plugins[$plugin] = TRUE; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | function plugins($plugins = array()) |
|---|
| 489 | { |
|---|
| 490 | $this->plugin($plugins); |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | function script($scripts = array()) |
|---|
| 509 | { |
|---|
| 510 | if ( ! is_array($scripts)) |
|---|
| 511 | { |
|---|
| 512 | $scripts = array($scripts); |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | foreach ($scripts as $script) |
|---|
| 516 | { |
|---|
| 517 | $script = strtolower(str_replace(EXT, '', $script)); |
|---|
| 518 | |
|---|
| 519 | if (isset($this->_ci_scripts[$script])) |
|---|
| 520 | { |
|---|
| 521 | continue; |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) |
|---|
| 525 | { |
|---|
| 526 | show_error('Unable to load the requested script: scripts/'.$script.EXT); |
|---|
| 527 | } |
|---|
| 528 | |
|---|
| 529 | include_once(APPPATH.'scripts/'.$script.EXT); |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | function language($file = array(), $lang = '') |
|---|
| 546 | { |
|---|
| 547 | $CI =& get_instance(); |
|---|
| 548 | |
|---|
| 549 | if ( ! is_array($file)) |
|---|
| 550 | { |
|---|
| 551 | $file = array($file); |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | foreach ($file as $langfile) |
|---|
| 555 | { |
|---|
| 556 | $CI->lang->load($langfile, $lang); |
|---|
| 557 | } |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | |
|---|
| 567 | function scaffold_language($file = '', $lang = '', $return = FALSE) |
|---|
| 568 | { |
|---|
| 569 | $CI =& get_instance(); |
|---|
| 570 | return $CI->lang->load($file, $lang, $return); |
|---|
| 571 | } |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) |
|---|
| 583 | { |
|---|
| 584 | $CI =& get_instance(); |
|---|
| 585 | $CI->config->load($file, $use_sections, $fail_gracefully); |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | function scaffolding($table = '') |
|---|
| 606 | { |
|---|
| 607 | if ($table === FALSE) |
|---|
| 608 | { |
|---|
| 609 | show_error('You must include the name of the table you would like to access when you initialize scaffolding'); |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | $CI =& get_instance(); |
|---|
| 613 | $CI->_ci_scaffolding = TRUE; |
|---|
| 614 | $CI->_ci_scaff_table = $table; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | function _ci_load($_ci_data) |
|---|
| 631 | { |
|---|
| 632 | |
|---|
| 633 | foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) |
|---|
| 634 | { |
|---|
| 635 | $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | if ($_ci_path == '') |
|---|
| 640 | { |
|---|
| 641 | $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); |
|---|
| 642 | $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; |
|---|
| 643 | $_ci_path = $this->_ci_view_path.$_ci_file; |
|---|
| 644 | } |
|---|
| 645 | else |
|---|
| 646 | { |
|---|
| 647 | $_ci_x = explode('/', $_ci_path); |
|---|
| 648 | $_ci_file = end($_ci_x); |
|---|
| 649 | } |
|---|
| 650 | |
|---|
| 651 | if ( ! file_exists($_ci_path)) |
|---|
| 652 | { |
|---|
| 653 | show_error('Unable to load the requested file: '.$_ci_file); |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | if ($this->_ci_is_instance()) |
|---|
| 661 | { |
|---|
| 662 | $_ci_CI =& get_instance(); |
|---|
| 663 | foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) |
|---|
| 664 | { |
|---|
| 665 | if ( ! isset($this->$_ci_key)) |
|---|
| 666 | { |
|---|
| 667 | $this->$_ci_key =& $_ci_CI->$_ci_key; |
|---|
| 668 | } |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | |
|---|
| 676 | |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | if (is_array($_ci_vars)) |
|---|
| 681 | { |
|---|
| 682 | $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); |
|---|
| 683 | } |
|---|
| 684 | extract($this->_ci_cached_vars); |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | ob_start(); |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) |
|---|
| 705 | { |
|---|
| 706 | echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path)))); |
|---|
| 707 | } |
|---|
| 708 | else |
|---|
| 709 | { |
|---|
| 710 | include($_ci_path); |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | log_message('debug', 'File loaded: '.$_ci_path); |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | if ($_ci_return === TRUE) |
|---|
| 717 | { |
|---|
| 718 | $buffer = ob_get_contents(); |
|---|
| 719 | @ob_end_clean(); |
|---|
| 720 | return $buffer; |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | if (ob_get_level() > $this->_ci_ob_level + 1) |
|---|
| 734 | { |
|---|
| 735 | ob_end_flush(); |
|---|
| 736 | } |
|---|
| 737 | else |
|---|
| 738 | { |
|---|
| 739 | |
|---|
| 740 | global $OUT; |
|---|
| 741 | $OUT->append_output(ob_get_contents()); |
|---|
| 742 | @ob_end_clean(); |
|---|
| 743 | } |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | function _ci_load_class($class, $params = NULL) |
|---|
| 759 | { |
|---|
| 760 | |
|---|
| 761 | $class = str_replace(EXT, '', $class); |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | foreach (array(ucfirst($class), strtolower($class)) as $class) |
|---|
| 765 | { |
|---|
| 766 | $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT; |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | if (file_exists($subclass)) |
|---|
| 770 | { |
|---|
| 771 | $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; |
|---|
| 772 | |
|---|
| 773 | if ( ! file_exists($baseclass)) |
|---|
| 774 | { |
|---|
| 775 | log_message('error', "Unable to load the requested class: ".$class); |
|---|
| 776 | show_error("Unable to load the requested class: ".$class); |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | |
|---|
| 780 | if (in_array($subclass, $this->_ci_classes)) |
|---|
| 781 | { |
|---|
| 782 | $is_duplicate = TRUE; |
|---|
| 783 | log_message('debug', $class." class already loaded. Second attempt ignored."); |
|---|
| 784 | return; |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | include_once($baseclass); |
|---|
| 788 | include_once($subclass); |
|---|
| 789 | $this->_ci_classes[] = $subclass; |
|---|
| 790 | |
|---|
| 791 | return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | $is_duplicate = FALSE; |
|---|
| 796 | for ($i = 1; $i < 3; $i++) |
|---|
| 797 | { |
|---|
| 798 | $path = ($i % 2) ? APPPATH : BASEPATH; |
|---|
| 799 | $filepath = $path.'libraries/'.$class.EXT; |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | if ( ! file_exists($filepath)) |
|---|
| 803 | { |
|---|
| 804 | continue; |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | if (in_array($filepath, $this->_ci_classes)) |
|---|
| 809 | { |
|---|
| 810 | $is_duplicate = TRUE; |
|---|
| 811 | log_message('debug', $class." class already loaded. Second attempt ignored."); |
|---|
| 812 | return; |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | include_once($filepath); |
|---|
| 816 | $this->_ci_classes[] = $filepath; |
|---|
| 817 | return $this->_ci_init_class($class, '', $params); |
|---|
| 818 | } |
|---|
| 819 | } |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | if ($is_duplicate == FALSE) |
|---|
| 824 | { |
|---|
| 825 | log_message('error', "Unable to load the requested class: ".$class); |
|---|
| 826 | show_error("Unable to load the requested class: ".$class); |
|---|
| 827 | } |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | function _ci_init_class($class, $prefix = '', $config = FALSE) |
|---|
| 841 | { |
|---|
| 842 | $class = strtolower($class); |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | if ($config === NULL) |
|---|
| 846 | { |
|---|
| 847 | if (file_exists(APPPATH.'config/'.$class.EXT)) |
|---|
| 848 | { |
|---|
| 849 | include_once(APPPATH.'config/'.$class.EXT); |
|---|
| 850 | } |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | if ($prefix == '') |
|---|
| 854 | { |
|---|
| 855 | $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; |
|---|
| 856 | } |
|---|
| 857 | else |
|---|
| 858 | { |
|---|
| 859 | $name = $prefix.$class; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | $CI =& get_instance(); |
|---|
| 867 | if ($config !== NULL) |
|---|
| 868 | { |
|---|
| 869 | $CI->$classvar = new $name($config); |
|---|
| 870 | } |
|---|
| 871 | else |
|---|
| 872 | { |
|---|
| 873 | $CI->$classvar = new $name; |
|---|
| 874 | } |
|---|
| 875 | } |
|---|
| 876 | |
|---|
| 877 | |
|---|
| 878 | |
|---|
| 879 | |
|---|
| 880 | |
|---|
| 881 | |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | function _ci_autoloader() |
|---|
| 890 | { |
|---|
| 891 | include_once(APPPATH.'config/autoload'.EXT); |
|---|
| 892 | |
|---|
| 893 | if ( ! isset($autoload)) |
|---|
| 894 | { |
|---|
| 895 | return FALSE; |
|---|
| 896 | } |
|---|
| 897 | |
|---|
| 898 | |
|---|
| 899 | if (count($autoload['config']) > 0) |
|---|
| 900 | { |
|---|
| 901 | $CI =& get_instance(); |
|---|
| 902 | foreach ($autoload['config'] as $key => $val) |
|---|
| 903 | { |
|---|
| 904 | $CI->config->load($val); |
|---|
| 905 | } |
|---|
| 906 | } |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | foreach (array('helper', 'plugin', 'language') as $type) |
|---|
| 910 | { |
|---|
| 911 | if (isset($autoload[$type]) AND count($autoload[$type]) > 0) |
|---|
| 912 | { |
|---|
| 913 | $this->$type($autoload[$type]); |
|---|
| 914 | } |
|---|
| 915 | } |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | if ( ! isset($autoload['libraries'])) |
|---|
| 922 | { |
|---|
| 923 | $autoload['libraries'] = $autoload['core']; |
|---|
| 924 | } |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) |
|---|
| 928 | { |
|---|
| 929 | |
|---|
| 930 | if (in_array('database', $autoload['libraries'])) |
|---|
| 931 | { |
|---|
| 932 | $this->database(); |
|---|
| 933 | $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); |
|---|
| 934 | } |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | if (in_array('scaffolding', $autoload['libraries'])) |
|---|
| 938 | { |
|---|
| 939 | $this->scaffolding(); |
|---|
| 940 | $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | foreach ($autoload['libraries'] as $item) |
|---|
| 945 | { |
|---|
| 946 | $this->library($item); |
|---|
| 947 | } |
|---|
| 948 | } |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | if (isset($autoload['model'])) |
|---|
| 952 | { |
|---|
| 953 | $this->model($autoload['model']); |
|---|
| 954 | } |
|---|
| 955 | |
|---|
| 956 | } |
|---|
| 957 | |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | |
|---|
| 961 | |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | |
|---|
| 966 | |
|---|
| 967 | |
|---|
| 968 | |
|---|
| 969 | |
|---|
| 970 | function _ci_assign_to_models() |
|---|
| 971 | { |
|---|
| 972 | if (count($this->_ci_models) == 0) |
|---|
| 973 | { |
|---|
| 974 | return; |
|---|
| 975 | } |
|---|
| 976 | |
|---|
| 977 | if ($this->_ci_is_instance()) |
|---|
| 978 | { |
|---|
| 979 | $CI =& get_instance(); |
|---|
| 980 | foreach ($this->_ci_models as $model) |
|---|
| 981 | { |
|---|
| 982 | $CI->$model->_assign_libraries(); |
|---|
| 983 | } |
|---|
| 984 | } |
|---|
| 985 | else |
|---|
| 986 | { |
|---|
| 987 | foreach ($this->_ci_models as $model) |
|---|
| 988 | { |
|---|
| 989 | $this->$model->_assign_libraries(); |
|---|
| 990 | } |
|---|
| 991 | } |
|---|
| 992 | } |
|---|
| 993 | |
|---|
| 994 | |
|---|
| 995 | |
|---|
| 996 | |
|---|
| 997 | |
|---|
| 998 | |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | |
|---|
| 1002 | |
|---|
| 1003 | |
|---|
| 1004 | |
|---|
| 1005 | function _ci_object_to_array($object) |
|---|
| 1006 | { |
|---|
| 1007 | return (is_object($object)) ? get_object_vars($object) : $object; |
|---|
| 1008 | } |
|---|
| 1009 | |
|---|
| 1010 | |
|---|
| 1011 | |
|---|
| 1012 | |
|---|
| 1013 | |
|---|
| 1014 | |
|---|
| 1015 | |
|---|
| 1016 | |
|---|
| 1017 | |
|---|
| 1018 | function _ci_is_instance() |
|---|
| 1019 | { |
|---|
| 1020 | if ($this->_ci_is_php5 == TRUE) |
|---|
| 1021 | { |
|---|
| 1022 | return TRUE; |
|---|
| 1023 | } |
|---|
| 1024 | |
|---|
| 1025 | global $CI; |
|---|
| 1026 | return (is_object($CI)) ? TRUE : FALSE; |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | } |
|---|
| 1030 | |
|---|
| 1031 | |
|---|
| 1032 | |
|---|