Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/images/image_tag_processor.php
Show All 28 Lines | |||||
{ | { | ||||
$image_url = $this->ImageSrc($block_params); | $image_url = $this->ImageSrc($block_params); | ||||
if ( !$image_url ) { | if ( !$image_url ) { | ||||
return ; | return ; | ||||
} | } | ||||
$parent_prefix = $this->Application->getUnitOption($object->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($object->Prefix, 'ParentPrefix'); | ||||
/** @var kDBItem $parent_item */ | |||||
$parent_item = $this->Application->recallObject($parent_prefix); | $parent_item = $this->Application->recallObject($parent_prefix); | ||||
/* @var $parent_item kDBItem */ | |||||
$block_params['img_path'] = $image_url; | $block_params['img_path'] = $image_url; | ||||
$image_dimensions = $this->ImageSize($block_params); | $image_dimensions = $this->ImageSize($block_params); | ||||
$block_params['img_size'] = $image_dimensions ? $image_dimensions : ' width="' . $block_params['DefaultWidth'] . '"'; | $block_params['img_size'] = $image_dimensions ? $image_dimensions : ' width="' . $block_params['DefaultWidth'] . '"'; | ||||
$block_params['alt'] = $object->GetField('AltName') ? $object->GetField('AltName') : $this->getItemTitle($parent_item); | $block_params['alt'] = $object->GetField('AltName') ? $object->GetField('AltName') : $this->getItemTitle($parent_item); | ||||
$block_params['align'] = array_key_exists('align', $block_params) ? $block_params['align'] : 'left'; | $block_params['align'] = array_key_exists('align', $block_params) ? $block_params['align'] : 'left'; | ||||
// TODO: consider escaping in template instead | // TODO: consider escaping in template instead | ||||
Show All 36 Lines | |||||
} | } | ||||
else { | else { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
function LoadItemImage($params) | function LoadItemImage($params) | ||||
{ | { | ||||
/** @var kCatDBItem $parent_item */ | |||||
$parent_item = $this->Application->recallObject($params['PrefixSpecial']); | $parent_item = $this->Application->recallObject($params['PrefixSpecial']); | ||||
/* @var $parent_item kCatDBItem */ | |||||
/** @var kDBItem $object */ | |||||
$object = $this->Application->recallObject($this->getPrefixSpecial(), null, Array('skip_autoload' => true)); | $object = $this->Application->recallObject($this->getPrefixSpecial(), null, Array('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | |||||
$object->Clear(); | $object->Clear(); | ||||
// if we need primary thumbnail which is preloaded with category item's list | // if we need primary thumbnail which is preloaded with category item's list | ||||
$is_primary = $this->SelectParam($params, 'primary,Primary'); | $is_primary = $this->SelectParam($params, 'primary,Primary'); | ||||
$image_name = $this->SelectParam($params, 'name,Name'); | $image_name = $this->SelectParam($params, 'name,Name'); | ||||
$image_field = $this->SelectParam($params, 'field,Field'); // ie. virtual names PrimaryImage, Image1, Image2 | $image_field = $this->SelectParam($params, 'field,Field'); // ie. virtual names PrimaryImage, Image1, Image2 | ||||
$image_id = $this->Application->GetVar($this->Prefix.'_id'); | $image_id = $this->Application->GetVar($this->Prefix.'_id'); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | |||||
$local_path = $object->GetDBField('LocalPath'); | $local_path = $object->GetDBField('LocalPath'); | ||||
if ($local_path && substr($local_path, 0, 1) != DIRECTORY_SEPARATOR) { | if ($local_path && substr($local_path, 0, 1) != DIRECTORY_SEPARATOR) { | ||||
$object->SetDBField('LocalPath', DIRECTORY_SEPARATOR . $local_path); | $object->SetDBField('LocalPath', DIRECTORY_SEPARATOR . $local_path); | ||||
} | } | ||||
} | } | ||||
function ImageSrc($params) | function ImageSrc($params) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $this->getObject($params); | $object = $this->getObject($params); | ||||
/* @var $object kDBItem */ | |||||
$this->makeRelativePaths($object); | $this->makeRelativePaths($object); | ||||
// show "noimage.gif" when requested image is missing OR was not uploaded | // show "noimage.gif" when requested image is missing OR was not uploaded | ||||
$use_default_image = !(defined('DBG_IMAGE_RECOVERY') && DBG_IMAGE_RECOVERY); | $use_default_image = !(defined('DBG_IMAGE_RECOVERY') && DBG_IMAGE_RECOVERY); | ||||
$src_image_url = $this->_getImageUrl($params); | $src_image_url = $this->_getImageUrl($params); | ||||
$src_image = $this->_getImagePath($src_image_url); | $src_image = $this->_getImagePath($src_image_url); | ||||
if (!$object->isLoaded() || ($src_image_url && $src_image)) { | if (!$object->isLoaded() || ($src_image_url && $src_image)) { | ||||
// we can auto-resize image, when it is stored locally | // we can auto-resize image, when it is stored locally | ||||
$max_width = $this->getImageDimension('Width', $params); | $max_width = $this->getImageDimension('Width', $params); | ||||
$max_height = $this->getImageDimension('Height', $params); | $max_height = $this->getImageDimension('Height', $params); | ||||
$format = array_key_exists('format', $params) ? $params['format'] : false; | $format = array_key_exists('format', $params) ? $params['format'] : false; | ||||
if (!$max_width && $format) { | if (!$max_width && $format) { | ||||
// user watermarks from format param | // user watermarks from format param | ||||
$max_width = $format; | $max_width = $format; | ||||
} | } | ||||
if ($max_width > 0 || $max_height > 0 || $format) { | if ($max_width > 0 || $max_height > 0 || $format) { | ||||
list ($max_width, $max_height) = $this->_transformParams($params, $max_width, $max_height); | list ($max_width, $max_height) = $this->_transformParams($params, $max_width, $max_height); | ||||
if ($object->isLoaded() && file_exists($src_image)) { | if ($object->isLoaded() && file_exists($src_image)) { | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
return $image_helper->ResizeImage($src_image, $max_width, $max_height); | return $image_helper->ResizeImage($src_image, $max_width, $max_height); | ||||
} | } | ||||
elseif ($use_default_image) { | elseif ($use_default_image) { | ||||
return $this->_getDefaultImage($params, $max_width, $max_height); | return $this->_getDefaultImage($params, $max_width, $max_height); | ||||
} | } | ||||
return $src_image_url; | return $src_image_url; | ||||
Show All 22 Lines | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
function _getImagePath($src_image) | function _getImagePath($src_image) | ||||
{ | { | ||||
if (!$src_image) { | if (!$src_image) { | ||||
return false; | return false; | ||||
} | } | ||||
/** @var FileHelper $file_helper */ | |||||
$file_helper = $this->Application->recallObject('FileHelper'); | $file_helper = $this->Application->recallObject('FileHelper'); | ||||
/* @var $file_helper FileHelper */ | |||||
$dst_image = $file_helper->urlToPath($src_image); | $dst_image = $file_helper->urlToPath($src_image); | ||||
return $dst_image != $src_image ? $dst_image : false; | return $dst_image != $src_image ? $dst_image : false; | ||||
} | } | ||||
function _getImageUrl($params) | function _getImageUrl($params) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $this->getObject($params); | $object = $this->getObject($params); | ||||
/* @var $object kDBItem */ | |||||
$base_url = rtrim($this->Application->BaseURL(), '/'); | $base_url = rtrim($this->Application->BaseURL(), '/'); | ||||
// if we need thumbnail, or full image is same as thumbnail | // if we need thumbnail, or full image is same as thumbnail | ||||
$show_thumbnail = $this->SelectParam($params, 'thumbnail,Thumbnail') || // old style | $show_thumbnail = $this->SelectParam($params, 'thumbnail,Thumbnail') || // old style | ||||
(isset($params['MaxWidth']) && $params['MaxWidth'] == 'thumbnail') || // new style | (isset($params['MaxWidth']) && $params['MaxWidth'] == 'thumbnail') || // new style | ||||
(isset($params['MaxHeight']) && $params['MaxHeight'] == 'thumbnail'); | (isset($params['MaxHeight']) && $params['MaxHeight'] == 'thumbnail'); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
return ''; | return ''; | ||||
} | } | ||||
// show default image, use different base urls for admin and front-end | // show default image, use different base urls for admin and front-end | ||||
$base_url = rtrim($this->Application->BaseURL(), '/'); | $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 !== false) || ($max_height !== false)) { | if (($max_width !== false) || ($max_height !== false)) { | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
$src_image = FULL_PATH . $sub_folder . '/' . $default_image; | $src_image = FULL_PATH . $sub_folder . '/' . $default_image; | ||||
return $image_helper->ResizeImage($src_image, $max_width, $max_height); | return $image_helper->ResizeImage($src_image, $max_width, $max_height); | ||||
} | } | ||||
return $base_url . $sub_folder . '/' . $default_image; | return $base_url . $sub_folder . '/' . $default_image; | ||||
} | } | ||||
function getFullPath($path) | function getFullPath($path) | ||||
{ | { | ||||
if (!$path) { | if (!$path) { | ||||
return $path; | return $path; | ||||
} | } | ||||
// absolute url | // absolute url | ||||
if (preg_match('/^(.*):\/\/(.*)$/U', $path)) { | if (preg_match('/^(.*):\/\/(.*)$/U', $path)) { | ||||
/** @var FileHelper $file_helper */ | |||||
$file_helper = $this->Application->recallObject('FileHelper'); | $file_helper = $this->Application->recallObject('FileHelper'); | ||||
/* @var $file_helper FileHelper */ | |||||
return $file_helper->urlToPath($path); | return $file_helper->urlToPath($path); | ||||
} | } | ||||
// TODO: change to urlToPath usage later | // TODO: change to urlToPath usage later | ||||
// relative url (we add sort of <inp2:m_TemplatesBase/> does | // relative url (we add sort of <inp2:m_TemplatesBase/> does | ||||
return FULL_PATH . '/' . mb_substr(THEMES_PATH, 1) . '/' . kUtil::unescape($path, kUtil::ESCAPE_URL); | return FULL_PATH . '/' . mb_substr(THEMES_PATH, 1) . '/' . kUtil::unescape($path, kUtil::ESCAPE_URL); | ||||
} | } | ||||
/** | /** | ||||
* Makes size clause for img tag, such as | * Makes size clause for img tag, such as | ||||
* ' width="80" height="100"' according to max_width | * ' width="80" height="100"' according to max_width | ||||
* and max_heght limits. | * and max_heght limits. | ||||
* | * | ||||
* @param array $params | * @param array $params | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
function ImageSize($params) | function ImageSize($params) | ||||
{ | { | ||||
$img_path = $this->getFullPath($params['img_path']); | $img_path = $this->getFullPath($params['img_path']); | ||||
/** @var ImageHelper $image_helper */ | |||||
$image_helper = $this->Application->recallObject('ImageHelper'); | $image_helper = $this->Application->recallObject('ImageHelper'); | ||||
/* @var $image_helper ImageHelper */ | |||||
$max_width = $this->getImageDimension('Width', $params); | $max_width = $this->getImageDimension('Width', $params); | ||||
$max_height = $this->getImageDimension('Height', $params); | $max_height = $this->getImageDimension('Height', $params); | ||||
$image_dimensions = $image_helper->GetImageDimensions($img_path, $max_width, $max_height, $params); | $image_dimensions = $image_helper->GetImageDimensions($img_path, $max_width, $max_height, $params); | ||||
if (!$image_dimensions) { | if (!$image_dimensions) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 11 Lines | |||||
protected function Image($params) | protected function Image($params) | ||||
{ | { | ||||
$image_url = $this->ImageSrc($params); | $image_url = $this->ImageSrc($params); | ||||
if ( !$image_url ) { | if ( !$image_url ) { | ||||
return ''; | return ''; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $this->getObject($params); | $object = $this->getObject($params); | ||||
/* @var $object kDBItem */ | |||||
$params['img_path'] = $image_url; | $params['img_path'] = $image_url; | ||||
$image_dimensions = $this->ImageSize($params); | $image_dimensions = $this->ImageSize($params); | ||||
$params['img_size'] = $image_dimensions ? $image_dimensions : ' width="' . $params['DefaultWidth'] . '"'; | $params['img_size'] = $image_dimensions ? $image_dimensions : ' width="' . $params['DefaultWidth'] . '"'; | ||||
$params['alt'] = $object->GetField('AltName'); // really used ? | $params['alt'] = $object->GetField('AltName'); // really used ? | ||||
$params['name'] = $this->SelectParam($params, 'block,render_as'); | $params['name'] = $this->SelectParam($params, 'block,render_as'); | ||||
$params['align'] = array_key_exists('align', $params) ? $params['align'] : 'left'; | $params['align'] = array_key_exists('align', $params) ? $params['align'] : 'left'; | ||||
$params['no_editing'] = 1; | $params['no_editing'] = 1; | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |