From 65b44a8abbd1a01a2354b1a44b4663eed116798b Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 18 Oct 2014 15:00:40 -0700 Subject: [PATCH] Added support for embedded mail media in mailouts. --- e107_admin/mailout.php | 14 +++++--- e107_core/sql/core_sql.php | 1 + e107_core/templates/email_template.php | 30 ++++++++-------- e107_handlers/e_parse_class.php | 15 ++++++++ e107_handlers/mail.php | 49 +++++++++++++++++++++++--- e107_handlers/mail_manager_class.php | 12 +++++++ e107_handlers/mailout_admin_class.php | 2 +- 7 files changed, 100 insertions(+), 23 deletions(-) diff --git a/e107_admin/mailout.php b/e107_admin/mailout.php index 01bbc9421..eba6dc706 100644 --- a/e107_admin/mailout.php +++ b/e107_admin/mailout.php @@ -303,10 +303,12 @@ class mailout_main_ui extends e_admin_ui 'mail_attach' => array('title' => LAN_MAILOUT_153, 'tab'=>1, 'type'=>'method','data'=>false), 'mail_include_images' => array('title' => LAN_MAILOUT_224, 'tab'=>1, 'type'=>'boolean','data'=>false, 'proc' => 'yesno'), 'mail_send_style' => array('title' => LAN_MAILOUT_154,'type'=>'method','data'=>false), + 'mail_media' => array('title' => 'Embed Media', 'type' => 'images', 'data' => 'array', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => 'video=1', 'class' => 'center', 'thclass' => 'center', ), + 'mail_body' => array('title' => LAN_MAILOUT_100, 'type'=>'bbarea', 'proc' => 'trunc200'), 'mail_body_templated' => array('title' => LAN_MAILOUT_257, 'noedit'=>true, 'proc' => 'chars'), 'mail_other' => array('title' => LAN_MAILOUT_84, 'type'=>null, 'noedit'=>true, 'data'=>'array', 'nolist'=>true), - + 'options' => array('title' => LAN_OPTIONS, 'type'=>'method', 'width'=>'10%', 'forced' => TRUE) ); @@ -591,16 +593,17 @@ class mailout_main_ui extends e_admin_ui function previewPage() { $mailData = e107::getDb()->retrieve('mail_content','*','mail_source_id='.intval($_GET['id'])." LIMIT 1"); - + $data = $this->mailAdmin->dbToMail($mailData); $eml = array( 'subject' => $data['mail_subject'], 'body' => $data['mail_body'], 'template' => $data['mail_send_style'], - 'shortcodes' => array('USERNAME'=>'John Example', 'DISPLAYNAME'=> 'John Example', 'USERID'=>'555', 'UNSUBSCRIBE'=>SITEURL."unsubscribe/?id=example1234567") + 'shortcodes' => array('USERNAME'=>'John Example', 'DISPLAYNAME'=> 'John Example', 'USERID'=>'555', 'UNSUBSCRIBE'=>SITEURL."unsubscribe/?id=example1234567"), + 'media' => $data['mail_media'], ); - + return e107::getEmail()->preview($eml); exit; @@ -1297,7 +1300,10 @@ class mailout_admin_form_ui extends e_admin_form_ui if($mode == 'sent' || $mode == 'pending' || $mode == 'held') { $link = e_SELF."?searchquery=&filter_options=mail_detail_id__".$id."&mode=recipients&action=list"; + $preview = e_SELF."?mode=main&action=preview&id=".$id; $text .= "".E_32_USER.""; + $text .= "".E_32_SEARCH.""; + $att['readParms']['editClass'] = e_UC_NOBODY; $text .= $this->renderValue('options',$value,$att,$id); return $text; diff --git a/e107_core/sql/core_sql.php b/e107_core/sql/core_sql.php index f185b9b52..2ed42e058 100644 --- a/e107_core/sql/core_sql.php +++ b/e107_core/sql/core_sql.php @@ -273,6 +273,7 @@ CREATE TABLE mail_content ( mail_body text, mail_body_templated text, mail_other text, + mail_media text, PRIMARY KEY (mail_source_id), KEY mail_content_status (mail_content_status) ) ENGINE=MyISAM; diff --git a/e107_core/templates/email_template.php b/e107_core/templates/email_template.php index 51d6719a4..9f9562d9b 100644 --- a/e107_core/templates/email_template.php +++ b/e107_core/templates/email_template.php @@ -37,8 +37,6 @@ See e_HANDLER.mail.php for more information if (!defined('e107_INIT')) { exit; } - -// @TODO: Move signup email into templated form $includeSiteButton = e107::getPref('sitebutton'); /* @@ -159,6 +157,7 @@ LAN_SIGNUP_97." {SITENAME}
* Format for individual emails sent by e107 (not bulk emails for now) - a work in progress - bulk could be ported later. * @see e107Email::sendEmail(); * Aim: to make email templates follow the same spec. as other templates while remaining as intuitive as other v2 templates in e107. + * Note: giving a template a 'name' value will make it available in the admin->mailout area. */ @@ -172,7 +171,8 @@ $EMAIL_TEMPLATE['default']['header'] = " @@ -264,21 +264,23 @@ $EMAIL_TEMPLATE['notify']['body'] = $EMAIL_TEMPLATE['default']['body']; // wi $EMAIL_TEMPLATE['notify']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default header above. -// ------ User-Mailout Templates +// ------ User-Specific Templates -$EMAIL_TEMPLATE['user-monthly']['name'] = 'Monthly Update'; -$EMAIL_TEMPLATE['user-monthly']['subject'] = '{SITENAME}: {SUBJECT} '; -$EMAIL_TEMPLATE['user-monthly']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. -$EMAIL_TEMPLATE['user-monthly']['body'] = "Just to keep you up to date, here's a reminder of what's changed in the past month.
{BODY}
To find out more, simply click on the links!"; -$EMAIL_TEMPLATE['user-monthly']['footer'] = $EMAIL_TEMPLATE['default']['footer']; +$EMAIL_TEMPLATE['monthly']['name'] = 'Monthly Update'; +$EMAIL_TEMPLATE['monthly']['subject'] = '{SITENAME}: {SUBJECT} '; +$EMAIL_TEMPLATE['monthly']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. +$EMAIL_TEMPLATE['monthly']['body'] = "Just to keep you up to date, here's a reminder of what's changed in the past month.
{BODY}{MEDIA1}{MEDIA2}{MEDIA3}{MEDIA4}{MEDIA5}To find out more, simply click on the links!"; +$EMAIL_TEMPLATE['monthly']['footer'] = $EMAIL_TEMPLATE['default']['footer']; -$EMAIL_TEMPLATE['user-whatsnew']['name'] = "What's New"; -$EMAIL_TEMPLATE['user-whatsnew']['subject'] = '{SITENAME}: {SUBJECT} '; -$EMAIL_TEMPLATE['user-whatsnew']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. -$EMAIL_TEMPLATE['user-whatsnew']['body'] = "All the latest news and updates.
{BODY}
To find out more, simply click on the links!"; -$EMAIL_TEMPLATE['user-whatsnew']['footer'] = $EMAIL_TEMPLATE['default']['footer']; + + +$EMAIL_TEMPLATE['whatsnew']['name'] = "What's New"; +$EMAIL_TEMPLATE['whatsnew']['subject'] = '{SITENAME}: {SUBJECT} '; +$EMAIL_TEMPLATE['whatsnew']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. +$EMAIL_TEMPLATE['whatsnew']['body'] = "All the latest news and updates.
{BODY}
To find out more, simply click on the links!"; +$EMAIL_TEMPLATE['whatsnew']['footer'] = $EMAIL_TEMPLATE['default']['footer']; diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 66253db74..ae7f560b4 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2949,6 +2949,21 @@ class e_parser return "Youtube Video"; } + if($thumb == 'email') + { + $thumbSrc = "http://i1.ytimg.com/vi/".$id."/maxresdefault.jpg"; // 640 x 480 + $filename = 'temp/yt-thumb-'.md5($id).".jpg"; + $filepath = e_MEDIA.$filename; + $url = 'http://youtu.be/'.$id; + + if(!file_exists($filepath)) + { + e107::getFile()->getRemoteFile($thumbSrc, $filename,'media'); + } + + return "Youtube Video"; + } + if($thumb == 'src') { return $thumbSrc; diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index aab1b1b7c..2f76952ee 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -619,6 +619,42 @@ class e107Email extends PHPMailer } + function processShortcodes($eml) + { + $tp = e107::getParser(); + + $eml['shortcodes']['BODY'] = $tp->toEmail($eml['body']); + $eml['shortcodes']['SUBJECT'] = $eml['subject']; + $eml['shortcodes']['THEME'] = 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); + + if($tp->isVideo($val['path'])) + { + $eml['shortcodes'][$id] = "
".$tp->toVideo($val['path'],array('thumb'=>'email'))."
"; + } + else + { + $eml['shortcodes'][$id] = "
"; + } + + } + } + + + } + + return $eml['shortcodes']; + + } + /** * Sets one or more parameters from an array. See @see{sendEmail()} for list of parameters @@ -645,15 +681,20 @@ class e107Email extends PHPMailer } + if(vartrue($eml['template'])) // @see e107_core/templates/email_template.php - { + { 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['shortcodes']['BODY'] = $tp->toEmail($eml['body']); - $eml['shortcodes']['SUBJECT'] = $eml['subject']; - $eml['shortcodes']['THEME'] = e_THEME.$this->pref['sitetheme'].'/'; // Always use front-end theme path. + // $eml['shortcodes']['BODY'] = $tp->toEmail($eml['body']); + // $eml['shortcodes']['SUBJECT'] = $eml['subject']; + // $eml['shortcodes']['THEME'] = e_THEME.$this->pref['sitetheme'].'/'; // Always use front-end theme path. + $eml['shortcodes'] = $this->processShortcodes($eml); + + // print_a($eml); + $emailBody = $tmpl['header']. $tmpl['body'] . $tmpl['footer']; $eml['body'] = $tp->parseTemplate($emailBody, true, varset($eml['shortcodes'],null)); diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php index 3a5ba7ce6..35009ec34 100644 --- a/e107_handlers/mail_manager_class.php +++ b/e107_handlers/mail_manager_class.php @@ -315,6 +315,12 @@ class e107MailManager $res[$f] = ''; } } + + if (isset($data['mail_media'])) + { + $res['mail_media'] = e107::unserialize($data['mail_media']); + } + return $res; } @@ -443,6 +449,12 @@ class e107MailManager $tmp = e107::unserialize(str_replace('\\\'', '\'',$data['mail_target_info'])); // May have escaped data $res['mail_target_info'] = $tmp; } + + if (isset($data['mail_media'])) + { + $res['mail_media'] = e107::unserialize($data['mail_media']); + } + return $res; } diff --git a/e107_handlers/mailout_admin_class.php b/e107_handlers/mailout_admin_class.php index e01d7e244..74e56fab2 100644 --- a/e107_handlers/mailout_admin_class.php +++ b/e107_handlers/mailout_admin_class.php @@ -2049,7 +2049,7 @@ class mailoutAdminClass extends e107MailManager foreach($templates as $key => $layout) { - if(substr($key, 0, 5) == 'user-' || $key == 'default') + if(vartrue($layout['name'])) { $ret[$key] = $layout['name']; }