1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Bulk mail templates can now resize images to keep email sizes smaller. eg. {MEDIA1: w=500} Improved debugging of thumb.php.

This commit is contained in:
Cameron
2016-05-11 18:52:42 -07:00
parent dfa289ba13
commit 42246f7381
4 changed files with 86 additions and 21 deletions

View File

@@ -593,6 +593,9 @@ class mailout_main_ui extends e_admin_ui
'media' => array(
0 => array('path' => '{e_PLUGIN}gallery/images/butterfly.jpg'),
1 => array('path' => 'h-v880sXEOQ.youtube'),
2 => array('path' => '{e_PLUGIN}gallery/images/horse.jpg'),
3 => array('path' => '{e_PLUGIN}gallery/images/butterfly.jpg'),
4 => array('path' => '{e_PLUGIN}gallery/images/horse.jpg'),
)
);
@@ -952,7 +955,7 @@ class mailout_main_ui extends e_admin_ui
$pause = e107::getConfig()->get('mail_pausetime',1);
$interval = ($pause * 1000);
$text = e107::getForm()->progressBar('mail-progress',1, array('btn-label'=>'Start', 'interval'=>$interval, 'url'=> e_SELF, 'mode'=>$id));
$text = e107::getForm()->progressBar('mail-progress',0, array('btn-label'=>'Start', 'interval'=>$interval, 'url'=> e_SELF, 'mode'=>$id));
}
return $text;

View File

@@ -735,6 +735,26 @@ class e107Email extends PHPMailer
{
$tp = e107::getParser();
$mediaParms = array();
if(strpos($eml['templateHTML']['body'], '{MEDIA') !==false )
{
// check for media sizing.
if(preg_match_all('/\{MEDIA([\d]): w=([\d]*)\}/', $eml['templateHTML']['body'], $match))
{
foreach($match[1] as $k=>$num)
{
//$key = $match[1][$k];
$mediaParms[$num]['w'] = $match[2][$k];
}
}
}
if(!empty($eml['html']) || strip_tags($eml['template']) != $eml['template']) // HTML Email.
{
$eml['shortcodes']['BODY'] = !empty($eml['body']) ? $eml['body'] : ''; // using toEmail() on html templates adds unnecessary <br /> to code.
@@ -749,13 +769,15 @@ class e107Email extends PHPMailer
$eml['shortcodes']['THEME'] = ($this->previewMode == true) ? e_THEME_ABS.$this->pref['sitetheme'].'/' : e_THEME.$this->pref['sitetheme'].'/'; // Always use front-end theme path.
if(!empty($eml['media']) && is_array($eml['media']))
{
foreach($eml['media'] as $k=>$val)
{
if(vartrue($val['path']))
{
$id = 'MEDIA'.($k+1);
$nk = ($k+1);
$id = 'MEDIA'.$nk;
if($tp->isVideo($val['path']))
{
@@ -763,7 +785,9 @@ class e107Email extends PHPMailer
}
else
{
$eml['shortcodes'][$id] = "<div class='media media-image'><img class='img-responsive' src='".$val['path']."' alt='' /></div>";
$size = isset($mediaParms[$nk]) ? "?w=".$mediaParms[$nk]['w'] : '';
//echo $nk.": ".$val['path'].$size."<br />";
$eml['shortcodes'][$id] = "<div class='media media-image'><img class='img-responsive ".strtolower($id)."' src='".$val['path'].$size."' alt='' /></div>";
}
}
@@ -809,7 +833,7 @@ class e107Email extends PHPMailer
if($tmpl = e107::getCoreTemplate('email', $eml['template'], 'front', true)) //FIXME - Core template is failing with template 'notify'. Works with theme template. Issue with core template registry?
{
$eml['templateHTML'] = $tmpl;
$eml['shortcodes'] = $this->processShortcodes($eml);
$emailBody = $tmpl['header']. str_replace('{BODY}', $eml['body'], $tmpl['body']) . $tmpl['footer'];
@@ -1118,12 +1142,21 @@ class e107Email extends PHPMailer
{
$url = $tp->replaceConstants($url);
$size = 'w=800';
if(strpos($url, '?w=')!==false)
{
list($url,$size) = explode('?', $url);
}
// resize on the fly.
if($this->debug)
{
echo "<br />Attempting Resize...".$url;
}
if($resized = e107::getMedia()->resizeImage($url, e_TEMP.basename($url),'w=800'))
// e107::getMessage()->addInfo("Resizing: ".$url." to ".$size);
if($resized = e107::getMedia()->resizeImage($url, e_TEMP.basename($url), $size))
{
$url = $resized;
}

View File

@@ -67,6 +67,7 @@ class plugin_gallery_index_controller extends eControllerFront
public function init()
{
e107::plugLan('gallery', 'front');
e107::css('gallery', 'css/gallery.css');
$this->catList = e107::getMedia()->getCategories('gallery');
}

View File

@@ -48,6 +48,10 @@ exit;
class e_thumbpage
{
private $_debug = false;
private $_cache = true;
/**
* Page request
* @var array
@@ -232,7 +236,13 @@ class e_thumbpage
$parm = array('size' => $width."x".$height);
$this->placeholder($parm);
return;
return false;
}
if($this->_debug === true)
{
var_dump($this->_request);
// return false;
}
if(!$this->_src_path)
@@ -248,15 +258,17 @@ class e_thumbpage
if(is_file(e_CACHE_IMAGE.$fname) && is_readable(e_CACHE_IMAGE.$fname))
if($this->_cache = true && is_file(e_CACHE_IMAGE.$fname) && is_readable(e_CACHE_IMAGE.$fname) && ($this->_debug !== true))
{
$thumbnfo['lmodified'] = filemtime(e_CACHE_IMAGE.$fname);
$thumbnfo['md5s'] = md5_file(e_CACHE_IMAGE.$fname);
$thumbnfo['fsize'] = filesize(e_CACHE_IMAGE.$fname);
// Send required headers
if($this->_debug !== true)
{
$this->sendHeaders($thumbnfo);
}
//$bench->end()->logResult('thumb.php', $_GET['src'].' - 304 not modified');
// exit;
@@ -278,11 +290,15 @@ class e_thumbpage
}
// TODO - wrap it around generic e107 thumb handler
if($this->_debug === true)
{
$start = microtime(true);
}
@require(e_HANDLER.'phpthumb/ThumbLib.inc.php');
try
{
$thumb = PhpThumbFactory::create($this->_src_path);
$sizeUp = ($this->_request['w'] > 110) ? true : false; // don't resizeUp the icon images.
$sizeUp = ($this->_request['w'] > 110 || $this->_request['aw'] > 110) ? true : false; // don't resizeUp the icon images.
$thumb->setOptions(array(
'correctPermissions' => true,
'resizeUp' => $sizeUp,
@@ -300,8 +316,9 @@ class e_thumbpage
if(isset($this->_request['w']) || isset($this->_request['h']))
{
$thumb->resize((integer) vartrue($this->_request['w'], 0), (integer) vartrue($this->_request['h'], 0));
echo __LINE__;
}
elseif(vartrue($this->_request['ah']))
elseif(!empty($this->_request['ah']))
{
//Typically gives a better result with images of people than adaptiveResize().
//TODO TBD Add Pref for Top, Bottom, Left, Right, Center?
@@ -312,6 +329,15 @@ class e_thumbpage
$thumb->adaptiveResize((integer) vartrue($this->_request['aw'], 0), (integer) vartrue($this->_request['ah'], 0));
}
if($this->_debug === true)
{
echo "time: ".round((microtime(true) - $start),4);
var_dump($thumb);
return false;
}
// Watermark Option - See admin->MediaManager->prefs for details.
if(($this->_watermark['activate'] < $options['w']
@@ -329,12 +355,14 @@ class e_thumbpage
// echo "hello";
//exit;
// set cache
$thumb->save(e_CACHE_IMAGE.$fname);
// show thumb
$thumb->show();
}