Index: trunk/kernel/units/images/image_tag_processor.php =================================================================== diff -u -N -r8474 -r8686 --- trunk/kernel/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 8474) +++ trunk/kernel/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 8686) @@ -23,26 +23,24 @@ } /** - * [AGGREGATED TAG] works as + * [AGGREGATED TAGS] works as * * @param Array $params * @return string */ - function ItemImage($params) + function ItemImageTag($params) { $this->LoadItemImage($params); - return $this->Image($params); + return $this->$params['original_tag']($params); } function LargeImageExists($params) { $object =& $this->getObject($params); - if ( $object->GetDBField('SameImages') == null || $object->GetDBField('SameImages')=='1' ) - { + if ($object->GetDBField('SameImages') == null || $object->GetDBField('SameImages') == 1) { return false; } - else - { + else { return true; } } @@ -56,25 +54,19 @@ $object->Clear(); - // if we need primary thumbnail which is preloaded with products list + // if we need primary thumbnail which is preloaded with category item's list + $is_primary = $this->SelectParam($params, 'primary,Primary'); + if ( - $this->SelectParam($params, 'thumbnail,Thumbnail') && - ( - ( - $this->SelectParam($params, 'primary,Primary') - || - !isset($params['name']) - ) - && - !$this->Application->GetVar('img_id') - && - isset($parent_item->Fields['LocalThumb']) - ) - ) - { + ($is_primary || !isset($params['name'])) + && + !$this->Application->GetVar('img_id') + && + isset($parent_item->Fields['LocalThumb']) + ) { $object->SetDefaultValues(); $object->SetDBField('Url', $parent_item->GetDBField('FullUrl')); - $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath') ); + $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 @@ -90,6 +82,10 @@ elseif ( getArrayValue($params, 'name') ) { //load by name $keys['Name'] = $params['name']; } + elseif ( getArrayValue($params, 'field') ) { //load by virtual field name in main object + $field_options = $parent_item->GetFieldOptions($params['field']); + $keys['Name'] = $field_options['original_field']; + } elseif ( $image_id = $this->Application->GetVar($this->Prefix.'_id') ) { $keys['ImageId'] = $image_id; } @@ -101,16 +97,68 @@ } } + function getImageDimension($type, $params) + { + $ret = isset($params['Max'.$type]) ? $params['Max'.$type] : false; + if (!$ret) { + return $ret; + } + $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); + + if ($ret == 'thumbnail') { + $ret = $this->Application->ConfigValue($parent_prefix.'_ThumbnailImage'.$type); + } + if ($ret == 'fullsize') { + $ret = $this->Application->ConfigValue($parent_prefix.'_FullImage'.$type); + } + + return $ret; + } + function ImageSrc($params) { $object =& $this->getObject($params); - $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 + + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ + + $max_width = $this->getImageDimension('Width', $params); + $max_height = $this->getImageDimension('Height', $params); + + if ($max_width > 0 || $max_height > 0) { + // image auto-resize is required + $src_image = FULL_PATH.$object->GetDBField('ThumbPath'); + list ($max_width, $max_height, $resized) = $image_helper->GetImageDimensions($src_image, $max_width, $max_height); + + if ($resized) { + $src_path = FULL_PATH.($this->Application->IsAdmin() ? IMAGES_PENDING_PATH : IMAGES_PATH); + $dst_image = preg_replace('/^'.preg_quote($src_path, '/').'(.*)\.(.*)$/', $src_path.'resized/\\1_'.$max_width.'x'.$max_height.'.\\2', $src_image); + if (!file_exists($dst_image) || filemtime($src_image) > filemtime($dst_image)) { + // resized image not available OR should be recreated due source image change + $image_resized = $image_helper->ScaleImage($src_image, $dst_image, $max_width, $max_height); + if (!$image_resized) { + // resize failed, because of server error + $dst_image = $src_image; + } + } + + return preg_replace('/^'.preg_quote(FULL_PATH, '/').'(.*)/', $base_url.'\\1', $dst_image); + } + } + } + $ret = ''; - // if we need thumb, or full image is same as thumb - if ( $this->SelectParam($params, 'thumbnail,Thumbnail') || $object->GetDBField('SameImages') ) - { + + // 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')) { @@ -160,7 +208,10 @@ $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ - $image_dimensions = $image_helper->GetImageDimensions($img_path, getArrayValue($params, 'MaxWidth'), getArrayValue($params, 'MaxHeight')); + $max_width = $this->getImageDimension('Width', $params); + $max_height = $this->getImageDimension('Height', $params); + + $image_dimensions = $image_helper->GetImageDimensions($img_path, $max_width, $max_height); if (!$image_dimensions) { return false; }