/** * Class registry * * This function acts as a singleton. If the requested class does not * exist it is instantiated and set to a static variable. If it has * previously been instantiated the variable is returned. * * @access public * @param string the class name being requested * @param bool optional flag that lets classes get loaded but not instantiated * @return object */ function &load_class($class, $instantiate = TRUE) { static $objects = array(); // Does the class exist? If so, we're done... if (isset($objects[$class])) { return $objects[$class]; } // If the requested class does not exist in the application/libraries // folder we'll load the native class from the system/libraries folder. if (file_exists(APPPATH . 'libraries/' . config_item('subclass_prefix') . $class . EXT)) { require BASEPATH . 'libraries/' . $class . EXT; require APPPATH . 'libraries/' . config_item('subclass_prefix') . $class . EXT; $is_subclass = TRUE; } else { if (file_exists(APPPATH . 'libraries/' . $class . EXT)) { require APPPATH . 'libraries/' . $class . EXT; $is_subclass = FALSE; } else { require BASEPATH . 'libraries/' . $class . EXT; $is_subclass = FALSE; } } if ($instantiate == FALSE) { $objects[$class] = TRUE; return $objects[$class]; } if ($is_subclass == TRUE) { $name = config_item('subclass_prefix') . $class; $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } $name = $class != 'Controller' ? 'CI_' . $class : $class; $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; }
/** * Load the Utilities Class * * @access public * @return string */ function dbutil() { if (!class_exists('CI_DB')) { $this->database(); } $CI =& get_instance(); // for backwards compatibility, load dbforge so we can extend dbutils off it // this use is deprecated and strongly discouraged $CI->load->dbforge(); require_once BASEPATH . 'database/DB_utility' . EXT; require_once BASEPATH . 'database/drivers/' . $CI->db->dbdriver . '/' . $CI->db->dbdriver . '_utility' . EXT; $class = 'CI_DB_' . $CI->db->dbdriver . '_utility'; $CI->dbutil =& instantiate_class(new $class()); $CI->load->_ci_assign_to_models(); }
/** * Initialize the database * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ function &DB($params = '', $active_record_override = NULL) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) and strpos($params, '://') === FALSE) { include APPPATH . 'config/database' . EXT; if (!isset($db) or count($db) == 0) { show_error('No database connection settings were found in the database config file.'); } if ($params != '') { $active_group = $params; } if (!isset($active_group) or !isset($db[$active_group])) { show_error('You have specified an invalid database connection group.'); } $params = $db[$active_group]; } elseif (is_string($params)) { /* parse the URL from the DSN string * Database settings can be passed as discreet * parameters or as a data source name in the first * parameter. DSNs must have this prototype: * $dsn = 'driver://*****:*****@hostname/database'; */ if (($dns = @parse_url($params)) === FALSE) { show_error('Invalid DB Connection String'); } $params = array('dbdriver' => $dns['scheme'], 'hostname' => isset($dns['host']) ? rawurldecode($dns['host']) : '', 'username' => isset($dns['user']) ? rawurldecode($dns['user']) : '', 'password' => isset($dns['pass']) ? rawurldecode($dns['pass']) : '', 'database' => isset($dns['path']) ? rawurldecode(substr($dns['path'], 1)) : ''); // were additional config items set? if (isset($dns['query'])) { parse_str($dns['query'], $extra); foreach ($extra as $key => $val) { // booleans please if (strtoupper($val) == "TRUE") { $val = TRUE; } elseif (strtoupper($val) == "FALSE") { $val = FALSE; } $params[$key] = $val; } } } // No DB specified yet? Beat them senseless... if (!isset($params['dbdriver']) or $params['dbdriver'] == '') { show_error('You have not selected a database type to connect to.'); } // Load the DB classes. Note: Since the active record class is optional // we need to dynamically create a class that extends proper parent class // based on whether we're using the active record class or not. // Kudos to Paul for discovering this clever use of eval() if ($active_record_override !== NULL) { $active_record = $active_record_override; } require_once BASEPATH . 'database/DB_driver' . EXT; if (!isset($active_record) or $active_record == TRUE) { require_once BASEPATH . 'database/DB_active_rec' . EXT; if (!class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_active_record { }'); } } else { if (!class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_driver { }'); } } require_once BASEPATH . 'database/drivers/' . $params['dbdriver'] . '/' . $params['dbdriver'] . '_driver' . EXT; // Instantiate the DB adapter $driver = 'CI_DB_' . $params['dbdriver'] . '_driver'; $DB =& instantiate_class(new $driver($params)); if ($DB->autoinit == TRUE) { $DB->initialize(); } return $DB; }
/** * Class registry * * This function acts as a singleton. If the requested class does not * exist it is instantiated and set to a static variable. If it has * previously been instantiated the variable is returned. * * @access public * @param string the class name being requested * @param bool optional flag that lets classes get loaded but not instantiated * @return object */ function &load_class($class, $instantiate = TRUE) { static $objects = array(); // Does the class exist? If so, we're done... if (isset($objects[$class])) { return $objects[$class]; } $subclass_prefix = config_item('subclass_prefix'); $subclass = APPPATH . "libraries/{$subclass_prefix}{$class}.php"; $baseclass = BASEPATH . "libraries/{$class}.php"; // If the requested class does not exist in the application/libraries // folder we'll load the native class from the system/libraries folder. if (file_exists($subclass)) { require $baseclass; require $subclass; $is_subclass = TRUE; } else { $overwrite_class = APPPATH . "libraries/{$class}.php"; if (file_exists($overwrite_class)) { require $overwrite_class; } else { require $baseclass; } $is_subclass = FALSE; } if (!$instantiate) { $objects[$class] = TRUE; return $objects[$class]; } if ($is_subclass == TRUE) { $name = $subclass_prefix . $class; $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } $name = $class != 'Controller' ? 'CI_' . $class : $class; $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; }
/** * Class registry * * This function acts as a singleton. If the requested class does not * exist it is instantiated and set to a static variable. If it has * previously been instantiated the variable is returned. * * @access public * @param string the class name being requested * @param string the directory where the class should be found * @param string the class name prefix * @return object */ function &load_class($class, $directory = 'libraries', $prefix = 'CI_') { static $_classes = array(); // Does the class exist? If so, we're done... if (isset($_classes[$class])) { return $_classes[$class]; } $name = FALSE; // Look for the class first in the native system/libraries folder // thenin the local application/libraries folder foreach (array(BASEPATH, APPPATH) as $path) { if (file_exists($path . $directory . '/' . $class . EXT)) { $name = $prefix . $class; if (class_exists($name) === FALSE) { require $path . $directory . '/' . $class . EXT; } break; } } // Is the request a class extension? If so we load it too if (file_exists(APPPATH . $directory . '/' . config_item('subclass_prefix') . $class . EXT)) { $name = config_item('subclass_prefix') . $class; if (class_exists($name) === FALSE) { require APPPATH . $directory . '/' . config_item('subclass_prefix') . $class . EXT; } } // Did we find the class? if ($name === FALSE) { // Note: We use exit() rather then show_error() in order to avoid a // self-referencing loop with the Excptions class exit('Unable to locate the specified class: ' . $class . EXT); } // Keep track of what we just loaded is_loaded($class); $_classes[$class] =& instantiate_class(new $name()); return $_classes[$class]; }
/** * Load the Utilities Class * * @return string */ public function dbutil() { if (class_exists('CI_DB_utility')) { return; } if (!class_exists('CI_DB')) { $this->database(); } require BASEPATH . 'database/DB_utility.php'; require BASEPATH . "database/drivers/{$this->CI->db->dbdriver}/{$this->CI->db->dbdriver}_utility.php"; $class = 'CI_DB_' . $this->CI->db->dbdriver . '_utility'; $this->CI->dbutil =& instantiate_class(new $class()); $this->CI->load->_ci_assign_to_models(); }
function sanitize($data, $type, $base = '') { $data = trim($data); if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI) { if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) { if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\\/[A-Za-z][^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x2F\\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) { $type |= SIMPLEPIE_CONSTRUCT_HTML; } else { $type |= SIMPLEPIE_CONSTRUCT_TEXT; } } if ($type & SIMPLEPIE_CONSTRUCT_BASE64) { $data = base64_decode($data); } if ($type & SIMPLEPIE_CONSTRUCT_XHTML) { if ($this->remove_div) { $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data); $data = preg_replace('/<\\/div>$/', '', $data); } else { $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data); } } if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML)) { // Strip comments if ($this->strip_comments) { $data = SimplePie_Misc::strip_comments($data); } // Strip out HTML tags and attributes that might cause various security problems. // Based on recommendations by Mark Pilgrim at: // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely if ($this->strip_htmltags) { foreach ($this->strip_htmltags as $tag) { $pcre = "/<({$tag})" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\\/{$tag}" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\\/)?>)/siU'; while (preg_match($pcre, $data)) { $data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data); } } } if ($this->strip_attributes) { foreach ($this->strip_attributes as $attrib) { $data = preg_replace('/(<[A-Za-z][^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x2F\\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\\s*=\\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x22\\x27\\x3E][^\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\x3E]*)?))?' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\\1\\2\\3>', $data); } } // Replace relative URLs $this->base = $base; foreach ($this->replace_url_attributes as $element => $attributes) { $data = $this->replace_urls($data, $element, $attributes); } // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags. if (isset($this->image_handler) && (string) $this->image_handler !== '' && $this->enable_cache) { $images = SimplePie_Misc::get_element('img', $data); foreach ($images as $img) { if (isset($img['attribs']['src']['data'])) { $image_url = call_user_func($this->cache_name_function, $img['attribs']['src']['data']); $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $image_url, 'spi'); if ($cache->load()) { $img['attribs']['src']['data'] = $this->image_handler . $image_url; $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data); } else { $file =& instantiate_class(new $this->file_class($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen)); $headers = $file->headers; if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) { if ($cache->save(array('headers' => $file->headers, 'body' => $file->body))) { $img['attribs']['src']['data'] = $this->image_handler . $image_url; $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data); } else { trigger_error("{$this->cache_location} is not writeable", E_USER_WARNING); } } } } } } // Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data $data = trim($data); } if ($type & SIMPLEPIE_CONSTRUCT_IRI) { $data = SimplePie_Misc::absolutize_url($data, $base); } if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI)) { $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8'); } if ($this->output_encoding !== 'UTF-8') { $data = SimplePie_Misc::change_encoding($data, 'UTF-8', $this->output_encoding); } } return $data; }
/** * fooStack lets plugins each extend their own CI libraries. * in order to be able to do that we have to find out what files are to be included * and what objects have to be intermediary */ function find_load_order($class) { //user prefix $prefix = config_item('subclass_prefix'); //foostack config var $fs = foo_config(); //foostack end user class prefix - foostack classes can be exended by the user $fooprefix = $fs['prefix']; //main cases: //base classes - fooextension classes - fooadditional classes - user classes - user extension classes // load base class (fooconfig decideds if we extend it) // load non-base class, either fooclass $is_fooclass = FALSE; //is it in a subfolder? $folders = explode('/', $class); if (count($folders) > 1) { $class = array_pop($folders); $folders = join('/', $folders) . '/'; } else { $folders = ''; } //echo "folder:".print_r($folders,1); //echo "class:".print_r($class,1)." *\n"; // Does the class exist? If so, we're done... if (isset($objects[$class])) { return $objects[$class]; } // user extension class? if (file_exists(APPPATH . 'libraries/' . $folders . $prefix . $class . EXT)) { // require Base Class require BASEPATH . 'libraries/' . $class . EXT; // extend with fooStack class if (file_exists(FSPATH . $fooprefix . $class . EXT)) { require FSPATH . $fooprefix . $class . EXT; $is_fooclass = TRUE; } // load user class require APPPATH . 'libraries/' . $folders . $prefix . $class . EXT; $is_subclass = TRUE; } else { // independent user class? if (file_exists(APPPATH . 'libraries/' . $folders . $class . EXT)) { //load it require APPPATH . 'libraries/' . $folders . $class . EXT; $is_subclass = FALSE; $is_fooclass = FALSE; } else { // so it must be a base class / or foostack class require BASEPATH . 'libraries/' . $class . EXT; if (file_exists(FSPATH . $fooprefix . $class . EXT)) { require FSPATH . $fooprefix . $class . EXT; $is_fooclass = TRUE; } $is_subclass = FALSE; } } if ($instantiate == FALSE) { $objects[$class] = TRUE; return $objects[$class]; } if ($is_subclass == TRUE) { $name = $prefix . $class; echo "Subclass " . $name . " loading.."; $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } $prefix = $is_fooclass ? $fooprefix : 'CI_'; $name = $class != 'Controller' ? $prefix . $class : $class; //echo "Class ". $name. " loading.."; $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; }