Skip to content

Commit

Permalink
Merge pull request #1300 from timw4mail/patch
Browse files Browse the repository at this point in the history
Fix rest of the helpers
  • Loading branch information
narfbg committed May 17, 2012
2 parents ae31eb5 + 98fde46 commit e30b3f7
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 516 deletions.
98 changes: 50 additions & 48 deletions system/helpers/inflector_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@

// --------------------------------------------------------------------

/**
* Singular
*
* Takes a plural word and makes it singular
*
* @param string
* @return str
*/
if ( ! function_exists('singular'))
{
/**
* Singular
*
* Takes a plural word and makes it singular
*
* @param string
* @return string
*/
function singular($str)
{
$result = strval($str);
Expand Down Expand Up @@ -101,17 +101,17 @@ function singular($str)

// --------------------------------------------------------------------

/**
* Plural
*
* Takes a singular word and makes it plural
*
* @param string
* @param bool
* @return str
*/
if ( ! function_exists('plural'))
{
/**
* Plural
*
* Takes a singular word and makes it plural
*
* @param string
* @param bool
* @return string
*/
function plural($str, $force = FALSE)
{
$result = strval($str);
Expand Down Expand Up @@ -158,16 +158,16 @@ function plural($str, $force = FALSE)

// --------------------------------------------------------------------

/**
* Camelize
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
* @param string
* @return str
*/
if ( ! function_exists('camelize'))
{
/**
* Camelize
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
* @param string
* @return string
*/
function camelize($str)
{
return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
Expand All @@ -176,16 +176,16 @@ function camelize($str)

// --------------------------------------------------------------------

/**
* Underscore
*
* Takes multiple words separated by spaces and underscores them
*
* @param string
* @return str
*/
if ( ! function_exists('underscore'))
{
/**
* Underscore
*
* Takes multiple words separated by spaces and underscores them
*
* @param string
* @return string
*/
function underscore($str)
{
return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
Expand All @@ -194,31 +194,33 @@ function underscore($str)

// --------------------------------------------------------------------

/**
* Humanize
*
* Takes multiple words separated by the separator and changes them to spaces
*
* @param string $str
* @param string $separator
* @return string
*/
if ( ! function_exists('humanize'))
{
/**
* Humanize
*
* Takes multiple words separated by the separator and changes them to spaces
*
* @param string $str
* @param string $separator
* @return string
*/
function humanize($str, $separator = '_')
{
return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str))));
}
}

/**
* Checks if the given word has a plural version.
*
* @param string the word to check
* @return bool if the word is countable
*/
// --------------------------------------------------------------------

if ( ! function_exists('is_countable'))
{
/**
* Checks if the given word has a plural version.
*
* @param string the word to check
* @return bool if the word is countable
*/
function is_countable($word)
{
return ! in_array(strtolower(strval($word)),
Expand Down
18 changes: 9 additions & 9 deletions system/helpers/language_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@

// ------------------------------------------------------------------------

/**
* Lang
*
* Fetches a language variable and optionally outputs a form label
*
* @param string the language line
* @param string the id of the form element
* @return string
*/
if ( ! function_exists('lang'))
{
/**
* Lang
*
* Fetches a language variable and optionally outputs a form label
*
* @param string the language line
* @param string the id of the form element
* @return string
*/
function lang($line, $id = '')
{
$CI =& get_instance();
Expand Down
13 changes: 7 additions & 6 deletions system/helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@

// ------------------------------------------------------------------------

/**
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
*
* @param mixed // will be cast as int
* @return string
*/
if ( ! function_exists('byte_format'))
{
/**
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
*
* @param mixed will be cast as int
* @param int
* @return string
*/
function byte_format($num, $precision = 1)
{
$CI =& get_instance();
Expand Down
14 changes: 7 additions & 7 deletions system/helpers/path_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@

// ------------------------------------------------------------------------

/**
* Set Realpath
*
* @param string
* @param bool checks to see if the path exists
* @return string
*/
if ( ! function_exists('set_realpath'))
{
/**
* Set Realpath
*
* @param string
* @param bool checks to see if the path exists
* @return string
*/
function set_realpath($path, $check_existance = FALSE)
{
// Security check to make sure the path is NOT a URL. No remote file inclusion!
Expand Down
63 changes: 32 additions & 31 deletions system/helpers/security_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@

// ------------------------------------------------------------------------

/**
* XSS Filtering
*
* @param string
* @param bool whether or not the content is an image file
* @return string
*/
if ( ! function_exists('xss_clean'))
{
/**
* XSS Filtering
*
* @param string
* @param bool whether or not the content is an image file
* @return string
*/
function xss_clean($str, $is_image = FALSE)
{
$CI =& get_instance();
Expand All @@ -55,14 +55,14 @@ function xss_clean($str, $is_image = FALSE)

// ------------------------------------------------------------------------

/**
* Sanitize Filename
*
* @param string
* @return string
*/
if ( ! function_exists('sanitize_filename'))
{
/**
* Sanitize Filename
*
* @param string
* @return string
*/
function sanitize_filename($filename)
{
$CI =& get_instance();
Expand All @@ -72,14 +72,15 @@ function sanitize_filename($filename)

// --------------------------------------------------------------------

/**
* Hash encode a string
*
* @param string
* @return string
*/
if ( ! function_exists('do_hash'))
{
/**
* Hash encode a string
*
* @param string
* @param string
* @return string
*/
function do_hash($str, $type = 'sha1')
{
if ( ! in_array(strtolower($type), hash_algos()))
Expand All @@ -93,14 +94,14 @@ function do_hash($str, $type = 'sha1')

// ------------------------------------------------------------------------

/**
* Strip Image Tags
*
* @param string
* @return string
*/
if ( ! function_exists('strip_image_tags'))
{
/**
* Strip Image Tags
*
* @param string
* @return string
*/
function strip_image_tags($str)
{
return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str);
Expand All @@ -109,14 +110,14 @@ function strip_image_tags($str)

// ------------------------------------------------------------------------

/**
* Convert PHP tags to entities
*
* @param string
* @return string
*/
if ( ! function_exists('encode_php_tags'))
{
/**
* Convert PHP tags to entities
*
* @param string
* @return string
*/
function encode_php_tags($str)
{
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
Expand Down

0 comments on commit e30b3f7

Please sign in to comment.