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 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}">&lt;&lt;</a></th>', 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>', 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</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' => '&nbsp;', '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
protected function _reduce_array($array, $keys, $i = 0) { if (is_array($array) && isset($keys[$i])) { return isset($array[$keys[$i]]) ? $this->_reduce_array($array[$keys[$i]], $keys, ($i+1)) : NULL; } // NULL must be returned for empty fields return ($array === '') ? NULL : $array; }
Traverse a multidimensional $_POST array index until the data is found @param array @param array @param int @return mixed
_reduce_array
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
protected function _reset_post_array() { foreach ($this->_field_data as $field => $row) { if ($row['postdata'] !== NULL) { if ($row['is_array'] === FALSE) { isset($_POST[$field]) && $_POST[$field] = $row['postdata']; } else { // start with a reference $post_ref =& $_POST; // before we assign values, make a reference to the right POST key if (count($row['keys']) === 1) { $post_ref =& $post_ref[current($row['keys'])]; } else { foreach ($row['keys'] as $val) { $post_ref =& $post_ref[$val]; } } $post_ref = $row['postdata']; } } } }
Re-populate the _POST array with our finalized and processed data @return void
_reset_post_array
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
protected function _get_error_message($rule, $field) { // check if a custom message is defined through validation config row. if (isset($this->_field_data[$field]['errors'][$rule])) { return $this->_field_data[$field]['errors'][$rule]; } // check if a custom message has been set using the set_message() function elseif (isset($this->_error_messages[$rule])) { return $this->_error_messages[$rule]; } elseif (FALSE !== ($line = $this->CI->lang->line('form_validation_'.$rule))) { return $line; } // DEPRECATED support for non-prefixed keys, lang file again elseif (FALSE !== ($line = $this->CI->lang->line($rule, FALSE))) { return $line; } return $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule.')'; }
Get the error message for the rule @param string $rule The rule name @param string $field The field name @return string
_get_error_message
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
protected function _build_error_msg($line, $field = '', $param = '') { // Check for %s in the string for legacy support. if (strpos($line, '%s') !== FALSE) { return sprintf($line, $field, $param); } return str_replace(array('{field}', '{param}'), array($field, $param), $line); }
Build an error message using the field and param. @param string The error message line @param string A field's human name @param mixed A rule's optional parameter @return string
_build_error_msg
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function has_rule($field) { return isset($this->_field_data[$field]); }
Checks if the rule is present within the validator Permits you to check if a rule is present within the validator @param string the field name @return bool
has_rule
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function set_value($field = '', $default = '') { if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata'])) { return $default; } // If the data is an array output them one at a time. // E.g: form_input('name[]', set_value('name[]'); if (is_array($this->_field_data[$field]['postdata'])) { return array_shift($this->_field_data[$field]['postdata']); } return $this->_field_data[$field]['postdata']; }
Get the value from a form Permits you to repopulate a form field with the value it was submitted with, or, if that value doesn't exist, with the default @param string the field name @param string @return string
set_value
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function set_select($field = '', $value = '', $default = FALSE) { if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata'])) { return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : ''; } $field = $this->_field_data[$field]['postdata']; $value = (string) $value; if (is_array($field)) { // Note: in_array('', array(0)) returns TRUE, do not use it foreach ($field as &$v) { if ($value === $v) { return ' selected="selected"'; } } return ''; } elseif (($field === '' OR $value === '') OR ($field !== $value)) { return ''; } return ' selected="selected"'; }
Set Select Enables pull-down lists to be set to the value the user selected in the event of an error @param string @param string @param bool @return string
set_select
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function set_radio($field = '', $value = '', $default = FALSE) { if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata'])) { return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : ''; } $field = $this->_field_data[$field]['postdata']; $value = (string) $value; if (is_array($field)) { // Note: in_array('', array(0)) returns TRUE, do not use it foreach ($field as &$v) { if ($value === $v) { return ' checked="checked"'; } } return ''; } elseif (($field === '' OR $value === '') OR ($field !== $value)) { return ''; } return ' checked="checked"'; }
Set Radio Enables radio buttons to be set to the value the user selected in the event of an error @param string @param string @param bool @return string
set_radio
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function set_checkbox($field = '', $value = '', $default = FALSE) { // Logic is exactly the same as for radio fields return $this->set_radio($field, $value, $default); }
Set Checkbox Enables checkboxes to be set to the value the user selected in the event of an error @param string @param string @param bool @return string
set_checkbox
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function regex_match($str, $regex) { return (bool) preg_match($regex, $str); }
Performs a Regular Expression match test. @param string @param string regex @return bool
regex_match
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function is_unique($str, $field) { sscanf($field, '%[^.].%[^.]', $table, $field); return isset($this->CI->db) ? ($this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 0) : FALSE; }
Is Unique Check if the input value doesn't already exist in the specified database field. @param string $str @param string $field @return bool
is_unique
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function alpha_dash($str) { return (bool) preg_match('/^[a-z0-9_-]+$/i', $str); }
Alpha-numeric with underscores and dashes @param string @return bool
alpha_dash
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function in_list($value, $list) { return in_array($value, explode(',', $list), TRUE); }
Value should be within an array of values @param string @param string @return bool
in_list
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function is_natural($str) { return ctype_digit((string) $str); }
Is a Natural number (0,1,2,3, etc.) @param string @return bool
is_natural
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function is_natural_no_zero($str) { return ($str != 0 && ctype_digit((string) $str)); }
Is a Natural number, but not a zero (1,2,3, etc.) @param string @return bool
is_natural_no_zero
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function valid_base64($str) { return (base64_encode(base64_decode($str)) === $str); }
Valid Base64 Tests a string for characters outside of the Base64 alphabet as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 @param string @return bool
valid_base64
php
ronknight/InventorySystem
system/libraries/Form_validation.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Form_validation.php
MIT
public function format_characters($str) { static $table; if ( ! isset($table)) { $table = array( // nested smart quotes, opening and closing // note that rules for grammar (English) allow only for two levels deep // and that single quotes are _supposed_ to always be on the outside // but we'll accommodate both // Note that in all cases, whitespace is the primary determining factor // on which direction to curl, with non-word characters like punctuation // being a secondary factor only after whitespace is addressed. '/\'"(\s|$)/' => '&#8217;&#8221;$1', '/(^|\s|<p>)\'"/' => '$1&#8216;&#8220;', '/\'"(\W)/' => '&#8217;&#8221;$1', '/(\W)\'"/' => '$1&#8216;&#8220;', '/"\'(\s|$)/' => '&#8221;&#8217;$1', '/(^|\s|<p>)"\'/' => '$1&#8220;&#8216;', '/"\'(\W)/' => '&#8221;&#8217;$1', '/(\W)"\'/' => '$1&#8220;&#8216;', // single quote smart quotes '/\'(\s|$)/' => '&#8217;$1', '/(^|\s|<p>)\'/' => '$1&#8216;', '/\'(\W)/' => '&#8217;$1', '/(\W)\'/' => '$1&#8216;', // double quote smart quotes '/"(\s|$)/' => '&#8221;$1', '/(^|\s|<p>)"/' => '$1&#8220;', '/"(\W)/' => '&#8221;$1', '/(\W)"/' => '$1&#8220;', // apostrophes "/(\w)'(\w)/" => '$1&#8217;$2', // Em dash and ellipses dots '/\s?\-\-\s?/' => '&#8212;', '/(\w)\.{3}/' => '$1&#8230;', // double space after sentences '/(\W) /' => '$1&nbsp; ', // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&amp;' ); } return preg_replace(array_keys($table), $table, $str); }
Format Characters This function mainly converts double and single quotes to curly entities, but it also converts em-dashes, double spaces, and ampersands @param string @return string
format_characters
php
ronknight/InventorySystem
system/libraries/Typography.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Typography.php
MIT
protected function _format_newlines($str) { if ($str === '' OR (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required))) { return $str; } // Convert two consecutive newlines to paragraphs $str = str_replace("\n\n", "</p>\n\n<p>", $str); // Convert single spaces to <br /> tags $str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str); // Wrap the whole enchilada in enclosing paragraphs if ($str !== "\n") { // We trim off the right-side new line so that the closing </p> tag // will be positioned immediately following the string, matching // the behavior of the opening <p> tag $str = '<p>'.rtrim($str).'</p>'; } // Remove empty paragraphs if they are on the first line, as this // is a potential unintended consequence of the previous code return preg_replace('/<p><\/p>(.*)/', '\\1', $str, 1); }
Format Newlines Converts newline characters into either <p> tags or <br /> @param string @return string
_format_newlines
php
ronknight/InventorySystem
system/libraries/Typography.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Typography.php
MIT
public function auto_typography($str, $reduce_linebreaks = FALSE) { if ($str === '') { return ''; } // Standardize Newlines to make matching easier if (strpos($str, "\r") !== FALSE) { $str = str_replace(array("\r\n", "\r"), "\n", $str); } // Reduce line breaks. If there are more than two consecutive linebreaks // we'll compress them down to a maximum of two since there's no benefit to more. if ($reduce_linebreaks === TRUE) { $str = preg_replace("/\n\n+/", "\n\n", $str); } // HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed $html_comments = array(); if (strpos($str, '<!--') !== FALSE && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches)) { for ($i = 0, $total = count($matches[0]); $i < $total; $i++) { $html_comments[] = $matches[0][$i]; $str = str_replace($matches[0][$i], '{@HC'.$i.'}', $str); } } // match and yank <pre> tags if they exist. It's cheaper to do this separately since most content will // not contain <pre> tags, and it keeps the PCRE patterns below simpler and faster if (strpos($str, '<pre') !== FALSE) { $str = preg_replace_callback('#<pre.*?>.*?</pre>#si', array($this, '_protect_characters'), $str); } // Convert quotes within tags to temporary markers. $str = preg_replace_callback('#<.+?>#si', array($this, '_protect_characters'), $str); // Do the same with braces if necessary if ($this->protect_braced_quotes === TRUE) { $str = preg_replace_callback('#\{.+?\}#si', array($this, '_protect_characters'), $str); } // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} $str = preg_replace('#<(/*)('.$this->inline_elements.')([ >])#i', '{@TAG}\\1\\2\\3', $str); /* Split the string at every tag. This expression creates an array with this prototype: * * [array] * { * [0] = <opening tag> * [1] = Content... * [2] = <closing tag> * Etc... * } */ $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text $str = ''; $process = TRUE; for ($i = 0, $c = count($chunks) - 1; $i <= $c; $i++) { // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip <pre> tags and a few other things. if (preg_match('#<(/*)('.$this->block_elements.').*?>#', $chunks[$i], $match)) { if (preg_match('#'.$this->skip_elements.'#', $match[2])) { $process = ($match[1] === '/'); } if ($match[1] === '') { $this->last_block_element = $match[2]; } $str .= $chunks[$i]; continue; } if ($process === FALSE) { $str .= $chunks[$i]; continue; } // Force a newline to make sure end tags get processed by _format_newlines() if ($i === $c) { $chunks[$i] .= "\n"; } // Convert Newlines into <p> and <br /> tags $str .= $this->_format_newlines($chunks[$i]); } // No opening block level tag? Add it if needed. if ( ! preg_match('/^\s*<(?:'.$this->block_elements.')/i', $str)) { $str = preg_replace('/^(.*?)<('.$this->block_elements.')/i', '<p>$1</p><$2', $str); } // Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands $str = $this->format_characters($str); // restore HTML comments for ($i = 0, $total = count($html_comments); $i < $total; $i++) { // remove surrounding paragraph tags, but only if there's an opening paragraph tag // otherwise HTML comments at the ends of paragraphs will have the closing tag removed // if '<p>{@HC1}' then replace <p>{@HC1}</p> with the comment, else replace only {@HC1} with the comment $str = preg_replace('#(?(?=<p>\{@HC'.$i.'\})<p>\{@HC'.$i.'\}(\s*</p>)|\{@HC'.$i.'\})#s', $html_comments[$i], $str); } // Final clean up $table = array( // If the user submitted their own paragraph tags within the text // we will retain them instead of using our tags. '/(<p[^>*?]>)<p>/' => '$1', // <?php BBEdit syntax coloring bug fix // Reduce multiple instances of opening/closing paragraph tags to a single one '#(</p>)+#' => '</p>', '/(<p>\W*<p>)+/' => '<p>', // Clean up stray paragraph tags that appear before block level elements '#<p></p><('.$this->block_elements.')#' => '<$1', // Clean up stray non-breaking spaces preceding block elements '#(&nbsp;\s*)+<('.$this->block_elements.')#' => ' <$2', // Replace the temporary markers we added earlier '/\{@TAG\}/' => '<', '/\{@DQ\}/' => '"', '/\{@SQ\}/' => "'", '/\{@DD\}/' => '--', '/\{@NBS\}/' => ' ', // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in <p> tags // starting immediately after <block> tags on the same line. // This forces a newline after such occurrences, which looks much nicer. "/><p>\n/" => ">\n<p>", // Similarly, there might be cases where a closing </block> will follow // a closing </p> tag, so we'll correct it by adding a newline in between '#</p></#' => "</p>\n</" ); // Do we need to reduce empty lines? if ($reduce_linebreaks === TRUE) { $table['#<p>\n*</p>#'] = ''; } else { // If we have empty paragraph tags we add a non-breaking space // otherwise most browsers won't treat them as true paragraphs $table['#<p></p>#'] = '<p>&nbsp;</p>'; } return preg_replace(array_keys($table), $table, $str); } // -------------------------------------------------------------------- /** * Format Characters * * This function mainly converts double and single quotes * to curly entities, but it also converts em-dashes, * double spaces, and ampersands * * @param string * @return string */ public function format_characters($str) { static $table; if ( ! isset($table)) { $table = array( // nested smart quotes, opening and closing // note that rules for grammar (English) allow only for two levels deep // and that single quotes are _supposed_ to always be on the outside // but we'll accommodate both // Note that in all cases, whitespace is the primary determining factor // on which direction to curl, with non-word characters like punctuation // being a secondary factor only after whitespace is addressed. '/\'"(\s|$)/' => '&#8217;&#8221;$1', '/(^|\s|<p>)\'"/' => '$1&#8216;&#8220;', '/\'"(\W)/' => '&#8217;&#8221;$1', '/(\W)\'"/' => '$1&#8216;&#8220;', '/"\'(\s|$)/' => '&#8221;&#8217;$1', '/(^|\s|<p>)"\'/' => '$1&#8220;&#8216;', '/"\'(\W)/' => '&#8221;&#8217;$1', '/(\W)"\'/' => '$1&#8220;&#8216;', // single quote smart quotes '/\'(\s|$)/' => '&#8217;$1', '/(^|\s|<p>)\'/' => '$1&#8216;', '/\'(\W)/' => '&#8217;$1', '/(\W)\'/' => '$1&#8216;', // double quote smart quotes '/"(\s|$)/' => '&#8221;$1', '/(^|\s|<p>)"/' => '$1&#8220;', '/"(\W)/' => '&#8221;$1', '/(\W)"/' => '$1&#8220;', // apostrophes "/(\w)'(\w)/" => '$1&#8217;$2', // Em dash and ellipses dots '/\s?\-\-\s?/' => '&#8212;', '/(\w)\.{3}/' => '$1&#8230;', // double space after sentences '/(\W) /' => '$1&nbsp; ', // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&amp;' ); } return preg_replace(array_keys($table), $table, $str); } // -------------------------------------------------------------------- /** * Format Newlines * * Converts newline characters into either <p> tags or <br /> * * @param string * @return string */ protected function _format_newlines($str) { if ($str === '' OR (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required))) { return $str; } // Convert two consecutive newlines to paragraphs $str = str_replace("\n\n", "</p>\n\n<p>", $str); // Convert single spaces to <br /> tags $str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str); // Wrap the whole enchilada in enclosing paragraphs if ($str !== "\n") { // We trim off the right-side new line so that the closing </p> tag // will be positioned immediately following the string, matching // the behavior of the opening <p> tag $str = '<p>'.rtrim($str).'</p>'; } // Remove empty paragraphs if they are on the first line, as this // is a potential unintended consequence of the previous code return preg_replace('/<p><\/p>(.*)/', '\\1', $str, 1); } // ------------------------------------------------------------------------ /** * Protect Characters * * Protects special characters from being formatted later * We don't want quotes converted within tags so we'll temporarily convert them to {@DQ} and {@SQ} * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} * likewise double spaces are converted to {@NBS} to prevent entity conversion * * @param array * @return string */ protected function _protect_characters($match) { return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } // -------------------------------------------------------------------- /** * Convert newlines to HTML line breaks except within PRE tags * * @param string * @return string */ public function nl2br_except_pre($str) { $newstr = ''; for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) { $newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i]; if ($ct - 1 !== $i) { $newstr .= 'pre>'; } } return $newstr; } }
Auto Typography This function converts text, making it typographically correct: - Converts double spaces into paragraphs. - Converts single line breaks into <br /> tags - Converts single and double quotes into correctly facing curly quote entities. - Converts three dots into ellipsis. - Converts double dashes into em-dashes. - Converts two spaces into entities @param string @param bool whether to reduce more then two consecutive newlines to two @return string
auto_typography
php
ronknight/InventorySystem
system/libraries/Typography.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Typography.php
MIT
public function remove($rowid) { // unset & save unset($this->_cart_contents[$rowid]); $this->_save_cart(); return TRUE; }
Remove Item Removes an item from the cart @param int @return bool
remove
php
ronknight/InventorySystem
system/libraries/Cart.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php
MIT
public function total_items() { return $this->_cart_contents['total_items']; }
Total Items Returns the total item count @return int
total_items
php
ronknight/InventorySystem
system/libraries/Cart.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php
MIT
public function contents($newest_first = FALSE) { // do we want the newest first? $cart = ($newest_first) ? array_reverse($this->_cart_contents) : $this->_cart_contents; // Remove these so they don't create a problem when showing the cart table unset($cart['total_items']); unset($cart['cart_total']); return $cart; }
Cart Contents Returns the entire cart array @param bool @return array
contents
php
ronknight/InventorySystem
system/libraries/Cart.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php
MIT
public function get_item($row_id) { return (in_array($row_id, array('total_items', 'cart_total'), TRUE) OR ! isset($this->_cart_contents[$row_id])) ? FALSE : $this->_cart_contents[$row_id]; }
Get cart item Returns the details of a specific item in the cart @param string $row_id @return array
get_item
php
ronknight/InventorySystem
system/libraries/Cart.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php
MIT
public function has_options($row_id = '') { return (isset($this->_cart_contents[$row_id]['options']) && count($this->_cart_contents[$row_id]['options']) !== 0); }
Has options Returns TRUE if the rowid passed to this function correlates to an item that has options associated with it. @param string $row_id = '' @return bool
has_options
php
ronknight/InventorySystem
system/libraries/Cart.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php
MIT
public function product_options($row_id = '') { return isset($this->_cart_contents[$row_id]['options']) ? $this->_cart_contents[$row_id]['options'] : array(); }
Product options Returns the an array of options, for a particular product row ID @param string $row_id = '' @return array
product_options
php
ronknight/InventorySystem
system/libraries/Cart.php
https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php
MIT