Skip to content

Commit

Permalink
check for array index before using it it install_conf, replace pear e…
Browse files Browse the repository at this point in the history
…rrors with exceptions in image class
  • Loading branch information
ahilles107 committed Mar 31, 2015
1 parent 8fefff5 commit c5a7a73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
26 changes: 12 additions & 14 deletions newscoop/classes/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions newscoop/conf/install_conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit c5a7a73

Please sign in to comment.