From c839d28f4230dce0c658338f267b821cc16490a2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 7 Jun 2012 14:35:27 +0300 Subject: Remove some unnecessary function_exists() checks and some minor improvements --- system/core/Output.php | 2 +- system/helpers/path_helper.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Unit_test.php | 16 ++++++---------- system/libraries/Upload.php | 20 +++++++------------- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/system/core/Output.php b/system/core/Output.php index 0bf982289..5588ffe8e 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -370,7 +370,7 @@ class CI_Output { if ($this->parse_exec_vars === TRUE) { - $memory = function_exists('memory_get_usage') ? round(memory_get_usage()/1024/1024, 2).'MB' : '0'; + $memory = round(memory_get_usage() / 1024 / 1024, 2).'MB'; $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); } diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 13410545c..fec4a1a10 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -55,7 +55,7 @@ if ( ! function_exists('set_realpath')) } // Resolve the path - if (function_exists('realpath') && @realpath($path) !== FALSE) + if (@realpath($path) !== FALSE) { $path = realpath($path); } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index aaac0c518..d96088c14 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -402,7 +402,7 @@ class CI_Profiler { ."\n" .'  '.$this->CI->lang->line('profiler_memory_usage')."  \n" .'
' - .((function_exists('memory_get_usage') && ($usage = memory_get_usage()) !== '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) + .(($usage = memory_get_usage()) != '' ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) .'
'; } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index a87cf7e14..70ad8dc41 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -124,7 +124,7 @@ class CI_Unit_test { $this->results[] = $report; - return($this->report($this->result($report))); + return $this->report($this->result($report)); } // -------------------------------------------------------------------- @@ -289,15 +289,11 @@ class CI_Unit_test { */ protected function _backtrace() { - if (function_exists('debug_backtrace')) - { - $back = debug_backtrace(); - return array( - 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''), - 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '') - ); - } - return array('file' => 'Unknown', 'line' => 'Unknown'); + $back = debug_backtrace(); + return array( + 'file' => (isset($back[1]['file']) ? $back[1]['file'] : ''), + 'line' => (isset($back[1]['line']) ? $back[1]['line'] : '') + ); } // -------------------------------------------------------------------- diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c1e07de7a..1f6aeeb6b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -694,7 +694,7 @@ class CI_Upload { return FALSE; } - if (function_exists('realpath') && @realpath($this->upload_path) !== FALSE) + if (@realpath($this->upload_path) !== FALSE) { $this->upload_path = str_replace('\\', '/', realpath($this->upload_path)); } @@ -815,17 +815,17 @@ class CI_Upload { return FALSE; } - if (function_exists('memory_get_usage') && memory_get_usage() && ini_get('memory_limit')) + if (memory_get_usage() && ($memory_limit = ini_get('memory_limit'))) { - $current = ini_get('memory_limit') * 1024 * 1024; + $memory_limit *= 1024 * 1024; // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output // into scientific notation. number_format() ensures this number is an integer // http://bugs.php.net/bug.php?id=43053 - $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', ''); + $memory_limit = number_format(ceil(filesize($file) + $memory_limit), 0, '.', ''); - ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net + ini_set('memory_limit', $memory_limit); // When an integer is used, the value is measured in bytes. - PHP.net } // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but @@ -849,14 +849,8 @@ class CI_Upload { // ]/i', $opening_bytes)) - { - return TRUE; // its an image, no "triggers" detected in the first 256 bytes, we're good - } - else - { - return FALSE; - } + // if its an image or no "triggers" detected in the first 256 bytes - we're good + return ! preg_match('/<(a|body|head|html|img|plaintext|pre|script|table|title)[\s>]/i', $opening_bytes); } if (($data = @file_get_contents($file)) === FALSE) -- cgit v1.2.3-24-g4f1b