code
stringlengths 17
296k
| 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 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;"> '.$this->CI->lang->line('profiler_controller_info')." </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 |
public function is_allowed_filetype($ignore_mime = FALSE)
{
if ($this->allowed_types === '*')
{
return TRUE;
}
if (empty($this->allowed_types) OR ! is_array($this->allowed_types))
{
$this->set_error('upload_no_file_types', 'debug');
return FALSE;
}
$ext = strtolower(ltrim($this->file_ext, '.'));
if ( ! in_array($ext, $this->allowed_types, TRUE))
{
return FALSE;
}
// Images get some additional checks
if (in_array($ext, array('gif', 'jpg', 'jpeg', 'jpe', 'png'), TRUE) && @getimagesize($this->file_temp) === FALSE)
{
return FALSE;
}
if ($ignore_mime === TRUE)
{
return TRUE;
}
if (isset($this->_mimes[$ext]))
{
return is_array($this->_mimes[$ext])
? in_array($this->file_type, $this->_mimes[$ext], TRUE)
: ($this->_mimes[$ext] === $this->file_type);
}
return FALSE;
} | Verify that the filetype is allowed
@param bool $ignore_mime
@return bool | is_allowed_filetype | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
public function is_allowed_filesize()
{
return ($this->max_size === 0 OR $this->max_size > $this->file_size);
} | Verify that the file is within the allowed size
@return bool | is_allowed_filesize | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
public function is_allowed_dimensions()
{
if ( ! $this->is_image())
{
return TRUE;
}
if (function_exists('getimagesize'))
{
$D = @getimagesize($this->file_temp);
if ($this->max_width > 0 && $D[0] > $this->max_width)
{
return FALSE;
}
if ($this->max_height > 0 && $D[1] > $this->max_height)
{
return FALSE;
}
if ($this->min_width > 0 && $D[0] < $this->min_width)
{
return FALSE;
}
if ($this->min_height > 0 && $D[1] < $this->min_height)
{
return FALSE;
}
}
return TRUE;
} | Verify that the image is within the allowed width/height
@return bool | is_allowed_dimensions | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
public function validate_upload_path()
{
if ($this->upload_path === '')
{
$this->set_error('upload_no_filepath', 'error');
return FALSE;
}
if (realpath($this->upload_path) !== FALSE)
{
$this->upload_path = str_replace('\\', '/', realpath($this->upload_path));
}
if ( ! is_dir($this->upload_path))
{
$this->set_error('upload_no_filepath', 'error');
return FALSE;
}
if ( ! is_really_writable($this->upload_path))
{
$this->set_error('upload_not_writable', 'error');
return FALSE;
}
$this->upload_path = preg_replace('/(.+?)\/*$/', '\\1/', $this->upload_path);
return TRUE;
} | Validate Upload Path
Verifies that it is a valid upload path with proper permissions.
@return bool | validate_upload_path | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
public function do_xss_clean()
{
$file = $this->file_temp;
if (filesize($file) == 0)
{
return FALSE;
}
if (memory_get_usage() && ($memory_limit = ini_get('memory_limit')) > 0)
{
$memory_limit = str_split($memory_limit, strspn($memory_limit, '1234567890'));
if ( ! empty($memory_limit[1]))
{
switch ($memory_limit[1][0])
{
case 'g':
case 'G':
$memory_limit[0] *= 1024 * 1024 * 1024;
break;
case 'm':
case 'M':
$memory_limit[0] *= 1024 * 1024;
break;
default:
break;
}
}
$memory_limit = (int) ceil(filesize($file) + $memory_limit[0]);
ini_set('memory_limit', $memory_limit); // When an integer is used, the value is measured in bytes. - PHP.net
}
// If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but
// IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone
// using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this
// CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of
// processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an
// attempted XSS attack.
if (function_exists('getimagesize') && @getimagesize($file) !== FALSE)
{
if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary
{
return FALSE; // Couldn't open the file, return FALSE
}
$opening_bytes = fread($file, 256);
fclose($file);
// These are known to throw IE into mime-type detection chaos
// <a, <body, <head, <html, <img, <plaintext, <pre, <script, <table, <title
// title is basically just in SVG, but we filter it anyhow
// if it's an image or no "triggers" detected in the first 256 bytes - we're good
return ! preg_match('/<(a|body|head|html|img|plaintext|pre|script|table|title)[\s>]/i', $opening_bytes);
}
if (($data = @file_get_contents($file)) === FALSE)
{
return FALSE;
}
return $this->_CI->security->xss_clean($data, TRUE);
} | Runs the file through the XSS clean function
This prevents people from embedding malicious code in their files.
I'm not sure that it won't negatively affect certain files in unexpected ways,
but so far I haven't found that it causes trouble.
@return string | do_xss_clean | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
protected function _prep_filename($filename)
{
if ($this->mod_mime_fix === FALSE OR $this->allowed_types === '*' OR ($ext_pos = strrpos($filename, '.')) === FALSE)
{
return $filename;
}
$ext = substr($filename, $ext_pos);
$filename = substr($filename, 0, $ext_pos);
return str_replace('.', '_', $filename).$ext;
} | Prep Filename
Prevents possible script execution from Apache's handling
of files' multiple extensions.
@link http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext
@param string $filename
@return string | _prep_filename | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
protected function _file_mime_type($file)
{
// We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
$regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
/**
* Fileinfo extension - most reliable method
*
* Apparently XAMPP, CentOS, cPanel and who knows what
* other PHP distribution channels EXPLICITLY DISABLE
* ext/fileinfo, which is otherwise enabled by default
* since PHP 5.3 ...
*/
if (function_exists('finfo_file'))
{
$finfo = @finfo_open(FILEINFO_MIME);
if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
{
$mime = @finfo_file($finfo, $file['tmp_name']);
finfo_close($finfo);
/* According to the comments section of the PHP manual page,
* it is possible that this function returns an empty string
* for some files (e.g. if they don't exist in the magic MIME database)
*/
if (is_string($mime) && preg_match($regexp, $mime, $matches))
{
$this->file_type = $matches[1];
return;
}
}
}
/* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type,
* which is still more secure than depending on the value of $_FILES[$field]['type'], and as it
* was reported in issue #750 (https://github.com/EllisLab/CodeIgniter/issues/750) - it's better
* than mime_content_type() as well, hence the attempts to try calling the command line with
* three different functions.
*
* Notes:
* - the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system
* - many system admins would disable the exec(), shell_exec(), popen() and similar functions
* due to security concerns, hence the function_usable() checks
*/
if (DIRECTORY_SEPARATOR !== '\\')
{
$cmd = function_exists('escapeshellarg')
? 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1'
: 'file --brief --mime '.$file['tmp_name'].' 2>&1';
if (function_usable('exec'))
{
/* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
* However, we only need the last line, which is the actual return value of exec(), and as such - it overwrites
* anything that could already be set for $mime previously. This effectively makes the second parameter a dummy
* value, which is only put to allow us to get the return status code.
*/
$mime = @exec($cmd, $mime, $return_status);
if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches))
{
$this->file_type = $matches[1];
return;
}
}
if ( ! ini_get('safe_mode') && function_usable('shell_exec'))
{
$mime = @shell_exec($cmd);
if (strlen($mime) > 0)
{
$mime = explode("\n", trim($mime));
if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
{
$this->file_type = $matches[1];
return;
}
}
}
if (function_usable('popen'))
{
$proc = @popen($cmd, 'r');
if (is_resource($proc))
{
$mime = @fread($proc, 512);
@pclose($proc);
if ($mime !== FALSE)
{
$mime = explode("\n", trim($mime));
if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
{
$this->file_type = $matches[1];
return;
}
}
}
}
}
// Fall back to mime_content_type(), if available (still better than $_FILES[$field]['type'])
if (function_exists('mime_content_type'))
{
$this->file_type = @mime_content_type($file['tmp_name']);
if (strlen($this->file_type) > 0) // It's possible that mime_content_type() returns FALSE or an empty string
{
return;
}
}
$this->file_type = $file['type'];
} | File MIME type
Detects the (actual) MIME type of the uploaded file, if possible.
The input array is expected to be $_FILES[$field]
@param array $file
@return void | _file_mime_type | php | ronknight/InventorySystem | system/libraries/Upload.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Upload.php | MIT |
public function changedir($path, $suppress_debug = FALSE)
{
if ( ! $this->_is_conn())
{
return FALSE;
}
$result = @ftp_chdir($this->conn_id, $path);
if ($result === FALSE)
{
if ($this->debug === TRUE && $suppress_debug === FALSE)
{
$this->_error('ftp_unable_to_changedir');
}
return FALSE;
}
return TRUE;
} | Change directory
The second parameter lets us momentarily turn off debugging so that
this function can be used to test for the existence of a folder
without throwing an error. There's no FTP equivalent to is_dir()
so we do it by trying to change to a particular directory.
Internally, this parameter is only used by the "mirror" function below.
@param string $path
@param bool $suppress_debug
@return bool | changedir | php | ronknight/InventorySystem | system/libraries/Ftp.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Ftp.php | MIT |
public function download($rempath, $locpath, $mode = 'auto')
{
if ( ! $this->_is_conn())
{
return FALSE;
}
// Set the mode if not specified
if ($mode === 'auto')
{
// Get the file extension so we can set the upload type
$ext = $this->_getext($rempath);
$mode = $this->_settype($ext);
}
$mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
$result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
if ($result === FALSE)
{
if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_download');
}
return FALSE;
}
return TRUE;
} | Download a file from a remote server to the local server
@param string $rempath
@param string $locpath
@param string $mode
@return bool | download | php | ronknight/InventorySystem | system/libraries/Ftp.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Ftp.php | MIT |
public function delete_dir($filepath)
{
if ( ! $this->_is_conn())
{
return FALSE;
}
// Add a trailing slash to the file path if needed
$filepath = preg_replace('/(.+?)\/*$/', '\\1/', $filepath);
$list = $this->list_files($filepath);
if ( ! empty($list))
{
for ($i = 0, $c = count($list); $i < $c; $i++)
{
// If we can't delete the item it's probably a directory,
// so we'll recursively call delete_dir()
if ( ! preg_match('#/\.\.?$#', $list[$i]) && ! @ftp_delete($this->conn_id, $list[$i]))
{
$this->delete_dir($filepath.$list[$i]);
}
}
}
if (@ftp_rmdir($this->conn_id, $filepath) === FALSE)
{
if ($this->debug === TRUE)
{
$this->_error('ftp_unable_to_delete');
}
return FALSE;
}
return TRUE;
} | Delete a folder and recursively delete everything (including sub-folders)
contained within it.
@param string $filepath
@return bool | delete_dir | php | ronknight/InventorySystem | system/libraries/Ftp.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Ftp.php | MIT |
public function list_files($path = '.')
{
return $this->_is_conn()
? ftp_nlist($this->conn_id, $path)
: FALSE;
} | FTP List files in the specified directory
@param string $path
@return array | list_files | php | ronknight/InventorySystem | system/libraries/Ftp.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Ftp.php | MIT |
public function parse($template, $data, $return = FALSE)
{
$template = $this->CI->load->view($template, $data, TRUE);
return $this->_parse($template, $data, $return);
} | Parse a template
Parses pseudo-variables contained in the specified template view,
replacing them with the data in the second param
@param string
@param array
@param bool
@return string | parse | php | ronknight/InventorySystem | system/libraries/Parser.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Parser.php | MIT |
public function parse_string($template, $data, $return = FALSE)
{
return $this->_parse($template, $data, $return);
} | Parse a String
Parses pseudo-variables contained in the specified string,
replacing them with the data in the second param
@param string
@param array
@param bool
@return string | parse_string | php | ronknight/InventorySystem | system/libraries/Parser.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Parser.php | MIT |
public function set_delimiters($l = '{', $r = '}')
{
$this->l_delim = $l;
$this->r_delim = $r;
} | Set the left/right variable delimiters
@param string
@param string
@return void | set_delimiters | php | ronknight/InventorySystem | system/libraries/Parser.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Parser.php | MIT |
public function set_empty($value)
{
$this->empty_cells = $value;
return $this;
} | Set "empty" cells
Can be passed as an array or discreet params
@param mixed $value
@return CI_Table | set_empty | php | ronknight/InventorySystem | system/libraries/Table.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Table.php | MIT |
public function clear()
{
$this->rows = array();
$this->heading = array();
$this->auto_heading = TRUE;
return $this;
} | Clears the table arrays. Useful if multiple tables are being generated
@return CI_Table | clear | php | ronknight/InventorySystem | system/libraries/Table.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Table.php | MIT |
public function blur($element = 'this', $js = '')
{
return $this->js->_blur($element, $js);
} | Blur
Outputs a javascript library blur event
@param string The element to attach the event to
@param string The code to execute
@return string | blur | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function change($element = 'this', $js = '')
{
return $this->js->_change($element, $js);
} | Change
Outputs a javascript library change event
@param string The element to attach the event to
@param string The code to execute
@return string | change | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function click($element = 'this', $js = '', $ret_false = TRUE)
{
return $this->js->_click($element, $js, $ret_false);
} | Click
Outputs a javascript library click event
@param string The element to attach the event to
@param string The code to execute
@param bool whether or not to return false
@return string | click | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function dblclick($element = 'this', $js = '')
{
return $this->js->_dblclick($element, $js);
} | Double Click
Outputs a javascript library dblclick event
@param string The element to attach the event to
@param string The code to execute
@return string | dblclick | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function error($element = 'this', $js = '')
{
return $this->js->_error($element, $js);
} | Error
Outputs a javascript library error event
@param string The element to attach the event to
@param string The code to execute
@return string | error | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function focus($element = 'this', $js = '')
{
return $this->js->_focus($element, $js);
} | Focus
Outputs a javascript library focus event
@param string The element to attach the event to
@param string The code to execute
@return string | focus | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function hover($element = 'this', $over = '', $out = '')
{
return $this->js->_hover($element, $over, $out);
} | Hover
Outputs a javascript library hover event
@param string - element
@param string - Javascript code for mouse over
@param string - Javascript code for mouse out
@return string | hover | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function keydown($element = 'this', $js = '')
{
return $this->js->_keydown($element, $js);
} | Keydown
Outputs a javascript library keydown event
@param string The element to attach the event to
@param string The code to execute
@return string | keydown | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function keyup($element = 'this', $js = '')
{
return $this->js->_keyup($element, $js);
} | Keyup
Outputs a javascript library keydown event
@param string The element to attach the event to
@param string The code to execute
@return string | keyup | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function load($element = 'this', $js = '')
{
return $this->js->_load($element, $js);
} | Load
Outputs a javascript library load event
@param string The element to attach the event to
@param string The code to execute
@return string | load | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function mousedown($element = 'this', $js = '')
{
return $this->js->_mousedown($element, $js);
} | Mousedown
Outputs a javascript library mousedown event
@param string The element to attach the event to
@param string The code to execute
@return string | mousedown | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function mouseout($element = 'this', $js = '')
{
return $this->js->_mouseout($element, $js);
} | Mouse Out
Outputs a javascript library mouseout event
@param string The element to attach the event to
@param string The code to execute
@return string | mouseout | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function mouseover($element = 'this', $js = '')
{
return $this->js->_mouseover($element, $js);
} | Mouse Over
Outputs a javascript library mouseover event
@param string The element to attach the event to
@param string The code to execute
@return string | mouseover | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function mouseup($element = 'this', $js = '')
{
return $this->js->_mouseup($element, $js);
} | Mouseup
Outputs a javascript library mouseup event
@param string The element to attach the event to
@param string The code to execute
@return string | mouseup | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function output($js)
{
return $this->js->_output($js);
} | Output
Outputs the called javascript to the screen
@param string The code to output
@return string | output | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function ready($js)
{
return $this->js->_document_ready($js);
} | Ready
Outputs a javascript library mouseup event
@param string $js Code to execute
@return string | ready | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function resize($element = 'this', $js = '')
{
return $this->js->_resize($element, $js);
} | Resize
Outputs a javascript library resize event
@param string The element to attach the event to
@param string The code to execute
@return string | resize | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function scroll($element = 'this', $js = '')
{
return $this->js->_scroll($element, $js);
} | Scroll
Outputs a javascript library scroll event
@param string The element to attach the event to
@param string The code to execute
@return string | scroll | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function unload($element = 'this', $js = '')
{
return $this->js->_unload($element, $js);
} | Unload
Outputs a javascript library unload event
@param string The element to attach the event to
@param string The code to execute
@return string | unload | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function addClass($element = 'this', $class = '')
{
return $this->js->_addClass($element, $class);
} | Add Class
Outputs a javascript library addClass event
@param string - element
@param string - Class to add
@return string | addClass | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function fadeIn($element = 'this', $speed = '', $callback = '')
{
return $this->js->_fadeIn($element, $speed, $callback);
} | Fade In
Outputs a javascript library hide event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | fadeIn | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function fadeOut($element = 'this', $speed = '', $callback = '')
{
return $this->js->_fadeOut($element, $speed, $callback);
} | Fade Out
Outputs a javascript library hide event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | fadeOut | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function slideUp($element = 'this', $speed = '', $callback = '')
{
return $this->js->_slideUp($element, $speed, $callback);
} | Slide Up
Outputs a javascript library slideUp event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | slideUp | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function removeClass($element = 'this', $class = '')
{
return $this->js->_removeClass($element, $class);
} | Remove Class
Outputs a javascript library removeClass event
@param string - element
@param string - Class to add
@return string | removeClass | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function slideDown($element = 'this', $speed = '', $callback = '')
{
return $this->js->_slideDown($element, $speed, $callback);
} | Slide Down
Outputs a javascript library slideDown event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | slideDown | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function slideToggle($element = 'this', $speed = '', $callback = '')
{
return $this->js->_slideToggle($element, $speed, $callback);
} | Slide Toggle
Outputs a javascript library slideToggle event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | slideToggle | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function hide($element = 'this', $speed = '', $callback = '')
{
return $this->js->_hide($element, $speed, $callback);
} | Hide
Outputs a javascript library hide action
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | hide | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function toggle($element = 'this')
{
return $this->js->_toggle($element);
} | Toggle
Outputs a javascript library toggle event
@param string - element
@return string | toggle | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function toggleClass($element = 'this', $class = '')
{
return $this->js->_toggleClass($element, $class);
} | Toggle Class
Outputs a javascript library toggle class event
@param string $element = 'this'
@param string $class = ''
@return string | toggleClass | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function show($element = 'this', $speed = '', $callback = '')
{
return $this->js->_show($element, $speed, $callback);
} | Show
Outputs a javascript library show event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | show | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function compile($view_var = 'script_foot', $script_tags = TRUE)
{
$this->js->_compile($view_var, $script_tags);
} | Compile
gather together all script needing to be output
@param string $view_var
@param bool $script_tags
@return string | compile | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function clear_compile()
{
$this->js->_clear_compile();
} | Clear Compile
Clears any previous javascript collected for output
@return void | clear_compile | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
protected function _close_script($extra = "\n")
{
return '</script>'.$extra;
} | Close Script
Outputs an closing </script>
@param string
@return string | _close_script | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function update($element = 'this', $speed = '', $callback = '')
{
return $this->js->_updater($element, $speed, $callback);
} | Update
Outputs a javascript library slideDown event
@param string - element
@param string - One of 'slow', 'normal', 'fast', or time in milliseconds
@param string - Javascript callback function
@return string | update | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
protected function _is_associative_array($arr)
{
foreach (array_keys($arr) as $key => $val)
{
if ($key !== $val)
{
return TRUE;
}
}
return FALSE;
} | Is associative array
Checks for an associative array
@param array
@return bool | _is_associative_array | php | ronknight/InventorySystem | system/libraries/Javascript.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Javascript.php | MIT |
public function adjust_date($month, $year)
{
$date = array();
$date['month'] = $month;
$date['year'] = $year;
while ($date['month'] > 12)
{
$date['month'] -= 12;
$date['year']++;
}
while ($date['month'] <= 0)
{
$date['month'] += 12;
$date['year']--;
}
if (strlen($date['month']) === 1)
{
$date['month'] = '0'.$date['month'];
}
return $date;
} | Adjust Date
This function makes sure that we have a valid month/year.
For example, if you submit 13 as the month, the year will
increment and the month will become January.
@param int the month
@param int the year
@return array | adjust_date | php | ronknight/InventorySystem | system/libraries/Calendar.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Calendar.php | MIT |
public function default_template()
{
return array(
'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
'heading_row_start' => '<tr>',
'heading_previous_cell' => '<th><a href="{previous_url}"><<</a></th>',
'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
'heading_next_cell' => '<th><a href="{next_url}">>></a></th>',
'heading_row_end' => '</tr>',
'week_row_start' => '<tr>',
'week_day_cell' => '<td>{week_day}</td>',
'week_row_end' => '</tr>',
'cal_row_start' => '<tr>',
'cal_cell_start' => '<td>',
'cal_cell_start_today' => '<td>',
'cal_cell_start_other' => '<td style="color: #666;">',
'cal_cell_content' => '<a href="{content}">{day}</a>',
'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
'cal_cell_no_content' => '{day}',
'cal_cell_no_content_today' => '<strong>{day}</strong>',
'cal_cell_blank' => ' ',
'cal_cell_other' => '{day}',
'cal_cell_end' => '</td>',
'cal_cell_end_today' => '</td>',
'cal_cell_end_other' => '</td>',
'cal_row_end' => '</tr>',
'table_close' => '</table>'
);
} | Set Default Template Data
This is used in the event that the user has not created their own template
@return array | default_template | php | ronknight/InventorySystem | system/libraries/Calendar.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Calendar.php | MIT |
public function set_test_items($items)
{
if ( ! empty($items) && is_array($items))
{
$this->_test_items_visible = $items;
}
} | Run the tests
Runs the supplied tests
@param array $items
@return void | set_test_items | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
{
if ($this->active === FALSE)
{
return FALSE;
}
if (in_array($expected, array('is_object', 'is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null', 'is_resource'), TRUE))
{
$result = $expected($test);
$extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected));
}
else
{
$result = ($this->strict === TRUE) ? ($test === $expected) : ($test == $expected);
$extype = gettype($expected);
}
$back = $this->_backtrace();
$report = array (
'test_name' => $test_name,
'test_datatype' => gettype($test),
'res_datatype' => $extype,
'result' => ($result === TRUE) ? 'passed' : 'failed',
'file' => $back['file'],
'line' => $back['line'],
'notes' => $notes
);
$this->results[] = $report;
return $this->report($this->result(array($report)));
} | Run the tests
Runs the supplied tests
@param mixed $test
@param mixed $expected
@param string $test_name
@param string $notes
@return string | run | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
public function use_strict($state = TRUE)
{
$this->strict = (bool) $state;
} | Use strict comparison
Causes the evaluation to use === rather than ==
@param bool $state
@return void | use_strict | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
public function active($state = TRUE)
{
$this->active = (bool) $state;
} | Make Unit testing active
Enables/disables unit testing
@param bool
@return void | active | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
public function set_template($template)
{
$this->_template = $template;
} | Set the template
This lets us set the template to be used to display results
@param string
@return void | set_template | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
protected function _backtrace()
{
$back = debug_backtrace();
return array(
'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''),
'line' => (isset($back[1]['line']) ? $back[1]['line'] : '')
);
} | Generate a backtrace
This lets us show file names and line numbers
@return array | _backtrace | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
function is_true($test)
{
return ($test === TRUE);
} | Helper function to test boolean TRUE
@param mixed $test
@return bool | is_true | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
function is_false($test)
{
return ($test === FALSE);
} | Helper function to test boolean FALSE
@param mixed $test
@return bool | is_false | php | ronknight/InventorySystem | system/libraries/Unit_test.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Unit_test.php | MIT |
public function get_key($key = '')
{
if ($key === '')
{
if ($this->encryption_key !== '')
{
return $this->encryption_key;
}
$key = config_item('encryption_key');
if ( ! self::strlen($key))
{
show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
}
}
return md5($key);
} | Fetch the encryption key
Returns it as MD5 in order to have an exact-length 128 bit key.
Mcrypt is sensitive to keys that are not the correct length
@param string
@return string | get_key | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
public function encode($string, $key = '')
{
return base64_encode($this->mcrypt_encode($string, $this->get_key($key)));
} | Encode
Encodes the message string using bitwise XOR encoding.
The key is combined with a random hash, and then it
too gets converted using XOR. The whole thing is then run
through mcrypt using the randomized key. The end result
is a double-encrypted message string that is randomized
with each call to this function, even if the supplied
message and key are the same.
@param string the string to encode
@param string the key
@return string | encode | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
public function decode($string, $key = '')
{
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) OR base64_encode(base64_decode($string)) !== $string)
{
return FALSE;
}
return $this->mcrypt_decode(base64_decode($string), $this->get_key($key));
} | Decode
Reverses the above process
@param string
@param string
@return string | decode | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
public function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '')
{
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
{
return FALSE;
}
// decode it first
// set mode temporarily to what it was when string was encoded with the legacy
// algorithm - typically MCRYPT_MODE_ECB
$current_mode = $this->_get_mode();
$this->set_mode($legacy_mode);
$key = $this->get_key($key);
$dec = base64_decode($string);
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
{
$this->set_mode($current_mode);
return FALSE;
}
$dec = $this->_xor_decode($dec, $key);
// set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC
$this->set_mode($current_mode);
// and re-encode
return base64_encode($this->mcrypt_encode($dec, $key));
} | Encode from Legacy
Takes an encoded string from the original Encryption class algorithms and
returns a newly encoded string using the improved method added in 2.0.0
This allows for backwards compatibility and a method to transition to the
new encryption algorithms.
For more details, see https://codeigniter.com/user_guide/installation/upgrade_200.html#encryption
@param string
@param int (mcrypt mode constant)
@param string
@return string | encode_from_legacy | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
protected function _xor_decode($string, $key)
{
$string = $this->_xor_merge($string, $key);
$dec = '';
for ($i = 0, $l = self::strlen($string); $i < $l; $i++)
{
$dec .= ($string[$i++] ^ $string[$i]);
}
return $dec;
} | XOR Decode
Takes an encoded string and key as input and generates the
plain-text original message
@param string
@param string
@return string | _xor_decode | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
protected function _xor_merge($string, $key)
{
$hash = $this->hash($key);
$str = '';
for ($i = 0, $ls = self::strlen($string), $lh = self::strlen($hash); $i < $ls; $i++)
{
$str .= $string[$i] ^ $hash[($i % $lh)];
}
return $str;
} | XOR key + string Combiner
Takes a string and key as input and computes the difference using XOR
@param string
@param string
@return string | _xor_merge | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
protected function _add_cipher_noise($data, $key)
{
$key = $this->hash($key);
$str = '';
for ($i = 0, $j = 0, $ld = self::strlen($data), $lk = self::strlen($key); $i < $ld; ++$i, ++$j)
{
if ($j >= $lk)
{
$j = 0;
}
$str .= chr((ord($data[$i]) + ord($key[$j])) % 256);
}
return $str;
} | Adds permuted noise to the IV + encrypted data to protect
against Man-in-the-middle attacks on CBC mode ciphers
http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
@param string
@param string
@return string | _add_cipher_noise | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
protected function _remove_cipher_noise($data, $key)
{
$key = $this->hash($key);
$str = '';
for ($i = 0, $j = 0, $ld = self::strlen($data), $lk = self::strlen($key); $i < $ld; ++$i, ++$j)
{
if ($j >= $lk)
{
$j = 0;
}
$temp = ord($data[$i]) - ord($key[$j]);
if ($temp < 0)
{
$temp += 256;
}
$str .= chr($temp);
}
return $str;
} | Removes permuted noise from the IV + encrypted data, reversing
_add_cipher_noise()
Function description
@param string $data
@param string $key
@return string | _remove_cipher_noise | php | ronknight/InventorySystem | system/libraries/Encrypt.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encrypt.php | MIT |
public function set_data(array $data)
{
if ( ! empty($data))
{
$this->validation_data = $data;
}
return $this;
} | By default, form validation uses the $_POST array to validate
If an array is set through this method, then this array will
be used instead of the $_POST array
Note that if you are validating multiple arrays, then the
reset_validation() function should be called after validating
each array due to the limitations of CI's singleton
@param array $data
@return CI_Form_validation | set_data | php | ronknight/InventorySystem | system/libraries/Form_validation.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php | MIT |
public function set_message($lang, $val = '')
{
if ( ! is_array($lang))
{
$lang = array($lang => $val);
}
$this->_error_messages = array_merge($this->_error_messages, $lang);
return $this;
} | Set Error Message
Lets users set their own error messages on the fly. Note:
The key name has to match the function name that it corresponds to.
@param array
@param string
@return CI_Form_validation | set_message | php | ronknight/InventorySystem | system/libraries/Form_validation.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php | MIT |
public function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
{
$this->_error_prefix = $prefix;
$this->_error_suffix = $suffix;
return $this;
} | Set The Error Delimiter
Permits a prefix/suffix to be added to each error message
@param string
@param string
@return CI_Form_validation | set_error_delimiters | php | ronknight/InventorySystem | system/libraries/Form_validation.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php | MIT |
public function error($field, $prefix = '', $suffix = '')
{
if (empty($this->_field_data[$field]['error']))
{
return '';
}
if ($prefix === '')
{
$prefix = $this->_error_prefix;
}
if ($suffix === '')
{
$suffix = $this->_error_suffix;
}
return $prefix.$this->_field_data[$field]['error'].$suffix;
} | Get Error Message
Gets the error message associated with a particular field
@param string $field Field name
@param string $prefix HTML start tag
@param string $suffix HTML end tag
@return string | error | php | ronknight/InventorySystem | system/libraries/Form_validation.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php | MIT |
public function error_array()
{
return $this->_error_array;
} | Get Array of Error Messages
Returns the error messages as an array
@return array | error_array | php | ronknight/InventorySystem | system/libraries/Form_validation.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php | MIT |
public function error_string($prefix = '', $suffix = '')
{
// No errors, validation passes!
if (count($this->_error_array) === 0)
{
return '';
}
if ($prefix === '')
{
$prefix = $this->_error_prefix;
}
if ($suffix === '')
{
$suffix = $this->_error_suffix;
}
// Generate the error string
$str = '';
foreach ($this->_error_array as $val)
{
if ($val !== '')
{
$str .= $prefix.$val.$suffix."\n";
}
}
return $str;
} | Error String
Returns the error messages as a string, wrapped in the error delimiters
@param string
@param string
@return string | error_string | php | ronknight/InventorySystem | system/libraries/Form_validation.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.