From 4eea9895e8ced75a1099c56215c09773de94b92c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Dec 2011 12:05:41 +0200 Subject: Add method visibility declarations and optimize display_errors() method in Image_lib, Trackback and Upload libraries --- system/libraries/Image_lib.php | 58 +++++++++++++++++++----------------------- system/libraries/Trackback.php | 42 +++++++++++++----------------- system/libraries/Upload.php | 10 ++------ 3 files changed, 46 insertions(+), 64 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 2ed488c7e..c4797e34a 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -114,7 +114,7 @@ class CI_Image_lib { * @access public * @return void */ - function clear() + public function clear() { $props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); @@ -158,7 +158,7 @@ class CI_Image_lib { * @param array * @return bool */ - function initialize($props = array()) + public function initialize($props = array()) { /* * Convert array elements into class variables @@ -379,7 +379,7 @@ class CI_Image_lib { * @access public * @return bool */ - function resize() + public function resize() { $protocol = 'image_process_'.$this->image_library; @@ -402,7 +402,7 @@ class CI_Image_lib { * @access public * @return bool */ - function crop() + public function crop() { $protocol = 'image_process_'.$this->image_library; @@ -425,7 +425,7 @@ class CI_Image_lib { * @access public * @return bool */ - function rotate() + public function rotate() { // Allowed rotation values $degs = array(90, 180, 270, 'vrt', 'hor'); @@ -478,7 +478,7 @@ class CI_Image_lib { * @param string * @return bool */ - function image_process_gd($action = 'resize') + public function image_process_gd($action = 'resize') { $v2_override = FALSE; @@ -590,7 +590,7 @@ class CI_Image_lib { * @param string * @return bool */ - function image_process_imagemagick($action = 'resize') + public function image_process_imagemagick($action = 'resize') { // Do we have a vaild library path? if ($this->library_path == '') @@ -660,7 +660,7 @@ class CI_Image_lib { * @param string * @return bool */ - function image_process_netpbm($action = 'resize') + public function image_process_netpbm($action = 'resize') { if ($this->library_path == '') { @@ -743,7 +743,7 @@ class CI_Image_lib { * @access public * @return bool */ - function image_rotate_gd() + public function image_rotate_gd() { // Create the image handle if ( ! ($src_img = $this->image_create_gd())) @@ -796,7 +796,7 @@ class CI_Image_lib { * @access public * @return bool */ - function image_mirror_gd() + public function image_mirror_gd() { if ( ! $src_img = $this->image_create_gd()) { @@ -882,7 +882,7 @@ class CI_Image_lib { * @param string * @return bool */ - function watermark() + public function watermark() { if ($this->wm_type == 'overlay') { @@ -902,7 +902,7 @@ class CI_Image_lib { * @access public * @return bool */ - function overlay_watermark() + public function overlay_watermark() { if ( ! function_exists('imagecolortransparent')) { @@ -1015,7 +1015,7 @@ class CI_Image_lib { * @access public * @return bool */ - function text_watermark() + public function text_watermark() { if ( ! ($src_img = $this->image_create_gd())) { @@ -1159,7 +1159,7 @@ class CI_Image_lib { * @param string * @return resource */ - function image_create_gd($path = '', $image_type = '') + public function image_create_gd($path = '', $image_type = '') { if ($path == '') $path = $this->full_src_path; @@ -1216,7 +1216,7 @@ class CI_Image_lib { * @param resource * @return bool */ - function image_save_gd($resource) + public function image_save_gd($resource) { switch ($this->image_type) { @@ -1277,7 +1277,7 @@ class CI_Image_lib { * @param resource * @return void */ - function image_display_gd($resource) + public function image_display_gd($resource) { header("Content-Disposition: filename={$this->source_image};"); header("Content-Type: {$this->mime_type}"); @@ -1312,7 +1312,7 @@ class CI_Image_lib { * @access public * @return void */ - function image_reproportion() + public function image_reproportion() { if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) return; @@ -1354,7 +1354,7 @@ class CI_Image_lib { * @param string * @return mixed */ - function get_image_properties($path = '', $return = FALSE) + public function get_image_properties($path = '', $return = FALSE) { // For now we require GD but we should // find a way to determine this using IM or NetPBM @@ -1414,7 +1414,7 @@ class CI_Image_lib { * @param array * @return array */ - function size_calculator($vals) + public function size_calculator($vals) { if ( ! is_array($vals)) { @@ -1462,7 +1462,7 @@ class CI_Image_lib { * @param array * @return array */ - function explode_name($source_image) + public function explode_name($source_image) { $ext = strrchr($source_image, '.'); $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext)); @@ -1478,7 +1478,7 @@ class CI_Image_lib { * @access public * @return bool */ - function gd_loaded() + public function gd_loaded() { if ( ! extension_loaded('gd')) { @@ -1499,7 +1499,7 @@ class CI_Image_lib { * @access public * @return mixed */ - function gd_version() + public function gd_version() { if (function_exists('gd_info')) { @@ -1521,7 +1521,7 @@ class CI_Image_lib { * @param string * @return void */ - function set_error($msg) + public function set_error($msg) { $CI =& get_instance(); $CI->lang->load('imglib'); @@ -1553,19 +1553,13 @@ class CI_Image_lib { * @param string * @return string */ - function display_errors($open = '

', $close = '

') + public function display_errors($open = '

', $close = '

') { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; + return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; } } // END Image_lib Class /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file +/* Location: ./system/libraries/Image_lib.php */ diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index e903ea7d0..3fa55ca20 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -5,9 +5,9 @@ * An open source application development framework for PHP 5.1.6 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -66,7 +66,7 @@ class CI_Trackback { * @param array * @return bool */ - function send($tb_data) + public function send($tb_data) { if ( ! is_array($tb_data)) { @@ -147,7 +147,7 @@ class CI_Trackback { * @access public * @return bool */ - function receive() + public function receive() { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { @@ -190,7 +190,7 @@ class CI_Trackback { * @param string * @return void */ - function send_error($message = 'Incomplete Information') + public function send_error($message = 'Incomplete Information') { echo "\n\n1\n".$message."\n"; exit; @@ -207,7 +207,7 @@ class CI_Trackback { * @access public * @return void */ - function send_success() + public function send_success() { echo "\n\n0\n"; exit; @@ -222,7 +222,7 @@ class CI_Trackback { * @param string * @return string */ - function data($item) + public function data($item) { return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; } @@ -240,7 +240,7 @@ class CI_Trackback { * @param string * @return bool */ - function process($url, $data) + public function process($url, $data) { $target = parse_url($url); @@ -309,7 +309,7 @@ class CI_Trackback { * @param string * @return string */ - function extract_urls($urls) + public function extract_urls($urls) { // Remove the pesky white space and replace with a comma. $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls); @@ -345,7 +345,7 @@ class CI_Trackback { * @param string * @return string */ - function validate_url($url) + public function validate_url($url) { $url = trim($url); @@ -364,7 +364,7 @@ class CI_Trackback { * @param string * @return string */ - function get_id($url) + public function get_id($url) { $tb_id = ""; @@ -413,7 +413,7 @@ class CI_Trackback { * @param string * @return string */ - function convert_xml($str) + public function convert_xml($str) { $temp = '__TEMP_AMPERSANDS__'; @@ -443,7 +443,7 @@ class CI_Trackback { * @param string * @return string */ - function limit_characters($str, $n = 500, $end_char = '…') + public function limit_characters($str, $n = 500, $end_char = '…') { if (strlen($str) < $n) { @@ -480,7 +480,7 @@ class CI_Trackback { * @param string * @return string */ - function convert_ascii($str) + public function convert_ascii($str) { $count = 1; $out = ''; @@ -526,7 +526,7 @@ class CI_Trackback { * @param string * @return void */ - function set_error($msg) + public function set_error($msg) { log_message('error', $msg); $this->error_msg[] = $msg; @@ -542,19 +542,13 @@ class CI_Trackback { * @param string * @return string */ - function display_errors($open = '

', $close = '

') + public function display_errors($open = '

', $close = '

') { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; + return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; } } // END Trackback Class /* End of file Trackback.php */ -/* Location: ./system/libraries/Trackback.php */ \ No newline at end of file +/* Location: ./system/libraries/Trackback.php */ diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 66e91c5b6..ab97d1a0f 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -934,13 +934,7 @@ class CI_Upload { */ public function display_errors($open = '

', $close = '

') { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; + return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; } // -------------------------------------------------------------------- @@ -1086,4 +1080,4 @@ class CI_Upload { // END Upload Class /* End of file Upload.php */ -/* Location: ./system/libraries/Upload.php */ \ No newline at end of file +/* Location: ./system/libraries/Upload.php */ -- cgit v1.2.3-24-g4f1b