summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-02-26 17:31:02 +0100
committerAndrey Andreev <narf@devilix.net>2014-02-26 17:31:02 +0100
commitea41c8aa1951216b6a9ccc99832d69d2b41c5ead (patch)
tree57b8b39c7325217795e172cafb71e5f7e63fc563 /system
parent4247ed1c0fb588f968f18fd80a5f95debefc63f6 (diff)
Don't use error suppression on realpath() + style adjustments
Diffstat (limited to 'system')
-rw-r--r--system/helpers/file_helper.php34
-rw-r--r--system/helpers/form_helper.php59
-rw-r--r--system/helpers/html_helper.php40
-rw-r--r--system/helpers/path_helper.php2
-rw-r--r--system/helpers/smiley_helper.php4
-rw-r--r--system/helpers/text_helper.php57
-rw-r--r--system/helpers/url_helper.php21
-rw-r--r--system/helpers/xml_helper.php8
-rw-r--r--system/libraries/Image_lib.php4
-rw-r--r--system/libraries/Upload.php2
10 files changed, 124 insertions, 107 deletions
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index b8b70534f..8cfe0f1c1 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -137,14 +137,12 @@ if ( ! function_exists('delete_files'))
}
}
}
- @closedir($current_dir);
- if ($del_dir === TRUE && $_level > 0)
- {
- return @rmdir($path);
- }
+ closedir($current_dir);
- return TRUE;
+ return ($del_dir === TRUE && $_level > 0)
+ ? @rmdir($path)
+ : TRUE;
}
}
@@ -178,7 +176,7 @@ if ( ! function_exists('get_filenames'))
while (FALSE !== ($file = readdir($fp)))
{
- if (@is_dir($source_dir.$file) && $file[0] !== '.')
+ if (is_dir($source_dir.$file) && $file[0] !== '.')
{
get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
}
@@ -187,8 +185,8 @@ if ( ! function_exists('get_filenames'))
$_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file;
}
}
- closedir($fp);
+ closedir($fp);
return $_filedata;
}
@@ -230,7 +228,7 @@ if ( ! function_exists('get_dir_file_info'))
// foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast
while (FALSE !== ($file = readdir($fp)))
{
- if (@is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
+ if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
{
get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
}
@@ -240,8 +238,8 @@ if ( ! function_exists('get_dir_file_info'))
$_filedata[$file]['relative_path'] = $relative_path;
}
}
- closedir($fp);
+ closedir($fp);
return $_filedata;
}
@@ -330,8 +328,6 @@ if ( ! function_exists('get_mime_by_extension'))
*/
function get_mime_by_extension($filename)
{
- $extension = strtolower(substr(strrchr($filename, '.'), 1));
-
static $mimes;
if ( ! is_array($mimes))
@@ -344,6 +340,8 @@ if ( ! function_exists('get_mime_by_extension'))
}
}
+ $extension = strtolower(substr(strrchr($filename, '.'), 1));
+
if (isset($mimes[$extension]))
{
return is_array($mimes[$extension])
@@ -405,18 +403,18 @@ if ( ! function_exists('symbolic_permissions'))
// Owner
$symbolic .= (($perms & 0x0100) ? 'r' : '-')
- . (($perms & 0x0080) ? 'w' : '-')
- . (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
+ .(($perms & 0x0080) ? 'w' : '-')
+ .(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
// Group
$symbolic .= (($perms & 0x0020) ? 'r' : '-')
- . (($perms & 0x0010) ? 'w' : '-')
- . (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
+ .(($perms & 0x0010) ? 'w' : '-')
+ .(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
// World
$symbolic .= (($perms & 0x0004) ? 'r' : '-')
- . (($perms & 0x0002) ? 'w' : '-')
- . (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
+ .(($perms & 0x0002) ? 'w' : '-')
+ .(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
return $symbolic;
}
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index a724406f0..2592890cd 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -54,15 +54,15 @@ if ( ! function_exists('form_open'))
{
$CI =& get_instance();
- // If an action is not a full URL then turn it into one
- if ($action && strpos($action, '://') === FALSE)
+ // If no action is provided then set to the current url
+ if ( ! $action)
{
- $action = $CI->config->site_url($action);
+ $action = $CI->config->site_url($CI->uri->uri_string());
}
- elseif ( ! $action)
+ // If an action is not a full URL then turn it into one
+ elseif (strpos($action, '://') === FALSE)
{
- // If no action is provided then set to the current url
- $action = $CI->config->site_url($CI->uri->uri_string());
+ $action = $CI->config->site_url($action);
}
$attributes = _attributes_to_string($attributes);
@@ -80,7 +80,7 @@ if ( ! function_exists('form_open'))
$form = '<form action="'.$action.'"'.$attributes.">\n";
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
- if ($CI->config->item('csrf_protection') === TRUE && ! (strpos($action, $CI->config->base_url()) === FALSE OR stripos($form, 'method="get"')))
+ if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"'))
{
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
@@ -153,6 +153,7 @@ if ( ! function_exists('form_hidden'))
{
form_hidden($key, $val, TRUE);
}
+
return $form;
}
@@ -187,7 +188,11 @@ if ( ! function_exists('form_input'))
*/
function form_input($data = '', $value = '', $extra = '')
{
- $defaults = array('type' => 'text', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
+ $defaults = array(
+ 'type' => 'text',
+ 'name' => is_array($data) ? '' : $data,
+ 'value' => $value
+ );
return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
@@ -209,11 +214,7 @@ if ( ! function_exists('form_password'))
*/
function form_password($data = '', $value = '', $extra = '')
{
- if ( ! is_array($data))
- {
- $data = array('name' => $data);
- }
-
+ is_array($data) OR $data = array('name' => $data);
$data['type'] = 'password';
return form_input($data, $value, $extra);
}
@@ -256,7 +257,11 @@ if ( ! function_exists('form_textarea'))
*/
function form_textarea($data = '', $value = '', $extra = '')
{
- $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'cols' => '40', 'rows' => '10');
+ $defaults = array(
+ 'name' => is_array($data) ? '' : $data,
+ 'cols' => '40',
+ 'rows' => '10'
+ );
if ( ! is_array($data) OR ! isset($data['value']))
{
@@ -434,11 +439,7 @@ if ( ! function_exists('form_radio'))
*/
function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
{
- if ( ! is_array($data))
- {
- $data = array('name' => $data);
- }
-
+ is_array($data) OR $data = array('name' => $data);
$data['type'] = 'radio';
return form_checkbox($data, $value, $checked, $extra);
}
@@ -458,7 +459,12 @@ if ( ! function_exists('form_submit'))
*/
function form_submit($data = '', $value = '', $extra = '')
{
- $defaults = array('type' => 'submit', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
+ $defaults = array(
+ 'type' => 'submit',
+ 'name' => is_array($data) ? '' : $data,
+ 'value' => $value
+ );
+
return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
}
@@ -477,7 +483,12 @@ if ( ! function_exists('form_reset'))
*/
function form_reset($data = '', $value = '', $extra = '')
{
- $defaults = array('type' => 'reset', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
+ $defaults = array(
+ 'type' => 'reset',
+ 'name' => is_array($data) ? '' : $data,
+ 'value' => $value
+ );
+
return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
}
@@ -496,7 +507,11 @@ if ( ! function_exists('form_button'))
*/
function form_button($data = '', $content = '', $extra = '')
{
- $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'type' => 'button');
+ $defaults = array(
+ 'name' => is_array($data) ? '' : $data,
+ 'type' => 'button'
+ );
+
if (is_array($data) && isset($data['content']))
{
$content = $data['content'];
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 604d1144a..8246cbd2b 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -118,10 +118,10 @@ if ( ! function_exists('_list'))
}
// Set the indentation based on the depth
- $out = str_repeat(' ', $depth);
+ $out = str_repeat(' ', $depth)
+ // Write the opening list tag
+ .'<'.$type._stringify_attributes($attributes).">\n";
- // Write the opening list tag
- $out .= '<'.$type._stringify_attributes($attributes).">\n";
// Cycle through the list elements. If an array is
// encountered we will recursively call _list()
@@ -152,22 +152,6 @@ if ( ! function_exists('_list'))
// ------------------------------------------------------------------------
-if ( ! function_exists('br'))
-{
- /**
- * Generates HTML BR tags based on number supplied
- *
- * @param int $count Number of times to repeat the tag
- * @return string
- */
- function br($count = 1)
- {
- return str_repeat('<br />', $count);
- }
-}
-
-// ------------------------------------------------------------------------
-
if ( ! function_exists('img'))
{
/**
@@ -368,7 +352,7 @@ if ( ! function_exists('meta'))
$str = '';
foreach ($name as $meta)
{
- $type = ( ! isset($meta['type']) OR $meta['type'] === 'name') ? 'name' : 'http-equiv';
+ $type = (isset($meta['type']) && $meta['type'] !== 'name') ? 'http-equiv' : 'name';
$name = isset($meta['name']) ? $meta['name'] : '';
$content = isset($meta['content']) ? $meta['content'] : '';
$newline = isset($meta['newline']) ? $meta['newline'] : "\n";
@@ -382,6 +366,22 @@ if ( ! function_exists('meta'))
// ------------------------------------------------------------------------
+if ( ! function_exists('br'))
+{
+ /**
+ * Generates HTML BR tags based on number supplied
+ *
+ * @param int $count Number of times to repeat the tag
+ * @return string
+ */
+ function br($count = 1)
+ {
+ return str_repeat('<br />', $count);
+ }
+}
+
+// ------------------------------------------------------------------------
+
if ( ! function_exists('nbs'))
{
/**
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index ae1f0bf33..15e7968b9 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -56,7 +56,7 @@ if ( ! function_exists('set_realpath'))
}
// Resolve the path
- if (@realpath($path) !== FALSE)
+ if (realpath($path) !== FALSE)
{
$path = realpath($path);
}
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 57debffa9..f67890c5b 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -114,7 +114,9 @@ EOF;
}
}
- return ($inline) ? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>' : $r;
+ return ($inline)
+ ? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'
+ : $r;
}
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 76e1735b5..af14dfea2 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -157,8 +157,8 @@ if ( ! function_exists('ascii_to_entities'))
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);
+ ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
+ : (($temp[0] % 32) * 64) + ($temp[1] % 64);
$out .= '&#'.$number.';';
$count = 1;
@@ -220,9 +220,11 @@ if ( ! function_exists('entities_to_ascii'))
if ($all)
{
- return str_replace(array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'),
- array('&', '<', '>', '"', "'", '-'),
- $str);
+ return str_replace(
+ array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'),
+ array('&', '<', '>', '"', "'", '-'),
+ $str
+ );
}
return $str;
@@ -297,31 +299,37 @@ if ( ! function_exists('highlight_code'))
* so they don't accidentally break the string out of PHP,
* and thus, thwart the highlighting.
*/
- $str = str_replace(array('&lt;', '&gt;', '<?', '?>', '<%', '%>', '\\', '</script>'),
- array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
- $str);
+ $str = str_replace(
+ array('&lt;', '&gt;', '<?', '?>', '<%', '%>', '\\', '</script>'),
+ array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ $str
+ );
// The highlight_string function requires that the text be surrounded
// by PHP tags, which we will remove later
$str = highlight_string('<?php '.$str.' ?>', TRUE);
// Remove our artificially added PHP, and the syntax highlighting that came with it
- $str = preg_replace(array(
- '/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i',
- '/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is',
- '/<span style="color: #[A-Z0-9]+"\><\/span>/i'
- ),
- array(
- '<span style="color: #$1">',
- "$1</span>\n</span>\n</code>",
- ''
- ),
- $str);
+ $str = preg_replace(
+ array(
+ '/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i',
+ '/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is',
+ '/<span style="color: #[A-Z0-9]+"\><\/span>/i'
+ ),
+ array(
+ '<span style="color: #$1">',
+ "$1</span>\n</span>\n</code>",
+ ''
+ ),
+ $str
+ );
// Replace our markers back to PHP tags.
- return str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
- array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'),
- $str);
+ return str_replace(
+ array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'),
+ $str
+ );
}
}
@@ -408,10 +416,7 @@ if ( ! function_exists('word_wrap'))
function word_wrap($str, $charlim = 76)
{
// Set the character limit
- if ( ! is_numeric($charlim))
- {
- $charlim = 76;
- }
+ is_numeric($charlim) OR $charlim = 76;
// Reduce multiple spaces
$str = preg_replace('| +|', ' ', $str);
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 5f11a42ca..dff1a86d2 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -148,14 +148,9 @@ if ( ! function_exists('anchor'))
{
$title = (string) $title;
- if ( ! is_array($uri))
- {
- $site_url = preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri);
- }
- else
- {
- $site_url = site_url($uri);
- }
+ $site_url = is_array($uri)
+ ? site_url($uri)
+ : preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri);
if ($title === '')
{
@@ -481,11 +476,11 @@ if ( ! function_exists('url_title'))
$q_separator = preg_quote($separator, '#');
$trans = array(
- '&.+?;' => '',
- '[^a-z0-9 _-]' => '',
- '\s+' => $separator,
- '('.$q_separator.')+' => $separator
- );
+ '&.+?;' => '',
+ '[^a-z0-9 _-]' => '',
+ '\s+' => $separator,
+ '('.$q_separator.')+' => $separator
+ );
$str = strip_tags($str);
foreach ($trans as $key => $val)
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 4c38b6988..5c1414b70 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -60,9 +60,11 @@ if ( ! function_exists('xml_convert'))
$str = preg_replace('/&(\w+);/', $temp.'\\1;', $str);
}
- $str = str_replace(array('&', '<', '>', '"', "'", '-'),
- array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'),
- $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);
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index db45a80fc..ac3db416d 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -493,9 +493,9 @@ class CI_Image_lib {
* Either way, we'll try use realpath to generate the
* full server path in order to more reliably read it.
*/
- if (function_exists('realpath') && @realpath($this->source_image) !== FALSE)
+ if (($full_source_path = realpath($this->source_image)) !== FALSE)
{
- $full_source_path = str_replace('\\', '/', realpath($this->source_image));
+ $full_source_path = str_replace('\\', '/', $full_source_path);
}
else
{
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 583a97693..62cfb28c0 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -967,7 +967,7 @@ class CI_Upload {
return FALSE;
}
- if (@realpath($this->upload_path) !== FALSE)
+ if (realpath($this->upload_path) !== FALSE)
{
$this->upload_path = str_replace('\\', '/', realpath($this->upload_path));
}