Index: branches/5.1.x/core/units/images/image_tag_processor.php =================================================================== diff -u -N -r12657 -r13086 --- branches/5.1.x/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 12657) +++ branches/5.1.x/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 13086) @@ -1,6 +1,6 @@ Fields['ThumbPath']) && !$image_id ) { $object->SetDefaultValues(); - $object->SetDBField('Url', $parent_item->GetDBField('FullUrl')); - $object->SetDBField('AltName', $this->getItemTitle($parent_item)); - $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath')); - $object->Loaded = true; + if (is_null($parent_item->GetDBField('SameImages'))) { + // JOIN definetly failed, because it's not-null column + $object->Loaded = false; + } + else { + $object->SetDBField('Url', $parent_item->GetDBField('FullUrl')); + $object->SetDBField('AltName', $this->getItemTitle($parent_item)); + + $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath')); + $object->Loaded = true; + } + } else { // if requested image is not primary thumbnail - load it directly $id_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey'); @@ -140,7 +148,7 @@ // when image is uploaded to virtual field in main item, but not saved to db $object->SetDBField('ThumbPath', $image_src); - if (!$object->isLoaded()) { + if (!$object->isLoaded() && $image_src) { // set fields for displaing new image during main item suggestion with errors $fields_hash = Array ( 'Url' => '', @@ -221,34 +229,12 @@ if ($max_width > 0 || $max_height > 0 || $format) { $src_image = FULL_PATH.$object->GetDBField('ThumbPath'); + list ($max_width, $max_height) = $this->_transformParams($params, $max_width, $max_height); + if ($object->isLoaded() && file_exists($src_image)) { $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ - $resize_format = 'resize:' . $max_width . 'x' . $max_height; - - $crop = $this->SelectParam($params, 'Crop,crop'); - if ($crop) { - if (strpos($crop, ';') === false) { - $crop = 'c|c'; - } - - $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';crop:' . $crop; - $max_height = null; - } - - $fill = $this->SelectParam($params, 'Fill,fill'); - if ($fill) { - $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';fill:' . $fill; - $max_height = null; - } - - $watermark = $this->SelectParam($params, 'Watermark,watermark'); - if ($watermark) { - $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';wm:' . $watermark; - $max_height = null; - } - return $image_helper->ResizeImage($src_image, $max_width, $max_height); } elseif ($use_default_image) { @@ -283,11 +269,48 @@ } } - // return Default Image or false if NOT specified + // return Default Image or false if NOT specified (only for case, when SameImages = 0) return $this->_getDefaultImage($params); } /** + * Transforms Image/ImageSrc aggregated tag parameters into ones, that ResizeImage method understands + * + * @param Array $params + * @param int $max_width + * @param int $max_height + * @return Array + */ + function _transformParams($params, $max_width = false, $max_height = false) + { + $resize_format = 'resize:' . $max_width . 'x' . $max_height; + + $crop = $this->SelectParam($params, 'Crop,crop'); + if ($crop) { + if (strpos($crop, ';') === false) { + $crop = 'c|c'; + } + + $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';crop:' . $crop; + $max_height = null; + } + + $fill = $this->SelectParam($params, 'Fill,fill'); + if ($fill) { + $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';fill:' . $fill; + $max_height = null; + } + + $watermark = $this->SelectParam($params, 'Watermark,watermark'); + if ($watermark) { + $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';wm:' . $watermark; + $max_height = null; + } + + return Array ($max_width, $max_height); + } + + /** * Returns default full url to default images * * @param Array $params @@ -304,9 +327,9 @@ // show default image, use different base urls for admin and front-end $base_url = rtrim($this->Application->BaseURL(), '/'); - $sub_folder = $this->Application->IsAdmin() ? rtrim(IMAGES_PATH, '/') : THEMES_PATH; + $sub_folder = $this->Application->isAdmin ? rtrim(IMAGES_PATH, '/') : THEMES_PATH; - if ($max_width > 0 || $max_height > 0) { + if (($max_width !== false) || ($max_height !== false)) { $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */