mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 22:27:34 +02:00
Experimental parser method added: thumbSrcSet();
This commit is contained in:
@@ -469,6 +469,8 @@ class news_shortcodes extends e_shortcode
|
||||
|
||||
$class = 'news-thumbnail-'.$tmp['count'];
|
||||
$dimensions = null;
|
||||
$srcset = null;
|
||||
$tp = e107::getParser();
|
||||
|
||||
if(!$newsThumb && $parm != 'placeholder')
|
||||
{
|
||||
@@ -486,7 +488,7 @@ class news_shortcodes extends e_shortcode
|
||||
|
||||
if(empty($parms[2])) // get {SETIMAGE} values when no parm provided.
|
||||
{
|
||||
$parms[2] = array('aw' => e107::getParser()->thumbWidth(), 'ah'=> e107::getParser()->thumbHeight());
|
||||
$parms[2] = array('aw' => $tp->thumbWidth(), 'ah'=> $tp->thumbHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -513,8 +515,10 @@ class news_shortcodes extends e_shortcode
|
||||
|
||||
if($parms[2] || $parms[1] == 'placeholder')
|
||||
{
|
||||
// $srcset = "srcset='".$tp->thumbSrcSet($src,'all')."' size='100vw' ";
|
||||
$src = e107::getParser()->thumbUrl($src, $parms[2]);
|
||||
$dimensions = e107::getParser()->thumbDimensions();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,15 +532,15 @@ class news_shortcodes extends e_shortcode
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
return "<img class='news_image ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} />";
|
||||
return "<img class='news_image ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} {$srcset} />";
|
||||
break;
|
||||
|
||||
case 'img':
|
||||
return "<a href='".$_src."' rel='external image'><img class='news_image ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} /></a>";
|
||||
return "<a href='".$_src."' rel='external image'><img class='news_image ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} {$srcset} /></a>";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "<a href='".e107::getUrl()->create('news/view/item', $this->news_item)."'><img class='news_image img-responsive img-rounded ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} /></a>";
|
||||
return "<a href='".e107::getUrl()->create('news/view/item', $this->news_item)."'><img class='news_image img-responsive img-rounded ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} {$srcset} /></a>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -660,7 +664,7 @@ class news_shortcodes extends e_shortcode
|
||||
$class = "news_image news-image img-responsive img-rounded";
|
||||
$class .= ' news-image-'.$tmp['count'];
|
||||
$dimensions = null;
|
||||
|
||||
$srcset = null;
|
||||
|
||||
if($tp->isVideo($srcPath))
|
||||
{
|
||||
@@ -685,6 +689,7 @@ class news_shortcodes extends e_shortcode
|
||||
{
|
||||
$src = $tp->thumbUrl($srcPath);
|
||||
$dimensions = $tp->thumbDimensions();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -717,12 +722,12 @@ class news_shortcodes extends e_shortcode
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
return "<img class='{$class}' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} />";
|
||||
return "<img class='{$class}' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} {$srcset} />";
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
default:
|
||||
return "<a href='".e107::getUrl()->create('news/view/item', $this->news_item)."'><img class='{$class}' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} /></a>";
|
||||
return "<a href='".e107::getUrl()->create('news/view/item', $this->news_item)."'><img class='{$class}' src='".$src."' alt='' style='".$this->param['thumbnail']."' {$dimensions} {$srcset} /></a>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -2300,6 +2300,56 @@ class e_parse extends e_parser
|
||||
return $baseurl.$thurl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Experimental: Generate a Thumb URL for use in the img srcset attribute.
|
||||
* @param string $src eg. {e_MEDIA_IMAGE}myimage.jpg
|
||||
* @param int|str $width - desired size in px or '2x' or '3x' or null for all
|
||||
* @return string
|
||||
*/
|
||||
function thumbSrcSet($src='', $width=null)
|
||||
{
|
||||
|
||||
if($width == null || $width=='all')
|
||||
{
|
||||
$links = array();
|
||||
$mag = ($width == null) ? array(1, 2) : array(160,320,460,600,780,920,1100);
|
||||
foreach($mag as $v)
|
||||
{
|
||||
$w = ($this->thumbWidth * $v);
|
||||
$h = ($this->thumbHeight * $v);
|
||||
|
||||
$parms = !empty($this->thumbCrop) ? array('aw' => $w, 'ah' => $h) : array('w' => $w, 'h' => $h);
|
||||
|
||||
$add = ($width == null) ? " ".$v."x" : " ".$v."w";
|
||||
$links[] = $this->thumbUrl($src, $parms).$add; // " w".$width; //
|
||||
}
|
||||
|
||||
return implode(", ",$links);
|
||||
|
||||
}
|
||||
elseif($width == '2x')
|
||||
{
|
||||
$width = ($this->thumbWidth * 2);
|
||||
$height = ($this->thumbHeight * 2);
|
||||
}
|
||||
elseif($width == '3x')
|
||||
{
|
||||
$width = ($this->thumbWidth * 3);
|
||||
$height = ($this->thumbHeight * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
$height = (($this->thumbHeight * $width) / $this->thumbWidth);
|
||||
}
|
||||
|
||||
$parms = !empty($this->thumbCrop) ? array('aw' => $width, 'ah' => $height) : array('w' => $width, 'h' => $height );
|
||||
|
||||
return $this->thumbUrl($src, $parms)." ".$width."w";
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used by thumbUrl when SEF Image URLS is active. @see e107.htaccess
|
||||
* @param $url
|
||||
@@ -3395,6 +3445,13 @@ class e_parser
|
||||
{
|
||||
$path = $tp->thumbUrl($file,null,null,true);
|
||||
$dimensions = $this->thumbDimensions();
|
||||
$width2x = ($parm['w']*2);
|
||||
$height2x = ($parm['h']*2);
|
||||
|
||||
$path2x = $tp->thumbUrl($file,array('w'=> $width2x ,'h'=> $height2x ));
|
||||
|
||||
print_a($path2x);
|
||||
|
||||
}
|
||||
elseif($file[0] == '{') // Legacy v1.x path. Example: {e_WHEREEVER}
|
||||
{
|
||||
|
Reference in New Issue
Block a user