mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Issue #4270 - perform all webp conversion checks within e_thumbnail class. WebP conversion now works with SEF media URLS.
This commit is contained in:
@@ -418,11 +418,6 @@ $pref = e107::getPref(); // include pref class.
|
||||
$sysprefs = new prefs;
|
||||
//DEPRECATED, BC, call e107::getPref/findPref() instead
|
||||
|
||||
|
||||
if(e_ADMIN_AREA !== true && !isset($_E107['no_parser']) && !empty($pref['thumb_to_webp']) && (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false))
|
||||
{
|
||||
$tp->setConvertToWebP(true);
|
||||
}
|
||||
//this could be part of e107->init() method now, prefs will be auto-initialized
|
||||
//when proper called (e107::getPref())
|
||||
// $e107->set_base_path(); moved to init().
|
||||
|
@@ -250,7 +250,6 @@ class e_parse
|
||||
|
||||
private $bootstrap;
|
||||
private $fontawesome;
|
||||
private $convertToWebP = false;
|
||||
|
||||
private $removedList = array();
|
||||
private $nodesToDelete = array();
|
||||
@@ -2361,11 +2360,6 @@ class e_parse
|
||||
parse_str($options, $options);
|
||||
}
|
||||
|
||||
if($this->convertToWebP)
|
||||
{
|
||||
$options['type'] = 'webp';
|
||||
}
|
||||
|
||||
if(!empty($options['scale'])) // eg. scale the width height 2x 3x 4x. etc.
|
||||
{
|
||||
$options['return'] = 'src';
|
||||
@@ -2442,9 +2436,9 @@ class e_parse
|
||||
|
||||
}
|
||||
|
||||
if(!empty($options['type']) && ($options['type'] === 'webp'))
|
||||
if(!empty($options['type']))
|
||||
{
|
||||
$thurl .= '&type=webp';
|
||||
$thurl .= '&type='.$options['type'];
|
||||
}
|
||||
|
||||
|
||||
@@ -3592,15 +3586,6 @@ class e_parse
|
||||
$this->bootstrap = (int) $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bool
|
||||
*/
|
||||
public function setConvertToWebP($bool)
|
||||
{
|
||||
|
||||
$this->convertToWebP = (bool) $bool;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add leading zeros to a number. eg. 3 might become 000003
|
||||
|
@@ -45,6 +45,8 @@ class e_thumbnail
|
||||
|
||||
protected $_upsize = true;
|
||||
|
||||
protected $_forceWebP = false;
|
||||
|
||||
/**
|
||||
* Constructor - init paths
|
||||
*
|
||||
@@ -86,6 +88,7 @@ class e_thumbnail
|
||||
|
||||
$this->_upsize = ((isset($this->_request['w']) && $this->_request['w'] > 110) || (isset($this->_request['aw']) && ($this->_request['aw'] > 110))); // don't resizeUp the icon images.
|
||||
|
||||
$this->_forceWebP = empty($this->_request['type']) && !empty($pref['thumb_to_webp']) && (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false) ? true : false;
|
||||
// var_dump($this);
|
||||
// exit;
|
||||
return null;
|
||||
@@ -156,7 +159,7 @@ class e_thumbnail
|
||||
{
|
||||
$thumbnfo = pathinfo($this->_src_path);
|
||||
|
||||
if(!empty($this->_request['type']) && $this->_request['type'] == 'webp')
|
||||
if($this->_forceWebP === true || (!empty($this->_request['type']) && $this->_request['type'] == 'webp'))
|
||||
{
|
||||
$thumbnfo['extension'] = 'webp';
|
||||
}
|
||||
|
@@ -2301,25 +2301,7 @@ while($row = $sql->fetch())
|
||||
$result5 = $this->tp->toImage($src, ['type'=>'webp']);
|
||||
$this->assertStringContainsString('&type=webp', $result5); // src
|
||||
|
||||
$this->tp->setConvertToWebP(true);
|
||||
$result6 = $this->tp->toImage($src);
|
||||
$expected = '<img class="img-responsive img-fluid" src="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=80&h=80&type=webp" alt="butterfly.jpg" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=320&h=320&type=webp 4x" width="80" height="80" />';
|
||||
|
||||
/*
|
||||
$expected = '<picture class="img-responsive img-fluid">
|
||||
<source type="image/webp" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=320&h=320&type=webp 4x">
|
||||
<source type="image/jpeg" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=320&h=320 4x">
|
||||
<source type="image/webp" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=80&h=80&type=webp">
|
||||
<img class="img-responsive img-fluid" src="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=80&h=80" alt="butterfly.jpg" width="80" height="80" />
|
||||
</picture>';*/
|
||||
|
||||
// $tempDir = str_replace(['C:','\\'],['','/'], sys_get_temp_dir()).'/'; // FIXME
|
||||
$result6 = preg_replace('/"([^"]*)thumb.php/','"thumb.php', $result6);
|
||||
|
||||
// $result6 = str_replace($tempDir, '', $result6);
|
||||
$expected = str_replace("\r", '', $expected);
|
||||
$this->assertSame($expected,$result6);
|
||||
$this->tp->setConvertToWebP(false);
|
||||
|
||||
|
||||
$tests = array(
|
||||
|
Reference in New Issue
Block a user