code
stringlengths
17
247k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public function remove_package_path($path = '') { $config =& $this->_ci_get_component('config'); if ($path === '') { array_shift($this->_ci_library_paths); array_shift($this->_ci_model_paths); array_shift($this->_ci_helper_paths); array_shift($this->_ci_view_paths); array_pop($config->_config_paths); } else { $path = rtrim($path, '/').'/'; foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) { if (($key = array_search($path, $this->{$var})) !== FALSE) { unset($this->{$var}[$key]); } } if (isset($this->_ci_view_paths[$path.'views/'])) { unset($this->_ci_view_paths[$path.'views/']); } if (($key = array_search($path, $config->_config_paths)) !== FALSE) { unset($config->_config_paths[$key]); } } // make sure the application default paths are still in the array $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH))); $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE)); $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); return $this; }
Remove Package Path Remove a path from the library, model, helper and/or config path arrays if it exists. If no path is provided, the most recently added path will be removed removed. @param string $path Path to remove @return object
remove_package_path
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
protected function _ci_load_stock_library($library_name, $file_path, $params, $object_name) { $prefix = 'CI_'; if (class_exists($prefix.$library_name, FALSE)) { if (class_exists(config_item('subclass_prefix').$library_name, FALSE)) { $prefix = config_item('subclass_prefix'); } $property = $object_name; if (empty($property)) { $property = strtolower($library_name); isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; } $CI =& get_instance(); if ( ! isset($CI->$property)) { return $this->_ci_init_library($library_name, $prefix, $params, $object_name); } log_message('debug', $library_name.' class already loaded. Second attempt ignored.'); return; } $paths = $this->_ci_library_paths; array_pop($paths); // BASEPATH array_pop($paths); // APPPATH (needs to be the first path checked) array_unshift($paths, APPPATH); foreach ($paths as $path) { if (file_exists($path = $path.'libraries/'.$file_path.$library_name.'.php')) { // Override include_once($path); if (class_exists($prefix.$library_name, FALSE)) { return $this->_ci_init_library($library_name, $prefix, $params, $object_name); } log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name); } } include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php'); // Check for extensions $subclass = config_item('subclass_prefix').$library_name; foreach ($paths as $path) { if (file_exists($path = $path.'libraries/'.$file_path.$subclass.'.php')) { include_once($path); if (class_exists($subclass, FALSE)) { $prefix = config_item('subclass_prefix'); break; } log_message('debug', $path.' exists, but does not declare '.$subclass); } } return $this->_ci_init_library($library_name, $prefix, $params, $object_name); }
Internal CI Stock Library Loader @used-by CI_Loader::_ci_load_library() @uses CI_Loader::_ci_init_library() @param string $library_name Library name to load @param string $file_path Path to the library filename, relative to libraries/ @param mixed $params Optional parameters to pass to the class constructor @param string $object_name Optional object name to assign to @return void
_ci_load_stock_library
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
protected function _ci_prepare_view_vars($vars) { if ( ! is_array($vars)) { $vars = is_object($vars) ? get_object_vars($vars) : array(); } foreach (array_keys($vars) as $key) { if (strncmp($key, '_ci_', 4) === 0) { unset($vars[$key]); } } return $vars; }
Prepare variables for _ci_vars, to be later extract()-ed inside views Converts objects to associative arrays and filters-out internal variable names (i.e. keys prefixed with '_ci_'). @param mixed $vars @return array
_ci_prepare_view_vars
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
protected function &_ci_get_component($component) { $CI =& get_instance(); return $CI->$component; }
CI Component getter Get a reference to a specific library or model. @param string $component Component name @return bool
_ci_get_component
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function __construct($routing = NULL) { $this->config =& load_class('Config', 'core'); $this->uri =& load_class('URI', 'core'); $this->enable_query_strings = ( ! is_cli() && $this->config->item('enable_query_strings') === TRUE); // If a directory override is configured, it has to be set before any dynamic routing logic is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']); $this->_set_routing(); // Set any routing overrides that may exist in the main index file if (is_array($routing)) { empty($routing['controller']) OR $this->set_class($routing['controller']); empty($routing['function']) OR $this->set_method($routing['function']); } log_message('info', 'Router Class Initialized'); }
Class constructor Runs the route mapping function. @param array $routing @return void
__construct
php
ronknight/InventorySystem
system/core/Router.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Router.php
MIT
protected function _set_routing() { // Load the routes.php file. It would be great if we could // skip this for enable_query_strings = TRUE, but then // default_controller would be empty ... if (file_exists(APPPATH.'config/routes.php')) { include(APPPATH.'config/routes.php'); } if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } // Validate & get reserved routes if (isset($route) && is_array($route)) { isset($route['default_controller']) && $this->default_controller = $route['default_controller']; isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; unset($route['default_controller'], $route['translate_uri_dashes']); $this->routes = $route; } // Are query strings enabled in the config file? Normally CI doesn't utilize query strings // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently if ($this->enable_query_strings) { // If the directory is set at this time, it means an override exists, so skip the checks if ( ! isset($this->directory)) { $_d = $this->config->item('directory_trigger'); $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; if ($_d !== '') { $this->uri->filter_uri($_d); $this->set_directory($_d); } } $_c = trim($this->config->item('controller_trigger')); if ( ! empty($_GET[$_c])) { $this->uri->filter_uri($_GET[$_c]); $this->set_class($_GET[$_c]); $_f = trim($this->config->item('function_trigger')); if ( ! empty($_GET[$_f])) { $this->uri->filter_uri($_GET[$_f]); $this->set_method($_GET[$_f]); } $this->uri->rsegments = array( 1 => $this->class, 2 => $this->method ); } else { $this->_set_default_controller(); } // Routing rules don't apply to query strings and we don't need to detect // directories, so we're done here return; } // Is there anything to parse? if ($this->uri->uri_string !== '') { $this->_parse_routes(); } else { $this->_set_default_controller(); } }
Set route mapping Determines what should be served based on the URI request, as well as any "routes" that have been set in the routing config file. @return void
_set_routing
php
ronknight/InventorySystem
system/core/Router.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Router.php
MIT
protected function _validate_request($segments) { $c = count($segments); $directory_override = isset($this->directory); // Loop through our segments and return as soon as a controller // is found or when such a directory doesn't exist while ($c-- > 0) { $test = $this->directory .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && $directory_override === FALSE && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]) ) { $this->set_directory(array_shift($segments), TRUE); continue; } return $segments; } // This means that all segments were actually directories return $segments; }
Validate request Attempts validate the URI request and determine the controller path. @used-by CI_Router::_set_request() @param array $segments URI segments @return mixed URI segments
_validate_request
php
ronknight/InventorySystem
system/core/Router.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Router.php
MIT
public function fetch_directory() { return $this->directory; }
Fetch directory Feches the sub-directory (if any) that contains the requested controller class. @deprecated 3.0.0 Read the 'directory' property instead @return string
fetch_directory
php
ronknight/InventorySystem
system/core/Router.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Router.php
MIT
public function __construct() { $this->config =& get_config(); // Set the base_url automatically if none was provided if (empty($this->config['base_url'])) { if (isset($_SERVER['SERVER_ADDR'])) { if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { $server_addr = '['.$_SERVER['SERVER_ADDR'].']'; } else { $server_addr = $_SERVER['SERVER_ADDR']; } $base_url = (is_https() ? 'https' : 'http').'://'.$server_addr .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); } else { $base_url = 'http://localhost/'; } $this->set_item('base_url', $base_url); } log_message('info', 'Config Class Initialized'); }
Class constructor Sets the $config data from the primary config.php file as a class variable. @return void
__construct
php
ronknight/InventorySystem
system/core/Config.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Config.php
MIT
public function slash_item($item) { if ( ! isset($this->config[$item])) { return NULL; } elseif (trim($this->config[$item]) === '') { return ''; } return rtrim($this->config[$item], '/').'/'; }
Fetch a config file item with slash appended (if not empty) @param string $item Config item name @return string|null The configuration item or NULL if the item doesn't exist
slash_item
php
ronknight/InventorySystem
system/core/Config.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Config.php
MIT
public function site_url($uri = '', $protocol = NULL) { $base_url = $this->slash_item('base_url'); if (isset($protocol)) { // For protocol-relative links if ($protocol === '') { $base_url = substr($base_url, strpos($base_url, '//')); } else { $base_url = $protocol.substr($base_url, strpos($base_url, '://')); } } if (empty($uri)) { return $base_url.$this->item('index_page'); } $uri = $this->_uri_string($uri); if ($this->item('enable_query_strings') === FALSE) { $suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : ''; if ($suffix !== '') { if (($offset = strpos($uri, '?')) !== FALSE) { $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset); } else { $uri .= $suffix; } } return $base_url.$this->slash_item('index_page').$uri; } elseif (strpos($uri, '?') === FALSE) { $uri = '?'.$uri; } return $base_url.$this->item('index_page').$uri; }
Site URL Returns base_url . index_page [. uri_string] @uses CI_Config::_uri_string() @param string|string[] $uri URI string or an array of segments @param string $protocol @return string
site_url
php
ronknight/InventorySystem
system/core/Config.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Config.php
MIT
public function base_url($uri = '', $protocol = NULL) { $base_url = $this->slash_item('base_url'); if (isset($protocol)) { // For protocol-relative links if ($protocol === '') { $base_url = substr($base_url, strpos($base_url, '//')); } else { $base_url = $protocol.substr($base_url, strpos($base_url, '://')); } } return $base_url.$this->_uri_string($uri); }
Base URL Returns base_url [. uri_string] @uses CI_Config::_uri_string() @param string|string[] $uri URI string or an array of segments @param string $protocol @return string
base_url
php
ronknight/InventorySystem
system/core/Config.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Config.php
MIT
public function __get($key) { // Debugging note: // If you're here because you're getting an error message // saying 'Undefined Property: system/core/Model.php', it's // most likely a typo in your model code. return get_instance()->$key; }
__get magic Allows models to access CI's loaded classes using the same syntax as controllers. @param string $key
__get
php
ronknight/InventorySystem
system/core/Model.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Model.php
MIT
function is_php($version) { static $_is_php; $version = (string) $version; if ( ! isset($_is_php[$version])) { $_is_php[$version] = version_compare(PHP_VERSION, $version, '>='); } return $_is_php[$version]; }
Determines if the current version of PHP is equal to or greater than the supplied value @param string @return bool TRUE if the current version is $version or higher
is_php
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function is_really_writable($file) { // If we're on a Unix server with safe_mode off we call is_writable if (DIRECTORY_SEPARATOR === '/' && (is_php('5.4') OR ! ini_get('safe_mode'))) { return is_writable($file); } /* For Windows servers and safe_mode "on" installations we'll actually * write a file then read it. Bah... */ if (is_dir($file)) { $file = rtrim($file, '/').'/'.md5(mt_rand()); if (($fp = @fopen($file, 'ab')) === FALSE) { return FALSE; } fclose($fp); @chmod($file, 0777); @unlink($file); return TRUE; } elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE) { return FALSE; } fclose($fp); return TRUE; }
Tests for file writability is_writable() returns TRUE on Windows servers when you really can't write to the file, based on the read-only attribute. is_writable() is also unreliable on Unix servers if safe_mode is on. @link https://bugs.php.net/bug.php?id=54709 @param string @return bool
is_really_writable
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function &load_class($class, $directory = 'libraries', $param = NULL) { 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 local application/libraries folder // then in the native system/libraries folder foreach (array(APPPATH, BASEPATH) as $path) { if (file_exists($path.$directory.'/'.$class.'.php')) { $name = 'CI_'.$class; if (class_exists($name, FALSE) === FALSE) { require_once($path.$directory.'/'.$class.'.php'); } break; } } // Is the request a class extension? If so we load it too if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php')) { $name = config_item('subclass_prefix').$class; if (class_exists($name, FALSE) === FALSE) { require_once(APPPATH.$directory.'/'.$name.'.php'); } } // Did we find the class? if ($name === FALSE) { // Note: We use exit() rather than show_error() in order to avoid a // self-referencing loop with the Exceptions class set_status_header(503); echo 'Unable to locate the specified class: '.$class.'.php'; exit(5); // EXIT_UNK_CLASS } // Keep track of what we just loaded is_loaded($class); $_classes[$class] = isset($param) ? new $name($param) : new $name(); return $_classes[$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. @param string the class name being requested @param string the directory where the class should be found @param mixed an optional argument to pass to the class constructor @return object
load_class
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function &is_loaded($class = '') { static $_is_loaded = array(); if ($class !== '') { $_is_loaded[strtolower($class)] = $class; } return $_is_loaded; }
Keeps track of which libraries have been loaded. This function is called by the load_class() function above @param string @return array
is_loaded
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function config_item($item) { static $_config; if (empty($_config)) { // references cannot be directly assigned to static variables, so we use an array $_config[0] =& get_config(); } return isset($_config[0][$item]) ? $_config[0][$item] : NULL; }
Returns the specified config item @param string @return mixed
config_item
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function &get_mimes() { static $_mimes; if (empty($_mimes)) { $_mimes = file_exists(APPPATH.'config/mimes.php') ? include(APPPATH.'config/mimes.php') : array(); if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { $_mimes = array_merge($_mimes, include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')); } } return $_mimes; }
Returns the MIME types array from config/mimes.php @return array
get_mimes
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function is_https() { if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { return TRUE; } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') { return TRUE; } elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { return TRUE; } return FALSE; }
Is HTTPS? Determines if the application is accessed via an encrypted (HTTPS) connection. @return bool
is_https
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function is_cli() { return (PHP_SAPI === 'cli' OR defined('STDIN')); }
Is CLI? Test to see if a request was made from the command line. @return bool
is_cli
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') { $status_code = abs($status_code); if ($status_code < 100) { $exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN $status_code = 500; } else { $exit_status = 1; // EXIT_ERROR } $_error =& load_class('Exceptions', 'core'); echo $_error->show_error($heading, $message, 'error_general', $status_code); exit($exit_status); }
Error Handler This function lets us invoke the exception class and display errors using the standard error template located in application/views/errors/error_general.php This function will send the error page directly to the browser and exit. @param string @param int @param string @return void
show_error
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function show_404($page = '', $log_error = TRUE) { $_error =& load_class('Exceptions', 'core'); $_error->show_404($page, $log_error); exit(4); // EXIT_UNKNOWN_FILE }
404 Page Handler This function is similar to the show_error() function above However, instead of the standard error template it displays 404 errors. @param string @param bool @return void
show_404
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function log_message($level, $message) { static $_log; if ($_log === NULL) { // references cannot be directly assigned to static variables, so we use an array $_log[0] =& load_class('Log', 'core'); } $_log[0]->write_log($level, $message); }
Error Logging Interface We use this as a simple mechanism to access the logging class and send messages to be logged. @param string the error level: 'error', 'debug' or 'info' @param string the error message @return void
log_message
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function _error_handler($severity, $message, $filepath, $line) { $is_error = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $severity) === $severity); // When an error occurred, set the status header to '500 Internal Server Error' // to indicate to the client something went wrong. // This can't be done within the $_error->show_php_error method because // it is only called when the display_errors flag is set (which isn't usually // the case in a production environment) or when errors are ignored because // they are above the error_reporting threshold. if ($is_error) { set_status_header(500); } // Should we ignore the error? We'll get the current error_reporting // level and add its bits with the severity bits to find out. if (($severity & error_reporting()) !== $severity) { return; } $_error =& load_class('Exceptions', 'core'); $_error->log_exception($severity, $message, $filepath, $line); // Should we display the error? if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { $_error->show_php_error($severity, $message, $filepath, $line); } // If the error is fatal, the execution of the script should be stopped because // errors can't be recovered from. Halting the script conforms with PHP's // default error handling. See http://www.php.net/manual/en/errorfunc.constants.php if ($is_error) { exit(1); // EXIT_ERROR } }
Error Handler This is the custom error handler that is declared at the (relative) top of CodeIgniter.php. The main reason we use this is to permit PHP errors to be logged in our own log files since the user may not have access to server logs. Since this function effectively intercepts PHP errors, however, we also need to display errors based on the current error_reporting level. We do that with the use of a PHP error template. @param int $severity @param string $message @param string $filepath @param int $line @return void
_error_handler
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function _exception_handler($exception) { $_error =& load_class('Exceptions', 'core'); $_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine()); is_cli() OR set_status_header(500); // Should we display the error? if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { $_error->show_exception($exception); } exit(1); // EXIT_ERROR }
Exception Handler Sends uncaught exceptions to the logger and displays them only if display_errors is On so that they don't show up in production environments. @param Exception $exception @return void
_exception_handler
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function _shutdown_handler() { $last_error = error_get_last(); if (isset($last_error) && ($last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { _error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']); } }
Shutdown Handler This is the shutdown handler that is declared at the top of CodeIgniter.php. The main reason we use this is to simulate a complete custom exception handler. E_STRICT is purposively neglected because such events may have been caught. Duplication or none? None is preferred for now. @link http://insomanic.me.uk/post/229851073/php-trick-catching-fatal-errors-e-error-with-a @return void
_shutdown_handler
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function remove_invisible_characters($str, $url_encoded = TRUE) { $non_displayables = array(); // every control character except newline (dec 10), // carriage return (dec 13) and horizontal tab (dec 09) if ($url_encoded) { $non_displayables[] = '/%0[0-8bcef]/i'; // url encoded 00-08, 11, 12, 14, 15 $non_displayables[] = '/%1[0-9a-f]/i'; // url encoded 16-31 $non_displayables[] = '/%7f/i'; // url encoded 127 } $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 do { $str = preg_replace($non_displayables, '', $str, -1, $count); } while ($count); return $str; }
Remove Invisible Characters This prevents sandwiching null characters between ascii characters, like Java\0script. @param string @param bool @return string
remove_invisible_characters
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function function_usable($function_name) { static $_suhosin_func_blacklist; if (function_exists($function_name)) { if ( ! isset($_suhosin_func_blacklist)) { $_suhosin_func_blacklist = extension_loaded('suhosin') ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) : array(); } return ! in_array($function_name, $_suhosin_func_blacklist, TRUE); } return FALSE; }
Function usable Executes a function_exists() check, and if the Suhosin PHP extension is loaded - checks whether the function that is checked might be disabled in there as well. This is useful as function_exists() will return FALSE for functions disabled via the *disable_functions* php.ini setting, but not for *suhosin.executor.func.blacklist* and *suhosin.executor.disable_eval*. These settings will just terminate script execution if a disabled function is executed. The above described behavior turned out to be a bug in Suhosin, but even though a fix was committed for 0.9.34 on 2012-02-12, that version is yet to be released. This function will therefore be just temporary, but would probably be kept for a few years. @link http://www.hardened-php.net/suhosin/ @param string $function_name Function to check for @return bool TRUE if the function exists and is safe to call, FALSE otherwise.
function_usable
php
ronknight/InventorySystem
system/core/Common.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Common.php
MIT
function &get_instance() { return CI_Controller::get_instance(); }
Reference to the CI_Controller method. Returns current CI instance object @return CI_Controller
get_instance
php
ronknight/InventorySystem
system/core/CodeIgniter.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/CodeIgniter.php
MIT
public function __construct() { $this->_zlib_oc = (bool) ini_get('zlib.output_compression'); $this->_compress_output = ( $this->_zlib_oc === FALSE && config_item('compress_output') === TRUE && extension_loaded('zlib') ); isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); // Get mime types for later $this->mimes =& get_mimes(); log_message('info', 'Output Class Initialized'); }
Class constructor Determines whether zLib output compression will be used. @return void
__construct
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function get_output() { return $this->final_output; }
Get Output Returns the current output string. @return string
get_output
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function set_output($output) { $this->final_output = $output; return $this; }
Set Output Sets the output string. @param string $output Output data @return CI_Output
set_output
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function append_output($output) { $this->final_output .= $output; return $this; }
Append Output Appends data onto the output string. @param string $output Data to append @return CI_Output
append_output
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function set_header($header, $replace = TRUE) { // If zlib.output_compression is enabled it will compress the output, // but it will not modify the content-length header to compensate for // the reduction, causing the browser to hang waiting for more data. // We'll just skip content-length in those cases. if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0) { return $this; } $this->headers[] = array($header, $replace); return $this; }
Set Header Lets you set a server header which will be sent with the final output. Note: If a file is cached, headers will not be sent. @todo We need to figure out how to permit headers to be cached. @param string $header Header @param bool $replace Whether to replace the old header value, if already set @return CI_Output
set_header
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function get_content_type() { for ($i = 0, $c = count($this->headers); $i < $c; $i++) { if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1) { return $content_type; } } return 'text/html'; }
Get Current Content-Type Header @return string 'text/html', if not already set
get_content_type
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function set_status_header($code = 200, $text = '') { set_status_header($code, $text); return $this; }
Set HTTP Status Header As of version 1.7.2, this is an alias for common function set_status_header(). @param int $code Status code (default: 200) @param string $text Optional message @return CI_Output
set_status_header
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function set_cache_header($last_modified, $expiration) { $max_age = $expiration - $_SERVER['REQUEST_TIME']; if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $this->set_status_header(304); exit; } header('Pragma: public'); header('Cache-Control: max-age='.$max_age.', public'); header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT'); header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT'); }
Set Cache Header Set the HTTP headers to match the server-side file cache settings in order to reduce bandwidth. @param int $last_modified Timestamp of when the page was last modified @param int $expiration Timestamp of when should the requested page expire from cache @return void
set_cache_header
php
ronknight/InventorySystem
system/core/Output.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Output.php
MIT
public function __construct() { if ( defined('PREG_BAD_UTF8_ERROR') // PCRE must support UTF-8 && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) // iconv or mbstring must be installed && strtoupper(config_item('charset')) === 'UTF-8' // Application charset must be UTF-8 ) { define('UTF8_ENABLED', TRUE); log_message('debug', 'UTF-8 Support Enabled'); } else { define('UTF8_ENABLED', FALSE); log_message('debug', 'UTF-8 Support Disabled'); } log_message('info', 'Utf8 Class Initialized'); }
Class constructor Determines if UTF-8 support is to be enabled. @return void
__construct
php
ronknight/InventorySystem
system/core/Utf8.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Utf8.php
MIT
public function safe_ascii_for_xml($str) { return remove_invisible_characters($str, FALSE); }
Remove ASCII control characters Removes all ASCII control characters except horizontal tabs, line feeds, and carriage returns, as all others can cause problems in XML. @param string $str String to clean @return string
safe_ascii_for_xml
php
ronknight/InventorySystem
system/core/Utf8.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Utf8.php
MIT
public function is_ascii($str) { return (preg_match('/[^\x00-\x7F]/S', $str) === 0); }
Is ASCII? Tests if a string is standard 7-bit ASCII or not. @param string $str String to check @return bool
is_ascii
php
ronknight/InventorySystem
system/core/Utf8.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Utf8.php
MIT
public function log_exception($severity, $message, $filepath, $line) { $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity; log_message('error', 'Severity: '.$severity.' --> '.$message.' '.$filepath.' '.$line); }
Exception Logger Logs PHP generated error messages @param int $severity Log level @param string $message Error message @param string $filepath File path @param int $line Line number @return void
log_exception
php
ronknight/InventorySystem
system/core/Exceptions.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Exceptions.php
MIT
public function show_error($heading, $message, $template = 'error_general', $status_code = 500) { $templates_path = config_item('error_views_path'); if (empty($templates_path)) { $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; } if (is_cli()) { $message = "\t".(is_array($message) ? implode("\n\t", $message) : $message); $template = 'cli'.DIRECTORY_SEPARATOR.$template; }
General Error Page Takes an error message as input (either as a string or an array) and displays it using the specified template. @param string $heading Page heading @param string|string[] $message Error message @param string $template Template name @param int $status_code (default: 500) @return string Error page output
show_error
php
ronknight/InventorySystem
system/core/Exceptions.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Exceptions.php
MIT
protected function _run_hook($data) { // Closures/lambda functions and array($object, 'method') callables if (is_callable($data)) { is_array($data) ? $data[0]->{$data[1]}() : $data(); return TRUE; } elseif ( ! is_array($data)) { return FALSE; } // ----------------------------------- // Safety - Prevents run-away loops // ----------------------------------- // If the script being called happens to have the same // hook call within it a loop can happen if ($this->_in_progress === TRUE) { return; } // ----------------------------------- // Set file path // ----------------------------------- if ( ! isset($data['filepath'], $data['filename'])) { return FALSE; } $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; if ( ! file_exists($filepath)) { return FALSE; } // Determine and class and/or function names $class = empty($data['class']) ? FALSE : $data['class']; $function = empty($data['function']) ? FALSE : $data['function']; $params = isset($data['params']) ? $data['params'] : ''; if (empty($function)) { return FALSE; } // Set the _in_progress flag $this->_in_progress = TRUE; // Call the requested class and/or function if ($class !== FALSE) { // The object is stored? if (isset($this->_objects[$class])) { if (method_exists($this->_objects[$class], $function)) { $this->_objects[$class]->$function($params); } else { return $this->_in_progress = FALSE; } } else { class_exists($class, FALSE) OR require_once($filepath); if ( ! class_exists($class, FALSE) OR ! method_exists($class, $function)) { return $this->_in_progress = FALSE; } // Store the object and execute the method $this->_objects[$class] = new $class(); $this->_objects[$class]->$function($params); } } else { function_exists($function) OR require_once($filepath); if ( ! function_exists($function)) { return $this->_in_progress = FALSE; } $function($params); } $this->_in_progress = FALSE; return TRUE; }
Run Hook Runs a particular hook @param array $data Hook details @return bool TRUE on success or FALSE on failure
_run_hook
php
ronknight/InventorySystem
system/core/Hooks.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Hooks.php
MIT
public function mark($name) { $this->marker[$name] = microtime(TRUE); }
Set a benchmark marker Multiple calls to this function can be made so that several execution points can be timed. @param string $name Marker name @return void
mark
php
ronknight/InventorySystem
system/core/Benchmark.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Benchmark.php
MIT
public function elapsed_time($point1 = '', $point2 = '', $decimals = 4) { if ($point1 === '') { return '{elapsed_time}'; } if ( ! isset($this->marker[$point1])) { return ''; } if ( ! isset($this->marker[$point2])) { $this->marker[$point2] = microtime(TRUE); } return number_format($this->marker[$point2] - $this->marker[$point1], $decimals); }
Elapsed time Calculates the time difference between two marked points. If the first parameter is empty this function instead returns the {elapsed_time} pseudo-variable. This permits the full system execution time to be shown in a template. The output class will swap the real value for this variable. @param string $point1 A particular marked point @param string $point2 A particular marked point @param int $decimals Number of decimal places @return string Calculated elapsed time on success, an '{elapsed_string}' if $point1 is empty or an empty string if $point1 is not found.
elapsed_time
php
ronknight/InventorySystem
system/core/Benchmark.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Benchmark.php
MIT
public function memory_usage() { return '{memory_usage}'; }
Memory Usage Simply returns the {memory_usage} marker. This permits it to be put it anywhere in a template without the memory being calculated until the end. The output class will swap the real value for this variable. @return string '{memory_usage}'
memory_usage
php
ronknight/InventorySystem
system/core/Benchmark.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Benchmark.php
MIT
public function line($line, $log_errors = TRUE) { $value = isset($this->language[$line]) ? $this->language[$line] : FALSE; // Because killer robots like unicorns! if ($value === FALSE && $log_errors === TRUE) { log_message('error', 'Could not find the language line "'.$line.'"'); } return $value; }
Language line Fetches a single line of text from the language array @param string $line Language line key @param bool $log_errors Whether to log an error message if the line is not found @return string Translation
line
php
ronknight/InventorySystem
system/core/Lang.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Lang.php
MIT
public function __construct() { $this->_allow_get_array = (config_item('allow_get_array') === TRUE); $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); $this->_enable_csrf = (config_item('csrf_protection') === TRUE); $this->_standardize_newlines = (bool) config_item('standardize_newlines'); $this->security =& load_class('Security', 'core'); // Do we need the UTF-8 class? if (UTF8_ENABLED === TRUE) { $this->uni =& load_class('Utf8', 'core'); } // Sanitize global arrays $this->_sanitize_globals(); // CSRF Protection check if ($this->_enable_csrf === TRUE && ! is_cli()) { $this->security->csrf_verify(); } log_message('info', 'Input Class Initialized'); }
Class constructor Determines whether to globally enable the XSS processing and whether to allow the $_GET array. @return void
__construct
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function get($index = NULL, $xss_clean = NULL) { return $this->_fetch_from_array($_GET, $index, $xss_clean); }
Fetch an item from the GET array @param mixed $index Index for item to be fetched from $_GET @param bool $xss_clean Whether to apply XSS filtering @return mixed
get
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function post($index = NULL, $xss_clean = NULL) { return $this->_fetch_from_array($_POST, $index, $xss_clean); }
Fetch an item from the POST array @param mixed $index Index for item to be fetched from $_POST @param bool $xss_clean Whether to apply XSS filtering @return mixed
post
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function post_get($index, $xss_clean = NULL) { return isset($_POST[$index]) ? $this->post($index, $xss_clean) : $this->get($index, $xss_clean); }
Fetch an item from POST data with fallback to GET @param string $index Index for item to be fetched from $_POST or $_GET @param bool $xss_clean Whether to apply XSS filtering @return mixed
post_get
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function get_post($index, $xss_clean = NULL) { return isset($_GET[$index]) ? $this->get($index, $xss_clean) : $this->post($index, $xss_clean); }
Fetch an item from GET data with fallback to POST @param string $index Index for item to be fetched from $_GET or $_POST @param bool $xss_clean Whether to apply XSS filtering @return mixed
get_post
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function cookie($index = NULL, $xss_clean = NULL) { return $this->_fetch_from_array($_COOKIE, $index, $xss_clean); }
Fetch an item from the COOKIE array @param mixed $index Index for item to be fetched from $_COOKIE @param bool $xss_clean Whether to apply XSS filtering @return mixed
cookie
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function server($index, $xss_clean = NULL) { return $this->_fetch_from_array($_SERVER, $index, $xss_clean); }
Fetch an item from the SERVER array @param mixed $index Index for item to be fetched from $_SERVER @param bool $xss_clean Whether to apply XSS filtering @return mixed
server
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function input_stream($index = NULL, $xss_clean = NULL) { // Prior to PHP 5.6, the input stream can only be read once, // so we'll need to check if we have already done that first. if ( ! is_array($this->_input_stream)) { // $this->raw_input_stream will trigger __get(). parse_str($this->raw_input_stream, $this->_input_stream); is_array($this->_input_stream) OR $this->_input_stream = array(); } return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); }
Fetch an item from the php://input stream Useful when you need to access PUT, DELETE or PATCH request data. @param string $index Index for item to be fetched @param bool $xss_clean Whether to apply XSS filtering @return mixed
input_stream
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL) { if (is_array($name)) { // always leave 'name' in last place, as the loop will break otherwise, due to $$item foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item) { if (isset($name[$item])) { $$item = $name[$item]; } } } if ($prefix === '' && config_item('cookie_prefix') !== '') { $prefix = config_item('cookie_prefix'); } if ($domain == '' && config_item('cookie_domain') != '') { $domain = config_item('cookie_domain'); } if ($path === '/' && config_item('cookie_path') !== '/') { $path = config_item('cookie_path'); } $secure = ($secure === NULL && config_item('cookie_secure') !== NULL) ? (bool) config_item('cookie_secure') : (bool) $secure; $httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL) ? (bool) config_item('cookie_httponly') : (bool) $httponly; if ( ! is_numeric($expire)) { $expire = time() - 86500; } else { $expire = ($expire > 0) ? time() + $expire : 0; } setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly); }
Set cookie Accepts an arbitrary number of parameters (up to 7) or an associative array in the first parameter containing all the values. @param string|mixed[] $name Cookie name or an array containing parameters @param string $value Cookie value @param int $expire Cookie expiration time in seconds @param string $domain Cookie domain (e.g.: '.yourdomain.com') @param string $path Cookie path (default: '/') @param string $prefix Cookie name prefix @param bool $secure Whether to only transfer cookies via SSL @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript) @return void
set_cookie
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function ip_address() { if ($this->ip_address !== FALSE) { return $this->ip_address; } $proxy_ips = config_item('proxy_ips'); if ( ! empty($proxy_ips) && ! is_array($proxy_ips)) { $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips)); } $this->ip_address = $this->server('REMOTE_ADDR'); if ($proxy_ips) { foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header) { if (($spoof = $this->server($header)) !== NULL) { // Some proxies typically list the whole chain of IP // addresses through which the client has reached us. // e.g. client_ip, proxy_ip1, proxy_ip2, etc. sscanf($spoof, '%[^,]', $spoof); if ( ! $this->valid_ip($spoof)) { $spoof = NULL; } else { break; } } } if ($spoof) { for ($i = 0, $c = count($proxy_ips); $i < $c; $i++) { // Check if we have an IP address or a subnet if (strpos($proxy_ips[$i], '/') === FALSE) { // An IP address (and not a subnet) is specified. // We can compare right away. if ($proxy_ips[$i] === $this->ip_address) { $this->ip_address = $spoof; break; } continue; } // We have a subnet ... now the heavy lifting begins isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.'; // If the proxy entry doesn't match the IP protocol - skip it if (strpos($proxy_ips[$i], $separator) === FALSE) { continue; } // Convert the REMOTE_ADDR IP address to binary, if needed if ( ! isset($ip, $sprintf)) { if ($separator === ':') { // Make sure we're have the "full" IPv6 format $ip = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($this->ip_address, ':')), $this->ip_address ) ); for ($j = 0; $j < 8; $j++) { $ip[$j] = intval($ip[$j], 16); } $sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b'; } else { $ip = explode('.', $this->ip_address); $sprintf = '%08b%08b%08b%08b'; } $ip = vsprintf($sprintf, $ip); } // Split the netmask length off the network address sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen); // Again, an IPv6 address is most likely in a compressed form if ($separator === ':') { $netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr)); for ($j = 0; $j < 8; $j++) { $netaddr[$j] = intval($netaddr[$j], 16); } } else { $netaddr = explode('.', $netaddr); } // Convert to binary and finally compare if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0) { $this->ip_address = $spoof; break; } } } } if ( ! $this->valid_ip($this->ip_address)) { return $this->ip_address = '0.0.0.0'; } return $this->ip_address; }
Fetch the IP Address Determines and validates the visitor's IP address. @return string IP address
ip_address
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
protected function _clean_input_keys($str, $fatal = TRUE) { if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str)) { if ($fatal === TRUE) { return FALSE; } else { set_status_header(503); echo 'Disallowed Key Characters.'; exit(7); // EXIT_USER_INPUT } } // Clean UTF-8 if supported if (UTF8_ENABLED === TRUE) { return $this->uni->clean_string($str); } return $str; }
Clean Keys Internal method that helps to prevent malicious users from trying to exploit keys we make sure that keys are only named with alpha-numeric text and a few other items. @param string $str Input string @param bool $fatal Whether to terminate script exection or to return FALSE if an invalid key is encountered @return string|bool
_clean_input_keys
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function is_ajax_request() { return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); }
Is AJAX request? Test to see if a request contains the HTTP_X_REQUESTED_WITH header. @return bool
is_ajax_request
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function is_cli_request() { return is_cli(); }
Is CLI request? Test to see if a request was made from the command line. @deprecated 3.0.0 Use is_cli() instead @return bool
is_cli_request
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function method($upper = FALSE) { return ($upper) ? strtoupper($this->server('REQUEST_METHOD')) : strtolower($this->server('REQUEST_METHOD')); }
Get Request Method Return the request method @param bool $upper Whether to return in upper or lower case (default: FALSE) @return string
method
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
public function __get($name) { if ($name === 'raw_input_stream') { isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); return $this->_raw_input_stream; } elseif ($name === 'ip_address') { return $this->ip_address; } }
Magic __get() Allows read access to protected properties @param string $name @return mixed
__get
php
ronknight/InventorySystem
system/core/Input.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Input.php
MIT
protected function _parse_argv() { $args = array_slice($_SERVER['argv'], 1); return $args ? implode('/', $args) : ''; }
Parse CLI arguments Take each command line argument and assume it is a URI segment. @return string
_parse_argv
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
protected function _remove_relative_directory($uri) { $uris = array(); $tok = strtok($uri, '/'); while ($tok !== FALSE) { if (( ! empty($tok) OR $tok === '0') && $tok !== '..') { $uris[] = $tok; } $tok = strtok('/'); } return implode('/', $uris); }
Remove relative directory (../) and multi slashes (///) Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri() @param string $uri @return string
_remove_relative_directory
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
public function rsegment($n, $no_result = NULL) { return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; }
Fetch URI "routed" Segment Returns the re-routed URI segment (assuming routing rules are used) based on the index provided. If there is no routing, will return the same result as CI_URI::segment(). @see CI_URI::$rsegments @see CI_URI::segment() @param int $n Index @param mixed $no_result What to return if the segment index is not found @return mixed
rsegment
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
public function assoc_to_uri($array) { $temp = array(); foreach ((array) $array as $key => $val) { $temp[] = $key; $temp[] = $val; } return implode('/', $temp); }
Assoc to URI Generates a URI string from an associative array. @param array $array Input array of key/value pairs @return string URI string
assoc_to_uri
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
public function slash_segment($n, $where = 'trailing') { return $this->_slash_segment($n, $where, 'segment'); }
Slash segment Fetches an URI segment with a slash. @param int $n Index @param string $where Where to add the slash ('trailing' or 'leading') @return string
slash_segment
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
public function slash_rsegment($n, $where = 'trailing') { return $this->_slash_segment($n, $where, 'rsegment'); }
Slash routed segment Fetches an URI routed segment with a slash. @param int $n Index @param string $where Where to add the slash ('trailing' or 'leading') @return string
slash_rsegment
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
protected function _slash_segment($n, $where = 'trailing', $which = 'segment') { $leading = $trailing = '/'; if ($where === 'trailing') { $leading = ''; } elseif ($where === 'leading') { $trailing = ''; } return $leading.$this->$which($n).$trailing; }
Internal Slash segment Fetches an URI Segment and adds a slash to it. @used-by CI_URI::slash_segment() @used-by CI_URI::slash_rsegment() @param int $n Index @param string $where Where to add the slash ('trailing' or 'leading') @param string $which Array name ('segment' or 'rsegment') @return string
_slash_segment
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
public function total_rsegments() { return count($this->rsegments); }
Total number of routed segments @return int
total_rsegments
php
ronknight/InventorySystem
system/core/URI.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/URI.php
MIT
function mb_strlen($str, $encoding = NULL) { if (ICONV_ENABLED === TRUE) { return iconv_strlen($str, isset($encoding) ? $encoding : config_item('charset')); } log_message('debug', 'Compatibility (mbstring): iconv_strlen() is not available, falling back to strlen().'); return strlen($str); }
mb_strlen() WARNING: This function WILL fall-back to strlen() if iconv is not available! @link http://php.net/mb_strlen @param string $str @param string $encoding @return int
mb_strlen
php
ronknight/InventorySystem
system/core/compat/mbstring.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/compat/mbstring.php
MIT
function mb_strpos($haystack, $needle, $offset = 0, $encoding = NULL) { if (ICONV_ENABLED === TRUE) { return iconv_strpos($haystack, $needle, $offset, isset($encoding) ? $encoding : config_item('charset')); } log_message('debug', 'Compatibility (mbstring): iconv_strpos() is not available, falling back to strpos().'); return strpos($haystack, $needle, $offset); }
mb_strpos() WARNING: This function WILL fall-back to strpos() if iconv is not available! @link http://php.net/mb_strpos @param string $haystack @param string $needle @param int $offset @param string $encoding @return mixed
mb_strpos
php
ronknight/InventorySystem
system/core/compat/mbstring.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/compat/mbstring.php
MIT
function mb_substr($str, $start, $length = NULL, $encoding = NULL) { if (ICONV_ENABLED === TRUE) { isset($encoding) OR $encoding = config_item('charset'); return iconv_substr( $str, $start, isset($length) ? $length : iconv_strlen($str, $encoding), // NULL doesn't work $encoding ); } log_message('debug', 'Compatibility (mbstring): iconv_substr() is not available, falling back to substr().'); return isset($length) ? substr($str, $start, $length) : substr($str, $start); }
mb_substr() WARNING: This function WILL fall-back to substr() if iconv is not available. @link http://php.net/mb_substr @param string $str @param int $start @param int $length @param string $encoding @return string
mb_substr
php
ronknight/InventorySystem
system/core/compat/mbstring.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/compat/mbstring.php
MIT
public function methodSignature($m) { $parameters = $m->output_parameters(); $method_name = $parameters[0]; if (isset($this->methods[$method_name])) { if ($this->methods[$method_name]['signature']) { $sigs = array(); $signature = $this->methods[$method_name]['signature']; for ($i = 0, $c = count($signature); $i < $c; $i++) { $cursig = array(); $inSig = $signature[$i]; for ($j = 0, $jc = count($inSig); $j < $jc; $j++) { $cursig[]= new XML_RPC_Values($inSig[$j], 'string'); } $sigs[] = new XML_RPC_Values($cursig, 'array'); } return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array')); } return new XML_RPC_Response(new XML_RPC_Values('undef', 'string')); } return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); }
Server Function: Return Signature for Method @param mixed @return object
methodSignature
php
ronknight/InventorySystem
system/libraries/Xmlrpcs.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpcs.php
MIT
public function methodHelp($m) { $parameters = $m->output_parameters(); $method_name = $parameters[0]; if (isset($this->methods[$method_name])) { $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); } else { return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } }
Server Function: Doc String for Method @param mixed @return object
methodHelp
php
ronknight/InventorySystem
system/libraries/Xmlrpcs.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpcs.php
MIT
public function multicall_error($err) { $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); $struct['faultCode'] = new XML_RPC_Values($code, 'int'); $struct['faultString'] = new XML_RPC_Values($str, 'string'); return new XML_RPC_Values($struct, 'struct'); }
Multi-call Function: Error Handling @param mixed @return object
multicall_error
php
ronknight/InventorySystem
system/libraries/Xmlrpcs.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpcs.php
MIT
public function latest() { $migrations = $this->find_migrations(); if (empty($migrations)) { $this->_error_string = $this->lang->line('migration_none_found'); return FALSE; } $last_migration = basename(end($migrations)); // Calculate the last migration step from existing migration // filenames and proceed to the standard version migration return $this->version($this->_get_migration_number($last_migration)); }
Sets the schema to the latest migration @return mixed Current version string on success, FALSE on failure
latest
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
public function current() { return $this->version($this->_migration_version); }
Sets the schema to the migration version set in config @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure
current
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
protected function _get_migration_number($migration) { return sscanf($migration, '%[0-9]+', $number) ? $number : '0'; }
Extracts the migration number from a filename @param string $migration @return string Numeric portion of a migration filename
_get_migration_number
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
protected function _get_migration_name($migration) { $parts = explode('_', $migration); array_shift($parts); return implode('_', $parts); }
Extracts the migration class name from a filename @param string $migration @return string text portion of a migration filename
_get_migration_name
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
protected function _get_version() { $row = $this->db->select('version')->get($this->_migration_table)->row(); return $row ? $row->version : '0'; }
Retrieves current schema version @return string Current migration version
_get_version
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
protected function _update_version($migration) { $this->db->update($this->_migration_table, array( 'version' => $migration )); }
Stores the current schema version @param string $migration Migration reached @return void
_update_version
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
public function __get($var) { return get_instance()->$var; }
Enable the use of CI super-global @param string $var @return mixed
__get
php
ronknight/InventorySystem
system/libraries/Migration.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Migration.php
MIT
public function set_sections($config) { if (isset($config['query_toggle_count'])) { $this->_query_toggle_count = (int) $config['query_toggle_count']; unset($config['query_toggle_count']); } foreach ($config as $method => $enable) { if (in_array($method, $this->_available_sections)) { $this->_compile_{$method} = ($enable !== FALSE); } } }
Set Sections Sets the private _compile_* properties to enable/disable Profiler sections @param mixed $config @return void
set_sections
php
ronknight/InventorySystem
system/libraries/Profiler.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Profiler.php
MIT
protected function _compile_controller_info() { return "\n\n" .'<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' ."\n" .'<legend style="color:#995300;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_controller_info')."&nbsp;&nbsp;</legend>\n" .'<div style="color:#995300;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->router->class.'/'.$this->CI->router->method .'</div></fieldset>'; }
Show the controller and function that were called @return string
_compile_controller_info
php
ronknight/InventorySystem
system/libraries/Profiler.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Profiler.php
MIT
public function display_response() { return $this->response; }
Returns Remote Server Response @return string
display_response
php
ronknight/InventorySystem
system/libraries/Xmlrpc.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpc.php
MIT
public function send_error_message($number, $message) { return new XML_RPC_Response(0, $number, $message); }
Sends an Error Message for Server Request @param int $number @param string $message @return object
send_error_message
php
ronknight/InventorySystem
system/libraries/Xmlrpc.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpc.php
MIT
public function send_response($response) { // $response should be array of values, which will be parsed // based on their data and type into a valid group of XML-RPC values return new XML_RPC_Response($this->values_parsing($response)); }
Send Response for Server Request @param array $response @return object
send_response
php
ronknight/InventorySystem
system/libraries/Xmlrpc.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpc.php
MIT
public function iso8601_decode($time, $utc = FALSE) { // Return a time in the localtime, or UTC $t = 0; if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) { $fnc = ($utc === TRUE) ? 'gmmktime' : 'mktime'; $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); } return $t; }
ISO-8601 time to server or UTC time @param string @param bool @return int unix timestamp
iso8601_decode
php
ronknight/InventorySystem
system/libraries/Xmlrpc.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpc.php
MIT
public function iso8601_encode($time, $utc = FALSE) { return ($utc) ? strftime('%Y%m%dT%H:%i:%s', $time) : gmstrftime('%Y%m%dT%H:%i:%s', $time); }
Encode time in ISO-8601 form. Useful for sending time in XML-RPC @param int unix timestamp @param bool @return string
iso8601_encode
php
ronknight/InventorySystem
system/libraries/Xmlrpc.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Xmlrpc.php
MIT
public function __get($child) { // Try to load the driver return $this->load_driver($child); }
Get magic method The first time a child is used it won't exist, so we instantiate it subsequents calls will go straight to the proper child. @param string Child class name @return object Child class
__get
php
ronknight/InventorySystem
system/libraries/Driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Driver.php
MIT
public function load_driver($child) { // Get CodeIgniter instance and subclass prefix $prefix = config_item('subclass_prefix'); if ( ! isset($this->lib_name)) { // Get library name without any prefix $this->lib_name = str_replace(array('CI_', $prefix), '', get_class($this)); } // The child will be prefixed with the parent lib $child_name = $this->lib_name.'_'.$child; // See if requested child is a valid driver if ( ! in_array($child, $this->valid_drivers)) { // The requested driver isn't valid! $msg = 'Invalid driver requested: '.$child_name; log_message('error', $msg); show_error($msg); } // Get package paths and filename case variations to search $CI = get_instance(); $paths = $CI->load->get_package_paths(TRUE); // Is there an extension? $class_name = $prefix.$child_name; $found = class_exists($class_name, FALSE); if ( ! $found) { // Check for subclass file foreach ($paths as $path) { // Does the file exist? $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$prefix.$child_name.'.php'; if (file_exists($file)) { // Yes - require base class from BASEPATH $basepath = BASEPATH.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php'; if ( ! file_exists($basepath)) { $msg = 'Unable to load the requested class: CI_'.$child_name; log_message('error', $msg); show_error($msg); } // Include both sources and mark found include_once($basepath); include_once($file); $found = TRUE; break; } } } // Do we need to search for the class? if ( ! $found) { // Use standard class name $class_name = 'CI_'.$child_name; if ( ! class_exists($class_name, FALSE)) { // Check package paths foreach ($paths as $path) { // Does the file exist? $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php'; if (file_exists($file)) { // Include source include_once($file); break; } } } } // Did we finally find the class? if ( ! class_exists($class_name, FALSE)) { if (class_exists($child_name, FALSE)) { $class_name = $child_name; } else { $msg = 'Unable to load the requested driver: '.$class_name; log_message('error', $msg); show_error($msg); } } // Instantiate, decorate and add child $obj = new $class_name(); $obj->decorate($this); $this->$child = $obj; return $this->$child; }
Load driver Separate load_driver call to support explicit driver load by library or user @param string Driver name (w/o parent prefix) @return object Child class
load_driver
php
ronknight/InventorySystem
system/libraries/Driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Driver.php
MIT
public function decorate($parent) { $this->_parent = $parent; // Lock down attributes to what is defined in the class // and speed up references in magic methods $class_name = get_class($parent); if ( ! isset(self::$_reflections[$class_name])) { $r = new ReflectionObject($parent); foreach ($r->getMethods() as $method) { if ($method->isPublic()) { $this->_methods[] = $method->getName(); } } foreach ($r->getProperties() as $prop) { if ($prop->isPublic()) { $this->_properties[] = $prop->getName(); } } self::$_reflections[$class_name] = array($this->_methods, $this->_properties); } else { list($this->_methods, $this->_properties) = self::$_reflections[$class_name]; } }
Decorate Decorates the child with the parent driver lib's methods and properties @param object @return void
decorate
php
ronknight/InventorySystem
system/libraries/Driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Driver.php
MIT
public function __get($var) { if (in_array($var, $this->_properties)) { return $this->_parent->$var; } }
__get magic method Handles reading of the parent driver library's properties @param string @return mixed
__get
php
ronknight/InventorySystem
system/libraries/Driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Driver.php
MIT
public function __set($var, $val) { if (in_array($var, $this->_properties)) { $this->_parent->$var = $val; } }
__set magic method Handles writing to the parent driver library's properties @param string @param array @return mixed
__set
php
ronknight/InventorySystem
system/libraries/Driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Driver.php
MIT
public function data($index = NULL) { $data = array( 'file_name' => $this->file_name, 'file_type' => $this->file_type, 'file_path' => $this->upload_path, 'full_path' => $this->upload_path.$this->file_name, 'raw_name' => substr($this->file_name, 0, -strlen($this->file_ext)), 'orig_name' => $this->orig_name, 'client_name' => $this->client_name, 'file_ext' => $this->file_ext, 'file_size' => $this->file_size, 'is_image' => $this->is_image(), 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_type' => $this->image_type, 'image_size_str' => $this->image_size_str, ); if ( ! empty($index)) { return isset($data[$index]) ? $data[$index] : NULL; } return $data; }
Finalized Data Array Returns an associative array containing all of the information related to the upload, allowing the developer easy access in one array. @param string $index @return mixed
data
php
ronknight/InventorySystem
system/libraries/Upload.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php
MIT
public function set_filename($path, $filename) { if ($this->encrypt_name === TRUE) { $filename = md5(uniqid(mt_rand())).$this->file_ext; } if ($this->overwrite === TRUE OR ! file_exists($path.$filename)) { return $filename; } $filename = str_replace($this->file_ext, '', $filename); $new_filename = ''; for ($i = 1; $i < $this->max_filename_increment; $i++) { if ( ! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; break; } } if ($new_filename === '') { $this->set_error('upload_bad_filename', 'debug'); return FALSE; } else { return $new_filename; } }
Set the file name This function takes a filename/path as input and looks for the existence of a file with the same name. If found, it will append a number to the end of the filename to avoid overwriting a pre-existing file. @param string $path @param string $filename @return string
set_filename
php
ronknight/InventorySystem
system/libraries/Upload.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php
MIT
protected function set_max_size($n) { return $this->set_max_filesize($n); }
Set Maximum File Size An internal alias to set_max_filesize() to help with configuration as initialize() will look for a set_<property_name>() method ... @param int $n @return CI_Upload
set_max_size
php
ronknight/InventorySystem
system/libraries/Upload.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php
MIT
public function set_xss_clean($flag = FALSE) { $this->xss_clean = ($flag === TRUE); return $this; }
Set XSS Clean Enables the XSS flag so that the file that was uploaded will be run through the XSS filter. @param bool $flag @return CI_Upload
set_xss_clean
php
ronknight/InventorySystem
system/libraries/Upload.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php
MIT