1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-19 20:21:51 +02:00

New resizeImage() method added to MediaManager class. Inline images now resized on-the-fly prior to emailing. Sitebutton auto-resized prior to emailing.

This commit is contained in:
Cameron 2015-05-13 13:34:52 -07:00
parent 2f78304ab2
commit fba9816acd
4 changed files with 101 additions and 18 deletions

View File

@ -108,7 +108,10 @@ $EMAIL_TEMPLATE['default']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHT
.video-thumbnail { max-width: 400px }
.media img { max-width:600px }
.unsubscribe { font-size:11px; color:#aaaaaa; margin-top:20px; padding:20px 0; border-top:solid 1px #e5e5e5; }
.sitebutton img { max-height: 100px }
.sitebutton img { max-height: 100px; border-radius:4px }
h4.sitename { font-size: 20px; margin-bottom:5px; margin-top:0; text-decoration:none }
h4.sitename a { text-decoration:none }
a.siteurl { font-size: 14px }
</style>
</head>
@ -118,8 +121,11 @@ $EMAIL_TEMPLATE['default']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHT
$EMAIL_TEMPLATE['default']['body'] = "{BODY}<br />{MEDIA1}{MEDIA2}{MEDIA3}{MEDIA4}{MEDIA5}";
$EMAIL_TEMPLATE['default']['footer'] = "<br /><br />
{SITENAME=link}
$EMAIL_TEMPLATE['default']['footer'] = "<br /><br /><table cellspacing='4'>
<tr><td>{SITEBUTTON: type=email&h=60}</td>
<td><h4 class='sitename'>{SITENAME=link}</h4>
<a class='siteurl' href='{SITEURL}'>{SITEURL}</a></td></tr>
</table>
</div>
</body>
</html>";
@ -158,10 +164,13 @@ $EMAIL_TEMPLATE['signup']['body'] = "
<br />
".LAN_EMAIL_06."<br />
<br />
{SITENAME=link}<br />
{SITEURL}
<br /><br />{SITEBUTTON=email}
<br /><table cellspacing='4'>
<tr><td>{SITEBUTTON: type=email&h=60}</td>
<td><h4 class='sitename'>{SITENAME=link}</h4>
<a class='siteurl' href='{SITEURL}'>{SITEURL}</a></td></tr>
</table>
</div>
";
@ -206,6 +215,7 @@ $EMAIL_TEMPLATE['notify']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//
.media img { max-width:200px; border-radius:5px }
.text-right { text-align: right }
.text-muted { color: #cccccc; }
.pull-left { float:left }
h1,h2,h3,h4 { margin-top:0; }
h2 small { font-size: 50%; padding-left:20px }
h2 { margin-bottom: 5px }
@ -241,15 +251,17 @@ $EMAIL_TEMPLATE['notify']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//
td { padding:5px; vertical-align: top }
td.body { width:80% }
table { width: 100%; margin-top:8px; border-top: 1px solid #cccccc; border-bottom: 1px solid #cccccc;padding:10px }
table { width: 100%; margin-top:8px; border-top: 1px solid #cccccc; border-bottom: 1px solid #cccccc;padding:10px 0 }
.unsubscribe { font-size:11px; color:#aaaaaa; margin-top:20px; padding:20px 0; border-top:solid 1px #e5e5e5; }
.sitebutton img { padding-right:5px; border-radius:3px }
</style>
</head>
<body>
<div id='body'>
";
$EMAIL_TEMPLATE['notify']['body'] = "<h2>{SITENAME=link} <small class='text-muted datestamp'>{DATE_LONG}</small></h2><table><tr><td class='media'>{MEDIA1}</td><td class='body'>{BODY}</td></tr></table>";
$EMAIL_TEMPLATE['notify']['body'] = "<h2><span class='pull-left'>{SITEBUTTON: type=email&h=30}</span> {SITENAME=link} <small class='text-muted datestamp'>{DATE_LONG}</small></h2><table><tr><td class='media'>{MEDIA1}</td><td class='body'>{BODY}</td></tr></table>";
$EMAIL_TEMPLATE['notify']['footer'] = "<br /><br />

View File

@ -991,7 +991,7 @@ class e107Email extends PHPMailer
if(!empty($eml['SMTPDebug']))
{
e107::getMessage()->addError($mail->ErrorInfo);
e107::getMessage()->addError($this->ErrorInfo);
}
}
@ -1060,15 +1060,17 @@ class e107Email extends PHPMailer
foreach($images[3] as $i => $url)
{
// do not change urls for absolute images (thanks to corvuscorax)
if (!preg_match('#^[A-z]+://#',$url))
{
$url = $tp->replaceConstants($url);
// resize on the fly.
if($resized = e107::getMedia()->resizeImage($url, e_TEMP.basename($url),'w=800'))
{
$url = $resized;
}
$delim = $images[2][$i]; // Will be single or double quote
$filename = basename($url);
$directory = dirname($url);

View File

@ -1352,5 +1352,66 @@ class e_media
}
/**
* Resize an image.
* @param $src
* @param $dest
* @param string $opts
* @return bool
*/
function resizeImage($src='',$dest='',$opts=null)
{
$pref = e107::getPref();
$tp = e107::getParser();
if(is_string($opts))
{
parse_str($opts,$opts);
}
$quality = vartrue($pref['thumbnail_quality'], 65);
$src = $tp->replaceConstants($src);
$dest = $tp->replaceConstants($dest);
$maxWidth = varset($opts['w'], 800);
$maxHeight = varset($opts['h'], 800);
$destDir = dirname($dest);
$destFile = basename($dest);
$destFilePath = $destDir."/".varset($opts['prefix'],$maxWidth.'x'.$maxHeight).'_'.$destFile;
if(file_exists($destFilePath))
{
return $destFilePath;
}
@require(e_HANDLER.'phpthumb/ThumbLib.inc.php');
try
{
$thumb = PhpThumbFactory::create($src);
$thumb->setOptions(array('correctPermissions' => true, 'resizeUp' => false, 'jpegQuality' => $quality));
$thumb->resize($maxWidth, $maxHeight);
$thumb->save($destFilePath);
return $destFilePath;
}
catch (Exception $e)
{
$error = $e->getMessage();
echo $error;
e107::getMessage()->addDebug($error);
e107::getLog()->add("RESIZE ERROR",$error,E_LOG_INFORMATIVE,'RESIZE');
return false;
}
}
}

View File

@ -8,7 +8,7 @@ if (!defined('e107_INIT')) { exit; }
class siteinfo_shortcodes // must match the folder name of the plugin.
{
function sc_sitebutton($parm='')
function sc_sitebutton($parm=null)
{
if($_POST['sitebutton'] && $_POST['ajax_used'])
@ -19,10 +19,18 @@ class siteinfo_shortcodes // must match the folder name of the plugin.
{
$path = (strstr(SITEBUTTON, 'http:') ? SITEBUTTON : e_IMAGE.SITEBUTTON);
}
if($parm == 'email')
if($parm['type'] == 'email' || $parm == 'email') // (retain {} constants )
{
$h = !empty($parm['h']) ? $parm['h'] : 100;
$path = e107::getConfig()->get('sitebutton');
$realPath = e107::getParser()->replaceConstants($path);
if($resized = e107::getMedia()->resizeImage($path, e_MEDIA."temp/".basename($realPath),'h='.$h))
{
$path = e107::getParser()->createConstants($resized);
}
}
if(!empty($path))