summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/captcha_helper.php6
-rw-r--r--system/helpers/download_helper.php2
-rw-r--r--system/helpers/form_helper.php9
-rw-r--r--system/helpers/html_helper.php20
-rw-r--r--system/helpers/smiley_helper.php28
-rw-r--r--system/helpers/text_helper.php22
-rw-r--r--system/helpers/url_helper.php19
7 files changed, 65 insertions, 41 deletions
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php
index 83783324b..78e255a15 100644
--- a/system/helpers/captcha_helper.php
+++ b/system/helpers/captcha_helper.php
@@ -93,7 +93,7 @@ if ( ! function_exists('create_captcha'))
// Do we have a "word" yet?
// -----------------------------------
- if ($word === '')
+ if (empty($word))
{
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$word = '';
@@ -102,6 +102,10 @@ if ( ! function_exists('create_captcha'))
$word .= $pool[mt_rand(0, $mt_rand_max)];
}
}
+ elseif ( ! is_string($word))
+ {
+ $word = (string) $word;
+ }
// -----------------------------------
// Determine angle and position
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index d7691cb61..daf59f51b 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -58,7 +58,7 @@ if ( ! function_exists('force_download'))
}
elseif ($data === NULL)
{
- if (@is_file($filename) && @file_exists($filename) && ($filesize = @filesize($filename)) !== FALSE)
+ if (@is_file($filename) && ($filesize = @filesize($filename)) !== FALSE)
{
$filepath = $filename;
$filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename));
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index f343b6c71..692909c79 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -228,13 +228,10 @@ if ( ! function_exists('form_upload'))
*/
function form_upload($data = '', $value = '', $extra = '')
{
- if ( ! is_array($data))
- {
- $data = array('name' => $data);
- }
-
+ $defaults = array('type' => 'file', 'name' => '');
+ is_array($data) OR $data = array('name' => $data);
$data['type'] = 'file';
- return form_input($data, $value, $extra);
+ return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
}
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 2d474169b..80a27876f 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -238,26 +238,30 @@ if ( ! function_exists('doctype'))
*/
function doctype($type = 'xhtml1-strict')
{
- global $_doctypes;
+ static $doctypes;
- if ( ! is_array($_doctypes))
+ if ( ! is_array($doctypes))
{
- if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
+ if (file_exists(APPPATH.'config/doctypes.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
+ include(APPPATH.'config/doctypes.php');
}
- elseif (is_file(APPPATH.'config/doctypes.php'))
+
+ if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
{
- include(APPPATH.'config/doctypes.php');
+ include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
}
- if ( ! is_array($_doctypes))
+ if (empty($_doctypes) OR ! is_array($_doctypes))
{
+ $doctypes = array();
return FALSE;
}
+
+ $doctypes = $_doctypes;
}
- return isset($_doctypes[$type]) ? $_doctypes[$type] : FALSE;
+ return isset($doctypes[$type]) ? $doctypes[$type] : FALSE;
}
}
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 186b24ce9..d9a693493 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -213,16 +213,30 @@ if ( ! function_exists('_get_smiley_array'))
*/
function _get_smiley_array()
{
- if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
- {
- include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
- }
- elseif (file_exists(APPPATH.'config/smileys.php'))
+ static $_smileys;
+
+ if ( ! is_array($smileys))
{
- include(APPPATH.'config/smileys.php');
+ 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 (isset($smileys) && is_array($smileys)) ? $smileys : FALSE;
+ return $_smileys;
}
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 1c7eeaf5f..54db14f94 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -358,31 +358,35 @@ if ( ! function_exists('convert_accented_characters'))
/**
* Convert Accented Foreign Characters to ASCII
*
- * @param string the text string
+ * @param string $str Input string
* @return string
*/
function convert_accented_characters($str)
{
- global $foreign_characters;
+ static $_foreign_characters;
- if ( ! isset($foreign_characters) OR ! is_array($foreign_characters))
+ if ( ! is_array($_foreign_characters))
{
- if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
+ if (file_exists(APPPATH.'config/foreign_chars.php'))
{
- include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
+ include(APPPATH.'config/foreign_chars.php');
}
- elseif (is_file(APPPATH.'config/foreign_chars.php'))
+
+ if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
{
- include(APPPATH.'config/foreign_chars.php');
+ include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
}
- if ( ! isset($foreign_characters) OR ! is_array($foreign_characters))
+ if (empty($foreign_characters) OR ! is_array($foreign_characters))
{
+ $_foreign_characters = array();
return $str;
}
+
+ $_foreign_characters = $foreign_characters;
}
- return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str);
+ return preg_replace(array_keys($_foreign_characters), array_values($_foreign_characters), $str);
}
}
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 9a0153542..d6bf7e2c9 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -384,22 +384,23 @@ if ( ! function_exists('auto_link'))
function auto_link($str, $type = 'both', $popup = FALSE)
{
// Find and replace any URLs.
- if ($type !== 'email' && preg_match_all('#\b(([\w-]+://?|www\.)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#', $str, $matches, PREG_OFFSET_CAPTURE))
+ if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[^\s()<>;]+\w#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER))
{
// Set our target HTML if using popup links.
- $target = ($popup) ? 'target="_blank"' : '';
+ $target = ($popup) ? ' target="_blank"' : '';
// We process the links in reverse order (last -> first) so that
// the returned string offsets from preg_match_all() are not
// moved as we add more HTML.
- foreach (array_reverse($matches[0]) as $match)
+ foreach (array_reverse($matches) as $match)
{
- // $match is an array generated by the PREG_OFFSET_CAPTURE flag.
- // $match[0] is the matched string, $match[1] is the string offset.
-
- $anchor = anchor($match[0], '', $target);
-
- $str = substr_replace($str, $anchor, $match[1], strlen($match[0]));
+ // $match[0] is the matched string/link
+ // $match[1] is either a protocol prefix or 'www.'
+ //
+ // With PREG_OFFSET_CAPTURE, both of the above is an array,
+ // where the actual value is held in [0] and its offset at the [1] index.
+ $a = '<a href="'.(strpos($match[1][0], '/') ? '' : 'http://').$match[0][0].'"'.$target.'>'.$match[0][0].'</a>';
+ $str = substr_replace($str, $a, $match[0][1], strlen($match[0][0]));
}
}