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 |
---|---|---|---|---|---|---|---|
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|$)/' => '’”$1',
'/(^|\s|<p>)\'"/' => '$1‘“',
'/\'"(\W)/' => '’”$1',
'/(\W)\'"/' => '$1‘“',
'/"\'(\s|$)/' => '”’$1',
'/(^|\s|<p>)"\'/' => '$1“‘',
'/"\'(\W)/' => '”’$1',
'/(\W)"\'/' => '$1“‘',
// single quote smart quotes
'/\'(\s|$)/' => '’$1',
'/(^|\s|<p>)\'/' => '$1‘',
'/\'(\W)/' => '’$1',
'/(\W)\'/' => '$1‘',
// double quote smart quotes
'/"(\s|$)/' => '”$1',
'/(^|\s|<p>)"/' => '$1“',
'/"(\W)/' => '”$1',
'/(\W)"/' => '$1“',
// apostrophes
"/(\w)'(\w)/" => '$1’$2',
// Em dash and ellipses dots
'/\s?\-\-\s?/' => '—',
'/(\w)\.{3}/' => '$1…',
// double space after sentences
'/(\W) /' => '$1 ',
// ampersands, if not a character entity
'/&(?!#?[a-zA-Z0-9]{2,};)/' => '&'
);
}
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 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;
} | Convert newlines to HTML line breaks except within PRE tags
@param string
@return string | nl2br_except_pre | 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
'#( \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> </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|$)/' => '’”$1',
'/(^|\s|<p>)\'"/' => '$1‘“',
'/\'"(\W)/' => '’”$1',
'/(\W)\'"/' => '$1‘“',
'/"\'(\s|$)/' => '”’$1',
'/(^|\s|<p>)"\'/' => '$1“‘',
'/"\'(\W)/' => '”’$1',
'/(\W)"\'/' => '$1“‘',
// single quote smart quotes
'/\'(\s|$)/' => '’$1',
'/(^|\s|<p>)\'/' => '$1‘',
'/\'(\W)/' => '’$1',
'/(\W)\'/' => '$1‘',
// double quote smart quotes
'/"(\s|$)/' => '”$1',
'/(^|\s|<p>)"/' => '$1“',
'/"(\W)/' => '”$1',
'/(\W)"/' => '$1“',
// apostrophes
"/(\w)'(\w)/" => '$1’$2',
// Em dash and ellipses dots
'/\s?\-\-\s?/' => '—',
'/(\w)\.{3}/' => '$1…',
// double space after sentences
'/(\W) /' => '$1 ',
// ampersands, if not a character entity
'/&(?!#?[a-zA-Z0-9]{2,};)/' => '&'
);
}
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 |
public function format_number($n = '')
{
return ($n === '') ? '' : number_format( (float) $n, 2, '.', ',');
} | Format Number
Returns the supplied number with commas and a decimal point.
@param float
@return string | format_number | php | ronknight/InventorySystem | system/libraries/Cart.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cart.php | MIT |
public function attachment_cid($filename)
{
for ($i = 0, $c = count($this->_attachments); $i < $c; $i++)
{
if ($this->_attachments[$i]['name'][0] === $filename)
{
$this->_attachments[$i]['multipart'] = 'related';
$this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@');
return $this->_attachments[$i]['cid'];
}
}
return FALSE;
} | Set and return attachment Content-ID
Useful for attached inline pictures
@param string $filename
@return string | attachment_cid | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _get_content_type()
{
if ($this->mailtype === 'html')
{
return empty($this->_attachments) ? 'html' : 'html-attach';
}
elseif ($this->mailtype === 'text' && ! empty($this->_attachments))
{
return 'plain-attach';
}
else
{
return 'plain';
}
} | Get content type (text/html/attachment)
@return string | _get_content_type | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _get_alt_message()
{
if ( ! empty($this->alt_message))
{
return ($this->wordwrap)
? $this->word_wrap($this->alt_message, 76)
: $this->alt_message;
}
$body = preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body;
$body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
for ($i = 20; $i >= 3; $i--)
{
$body = str_replace(str_repeat("\n", $i), "\n\n", $body);
}
// Reduce multiple spaces
$body = preg_replace('| +|', ' ', $body);
return ($this->wordwrap)
? $this->word_wrap($body, 76)
: $body;
} | Build alternative plain text message
Provides the raw message for use in plain-text headers of
HTML-formatted emails.
If the user hasn't specified his own alternative message
it creates one by stripping the HTML
@return string | _get_alt_message | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _build_message()
{
if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
{
$this->_body = $this->word_wrap($this->_body);
}
$this->_write_headers();
$hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
$body = '';
switch ($this->_get_content_type())
{
case 'plain':
$hdr .= 'Content-Type: text/plain; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: '.$this->_get_encoding();
if ($this->_get_protocol() === 'mail')
{
$this->_header_str .= $hdr;
$this->_finalbody = $this->_body;
}
else
{
$this->_finalbody = $hdr.$this->newline.$this->newline.$this->_body;
}
return;
case 'html':
if ($this->send_multipart === FALSE)
{
$hdr .= 'Content-Type: text/html; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: quoted-printable';
}
else
{
$boundary = uniqid('B_ALT_');
$hdr .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"';
$body .= $this->_get_mime_message().$this->newline.$this->newline
.'--'.$boundary.$this->newline
.'Content-Type: text/plain; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
.$this->_get_alt_message().$this->newline.$this->newline
.'--'.$boundary.$this->newline
.'Content-Type: text/html; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline;
}
$this->_finalbody = $body.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline;
if ($this->_get_protocol() === 'mail')
{
$this->_header_str .= $hdr;
}
else
{
$this->_finalbody = $hdr.$this->newline.$this->newline.$this->_finalbody;
}
if ($this->send_multipart !== FALSE)
{
$this->_finalbody .= '--'.$boundary.'--';
}
return;
case 'plain-attach':
$boundary = uniqid('B_ATC_');
$hdr .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"';
if ($this->_get_protocol() === 'mail')
{
$this->_header_str .= $hdr;
}
$body .= $this->_get_mime_message().$this->newline
.$this->newline
.'--'.$boundary.$this->newline
.'Content-Type: text/plain; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline
.$this->newline
.$this->_body.$this->newline.$this->newline;
$this->_append_attachments($body, $boundary);
break;
case 'html-attach':
$alt_boundary = uniqid('B_ALT_');
$last_boundary = NULL;
if ($this->_attachments_have_multipart('mixed'))
{
$atc_boundary = uniqid('B_ATC_');
$hdr .= 'Content-Type: multipart/mixed; boundary="'.$atc_boundary.'"';
$last_boundary = $atc_boundary;
}
if ($this->_attachments_have_multipart('related'))
{
$rel_boundary = uniqid('B_REL_');
$rel_boundary_header = 'Content-Type: multipart/related; boundary="'.$rel_boundary.'"';
if (isset($last_boundary))
{
$body .= '--'.$last_boundary.$this->newline.$rel_boundary_header;
}
else
{
$hdr .= $rel_boundary_header;
}
$last_boundary = $rel_boundary;
}
if ($this->_get_protocol() === 'mail')
{
$this->_header_str .= $hdr;
}
self::strlen($body) && $body .= $this->newline.$this->newline;
$body .= $this->_get_mime_message().$this->newline.$this->newline
.'--'.$last_boundary.$this->newline
.'Content-Type: multipart/alternative; boundary="'.$alt_boundary.'"'.$this->newline.$this->newline
.'--'.$alt_boundary.$this->newline
.'Content-Type: text/plain; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
.$this->_get_alt_message().$this->newline.$this->newline
.'--'.$alt_boundary.$this->newline
.'Content-Type: text/html; charset='.$this->charset.$this->newline
.'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline
.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline
.'--'.$alt_boundary.'--'.$this->newline.$this->newline;
if ( ! empty($rel_boundary))
{
$body .= $this->newline.$this->newline;
$this->_append_attachments($body, $rel_boundary, 'related');
}
// multipart/mixed attachments
if ( ! empty($atc_boundary))
{
$body .= $this->newline.$this->newline;
$this->_append_attachments($body, $atc_boundary, 'mixed');
}
break;
}
$this->_finalbody = ($this->_get_protocol() === 'mail')
? $body
: $hdr.$this->newline.$this->newline.$body;
return TRUE;
} | Build Final Body and attachments
@return bool | _build_message | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
public function batch_bcc_send()
{
$float = $this->bcc_batch_size - 1;
$set = '';
$chunk = array();
for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
{
if (isset($this->_bcc_array[$i]))
{
$set .= ', '.$this->_bcc_array[$i];
}
if ($i === $float)
{
$chunk[] = self::substr($set, 1);
$float += $this->bcc_batch_size;
$set = '';
}
if ($i === $c-1)
{
$chunk[] = self::substr($set, 1);
}
}
for ($i = 0, $c = count($chunk); $i < $c; $i++)
{
unset($this->_headers['Bcc']);
$bcc = $this->clean_email($this->_str_to_array($chunk[$i]));
if ($this->protocol !== 'smtp')
{
$this->set_header('Bcc', implode(', ', $bcc));
}
else
{
$this->_bcc_array = $bcc;
}
if ($this->_build_message() === FALSE)
{
return FALSE;
}
$this->_spool_email();
}
} | Batch Bcc Send. Sends groups of BCCs in batches
@return void | batch_bcc_send | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _remove_nl_callback($matches)
{
if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
{
$matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
}
return $matches[1];
} | Strip line-breaks via callback
@param string $matches
@return string | _remove_nl_callback | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _validate_email_for_shell(&$email)
{
if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@'))
{
$email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos));
}
return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email && preg_match('#\A[a-z0-9._+-]+@[a-z0-9.-]{1,253}\z#i', $email));
} | Validate email for shell
Applies stricter, shell-safe validation to email addresses.
Introduced to prevent RCE via sendmail's -f option.
@see https://github.com/bcit-ci/CodeIgniter/issues/4963
@see https://gist.github.com/Zenexer/40d02da5e07f151adeaeeaa11af9ab36
@license https://creativecommons.org/publicdomain/zero/1.0/ CC0 1.0, Public Domain
Credits for the base concept go to Paul Buonopane <[email protected]>
@param string $email
@return bool | _validate_email_for_shell | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _smtp_end()
{
($this->smtp_keepalive)
? $this->_send_command('reset')
: $this->_send_command('quit');
} | SMTP End
Shortcut to send RSET or QUIT depending on keep-alive
@return void | _smtp_end | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
protected function _get_hostname()
{
if (isset($_SERVER['SERVER_NAME']))
{
return $_SERVER['SERVER_NAME'];
}
return isset($_SERVER['SERVER_ADDR']) ? '['.$_SERVER['SERVER_ADDR'].']' : '[127.0.0.1]';
} | Get Hostname
There are only two legal types of hostname - either a fully
qualified domain name (eg: "mail.example.com") or an IP literal
(eg: "[1.2.3.4]").
@link https://tools.ietf.org/html/rfc5321#section-2.3.5
@link http://cbl.abuseat.org/namingproblems.html
@return string | _get_hostname | php | ronknight/InventorySystem | system/libraries/Email.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Email.php | MIT |
public function __construct()
{
isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
$this->now = time();
log_message('info', 'Zip Compression Class Initialized');
} | Initialize zip compression class
@return void | __construct | php | ronknight/InventorySystem | system/libraries/Zip.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Zip.php | MIT |
protected function _get_mod_time($dir)
{
// filemtime() may return false, but raises an error for non-existing files
$date = file_exists($dir) ? getdate(filemtime($dir)) : getdate($this->now);
return array(
'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2,
'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']
);
} | Get file/directory modification time
If this is a newly created file/dir, we will set the time to 'now'
@param string $dir path to file
@return array filemtime/filemdate | _get_mod_time | php | ronknight/InventorySystem | system/libraries/Zip.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Zip.php | MIT |
public function read_file($path, $archive_filepath = FALSE)
{
if (file_exists($path) && FALSE !== ($data = file_get_contents($path)))
{
if (is_string($archive_filepath))
{
$name = str_replace('\\', '/', $archive_filepath);
}
else
{
$name = str_replace('\\', '/', $path);
if ($archive_filepath === FALSE)
{
$name = preg_replace('|.*/(.+)|', '\\1', $name);
}
}
$this->add_data($name, $data);
return TRUE;
}
return FALSE;
} | Read the contents of a file and add it to the zip
@param string $path
@param bool $archive_filepath
@return bool | read_file | php | ronknight/InventorySystem | system/libraries/Zip.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Zip.php | MIT |
public function archive($filepath)
{
if ( ! ($fp = @fopen($filepath, 'w+b')))
{
return FALSE;
}
flock($fp, LOCK_EX);
for ($result = $written = 0, $data = $this->get_zip(), $length = self::strlen($data); $written < $length; $written += $result)
{
if (($result = fwrite($fp, self::substr($data, $written))) === FALSE)
{
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
return is_int($result);
} | Write File to the specified directory
Lets you write a file
@param string $filepath the file name
@return bool | archive | php | ronknight/InventorySystem | system/libraries/Zip.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Zip.php | MIT |
public function clear_data()
{
$this->zipdata = '';
$this->directory = '';
$this->entries = 0;
$this->file_num = 0;
$this->offset = 0;
return $this;
} | Initialize Data
Lets you clear current zip data. Useful if you need to create
multiple zips with different data.
@return CI_Zip | clear_data | php | ronknight/InventorySystem | system/libraries/Zip.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Zip.php | MIT |
protected function _cipher_alias(&$cipher)
{
static $dictionary;
if (empty($dictionary))
{
$dictionary = array(
'mcrypt' => array(
'aes-128' => 'rijndael-128',
'aes-192' => 'rijndael-128',
'aes-256' => 'rijndael-128',
'des3-ede3' => 'tripledes',
'bf' => 'blowfish',
'cast5' => 'cast-128',
'rc4' => 'arcfour',
'rc4-40' => 'arcfour'
),
'openssl' => array(
'rijndael-128' => 'aes-128',
'tripledes' => 'des-ede3',
'blowfish' => 'bf',
'cast-128' => 'cast5',
'arcfour' => 'rc4-40',
'rc4' => 'rc4-40'
)
);
// Notes:
//
// - Rijndael-128 is, at the same time all three of AES-128,
// AES-192 and AES-256. The only difference between them is
// the key size. Rijndael-192, Rijndael-256 on the other hand
// also have different block sizes and are NOT AES-compatible.
//
// - Blowfish is said to be supporting key sizes between
// 4 and 56 bytes, but it appears that between MCrypt and
// OpenSSL, only those of 16 and more bytes are compatible.
// Also, don't know what MCrypt's 'blowfish-compat' is.
//
// - CAST-128/CAST5 produces a longer cipher when encrypted via
// OpenSSL, but (strangely enough) can be decrypted by either
// extension anyway.
// Also, it appears that OpenSSL uses 16 rounds regardless of
// the key size, while RFC2144 says that for key sizes lower
// than 11 bytes, only 12 rounds should be used. This makes
// it portable only with keys of between 11 and 16 bytes.
//
// - RC4 (ARCFour) has a strange implementation under OpenSSL.
// Its 'rc4-40' cipher method seems to work flawlessly, yet
// there's another one, 'rc4' that only works with a 16-byte key.
//
// - DES is compatible, but doesn't need an alias.
//
// Other seemingly matching ciphers between MCrypt, OpenSSL:
//
// - RC2 is NOT compatible and only an obscure forum post
// confirms that it is MCrypt's fault.
}
if (isset($dictionary[$this->_driver][$cipher]))
{
$cipher = $dictionary[$this->_driver][$cipher];
}
} | Cipher alias
Tries to translate cipher names between MCrypt and OpenSSL's "dialects".
@param string $cipher Cipher name
@return void | _cipher_alias | php | ronknight/InventorySystem | system/libraries/Encryption.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Encryption.php | MIT |
public function __construct()
{
$this->_load_agent_file();
if (isset($_SERVER['HTTP_USER_AGENT']))
{
$this->agent = trim($_SERVER['HTTP_USER_AGENT']);
$this->_compile_data();
}
log_message('info', 'User Agent Class Initialized');
} | Constructor
Sets the User Agent and runs the compilation routine
@return void | __construct | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
protected function _set_charsets()
{
if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET']))
{
$this->charsets = explode(',', preg_replace('/(;\s?q=.+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))));
}
if (count($this->charsets) === 0)
{
$this->charsets = array('Undefined');
}
} | Set the accepted character sets
@return void | _set_charsets | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
public function is_referral()
{
if ( ! isset($this->referer))
{
if (empty($_SERVER['HTTP_REFERER']))
{
$this->referer = FALSE;
}
else
{
$referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$own_host = parse_url(config_item('base_url'), PHP_URL_HOST);
$this->referer = ($referer_host && $referer_host !== $own_host);
}
}
return $this->referer;
} | Is this a referral from another site?
@return bool | is_referral | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
public function charsets()
{
if (count($this->charsets) === 0)
{
$this->_set_charsets();
}
return $this->charsets;
} | Get the accepted Character Sets
@return array | charsets | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
public function accept_lang($lang = 'en')
{
return in_array(strtolower($lang), $this->languages(), TRUE);
} | Test for a particular language
@param string $lang
@return bool | accept_lang | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
public function accept_charset($charset = 'utf-8')
{
return in_array(strtolower($charset), $this->charsets(), TRUE);
} | Test for a particular character set
@param string $charset
@return bool | accept_charset | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
public function parse($string)
{
// Reset values
$this->is_browser = FALSE;
$this->is_robot = FALSE;
$this->is_mobile = FALSE;
$this->browser = '';
$this->version = '';
$this->mobile = '';
$this->robot = '';
// Set the new user-agent string and parse it, unless empty
$this->agent = $string;
if ( ! empty($string))
{
$this->_compile_data();
}
} | Parse a custom user-agent string
@param string $string
@return void | parse | php | ronknight/InventorySystem | system/libraries/User_agent.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/User_agent.php | MIT |
public function send_error($message = 'Incomplete Information')
{
exit('<?xml version="1.0" encoding="utf-8"?'.">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>");
} | Send Trackback Error Message
Allows custom errors to be set. By default it
sends the "incomplete information" error, as that's
the most common one.
@param string
@return void | send_error | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function send_success()
{
exit('<?xml version="1.0" encoding="utf-8"?'.">\n<response>\n<error>0</error>\n</response>");
} | Send Trackback Success Message
This should be called when a trackback has been
successfully received and inserted.
@return void | send_success | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function process($url, $data)
{
$target = parse_url($url);
// Open the socket
if ( ! $fp = @fsockopen($target['host'], 80))
{
$this->set_error('Invalid Connection: '.$url);
return FALSE;
}
// Build the path
$path = isset($target['path']) ? $target['path'] : $url;
empty($target['query']) OR $path .= '?'.$target['query'];
// Add the Trackback ID to the data string
if ($id = $this->get_id($url))
{
$data = 'tb_id='.$id.'&'.$data;
}
// Transfer the data
fputs($fp, 'POST '.$path." HTTP/1.0\r\n");
fputs($fp, 'Host: '.$target['host']."\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, 'Content-length: '.strlen($data)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
// Was it successful?
$this->response = '';
while ( ! feof($fp))
{
$this->response .= fgets($fp, 128);
}
@fclose($fp);
if (stripos($this->response, '<error>0</error>') === FALSE)
{
$message = preg_match('/<message>(.*?)<\/message>/is', $this->response, $match)
? trim($match[1])
: 'An unknown error was encountered';
$this->set_error($message);
return FALSE;
}
return TRUE;
} | Process Trackback
Opens a socket connection and passes the data to
the server. Returns TRUE on success, FALSE on failure
@param string
@param string
@return bool | process | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function extract_urls($urls)
{
// Remove the pesky white space and replace with a comma, then replace doubles.
$urls = str_replace(',,', ',', preg_replace('/\s*(\S+)\s*/', '\\1,', $urls));
// Break into an array via commas and remove duplicates
$urls = array_unique(preg_split('/[,]/', rtrim($urls, ',')));
array_walk($urls, array($this, 'validate_url'));
return $urls;
} | Extract Trackback URLs
This function lets multiple trackbacks be sent.
It takes a string of URLs (separated by comma or
space) and puts each URL into an array
@param string
@return string | extract_urls | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function validate_url(&$url)
{
$url = trim($url);
if (stripos($url, 'http') !== 0)
{
$url = 'http://'.$url;
}
} | Validate URL
Simply adds "http://" if missing
@param string
@return void | validate_url | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function convert_xml($str)
{
$temp = '__TEMP_AMPERSANDS__';
$str = preg_replace(array('/&#(\d+);/', '/&(\w+);/'), $temp.'\\1;', $str);
$str = str_replace(array('&', '<', '>', '"', "'", '-'),
array('&', '<', '>', '"', ''', '-'),
$str);
return preg_replace(array('/'.$temp.'(\d+);/', '/'.$temp.'(\w+);/'), array('&#\\1;', '&\\1;'), $str);
} | Convert Reserved XML characters to Entities
@param string
@return string | convert_xml | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function limit_characters($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}
$str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
if (strlen($str) <= $n)
{
return $str;
}
$out = '';
foreach (explode(' ', trim($str)) as $val)
{
$out .= $val.' ';
if (strlen($out) >= $n)
{
return rtrim($out).$end_char;
}
}
} | Character limiter
Limits the string based on the character count. Will preserve complete words.
@param string
@param int
@param string
@return string | limit_characters | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function convert_ascii($str)
{
$count = 1;
$out = '';
$temp = array();
for ($i = 0, $s = strlen($str); $i < $s; $i++)
{
$ordinal = ord($str[$i]);
if ($ordinal < 128)
{
$out .= $str[$i];
}
else
{
if (count($temp) === 0)
{
$count = ($ordinal < 224) ? 2 : 3;
}
$temp[] = $ordinal;
if (count($temp) === $count)
{
$number = ($count === 3)
? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
: (($temp[0] % 32) * 64) + ($temp[1] % 64);
$out .= '&#'.$number.';';
$count = 1;
$temp = array();
}
}
}
return $out;
} | High ASCII to Entities
Converts Hight ascii text and MS Word special chars
to character entities
@param string
@return string | convert_ascii | php | ronknight/InventorySystem | system/libraries/Trackback.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Trackback.php | MIT |
public function clear()
{
$props = array('thumb_marker', 'library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path');
foreach ($props as $val)
{
$this->$val = '';
}
$this->image_library = 'gd2';
$this->dynamic_output = FALSE;
$this->quality = 90;
$this->create_thumb = FALSE;
$this->thumb_marker = '_thumb';
$this->maintain_ratio = TRUE;
$this->master_dim = 'auto';
$this->wm_type = 'text';
$this->wm_x_transp = 4;
$this->wm_y_transp = 4;
$this->wm_font_size = 17;
$this->wm_vrt_alignment = 'B';
$this->wm_hor_alignment = 'C';
$this->wm_padding = 0;
$this->wm_hor_offset = 0;
$this->wm_vrt_offset = 0;
$this->wm_font_color = '#ffffff';
$this->wm_shadow_distance = 2;
$this->wm_opacity = 50;
$this->create_fnc = 'imagecreatetruecolor';
$this->copy_fnc = 'imagecopyresampled';
$this->error_msg = array();
$this->wm_use_drop_shadow = FALSE;
$this->wm_use_truetype = FALSE;
} | Initialize image properties
Resets values in case this class is used in a loop
@return void | clear | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function resize()
{
$protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
return $this->$protocol('resize');
} | Image Resize
This is a wrapper function that chooses the proper
resize function based on the protocol specified
@return bool | resize | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function crop()
{
$protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
return $this->$protocol('crop');
} | Image Crop
This is a wrapper function that chooses the proper
cropping function based on the protocol specified
@return bool | crop | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function rotate()
{
// Allowed rotation values
$degs = array(90, 180, 270, 'vrt', 'hor');
if ($this->rotation_angle === '' OR ! in_array($this->rotation_angle, $degs))
{
$this->set_error('imglib_rotation_angle_required');
return FALSE;
}
// Reassign the width and height
if ($this->rotation_angle === 90 OR $this->rotation_angle === 270)
{
$this->width = $this->orig_height;
$this->height = $this->orig_width;
}
else
{
$this->width = $this->orig_width;
$this->height = $this->orig_height;
}
// Choose resizing function
if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm')
{
$protocol = 'image_process_'.$this->image_library;
return $this->$protocol('rotate');
}
return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
? $this->image_mirror_gd()
: $this->image_rotate_gd();
} | Image Rotate
This is a wrapper function that chooses the proper
rotation function based on the protocol specified
@return bool | rotate | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function image_process_gd($action = 'resize')
{
$v2_override = FALSE;
// If the target width/height match the source, AND if the new file name is not equal to the old file name
// we'll simply make a copy of the original with the new name... assuming dynamic rendering is off.
if ($this->dynamic_output === FALSE && $this->orig_width === $this->width && $this->orig_height === $this->height)
{
if ($this->source_image !== $this->new_image && @copy($this->full_src_path, $this->full_dst_path))
{
chmod($this->full_dst_path, $this->file_permissions);
}
return TRUE;
}
// Let's set up our values based on the action
if ($action === 'crop')
{
// Reassign the source width/height if cropping
$this->orig_width = $this->width;
$this->orig_height = $this->height;
// GD 2.0 has a cropping bug so we'll test for it
if ($this->gd_version() !== FALSE)
{
$gd_version = str_replace('0', '', $this->gd_version());
$v2_override = ($gd_version == 2);
}
}
else
{
// If resizing the x/y axis must be zero
$this->x_axis = 0;
$this->y_axis = 0;
}
// Create the image handle
if ( ! ($src_img = $this->image_create_gd()))
{
return FALSE;
}
/* Create the image
*
* Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
* it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
* below should that ever prove inaccurate.
*
* if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override === FALSE)
*/
if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
{
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
}
else
{
$create = 'imagecreate';
$copy = 'imagecopyresized';
}
$dst_img = $create($this->width, $this->height);
if ($this->image_type === 3) // png we can actually preserve transparency
{
imagealphablending($dst_img, FALSE);
imagesavealpha($dst_img, TRUE);
}
$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
// Show the image
if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($dst_img);
}
elseif ( ! $this->image_save_gd($dst_img)) // Or save it
{
return FALSE;
}
// Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
chmod($this->full_dst_path, $this->file_permissions);
return TRUE;
} | Image Process Using GD/GD2
This function will resize or crop
@param string
@return bool | image_process_gd | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function image_process_netpbm($action = 'resize')
{
if ($this->library_path === '')
{
$this->set_error('imglib_libpath_invalid');
return FALSE;
}
// Build the resizing command
switch ($this->image_type)
{
case 1 :
$cmd_in = 'giftopnm';
$cmd_out = 'ppmtogif';
break;
case 2 :
$cmd_in = 'jpegtopnm';
$cmd_out = 'ppmtojpeg';
break;
case 3 :
$cmd_in = 'pngtopnm';
$cmd_out = 'ppmtopng';
break;
}
if ($action === 'crop')
{
$cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
}
elseif ($action === 'rotate')
{
switch ($this->rotation_angle)
{
case 90: $angle = 'r270';
break;
case 180: $angle = 'r180';
break;
case 270: $angle = 'r90';
break;
case 'vrt': $angle = 'tb';
break;
case 'hor': $angle = 'lr';
break;
}
$cmd_inner = 'pnmflip -'.$angle.' ';
}
else // Resize
{
$cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height;
}
$cmd = $this->library_path.$cmd_in.' '.escapeshellarg($this->full_src_path).' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
$retval = 1;
// exec() might be disabled
if (function_usable('exec'))
{
@exec($cmd, $output, $retval);
}
// Did it work?
if ($retval > 0)
{
$this->set_error('imglib_image_process_failed');
return FALSE;
}
// With NetPBM we have to create a temporary image.
// If you try manipulating the original it fails so
// we have to rename the temp file.
copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
unlink($this->dest_folder.'netpbm.tmp');
chmod($this->full_dst_path, $this->file_permissions);
return TRUE;
} | Image Process Using NetPBM
This function will resize, crop or rotate
@param string
@return bool | image_process_netpbm | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function image_mirror_gd()
{
if ( ! $src_img = $this->image_create_gd())
{
return FALSE;
}
$width = $this->orig_width;
$height = $this->orig_height;
if ($this->rotation_angle === 'hor')
{
for ($i = 0; $i < $height; $i++)
{
$left = 0;
$right = $width - 1;
while ($left < $right)
{
$cl = imagecolorat($src_img, $left, $i);
$cr = imagecolorat($src_img, $right, $i);
imagesetpixel($src_img, $left, $i, $cr);
imagesetpixel($src_img, $right, $i, $cl);
$left++;
$right--;
}
}
}
else
{
for ($i = 0; $i < $width; $i++)
{
$top = 0;
$bottom = $height - 1;
while ($top < $bottom)
{
$ct = imagecolorat($src_img, $i, $top);
$cb = imagecolorat($src_img, $i, $bottom);
imagesetpixel($src_img, $i, $top, $cb);
imagesetpixel($src_img, $i, $bottom, $ct);
$top++;
$bottom--;
}
}
}
// Show the image
if ($this->dynamic_output === TRUE)
{
$this->image_display_gd($src_img);
}
elseif ( ! $this->image_save_gd($src_img)) // ... or save it
{
return FALSE;
}
// Kill the file handles
imagedestroy($src_img);
chmod($this->full_dst_path, $this->file_permissions);
return TRUE;
} | Create Mirror Image using GD
This function will flip horizontal or vertical
@return bool | image_mirror_gd | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function watermark()
{
return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark();
} | Image Watermark
This is a wrapper function that chooses the type
of watermarking based on the specified preference.
@return bool | watermark | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function image_create_gd($path = '', $image_type = '')
{
if ($path === '')
{
$path = $this->full_src_path;
}
if ($image_type === '')
{
$image_type = $this->image_type;
}
switch ($image_type)
{
case 1:
if ( ! function_exists('imagecreatefromgif'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
return FALSE;
}
return imagecreatefromgif($path);
case 2:
if ( ! function_exists('imagecreatefromjpeg'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
return FALSE;
}
return imagecreatefromjpeg($path);
case 3:
if ( ! function_exists('imagecreatefrompng'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
return FALSE;
}
return imagecreatefrompng($path);
default:
$this->set_error(array('imglib_unsupported_imagecreate'));
return FALSE;
}
} | Create Image - GD
This simply creates an image resource handle
based on the type of image being processed
@param string
@param string
@return resource | image_create_gd | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function image_save_gd($resource)
{
switch ($this->image_type)
{
case 1:
if ( ! function_exists('imagegif'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
return FALSE;
}
if ( ! @imagegif($resource, $this->full_dst_path))
{
$this->set_error('imglib_save_failed');
return FALSE;
}
break;
case 2:
if ( ! function_exists('imagejpeg'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
return FALSE;
}
if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
{
$this->set_error('imglib_save_failed');
return FALSE;
}
break;
case 3:
if ( ! function_exists('imagepng'))
{
$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
return FALSE;
}
if ( ! @imagepng($resource, $this->full_dst_path))
{
$this->set_error('imglib_save_failed');
return FALSE;
}
break;
default:
$this->set_error(array('imglib_unsupported_imagecreate'));
return FALSE;
break;
}
return TRUE;
} | Write image file to disk - GD
Takes an image resource as input and writes the file
to the specified destination
@param resource
@return bool | image_save_gd | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function image_reproportion()
{
if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
{
return;
}
// Sanitize
$this->width = (int) $this->width;
$this->height = (int) $this->height;
if ($this->master_dim !== 'width' && $this->master_dim !== 'height')
{
if ($this->width > 0 && $this->height > 0)
{
$this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0)
? 'width' : 'height';
}
else
{
$this->master_dim = ($this->height === 0) ? 'width' : 'height';
}
}
elseif (($this->master_dim === 'width' && $this->width === 0)
OR ($this->master_dim === 'height' && $this->height === 0))
{
return;
}
if ($this->master_dim === 'width')
{
$this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width);
}
else
{
$this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height);
}
} | Re-proportion Image Width/Height
When creating thumbs, the desired width/height
can end up warping the image due to an incorrect
ratio between the full-sized image and the thumb.
This function lets us re-proportion the width/height
if users choose to maintain the aspect ratio when resizing.
@return void | image_reproportion | php | ronknight/InventorySystem | system/libraries/Image_lib.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Image_lib.php | MIT |
public function get($id)
{
return $this->{$this->_adapter}->get($this->key_prefix.$id);
} | Get
Look for a value in the cache. If it exists, return the data
if not, return FALSE
@param string $id
@return mixed value matching $id or FALSE on failure | get | php | ronknight/InventorySystem | system/libraries/Cache/Cache.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/Cache.php | MIT |
public function is_supported($driver)
{
static $support;
if ( ! isset($support, $support[$driver]))
{
$support[$driver] = $this->{$driver}->is_supported();
}
return $support[$driver];
} | Is the requested driver supported in this environment?
@param string $driver The driver to test
@return array | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/Cache.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/Cache.php | MIT |
public function __construct()
{
if ( ! $this->is_supported())
{
log_message('error', 'Cache: Failed to initialize Wincache; extension not loaded/enabled?');
}
} | Class constructor
Only present so that an error message is logged
if APC is not available.
@return void | __construct | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_wincache.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_wincache.php | MIT |
public function get($id)
{
$success = FALSE;
$data = wincache_ucache_get($id, $success);
// Success returned by reference from wincache_ucache_get()
return ($success) ? $data : FALSE;
} | Get
Look for a value in the cache. If it exists, return the data,
if not, return FALSE
@param string $id Cache Ide
@return mixed Value that is stored/FALSE on failure | get | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_wincache.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_wincache.php | MIT |
public function is_supported()
{
return (extension_loaded('wincache') && ini_get('wincache.ucenabled'));
} | is_supported()
Check to see if WinCache is available on this system, bail if it isn't.
@return bool | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_wincache.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_wincache.php | MIT |
public function is_supported()
{
return (extension_loaded('memcached') OR extension_loaded('memcache'));
} | Is supported
Returns FALSE if memcached is not supported on the system.
If it is, we setup the memcached object & return TRUE
@return bool | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_memcached.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_memcached.php | MIT |
public function get($id)
{
return FALSE;
} | Get
Since this is the dummy class, it's always going to return FALSE.
@param string
@return bool FALSE | get | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_dummy.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_dummy.php | MIT |
public function is_supported()
{
return TRUE;
} | Is this caching driver supported on the system?
Of course this one is.
@return bool TRUE | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_dummy.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_dummy.php | MIT |
public function __construct()
{
if ( ! $this->is_supported())
{
log_message('error', 'Cache: Failed to initialize APC; extension not loaded/enabled?');
}
} | Class constructor
Only present so that an error message is logged
if APC is not available.
@return void | __construct | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_apc.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_apc.php | MIT |
public function get($id)
{
$success = FALSE;
$data = apc_fetch($id, $success);
return ($success === TRUE) ? $data : FALSE;
} | Get
Look for a value in the cache. If it exists, return the data
if not, return FALSE
@param string
@return mixed value that is stored/FALSE on failure | get | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_apc.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_apc.php | MIT |
public function is_supported()
{
return (extension_loaded('apc') && ini_get('apc.enabled'));
} | is_supported()
Check to see if APC is available on this system, bail if it isn't.
@return bool | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_apc.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_apc.php | MIT |
public function __construct()
{
if ( ! $this->is_supported())
{
log_message('error', 'Cache: Failed to create Redis object; extension not loaded?');
return;
}
$CI =& get_instance();
if ($CI->config->load('redis', TRUE, TRUE))
{
$config = array_merge(self::$_default_config, $CI->config->item('redis'));
}
else
{
$config = self::$_default_config;
}
$this->_redis = new Redis();
try
{
if ($config['socket_type'] === 'unix')
{
$success = $this->_redis->connect($config['socket']);
}
else // tcp socket
{
$success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']);
}
if ( ! $success)
{
log_message('error', 'Cache: Redis connection failed. Check your configuration.');
}
if (isset($config['password']) && ! $this->_redis->auth($config['password']))
{
log_message('error', 'Cache: Redis authentication failed.');
}
}
catch (RedisException $e)
{
log_message('error', 'Cache: Redis connection refused ('.$e->getMessage().')');
}
// Initialize the index of serialized values.
$serialized = $this->_redis->sMembers('_ci_redis_serialized');
empty($serialized) OR $this->_serialized = array_flip($serialized);
} | Class constructor
Setup Redis
Loads Redis config file if present. Will halt execution
if a Redis connection can't be established.
@return void
@see Redis::connect() | __construct | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_redis.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_redis.php | MIT |
public function cache_info($type = NULL)
{
return $this->_redis->info();
} | Get cache driver info
@param string $type Not supported in Redis.
Only included in order to offer a
consistent cache API.
@return array
@see Redis::info() | cache_info | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_redis.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_redis.php | MIT |
public function is_supported()
{
return extension_loaded('redis');
} | Check if Redis driver is supported
@return bool | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_redis.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_redis.php | MIT |
public function __destruct()
{
if ($this->_redis)
{
$this->_redis->close();
}
} | Class destructor
Closes the connection to Redis if present.
@return void | __destruct | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_redis.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_redis.php | MIT |
public function cache_info($type = NULL)
{
return get_dir_file_info($this->_cache_path);
} | Cache Info
Not supported by file-based caching
@param string user/filehits
@return mixed FALSE | cache_info | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_file.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_file.php | MIT |
public function is_supported()
{
return is_really_writable($this->_cache_path);
} | Is supported
In the file driver, check to see that the cache directory is indeed writable
@return bool | is_supported | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_file.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_file.php | MIT |
protected function _get($id)
{
if ( ! is_file($this->_cache_path.$id))
{
return FALSE;
}
$data = unserialize(file_get_contents($this->_cache_path.$id));
if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl'])
{
unlink($this->_cache_path.$id);
return FALSE;
}
return $data;
} | Get all data
Internal method to get all the relevant data about a cache item
@param string $id Cache ID
@return mixed Data array on success or FALSE on failure | _get | php | ronknight/InventorySystem | system/libraries/Cache/drivers/Cache_file.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Cache/drivers/Cache_file.php | MIT |
protected function _cookie_destroy()
{
return setcookie(
$this->_config['cookie_name'],
NULL,
1,
$this->_config['cookie_path'],
$this->_config['cookie_domain'],
$this->_config['cookie_secure'],
TRUE
);
} | Cookie destroy
Internal method to force removal of a cookie by the client
when session_destroy() is called.
@return bool | _cookie_destroy | php | ronknight/InventorySystem | system/libraries/Session/Session_driver.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session_driver.php | MIT |
protected function _get_lock($session_id)
{
$this->_lock = TRUE;
return TRUE;
} | Get lock
A dummy method allowing drivers with no locking functionality
(databases other than PostgreSQL and MySQL) to act as if they
do acquire a lock.
@param string $session_id
@return bool | _get_lock | php | ronknight/InventorySystem | system/libraries/Session/Session_driver.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session_driver.php | MIT |
protected function _fail()
{
ini_set('session.save_path', config_item('sess_save_path'));
return $this->_failure;
} | Fail
Drivers other than the 'files' one don't (need to) use the
session.save_path INI setting, but that leads to confusing
error messages emitted by PHP when open() or write() fail,
as the message contains session.save_path ...
To work around the problem, the drivers will call this method
so that the INI is set just in time for the error message to
be properly generated.
@return mixed | _fail | php | ronknight/InventorySystem | system/libraries/Session/Session_driver.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session_driver.php | MIT |
protected function _ci_load_classes($driver)
{
// PHP 5.4 compatibility
interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php');
$prefix = config_item('subclass_prefix');
if ( ! class_exists('CI_Session_driver', FALSE))
{
require_once(
file_exists(APPPATH.'libraries/Session/Session_driver.php')
? APPPATH.'libraries/Session/Session_driver.php'
: BASEPATH.'libraries/Session/Session_driver.php'
);
if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php'))
{
require_once($file_path);
}
}
$class = 'Session_'.$driver.'_driver';
// Allow custom drivers without the CI_ or MY_ prefix
if ( ! class_exists($class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php'))
{
require_once($file_path);
if (class_exists($class, FALSE))
{
return $class;
}
}
if ( ! class_exists('CI_'.$class, FALSE))
{
if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php'))
{
require_once($file_path);
}
if ( ! class_exists('CI_'.$class, FALSE) && ! class_exists($class, FALSE))
{
throw new UnexpectedValueException("Session: Configured driver '".$driver."' was not found. Aborting.");
}
}
if ( ! class_exists($prefix.$class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php'))
{
require_once($file_path);
if (class_exists($prefix.$class, FALSE))
{
return $prefix.$class;
}
else
{
log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
}
}
return 'CI_'.$class;
} | CI Load Classes
An internal method to load all possible dependency and extension
classes. It kind of emulates the CI_Driver library, but is
self-sufficient.
@param string $driver Driver name
@return string Driver class name | _ci_load_classes | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
protected function _configure(&$params)
{
$expiration = config_item('sess_expiration');
if (isset($params['cookie_lifetime']))
{
$params['cookie_lifetime'] = (int) $params['cookie_lifetime'];
}
else
{
$params['cookie_lifetime'] = ( ! isset($expiration) && config_item('sess_expire_on_close'))
? 0 : (int) $expiration;
}
isset($params['cookie_name']) OR $params['cookie_name'] = config_item('sess_cookie_name');
if (empty($params['cookie_name']))
{
$params['cookie_name'] = ini_get('session.name');
}
else
{
ini_set('session.name', $params['cookie_name']);
}
isset($params['cookie_path']) OR $params['cookie_path'] = config_item('cookie_path');
isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain');
isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure');
session_set_cookie_params(
$params['cookie_lifetime'],
$params['cookie_path'],
$params['cookie_domain'],
$params['cookie_secure'],
TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons
);
if (empty($expiration))
{
$params['expiration'] = (int) ini_get('session.gc_maxlifetime');
}
else
{
$params['expiration'] = (int) $expiration;
ini_set('session.gc_maxlifetime', $expiration);
}
$params['match_ip'] = (bool) (isset($params['match_ip']) ? $params['match_ip'] : config_item('sess_match_ip'));
isset($params['save_path']) OR $params['save_path'] = config_item('sess_save_path');
$this->_config = $params;
// Security is king
ini_set('session.use_trans_sid', 0);
ini_set('session.use_strict_mode', 1);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
$this->_configure_sid_length();
} | Configuration
Handle input parameters and configuration defaults
@param array &$params Input parameters
@return void | _configure | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
protected function _ci_init_vars()
{
if ( ! empty($_SESSION['__ci_vars']))
{
$current_time = time();
foreach ($_SESSION['__ci_vars'] as $key => &$value)
{
if ($value === 'new')
{
$_SESSION['__ci_vars'][$key] = 'old';
}
// Hacky, but 'old' will (implicitly) always be less than time() ;)
// DO NOT move this above the 'new' check!
elseif ($value < $current_time)
{
unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]);
}
}
if (empty($_SESSION['__ci_vars']))
{
unset($_SESSION['__ci_vars']);
}
}
$this->userdata =& $_SESSION;
} | Handle temporary variables
Clears old "flash" data, marks the new one for deletion and handles
"temp" data deletion.
@return void | _ci_init_vars | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function sess_destroy()
{
session_destroy();
} | Session destroy
Legacy CI_Session compatibility method
@return void | sess_destroy | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function sess_regenerate($destroy = FALSE)
{
$_SESSION['__ci_last_regenerate'] = time();
session_regenerate_id($destroy);
} | Session regenerate
Legacy CI_Session compatibility method
@param bool $destroy Destroy old session data flag
@return void | sess_regenerate | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function &get_userdata()
{
return $_SESSION;
} | Get userdata reference
Legacy CI_Session compatibility method
@returns array | get_userdata | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function set_userdata($data, $value = NULL)
{
if (is_array($data))
{
foreach ($data as $key => &$value)
{
$_SESSION[$key] = $value;
}
return;
}
$_SESSION[$data] = $value;
} | Set userdata
Legacy CI_Session compatibility method
@param mixed $data Session data key or an associative array
@param mixed $value Value to store
@return void | set_userdata | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function all_userdata()
{
return $this->userdata();
} | All userdata (fetch)
Legacy CI_Session compatibility method
@return array $_SESSION, excluding flash data items | all_userdata | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function has_userdata($key)
{
return isset($_SESSION[$key]);
} | Has userdata
Legacy CI_Session compatibility method
@param string $key Session data key
@return bool | has_userdata | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function set_flashdata($data, $value = NULL)
{
$this->set_userdata($data, $value);
$this->mark_as_flash(is_array($data) ? array_keys($data) : $data);
} | Set flashdata
Legacy CI_Session compatibility method
@param mixed $data Session data key or an associative array
@param mixed $value Value to store
@return void | set_flashdata | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
public function keep_flashdata($key)
{
$this->mark_as_flash($key);
} | Keep flashdata
Legacy CI_Session compatibility method
@param mixed $key Session data key(s)
@return void | keep_flashdata | php | ronknight/InventorySystem | system/libraries/Session/Session.php | https://github.com/ronknight/InventorySystem/blob/master/system/libraries/Session/Session.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.