From 8660d2d890fe42168ac8ed38a50acab6a47db69e Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 7 Feb 2016 13:28:55 -0800 Subject: [PATCH] Include width/height attributes in img tags with cropped thumbnails. --- e107_core/shortcodes/batch/page_shortcodes.php | 11 +++++++---- e107_handlers/e_parse_class.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/e107_core/shortcodes/batch/page_shortcodes.php b/e107_core/shortcodes/batch/page_shortcodes.php index d7628a5ab..e1a8ac732 100644 --- a/e107_core/shortcodes/batch/page_shortcodes.php +++ b/e107_core/shortcodes/batch/page_shortcodes.php @@ -201,6 +201,7 @@ class cpage_shortcodes extends e_shortcode elseif($path[0] !== '{') $path = '{e_MEDIA}'.$path; $thumb = $tp->thumbUrl($path); + $dimensions = $tp->thumbDimensions('double'); $type = varset($parms[2]['type'], 'tag'); switch($type) @@ -210,12 +211,12 @@ class cpage_shortcodes extends e_shortcode break; case 'link': - return ''.varset($parms[1]['alt']).''; + return ''.varset($parms[1]['alt']).''; break; case 'tag': default: - return ''.varset($parms[1]['alt']).''; + return ''.varset($parms[1]['alt']).''; break; } } @@ -312,8 +313,10 @@ class cpage_shortcodes extends e_shortcode { return $img; } - - return ""; + + $dimensions = $tp->thumbDimensions(); + + return ""; } function sc_cmenuicon($parm='') diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index a22f827b6..e33e54686 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2177,7 +2177,19 @@ class e_parse extends e_parser } + /** + * Retrieve img tag width and height attributes for current thumbnail. + * @return string + */ + public function thumbDimensions($type = 'single') + { + if(!empty($this->thumbCrop) && !empty($this->thumbWidth) && !empty($this->thumbHeight)) // dimensions are known. + { + return ($type == 'double') ? 'width="'.$this->thumbWidth.'" height="'.$this->thumbHeight.'"' : "width='".$this->thumbWidth."' height='".$this->thumbHeight."'"; + } + return null; + } /**