Index: branches/RC/core/units/images/image_tag_processor.php =================================================================== diff -u -r11419 -r11421 --- branches/RC/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 11419) +++ branches/RC/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 11421) @@ -187,6 +187,9 @@ $object =& $this->getObject($params); $this->makeRelativePaths($object); + // show "noimage.gif" when requested image is missing OR was not uploaded + $use_default_image = !(defined('DBG_IMAGE_RECOVERY') && DBG_IMAGE_RECOVERY); + $base_url = rtrim($this->Application->BaseURL(), '/'); if ($object->GetDBField('SameImages') && $object->GetDBField('ThumbPath')) { // we can auto-resize image, when source image available & we use same image for thumbnail & full image in admin @@ -201,56 +204,77 @@ } if ($max_width > 0 || $max_height > 0 || $format) { - $image_helper =& $this->Application->recallObject('ImageHelper'); - /* @var $image_helper ImageHelper */ - $src_image = FULL_PATH.$object->GetDBField('ThumbPath'); - return file_exists($src_image)? $image_helper->ResizeImage($src_image, $max_width, $max_height) : $this->_getDefaultImage($params); + if (file_exists($src_image)) { + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ + + return $image_helper->ResizeImage($src_image, $max_width, $max_height); + } + elseif ($use_default_image) { + return $this->_getDefaultImage($params, $max_width, $max_height); + } + + return $base_url . $object->GetDBField('ThumbPath'); } } - $ret = ''; - // if we need thumbnail, or full image is same as thumbnail $show_thumbnail = $this->SelectParam($params, 'thumbnail,Thumbnail') || // old style (isset($params['MaxWidth']) && $params['MaxWidth'] == 'thumbnail') || // new style (isset($params['MaxHeight']) && $params['MaxHeight'] == 'thumbnail'); if ($show_thumbnail || $object->GetDBField('SameImages')) { // return local image or url - $ret = $object->GetDBField('LocalThumb') ? $base_url.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl'); - if ($object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.$object->GetDBField('ThumbPath')) && !constOn('DBG_IMAGE_RECOVERY')) { - // local thumbnail file is missing - $ret = ''; - } + $ret = $object->GetDBField('LocalThumb') ? $base_url . $object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl'); } else { // if we need full which is not the same as thumb - $ret = $object->GetDBField('LocalImage') ? $base_url.$object->GetDBField('LocalPath') : $object->GetDBField('Url'); - if ($object->GetDBField('LocalImage') && !file_exists(FULL_PATH.$object->GetDBField('LocalPath'))) { - // local full image file is missing - $ret = ''; - } + $ret = $object->GetDBField('LocalImage') ? $base_url . $object->GetDBField('LocalPath') : $object->GetDBField('Url'); } - if ($ret && $ret != $base_url/* && file_exists($ret)*/) { - // image name and it's not just folder name - return $ret; + if ($ret && ($ret != $base_url)) { + // convert full url to full path! + $dst_image = preg_replace('/^' . preg_quote($base_url, '/') . '/', FULL_PATH, $ret, 1); + $image_found = $dst_image != $ret ? file_exists($dst_image) : true; + + if ($image_found) { + // image isn't deleted OR is stored on remote location + return $ret; + } } // return Default Image or false if NOT specified return $this->_getDefaultImage($params); } - function _getDefaultImage($params) + /** + * Returns default full url to default images + * + * @param Array $params + * @param int $max_width + * @param int $max_height + * @return string + */ + function _getDefaultImage($params, $max_width = false, $max_height = false) { - if (!$default_image = $this->SelectParam($params, 'default_image,DefaultImage')) { - return false; + $default_image = $this->SelectParam($params, 'default_image,DefaultImage'); + if (!$default_image) { + return ''; } // 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; + if ($max_width > 0 || $max_height > 0) { + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ + + $src_image = FULL_PATH . $sub_folder . '/' . $default_image; + + return $image_helper->ResizeImage($src_image, $max_width, $max_height); + } + return $base_url . $sub_folder . '/' . $default_image; }