From c5a7a7391c609855d0fb4c34422d4175bdf13ff3 Mon Sep 17 00:00:00 2001 From: Pawel Mikolajczuk Date: Tue, 31 Mar 2015 15:45:28 +0200 Subject: [PATCH] check for array index before using it it install_conf, replace pear errors with exceptions in image class --- newscoop/classes/Image.php | 26 ++++++++++++-------------- newscoop/conf/install_conf.php | 3 +-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/newscoop/classes/Image.php b/newscoop/classes/Image.php index eb98ede989..f68f3ebcc4 100644 --- a/newscoop/classes/Image.php +++ b/newscoop/classes/Image.php @@ -403,8 +403,7 @@ public function generateThumbnailFromImage() $createMethodName = Image::__GetImageTypeCreateMethod($imageInfo[2]); if (!isset($createMethodName)) { - throw new Exception($translator->trans("Image type $1 is not supported.", array( - '$1' => image_type_to_mime_type($p_imageType)), 'api')); + throw new Exception($translator->trans("Image type $1 is not supported.", array('$1' => image_type_to_mime_type($p_imageType)), 'api')); } $imageHandler = $createMethodName($target); @@ -690,38 +689,37 @@ public static function SaveImageToFile($p_image, $p_fileName, /** * Resizes the given image * - * @param resource $p_image + * @param resource $image * The image resource handler * @param int $p_maxWidth * The maximum width of the resized image * @param int $p_maxHeight * The maximum height of the resized image - * @param bool $p_keepRatio + * @param bool $keepRatio * If true keep the image ratio * @param int $type * Image type * @return int * Return the new image resource handler. */ - public static function ResizeImage($p_image, $p_maxWidth, $p_maxHeight, - $p_keepRatio = true, $type = IMAGETYPE_JPEG) + public static function ResizeImage($image, $p_maxWidth, $p_maxHeight, $keepRatio = true, $type = IMAGETYPE_JPEG) { - if (!isset($p_image) || empty($p_image)) { - return new PEAR_Error('The image resource handler is not available.'); + if (!isset($image) || empty($image)) { + throw new Exception('The image resource handler is not available.'); } - $origImageWidth = imagesx($p_image); - $origImageHeight = imagesy($p_image); + $origImageWidth = imagesx($image); + $origImageHeight = imagesy($image); if ($origImageWidth <= 0 || $origImageHeight <= 0) { - return new PEAR_Error("The file uploaded is not an image."); + throw new Exception("The file uploaded is not an image."); } $p_maxWidth = is_numeric($p_maxWidth) ? (int) $p_maxWidth : 0; $p_maxHeight = is_numeric($p_maxHeight) ? (int) $p_maxHeight : 0; if ($p_maxWidth <= 0 || $p_maxHeight <= 0) { - return new PEAR_Error("Invalid resize width/height."); + throw new Exception("Invalid resize width/height."); } - if ($p_keepRatio) { + if ($keepRatio) { $ratioOrig = $origImageWidth / $origImageHeight; $ratioNew = $p_maxWidth / $p_maxHeight; if ($ratioNew > $ratioOrig) { @@ -736,7 +734,7 @@ public static function ResizeImage($p_image, $p_maxWidth, $p_maxHeight, $newImageHeight = $p_maxHeight; } - $image = new \Imagine\Gd\Image($p_image); + $image = new \Imagine\Gd\Image($image); $image->resize(new Box($newImageWidth, $newImageHeight)); return $image; diff --git a/newscoop/conf/install_conf.php b/newscoop/conf/install_conf.php index 7dacde2c0c..8e285e3384 100644 --- a/newscoop/conf/install_conf.php +++ b/newscoop/conf/install_conf.php @@ -14,8 +14,7 @@ $Campsite['APACHE_USER'] = 'www-data'; $Campsite['APACHE_GROUP'] = 'www-data'; -$Campsite['CAMPSITE_DIR'] = (strlen($GLOBALS['g_campsiteDir']) > 0) - ? $GLOBALS['g_campsiteDir'] : dirname(dirname(__FILE__)); +$Campsite['CAMPSITE_DIR'] = (array_key_exists('g_campsiteDir', $GLOBALS)) ? $GLOBALS['g_campsiteDir'] : dirname(dirname(__FILE__)); $Campsite['ETC_DIR'] = $Campsite['CAMPSITE_DIR'].'/conf'; $Campsite['BIN_DIR'] = $Campsite['CAMPSITE_DIR'].'/bin'; $Campsite['WWW_DIR'] = $Campsite['CAMPSITE_DIR'];