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
protected function _limit($sql) { // Limit clause depends on if Interbase or Firebird if (stripos($this->version(), 'firebird') !== FALSE) { $select = 'FIRST '.$this->qb_limit .($this->qb_offset ? ' SKIP '.$this->qb_offset : ''); }
LIMIT Generates a platform-specific LIMIT clause @param string $sql SQL Query @return string
_limit
php
ronknight/InventorySystem
system/database/drivers/ibase/ibase_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/ibase/ibase_driver.php
MIT
protected function _insert_batch($table, $keys, $values) { return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; }
Insert batch statement Generates a platform-specific insert string from the supplied data. @param string $table Table name @param array $keys INSERT keys @param array $values INSERT values @return string|bool
_insert_batch
php
ronknight/InventorySystem
system/database/drivers/ibase/ibase_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/ibase/ibase_driver.php
MIT
public function num_rows() { return is_int($this->num_rows) ? $this->num_rows : $this->num_rows = @sqlite_num_rows($this->result_id); }
Number of rows in the result set @return int
num_rows
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_result.php
MIT
public function data_seek($n = 0) { return sqlite_seek($this->result_id, $n); }
Data Seek Moves the internal pointer to the desired offset. We call this internally before fetching results to make sure the result set starts at zero. @param int $n @return bool
data_seek
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_result.php
MIT
protected function _escape_str($str) { return sqlite_escape_string($str); }
Platform-dependant string escape @param string @return string
_escape_str
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_driver.php
MIT
protected function _list_columns($table = '') { // Not supported return FALSE; }
Show column query Generates a platform-specific query string so that the column names can be fetched @param string $table @return bool
_list_columns
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_driver.php
MIT
public function error() { $error = array('code' => sqlite_last_error($this->conn_id)); $error['message'] = sqlite_error_string($error['code']); return $error; }
Error Returns an array containing code and message of the last database error that has occured. @return array
error
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_driver.php
MIT
protected function _replace($table, $keys, $values) { return 'INSERT OR '.parent::_replace($table, $keys, $values); }
Replace statement Generates a platform-specific replace string from the supplied data @param string $table Table name @param array $keys INSERT keys @param array $values INSERT values @return string
_replace
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_driver.php
MIT
protected function _truncate($table) { return 'DELETE FROM '.$table; }
Truncate statement Generates a platform-specific truncate string from the supplied data If the database does not support the TRUNCATE statement, then this function maps to 'DELETE FROM table' @param string $table @return string
_truncate
php
ronknight/InventorySystem
system/database/drivers/sqlite/sqlite_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite/sqlite_driver.php
MIT
public function reconnect() { if (cubrid_ping($this->conn_id) === FALSE) { $this->conn_id = FALSE; } }
Reconnect Keep / reestablish the db connection if no queries have been sent for a length of time exceeding the server's idle timeout @return void
reconnect
php
ronknight/InventorySystem
system/database/drivers/cubrid/cubrid_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/cubrid/cubrid_driver.php
MIT
protected function _escape_str($str) { return cubrid_real_escape_string($str, $this->conn_id); }
Platform-dependent string escape @param string @return string
_escape_str
php
ronknight/InventorySystem
system/database/drivers/cubrid/cubrid_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/cubrid/cubrid_driver.php
MIT
public function __construct($params) { parent::__construct($params); if ( ! empty($this->dsn)) { return; } $this->dsn === '' OR $this->dsn = ''; if (strpos($this->hostname, '/') !== FALSE) { // If UNIX sockets are used, we shouldn't set a port $this->port = ''; } $this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' '; if ( ! empty($this->port) && ctype_digit($this->port)) { $this->dsn .= 'port='.$this->port.' '; } if ($this->username !== '') { $this->dsn .= 'user='.$this->username.' '; /* An empty password is valid! * * $db['password'] = NULL must be done in order to ignore it. */ $this->password === NULL OR $this->dsn .= "password='".$this->password."' "; } $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' '; /* We don't have these options as elements in our standard configuration * array, but they might be set by parse_url() if the configuration was * provided via string. Example: * * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1 */ foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key) { if (isset($this->$key) && is_string($this->$key) && $this->$key !== '') { $this->dsn .= $key."='".$this->$key."' "; } } $this->dsn = rtrim($this->dsn); }
Class constructor Creates a DSN string to be used for db_connect() and db_pconnect() @param array $params @return void
__construct
php
ronknight/InventorySystem
system/database/drivers/postgre/postgre_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/postgre/postgre_driver.php
MIT
public function is_write_type($sql) { if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) { return FALSE; } return parent::is_write_type($sql); }
Determines if a query is a "write" type. @param string An SQL query string @return bool
is_write_type
php
ronknight/InventorySystem
system/database/drivers/postgre/postgre_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/postgre/postgre_driver.php
MIT
protected function _list_columns($table = '') { return 'SELECT "column_name" FROM "information_schema"."columns" WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); }
List column query Generates a platform-specific query string so that the column names can be fetched @param string $table @return string
_list_columns
php
ronknight/InventorySystem
system/database/drivers/postgre/postgre_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/postgre/postgre_driver.php
MIT
public function insert_id() { return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->row()->insert_id; }
Insert ID Returns the last id created in the Identity column. @return string
insert_id
php
ronknight/InventorySystem
system/database/drivers/sqlsrv/sqlsrv_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlsrv/sqlsrv_driver.php
MIT
protected function _list_tables($prefix_limit = FALSE) { $sql = 'SELECT '.$this->escape_identifiers('name') .' FROM '.$this->escape_identifiers('sysobjects') .' WHERE '.$this->escape_identifiers('type')." = 'U'"; if ($prefix_limit === TRUE && $this->dbprefix !== '') { $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " .sprintf($this->_escape_like_str, $this->_escape_like_chr); } return $sql.' ORDER BY '.$this->escape_identifiers('name'); }
List table query Generates a platform-specific query string so that the table names can be fetched @param bool @return string $prefix_limit
_list_tables
php
ronknight/InventorySystem
system/database/drivers/sqlsrv/sqlsrv_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlsrv/sqlsrv_driver.php
MIT
public function db_connect($persistent = FALSE) { if ($persistent) { log_message('debug', 'SQLite3 doesn\'t support persistent connections'); } try { return ( ! $this->password) ? new SQLite3($this->database) : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); } catch (Exception $e) { return FALSE; } }
Non-persistent database connection @param bool $persistent @return SQLite3
db_connect
php
ronknight/InventorySystem
system/database/drivers/sqlite3/sqlite3_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite3/sqlite3_driver.php
MIT
public function data_seek($n = 0) { // Only resetting to the start of the result set is supported return ($n > 0) ? FALSE : $this->result_id->reset(); }
Data Seek Moves the internal pointer to the desired offset. We call this internally before fetching results to make sure the result set starts at zero. @param int $n (ignored) @return array
data_seek
php
ronknight/InventorySystem
system/database/drivers/sqlite3/sqlite3_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/sqlite3/sqlite3_result.php
MIT
public function __construct($params) { parent::__construct($params); if ( ! empty($this->port)) { $this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port; } }
Class constructor Appends the port number to the hostname, if needed. @param array $params @return void
__construct
php
ronknight/InventorySystem
system/database/drivers/mssql/mssql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mssql/mssql_driver.php
MIT
public function get_cursor() { return $this->curs_id = oci_new_cursor($this->conn_id); }
Get cursor. Returns a cursor from the database @return resource
get_cursor
php
ronknight/InventorySystem
system/database/drivers/oci8/oci8_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/oci8/oci8_driver.php
MIT
public function stored_procedure($package, $procedure, array $params) { if ($package === '' OR $procedure === '') { log_message('error', 'Invalid query: '.$package.'.'.$procedure); return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; } // Build the query string $sql = 'BEGIN '.$package.'.'.$procedure.'('; $have_cursor = FALSE; foreach ($params as $param) { $sql .= $param['name'].','; if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) { $have_cursor = TRUE; } } $sql = trim($sql, ',').'); END;'; $this->_reset_stmt_id = FALSE; $this->stmt_id = oci_parse($this->conn_id, $sql); $this->_bind_params($params); $result = $this->query($sql, FALSE, $have_cursor); $this->_reset_stmt_id = TRUE; return $result; }
Stored Procedure. Executes a stored procedure @param string package name in which the stored procedure is in @param string stored procedure name to execute @param array parameters @return mixed params array keys KEY OPTIONAL NOTES name no the name of the parameter should be in :<param_name> format value no the value of the parameter. If this is an OUT or IN OUT parameter, this should be a reference to a variable type yes the type of the parameter length yes the max size of the parameter
stored_procedure
php
ronknight/InventorySystem
system/database/drivers/oci8/oci8_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/oci8/oci8_driver.php
MIT
protected function _insert_batch($table, $keys, $values) { $keys = implode(', ', $keys); $sql = "INSERT ALL\n"; for ($i = 0, $c = count($values); $i < $c; $i++) { $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; } return $sql.'SELECT * FROM dual'; }
Insert batch statement Generates a platform-specific insert string from the supplied data @param string $table Table name @param array $keys INSERT keys @param array $values INSERT values @return string
_insert_batch
php
ronknight/InventorySystem
system/database/drivers/oci8/oci8_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/oci8/oci8_driver.php
MIT
function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) { if ($fp = @opendir($source_dir)) { $filedata = array(); $new_depth = $directory_depth - 1; $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { continue; } is_dir($source_dir.$file) && $file .= DIRECTORY_SEPARATOR; if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir.$file)) { $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden); } else { $filedata[] = $file; } } closedir($fp); return $filedata; } return FALSE; }
Create a Directory Map Reads the specified directory and builds an array representation of it. Sub-folders contained with the directory will be mapped as well. @param string $source_dir Path to source @param int $directory_depth Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) @param bool $hidden Whether to show hidden files @return array
directory_map
php
ronknight/InventorySystem
system/helpers/directory_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/directory_helper.php
MIT
function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL) { // Set the config file options get_instance()->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly); }
Set cookie Accepts seven parameters, or you can submit an associative array in the first parameter containing all the values. @param mixed @param string the value of the cookie @param string the number of seconds until expiration @param string the cookie domain. Usually: .yourdomain.com @param string the cookie path @param string the cookie prefix @param bool true makes the cookie secure @param bool true makes the cookie accessible via http(s) only (no javascript) @return void
set_cookie
php
ronknight/InventorySystem
system/helpers/cookie_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/cookie_helper.php
MIT
function get_cookie($index, $xss_clean = NULL) { is_bool($xss_clean) OR $xss_clean = (config_item('global_xss_filtering') === TRUE); $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix'); return get_instance()->input->cookie($prefix.$index, $xss_clean); }
Fetch an item from the COOKIE array @param string @param bool @return mixed
get_cookie
php
ronknight/InventorySystem
system/helpers/cookie_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/cookie_helper.php
MIT
function now($timezone = NULL) { if (empty($timezone)) { $timezone = config_item('time_reference'); } if ($timezone === 'local' OR $timezone === date_default_timezone_get()) { return time(); } $datetime = new DateTime('now', new DateTimeZone($timezone)); sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); return mktime($hour, $minute, $second, $month, $day, $year); }
Get "now" time Returns time() based on the timezone parameter or on the "time_reference" setting @param string @return int
now
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function standard_date($fmt = 'DATE_RFC822', $time = NULL) { if (empty($time)) { $time = now(); } // Procedural style pre-defined constants from the DateTime extension if (strpos($fmt, 'DATE_') !== 0 OR defined($fmt) === FALSE) { return FALSE; } return date(constant($fmt), $time); }
Standard Date Returns a date formatted according to the submitted standard. As of PHP 5.2, the DateTime extension provides constants that serve for the exact same purpose and are used with date(). @todo Remove in version 3.1+. @deprecated 3.0.0 Use PHP's native date() instead. @link http://www.php.net/manual/en/class.datetime.php#datetime.constants.types @example date(DATE_RFC822, now()); // default @example date(DATE_W3C, $time); // a different format and time @param string $fmt = 'DATE_RFC822' the chosen format @param int $time = NULL Unix timestamp @return string
standard_date
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function timespan($seconds = 1, $time = '', $units = 7) { $CI =& get_instance(); $CI->lang->load('date'); is_numeric($seconds) OR $seconds = 1; is_numeric($time) OR $time = time(); is_numeric($units) OR $units = 7; $seconds = ($time <= $seconds) ? 1 : $time - $seconds; $str = array(); $years = floor($seconds / 31557600); if ($years > 0) { $str[] = $years.' '.$CI->lang->line($years > 1 ? 'date_years' : 'date_year'); } $seconds -= $years * 31557600; $months = floor($seconds / 2629743); if (count($str) < $units && ($years > 0 OR $months > 0)) { if ($months > 0) { $str[] = $months.' '.$CI->lang->line($months > 1 ? 'date_months' : 'date_month'); } $seconds -= $months * 2629743; } $weeks = floor($seconds / 604800); if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0)) { if ($weeks > 0) { $str[] = $weeks.' '.$CI->lang->line($weeks > 1 ? 'date_weeks' : 'date_week'); } $seconds -= $weeks * 604800; } $days = floor($seconds / 86400); if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0)) { if ($days > 0) { $str[] = $days.' '.$CI->lang->line($days > 1 ? 'date_days' : 'date_day'); } $seconds -= $days * 86400; } $hours = floor($seconds / 3600); if (count($str) < $units && ($days > 0 OR $hours > 0)) { if ($hours > 0) { $str[] = $hours.' '.$CI->lang->line($hours > 1 ? 'date_hours' : 'date_hour'); } $seconds -= $hours * 3600; } $minutes = floor($seconds / 60); if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0)) { if ($minutes > 0) { $str[] = $minutes.' '.$CI->lang->line($minutes > 1 ? 'date_minutes' : 'date_minute'); } $seconds -= $minutes * 60; } if (count($str) === 0) { $str[] = $seconds.' '.$CI->lang->line($seconds > 1 ? 'date_seconds' : 'date_second'); } return implode(', ', $str); }
Timespan Returns a span of seconds in this format: 10 days 14 hours 36 minutes 47 seconds @param int a number of seconds @param int Unix timestamp @param int a number of display units @return string
timespan
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function local_to_gmt($time = '') { if ($time === '') { $time = time(); } return mktime( gmdate('G', $time), gmdate('i', $time), gmdate('s', $time), gmdate('n', $time), gmdate('j', $time), gmdate('Y', $time) ); }
Converts a local Unix timestamp to GMT @param int Unix timestamp @return int
local_to_gmt
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) { if ($time === '') { return now(); } $time += timezones($timezone) * 3600; return ($dst === TRUE) ? $time + 3600 : $time; }
Converts GMT time to a localized value Takes a Unix timestamp (in GMT) as input, and returns at the local value based on the timezone and DST setting submitted @param int Unix timestamp @param string timezone @param bool whether DST is active @return int
gmt_to_local
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function mysql_to_unix($time = '') { // We'll remove certain characters for backward compatibility // since the formatting changed with MySQL 4.1 // YYYY-MM-DD HH:MM:SS $time = str_replace(array('-', ':', ' '), '', $time); // YYYYMMDDHHMMSS return mktime( substr($time, 8, 2), substr($time, 10, 2), substr($time, 12, 2), substr($time, 4, 2), substr($time, 6, 2), substr($time, 0, 4) ); }
Converts a MySQL Timestamp to Unix @param int MySQL timestamp YYYY-MM-DD HH:MM:SS @return int Unix timstamp
mysql_to_unix
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; if ($fmt === 'us') { $r .= date('h', $time).':'.date('i', $time); } else { $r .= date('H', $time).':'.date('i', $time); } if ($seconds) { $r .= ':'.date('s', $time); } if ($fmt === 'us') { return $r.' '.date('A', $time); } return $r; }
Unix to "Human" Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM @param int Unix timestamp @param bool whether to show seconds @param string format: us or euro @return string
unix_to_human
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function human_to_unix($datestr = '') { if ($datestr === '') { return FALSE; } $datestr = preg_replace('/\040+/', ' ', trim($datestr)); if ( ! preg_match('/^(\d{2}|\d{4})\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) { return FALSE; } sscanf($datestr, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm); sscanf($time, '%d:%d:%d', $hour, $min, $sec); isset($sec) OR $sec = 0; if (isset($ampm)) { $ampm = strtolower($ampm); if ($ampm[0] === 'p' && $hour < 12) { $hour += 12; } elseif ($ampm[0] === 'a' && $hour === 12) { $hour = 0; } } return mktime($hour, $min, $sec, $month, $day, $year); }
Convert "human" date to GMT Reverses the above process @param string format: us or euro @return int
human_to_unix
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function timezones($tz = '') { // Note: Don't change the order of these even though // some items appear to be in the wrong order $zones = array( 'UM12' => -12, 'UM11' => -11, 'UM10' => -10, 'UM95' => -9.5, 'UM9' => -9, 'UM8' => -8, 'UM7' => -7, 'UM6' => -6, 'UM5' => -5, 'UM45' => -4.5, 'UM4' => -4, 'UM35' => -3.5, 'UM3' => -3, 'UM2' => -2, 'UM1' => -1, 'UTC' => 0, 'UP1' => +1, 'UP2' => +2, 'UP3' => +3, 'UP35' => +3.5, 'UP4' => +4, 'UP45' => +4.5, 'UP5' => +5, 'UP55' => +5.5, 'UP575' => +5.75, 'UP6' => +6, 'UP65' => +6.5, 'UP7' => +7, 'UP8' => +8, 'UP875' => +8.75, 'UP9' => +9, 'UP95' => +9.5, 'UP10' => +10, 'UP105' => +10.5, 'UP11' => +11, 'UP115' => +11.5, 'UP12' => +12, 'UP1275' => +12.75, 'UP13' => +13, 'UP14' => +14 ); if ($tz === '') { return $zones; } return isset($zones[$tz]) ? $zones[$tz] : 0; }
Timezones Returns an array of timezones. This is a helper function for various other ones in this library @param string timezone @return string
timezones
php
ronknight/InventorySystem
system/helpers/date_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/date_helper.php
MIT
function heading($data = '', $h = '1', $attributes = '') { return '<h'.$h._stringify_attributes($attributes).'>'.$data.'</h'.$h.'>'; }
Heading Generates an HTML heading tag. @param string content @param int heading level @param string @return string
heading
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function ul($list, $attributes = '') { return _list('ul', $list, $attributes); }
Unordered List Generates an HTML unordered list from an single or multi-dimensional array. @param array @param mixed @return string
ul
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function ol($list, $attributes = '') { return _list('ol', $list, $attributes); }
Ordered List Generates an HTML ordered list from an single or multi-dimensional array. @param array @param mixed @return string
ol
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function img($src = '', $index_page = FALSE, $attributes = '') { if ( ! is_array($src) ) { $src = array('src' => $src); } // If there is no alt attribute defined, set it to an empty string if ( ! isset($src['alt'])) { $src['alt'] = ''; } $img = '<img'; foreach ($src as $k => $v) { if ($k === 'src' && ! preg_match('#^(data:[a-z,;])|(([a-z]+:)?(?<!data:)//)#i', $v)) { if ($index_page === TRUE) { $img .= ' src="'.get_instance()->config->site_url($v).'"'; } else { $img .= ' src="'.get_instance()->config->slash_item('base_url').$v.'"'; } } else { $img .= ' '.$k.'="'.$v.'"'; } } return $img._stringify_attributes($attributes).' />'; }
Image Generates an <img /> element @param mixed @param bool @param mixed @return string
img
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function doctype($type = 'xhtml1-strict') { static $doctypes; if ( ! is_array($doctypes)) { if (file_exists(APPPATH.'config/doctypes.php')) { include(APPPATH.'config/doctypes.php'); } if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } if (empty($_doctypes) OR ! is_array($_doctypes)) { $doctypes = array(); return FALSE; } $doctypes = $_doctypes; } return isset($doctypes[$type]) ? $doctypes[$type] : FALSE; }
Doctype Generates a page document type declaration Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame, html4-strict, html4-trans, and html4-frame. All values are saved in the doctypes config file. @param string type The doctype to be generated @return string
doctype
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function br($count = 1) { return str_repeat('<br />', $count); }
Generates HTML BR tags based on number supplied @deprecated 3.0.0 Use str_repeat() instead @param int $count Number of times to repeat the tag @return string
br
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function nbs($num = 1) { return str_repeat('&nbsp;', $num); }
Generates non-breaking space entities based on number supplied @deprecated 3.0.0 Use str_repeat() instead @param int @return string
nbs
php
ronknight/InventorySystem
system/helpers/html_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/html_helper.php
MIT
function character_limiter($str, $n = 500, $end_char = '&#8230;') { if (mb_strlen($str) < $n) { return $str; } // a bit complicated, but faster than preg_replace with \s+ $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\v", "\f"), ' ', $str)); if (mb_strlen($str) <= $n) { return $str; } $out = ''; foreach (explode(' ', trim($str)) as $val) { $out .= $val.' '; if (mb_strlen($out) >= $n) { $out = trim($out); return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char; } } }
Character Limiter Limits the string based on the character count. Preserves complete words so the character count may not be exactly as specified. @param string @param int @param string the end character. Usually an ellipsis @return string
character_limiter
php
ronknight/InventorySystem
system/helpers/text_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/text_helper.php
MIT
function smiley_js($alias = '', $field_id = '', $inline = TRUE) { static $do_setup = TRUE; $r = ''; if ($alias !== '' && ! is_array($alias)) { $alias = array($alias => $field_id); } if ($do_setup === TRUE) { $do_setup = FALSE; $m = array(); if (is_array($alias)) { foreach ($alias as $name => $id) { $m[] = '"'.$name.'" : "'.$id.'"'; } } $m = '{'.implode(',', $m).'}'; $r .= <<<EOF var smiley_map = {$m}; function insert_smiley(smiley, field_id) { var el = document.getElementById(field_id), newStart; if ( ! el && smiley_map[field_id]) { el = document.getElementById(smiley_map[field_id]); if ( ! el) return false; } el.focus(); smiley = " " + smiley; if ('selectionStart' in el) { newStart = el.selectionStart + smiley.length; el.value = el.value.substr(0, el.selectionStart) + smiley + el.value.substr(el.selectionEnd, el.value.length); el.setSelectionRange(newStart, newStart); } else if (document.selection) { document.selection.createRange().text = smiley; } } EOF; } elseif (is_array($alias)) { foreach ($alias as $name => $id) { $r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n"; } } return ($inline) ? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>' : $r; }
Smiley Javascript Returns the javascript required for the smiley insertion. Optionally takes an array of aliases to loosely couple the smiley array to the view. @param mixed alias name or array of alias->field_id pairs @param string field_id if alias name was passed in @param bool @return array
smiley_js
php
ronknight/InventorySystem
system/helpers/smiley_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/smiley_helper.php
MIT
function get_clickable_smileys($image_url, $alias = '') { // For backward compatibility with js_insert_smiley if (is_array($alias)) { $smileys = $alias; } elseif (FALSE === ($smileys = _get_smiley_array())) { return FALSE; } // Add a trailing slash to the file path if needed $image_url = rtrim($image_url, '/').'/'; $used = array(); foreach ($smileys as $key => $val) { // Keep duplicates from being used, which can happen if the // mapping array contains multiple identical replacements. For example: // :-) and :) might be replaced with the same image so both smileys // will be in the array. if (isset($used[$smileys[$key][0]])) { continue; } $link[] = '<a href="javascript:void(0);" onclick="insert_smiley(\''.$key.'\', \''.$alias.'\')"><img src="'.$image_url.$smileys[$key][0].'" alt="'.$smileys[$key][3].'" style="width: '.$smileys[$key][1].'; height: '.$smileys[$key][2].'; border: 0;" /></a>'; $used[$smileys[$key][0]] = TRUE; } return $link; }
Get Clickable Smileys Returns an array of image tag links that can be clicked to be inserted into a form field. @param string the URL to the folder containing the smiley images @param array @return array
get_clickable_smileys
php
ronknight/InventorySystem
system/helpers/smiley_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/smiley_helper.php
MIT
function _get_smiley_array() { static $_smileys; if ( ! is_array($_smileys)) { if (file_exists(APPPATH.'config/smileys.php')) { include(APPPATH.'config/smileys.php'); } if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); } if (empty($smileys) OR ! is_array($smileys)) { $_smileys = array(); return FALSE; } $_smileys = $smileys; } return $_smileys; }
Get Smiley Array Fetches the config/smiley.php file @return mixed
_get_smiley_array
php
ronknight/InventorySystem
system/helpers/smiley_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/smiley_helper.php
MIT
function singular($str) { $result = strval($str); if ( ! is_countable($result)) { return $result; } $singular_rules = array( '/(matr)ices$/' => '\1ix', '/(vert|ind)ices$/' => '\1ex', '/^(ox)en/' => '\1', '/(alias)es$/' => '\1', '/([octop|vir])i$/' => '\1us', '/(cris|ax|test)es$/' => '\1is', '/(shoe)s$/' => '\1', '/(o)es$/' => '\1', '/(bus|campus)es$/' => '\1', '/([m|l])ice$/' => '\1ouse', '/(x|ch|ss|sh)es$/' => '\1', '/(m)ovies$/' => '\1\2ovie', '/(s)eries$/' => '\1\2eries', '/([^aeiouy]|qu)ies$/' => '\1y', '/([lr])ves$/' => '\1f', '/(tive)s$/' => '\1', '/(hive)s$/' => '\1', '/([^f])ves$/' => '\1fe', '/(^analy)ses$/' => '\1sis', '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis', '/([ti])a$/' => '\1um', '/(p)eople$/' => '\1\2erson', '/(m)en$/' => '\1an', '/(s)tatuses$/' => '\1\2tatus', '/(c)hildren$/' => '\1\2hild', '/(n)ews$/' => '\1\2ews', '/(quiz)zes$/' => '\1', '/([^us])s$/' => '\1' ); foreach ($singular_rules as $rule => $replacement) { if (preg_match($rule, $result)) { $result = preg_replace($rule, $replacement, $result); break; } } return $result; }
Singular Takes a plural word and makes it singular @param string $str Input string @return string
singular
php
ronknight/InventorySystem
system/helpers/inflector_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/inflector_helper.php
MIT
function plural($str) { $result = strval($str); if ( ! is_countable($result)) { return $result; } $plural_rules = array( '/(quiz)$/' => '\1zes', // quizzes '/^(ox)$/' => '\1\2en', // ox '/([m|l])ouse$/' => '\1ice', // mouse, louse '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency '/(hive)$/' => '\1s', // archive, hive '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife '/sis$/' => 'ses', // basis, diagnosis '/([ti])um$/' => '\1a', // datum, medium '/(p)erson$/' => '\1eople', // person, salesperson '/(m)an$/' => '\1en', // man, woman, spokesman '/(c)hild$/' => '\1hildren', // child '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato '/(bu|campu)s$/' => '\1\2ses', // bus, campus '/(alias|status|virus)$/' => '\1es', // alias '/(octop)us$/' => '\1i', // octopus '/(ax|cris|test)is$/' => '\1es', // axis, crisis '/s$/' => 's', // no change (compatibility) '/$/' => 's', ); foreach ($plural_rules as $rule => $replacement) { if (preg_match($rule, $result)) { $result = preg_replace($rule, $replacement, $result); break; } } return $result; }
Plural Takes a singular word and makes it plural @param string $str Input string @return string
plural
php
ronknight/InventorySystem
system/helpers/inflector_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/inflector_helper.php
MIT
function camelize($str) { return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1); }
Camelize Takes multiple words separated by spaces or underscores and camelizes them @param string $str Input string @return string
camelize
php
ronknight/InventorySystem
system/helpers/inflector_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/inflector_helper.php
MIT
function underscore($str) { return preg_replace('/[\s]+/', '_', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str))); }
Underscore Takes multiple words separated by spaces and underscores them @param string $str Input string @return string
underscore
php
ronknight/InventorySystem
system/helpers/inflector_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/inflector_helper.php
MIT
function humanize($str, $separator = '_') { return ucwords(preg_replace('/['.preg_quote($separator).']+/', ' ', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str)))); }
Humanize Takes multiple words separated by the separator and changes them to spaces @param string $str Input string @param string $separator Input separator @return string
humanize
php
ronknight/InventorySystem
system/helpers/inflector_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/inflector_helper.php
MIT
function is_countable($word) { return ! in_array( strtolower($word), array( 'audio', 'bison', 'chassis', 'compensation', 'coreopsis', 'data', 'deer', 'education', 'emoji', 'equipment', 'fish', 'furniture', 'gold', 'information', 'knowledge', 'love', 'rain', 'money', 'moose', 'nutrition', 'offspring', 'plankton', 'pokemon', 'police', 'rice', 'series', 'sheep', 'species', 'swine', 'traffic', 'wheat' ) ); }
Checks if the given word has a plural version. @param string $word Word to check @return bool
is_countable
php
ronknight/InventorySystem
system/helpers/inflector_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/inflector_helper.php
MIT
function form_password($data = '', $value = '', $extra = '') { is_array($data) OR $data = array('name' => $data); $data['type'] = 'password'; return form_input($data, $value, $extra); }
Password Field Identical to the input function but adds the "password" type @param mixed @param string @param mixed @return string
form_password
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function form_prep($str) { return html_escape($str, TRUE); }
Form Prep Formats text so that it can be safely placed in a form field in the event it has HTML tags. @deprecated 3.0.0 An alias for html_escape() @param string|string[] $str Value to escape @return string|string[] Escaped values
form_prep
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function set_value($field, $default = '', $html_escape = TRUE) { $CI =& get_instance(); $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) ? $CI->form_validation->set_value($field, $default) : $CI->input->post($field, FALSE); isset($value) OR $value = $default; return ($html_escape) ? html_escape($value) : $value; }
Form Value Grabs a value from the POST array for the specified field so you can re-populate an input field or textarea. If Form Validation is active it retrieves the info from the validation class @param string $field Field name @param string $default Default value @param bool $html_escape Whether to escape HTML special characters or not @return string
set_value
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function set_checkbox($field, $value = '', $default = FALSE) { $CI =& get_instance(); if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) { return $CI->form_validation->set_checkbox($field, $value, $default); } // Form inputs are always strings ... $value = (string) $value; $input = $CI->input->post($field, FALSE); if (is_array($input)) { // Note: in_array('', array(0)) returns TRUE, do not use it foreach ($input as &$v) { if ($value === $v) { return ' checked="checked"'; } } return ''; } // Unchecked checkbox and radio inputs are not even submitted by browsers ... if ($CI->input->method() === 'post') { return ($input === $value) ? ' checked="checked"' : ''; } return ($default === TRUE) ? ' checked="checked"' : ''; }
Set Checkbox Let's you set the selected value of a checkbox via the value in the POST array. If Form Validation is active it retrieves the info from the validation class @param string @param string @param bool @return string
set_checkbox
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function set_radio($field, $value = '', $default = FALSE) { $CI =& get_instance(); if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) { return $CI->form_validation->set_radio($field, $value, $default); } // Form inputs are always strings ... $value = (string) $value; $input = $CI->input->post($field, FALSE); if (is_array($input)) { // Note: in_array('', array(0)) returns TRUE, do not use it foreach ($input as &$v) { if ($value === $v) { return ' checked="checked"'; } } return ''; } // Unchecked checkbox and radio inputs are not even submitted by browsers ... if ($CI->input->method() === 'post') { return ($input === $value) ? ' checked="checked"' : ''; } return ($default === TRUE) ? ' checked="checked"' : ''; }
Set Radio Let's you set the selected value of a radio field via info in the POST array. If Form Validation is active it retrieves the info from the validation class @param string $field @param string $value @param bool $default @return string
set_radio
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function form_error($field = '', $prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) { return ''; } return $OBJ->error($field, $prefix, $suffix); }
Form Error Returns the error for a specific form field. This is a helper for the form validation class. @param string @param string @param string @return string
form_error
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function validation_errors($prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) { return ''; } return $OBJ->error_string($prefix, $suffix); }
Validation Error String Returns all the errors associated with a form submission. This is a helper function for the form validation class. @param string @param string @return string
validation_errors
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function _attributes_to_string($attributes) { if (empty($attributes)) { return ''; } if (is_object($attributes)) { $attributes = (array) $attributes; } if (is_array($attributes)) { $atts = ''; foreach ($attributes as $key => $val) { $atts .= ' '.$key.'="'.$val.'"'; } return $atts; } if (is_string($attributes)) { return ' '.$attributes; } return FALSE; }
Attributes To String Helper function used by some of the form helpers @param mixed @return string
_attributes_to_string
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function &_get_validation_object() { $CI =& get_instance(); // We set this as a variable since we're returning by reference. $return = FALSE; if (FALSE !== ($object = $CI->load->is_loaded('Form_validation'))) { if ( ! isset($CI->$object) OR ! is_object($CI->$object)) { return $return; } return $CI->$object; } return $return; }
Validation Object Determines what the form validation class was instantiated as, fetches the object and returns it. @return mixed
_get_validation_object
php
ronknight/InventorySystem
system/helpers/form_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/form_helper.php
MIT
function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; // Replace entities to temporary markers so that // ampersands won't get messed up $str = preg_replace('/&#(\d+);/', $temp.'\\1;', $str); if ($protect_all === TRUE) { $str = preg_replace('/&(\w+);/', $temp.'\\1;', $str); } $str = str_replace( array('&', '<', '>', '"', "'", '-'), array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'), $str ); // Decode the temp markers back to entities $str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str); if ($protect_all === TRUE) { return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str); } return $str; }
Convert Reserved XML characters to Entities @param string @param bool @return string
xml_convert
php
ronknight/InventorySystem
system/helpers/xml_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/xml_helper.php
MIT
function element($item, array $array, $default = NULL) { return array_key_exists($item, $array) ? $array[$item] : $default; }
Element Lets you determine whether an array index is set and whether it has a value. If the element is empty it returns NULL (or whatever you specify as the default value.) @param string @param array @param mixed @return mixed depends on what the array contains
element
php
ronknight/InventorySystem
system/helpers/array_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/array_helper.php
MIT
function random_element($array) { return is_array($array) ? $array[array_rand($array)] : $array; }
Random Element - Takes an array as input and returns a random element @param array @return mixed depends on what the array contains
random_element
php
ronknight/InventorySystem
system/helpers/array_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/array_helper.php
MIT
function trim_slashes($str) { return trim($str, '/'); }
Trim Slashes Removes any leading/trailing slashes from a string: /this/that/theother/ becomes: this/that/theother @todo Remove in version 3.1+. @deprecated 3.0.0 This is just an alias for PHP's native trim() @param string @return string
trim_slashes
php
ronknight/InventorySystem
system/helpers/string_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/string_helper.php
MIT
function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); }
Strip Quotes Removes single and double quotes from a string @param string @return string
strip_quotes
php
ronknight/InventorySystem
system/helpers/string_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/string_helper.php
MIT
function quotes_to_entities($str) { return str_replace(array("\'","\"","'",'"'), array("&#39;","&quot;","&#39;","&quot;"), $str); }
Quotes to Entities Converts single and double quotes to entities @param string @return string
quotes_to_entities
php
ronknight/InventorySystem
system/helpers/string_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/string_helper.php
MIT
function reduce_double_slashes($str) { return preg_replace('#(^|[^:])//+#', '\\1/', $str); }
Reduce Double Slashes Converts double slashes in a string to a single slash, except those found in http:// http://www.some-site.com//index.php becomes: http://www.some-site.com/index.php @param string @return string
reduce_double_slashes
php
ronknight/InventorySystem
system/helpers/string_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/string_helper.php
MIT
function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); return ($trim === TRUE) ? trim($str, $character) : $str; }
Reduce Multiples Reduces multiple instances of a particular character. Example: Fred, Bill,, Joe, Jimmy becomes: Fred, Bill, Joe, Jimmy @param string @param string the character you wish to reduce @param bool TRUE/FALSE - whether to trim the character from the beginning/end @return string
reduce_multiples
php
ronknight/InventorySystem
system/helpers/string_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/string_helper.php
MIT
function alternator() { static $i; if (func_num_args() === 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; }
Alternator Allows strings to be alternated. See docs... @param string (as many parameters as needed) @return string
alternator
php
ronknight/InventorySystem
system/helpers/string_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/string_helper.php
MIT
function read_file($file) { return @file_get_contents($file); }
Read File Opens the file specified in the path and returns it as a string. @todo Remove in version 3.1+. @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents(). @param string $file Path to file @return string File contents
read_file
php
ronknight/InventorySystem
system/helpers/file_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/file_helper.php
MIT
function write_file($path, $data, $mode = 'wb') { if ( ! $fp = @fopen($path, $mode)) { return FALSE; } flock($fp, LOCK_EX); for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) { if (($result = fwrite($fp, substr($data, $written))) === FALSE) { break; } } flock($fp, LOCK_UN); fclose($fp); return is_int($result); }
Write File Writes data to the file specified in the path. Creates a new file if non-existent. @param string $path File path @param string $data Data to write @param string $mode fopen() mode (default: 'wb') @return bool
write_file
php
ronknight/InventorySystem
system/helpers/file_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/file_helper.php
MIT
function get_mime_by_extension($filename) { static $mimes; if ( ! is_array($mimes)) { $mimes = get_mimes(); if (empty($mimes)) { return FALSE; } } $extension = strtolower(substr(strrchr($filename, '.'), 1)); if (isset($mimes[$extension])) { return is_array($mimes[$extension]) ? current($mimes[$extension]) // Multiple mime types, just give the first one : $mimes[$extension]; } return FALSE; }
Get Mime by Extension Translates a file extension into a mime type based on config/mimes.php. Returns FALSE if it can't determine the type, or open the mime config file Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience It should NOT be trusted, and should certainly NOT be used for security @param string $filename File name @return string
get_mime_by_extension
php
ronknight/InventorySystem
system/helpers/file_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/file_helper.php
MIT
function octal_permissions($perms) { return substr(sprintf('%o', $perms), -3); }
Octal Permissions Takes a numeric value representing a file's permissions and returns a three character string representing the file's octal permissions @param int $perms Permissions @return string
octal_permissions
php
ronknight/InventorySystem
system/helpers/file_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/file_helper.php
MIT
function site_url($uri = '', $protocol = NULL) { return get_instance()->config->site_url($uri, $protocol); }
Site URL Create a local URL based on your basepath. Segments can be passed via the first parameter either as a string or an array. @param string $uri @param string $protocol @return string
site_url
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function base_url($uri = '', $protocol = NULL) { return get_instance()->config->base_url($uri, $protocol); }
Base URL Create a local URL based on your basepath. Segments can be passed in as a string or an array, same as site_url or a URL to a file can be passed in, e.g. to an image file. @param string $uri @param string $protocol @return string
base_url
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function current_url() { $CI =& get_instance(); return $CI->config->site_url($CI->uri->uri_string()); }
Current URL Returns the full URL (including segments) of the page where this function is placed @return string
current_url
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function uri_string() { return get_instance()->uri->uri_string(); }
URL String Returns the URI segments. @return string
uri_string
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function index_page() { return get_instance()->config->item('index_page'); }
Index page Returns the "index_page" from your config file @return string
index_page
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; $site_url = is_array($uri) ? site_url($uri) : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri)); if ($title === '') { $title = $site_url; } if ($attributes !== '') { $attributes = _stringify_attributes($attributes); } return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>'; }
Anchor Link Creates an anchor based on the local URL. @param string the URL @param string the link title @param mixed any attributes @return string
anchor
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function safe_mailto($email, $title = '', $attributes = '') { $title = (string) $title; if ($title === '') { $title = $email; } $x = str_split('<a href="mailto:', 1); for ($i = 0, $l = strlen($email); $i < $l; $i++) { $x[] = '|'.ord($email[$i]); } $x[] = '"'; if ($attributes !== '') { if (is_array($attributes)) { foreach ($attributes as $key => $val) { $x[] = ' '.$key.'="'; for ($i = 0, $l = strlen($val); $i < $l; $i++) { $x[] = '|'.ord($val[$i]); } $x[] = '"'; } } else { for ($i = 0, $l = strlen($attributes); $i < $l; $i++) { $x[] = $attributes[$i]; } } } $x[] = '>'; $temp = array(); for ($i = 0, $l = strlen($title); $i < $l; $i++) { $ordinal = ord($title[$i]); if ($ordinal < 128) { $x[] = '|'.$ordinal; } 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); $x[] = '|'.$number; $count = 1; $temp = array(); } } } $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; $x = array_reverse($x); $output = "<script type=\"text/javascript\">\n" ."\t//<![CDATA[\n" ."\tvar l=new Array();\n"; for ($i = 0, $c = count($x); $i < $c; $i++) { $output .= "\tl[".$i."] = '".$x[$i]."';\n"; } $output .= "\n\tfor (var i = l.length-1; i >= 0; i=i-1) {\n" ."\t\tif (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");\n" ."\t\telse document.write(unescape(l[i]));\n" ."\t}\n" ."\t//]]>\n" .'</script>'; return $output; }
Encoded Mailto Link Create a spam-protected mailto link written in Javascript @param string the email address @param string the link title @param mixed any attributes @return string
safe_mailto
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function prep_url($str = '') { if ($str === 'http://' OR $str === '') { return ''; } $url = parse_url($str); if ( ! $url OR ! isset($url['scheme'])) { return 'http://'.$str; } return $str; }
Prep URL Simply adds the http:// part if no scheme is included @param string the URL @return string
prep_url
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function redirect($uri = '', $method = 'auto', $code = NULL) { if ( ! preg_match('#^(\w+:)?//#i', $uri)) { $uri = site_url($uri); } // IIS environment likely? Use 'refresh' for better compatibility if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) { $method = 'refresh'; } elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) { if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') { $code = ($_SERVER['REQUEST_METHOD'] !== 'GET') ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get : 307; } else { $code = 302; } } switch ($method) { case 'refresh': header('Refresh:0;url='.$uri); break; default: header('Location: '.$uri, TRUE, $code); break; } exit; }
Header Redirect Header redirect in two flavors For very fine grained control over headers, you could use the Output Library's set_header() function. @param string $uri URL @param string $method Redirect method 'auto', 'location' or 'refresh' @param int $code HTTP Response status code @return void
redirect
php
ronknight/InventorySystem
system/helpers/url_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/url_helper.php
MIT
function nl2br_except_pre($str) { $CI =& get_instance(); $CI->load->library('typography'); return $CI->typography->nl2br_except_pre($str); }
Convert newlines to HTML line breaks except within PRE tags @param string @return string
nl2br_except_pre
php
ronknight/InventorySystem
system/helpers/typography_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/typography_helper.php
MIT
function auto_typography($str, $reduce_linebreaks = FALSE) { $CI =& get_instance(); $CI->load->library('typography'); return $CI->typography->auto_typography($str, $reduce_linebreaks); }
Auto Typography Wrapper Function @param string $str @param bool $reduce_linebreaks = FALSE whether to reduce multiple instances of double newlines to two @return string
auto_typography
php
ronknight/InventorySystem
system/helpers/typography_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/typography_helper.php
MIT
function entity_decode($str, $charset = NULL) { return get_instance()->security->entity_decode($str, $charset); }
HTML Entities Decode This function is a replacement for html_entity_decode() @param string @param string @return string
entity_decode
php
ronknight/InventorySystem
system/helpers/typography_helper.php
https://github.com/ronknight/InventorySystem/blob/master/system/helpers/typography_helper.php
MIT
public function __construct() { $this->_ci_ob_level = ob_get_level(); $this->_ci_classes =& is_loaded(); log_message('info', 'Loader Class Initialized'); }
Class constructor Sets component load paths, gets the initial output buffering level. @return void
__construct
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function initialize() { $this->_ci_autoloader(); }
Initializer @todo Figure out a way to move this to the constructor without breaking *package_path*() methods. @uses CI_Loader::_ci_autoloader() @used-by CI_Controller::__construct() @return void
initialize
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function is_loaded($class) { return array_search(ucfirst($class), $this->_ci_classes, TRUE); }
Is Loaded A utility method to test if a class is in the self::$_ci_classes array. @used-by Mainly used by Form Helper function _get_validation_object(). @param string $class Class name to check for @return string|bool Class object name if loaded or FALSE
is_loaded
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function library($library, $params = NULL, $object_name = NULL) { if (empty($library)) { return $this; } elseif (is_array($library)) { foreach ($library as $key => $value) { if (is_int($key)) { $this->library($value, $params); } else { $this->library($key, $params, $value); } } return $this; } if ($params !== NULL && ! is_array($params)) { $params = NULL; } $this->_ci_load_library($library, $params, $object_name); return $this; }
Library Loader Loads and instantiates libraries. Designed to be called from application controllers. @param mixed $library Library name @param array $params Optional parameters to pass to the library class constructor @param string $object_name An optional object name to assign to @return object
library
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function database($params = '', $return = FALSE, $query_builder = NULL) { // Grab the super object $CI =& get_instance(); // Do we even need to load the database class? if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id)) { return FALSE; } require_once(BASEPATH.'database/DB.php'); if ($return === TRUE) { return DB($params, $query_builder); } // Initialize the db variable. Needed to prevent // reference errors with some configurations $CI->db = ''; // Load the DB class $CI->db =& DB($params, $query_builder); return $this; }
Database Loader @param mixed $params Database configuration options @param bool $return Whether to return the database object @param bool $query_builder Whether to enable Query Builder (overrides the configuration setting) @return object|bool Database object if $return is set to TRUE, FALSE on failure, CI_Loader instance in any other case
database
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function dbutil($db = NULL, $return = FALSE) { $CI =& get_instance(); if ( ! is_object($db) OR ! ($db instanceof CI_DB)) { class_exists('CI_DB', FALSE) OR $this->database(); $db =& $CI->db; } require_once(BASEPATH.'database/DB_utility.php'); require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php'); $class = 'CI_DB_'.$db->dbdriver.'_utility'; if ($return === TRUE) { return new $class($db); } $CI->dbutil = new $class($db); return $this; }
Load the Database Utilities Class @param object $db Database object @param bool $return Whether to return the DB Utilities class object or not @return object
dbutil
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function vars($vars, $val = '') { $vars = is_string($vars) ? array($vars => $val) : $this->_ci_prepare_view_vars($vars); foreach ($vars as $key => $val) { $this->_ci_cached_vars[$key] = $val; } return $this; }
Set Variables Once variables are set they become available within the controller class and its "view" files. @param array|object|string $vars An associative array or object containing values to be set, or a value's name if string @param string $val Value to set, only used if $vars is a string @return object
vars
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function clear_vars() { $this->_ci_cached_vars = array(); return $this; }
Clear Cached Variables Clears the cached variables. @return CI_Loader
clear_vars
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function get_var($key) { return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; }
Get Variable Check if a variable is set and retrieve it. @param string $key Variable name @return mixed The variable or NULL if not found
get_var
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function get_vars() { return $this->_ci_cached_vars; }
Get Variables Retrieves all loaded variables. @return array
get_vars
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function language($files, $lang = '') { get_instance()->lang->load($files, $lang); return $this; }
Language Loader Loads language files. @param string|string[] $files List of language file names to load @param string Language name @return object
language
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE) { return get_instance()->config->load($file, $use_sections, $fail_gracefully); }
Config Loader Loads a config file (an alias for CI_Config::load()). @uses CI_Config::load() @param string $file Configuration file name @param bool $use_sections Whether configuration values should be loaded into their own section @param bool $fail_gracefully Whether to just return FALSE or display an error message @return bool TRUE if the file was loaded correctly or FALSE on failure
config
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function driver($library, $params = NULL, $object_name = NULL) { if (is_array($library)) { foreach ($library as $key => $value) { if (is_int($key)) { $this->driver($value, $params); } else { $this->driver($key, $params, $value); } } return $this; } elseif (empty($library)) { return FALSE; } if ( ! class_exists('CI_Driver_Library', FALSE)) { // We aren't instantiating an object here, just making the base class available require BASEPATH.'libraries/Driver.php'; } // We can save the loader some time since Drivers will *always* be in a subfolder, // and typically identically named to the library if ( ! strpos($library, '/')) { $library = ucfirst($library).'/'.$library; } return $this->library($library, $params, $object_name); }
Driver Loader Loads a driver library. @param string|string[] $library Driver name(s) @param array $params Optional parameters to pass to the driver @param string $object_name An optional object name to assign to @return object|bool Object or FALSE on failure if $library is a string and $object_name is set. CI_Loader instance otherwise.
driver
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function add_package_path($path, $view_cascade = TRUE) { $path = rtrim($path, '/').'/'; array_unshift($this->_ci_library_paths, $path); array_unshift($this->_ci_model_paths, $path); array_unshift($this->_ci_helper_paths, $path); $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; // Add config file path $config =& $this->_ci_get_component('config'); $config->_config_paths[] = $path; return $this; }
Add Package Path Prepends a parent path to the library, model, helper and config path arrays. @see CI_Loader::$_ci_library_paths @see CI_Loader::$_ci_model_paths @see CI_Loader::$_ci_helper_paths @see CI_Config::$_config_paths @param string $path Path to add @param bool $view_cascade (default: TRUE) @return object
add_package_path
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT
public function get_package_paths($include_base = FALSE) { return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths; }
Get Package Paths Return a list of all package paths. @param bool $include_base Whether to include BASEPATH (default: FALSE) @return array
get_package_paths
php
ronknight/InventorySystem
system/core/Loader.php
https://github.com/ronknight/InventorySystem/blob/master/system/core/Loader.php
MIT