get('mail_pause',1);
$mailManager = new e107MailManager();
$mailManager->doEmailTask($perAjaxHit);
$sqld = e107::getDb('progress');
$sqld->select("mail_content","mail_total_count,mail_togo_count,mail_sent_count,mail_fail_count","mail_source_id= ".intval($id) );
$row = $sqld->fetch();
$rand = ($row['mail_sent_count'] + $row['mail_fail_count']);
$total = ($row['mail_total_count']);
$errors = ob_get_clean();
$errors .= " id=".$id;
e107::getMessage()->addDebug($errors);
$inc = round(($rand / $total) * 100);
$errors .= " inc=".$inc;
file_put_contents(e_LOG.'send-mail-progress.txt',$errors);
e107::getMessage()->addDebug("Returned: ".$inc);
return $inc;
}
if(!empty($_GET['iframe']))
{
define('e_IFRAME', true);
}
if(e_AJAX_REQUEST)
{
$id = intval($_GET['mode']);
echo sendProgress($id);
exit;
}
if(vartrue($_GET['mode']) == "progress")
{
// session_write_close();
// sendProgress();
// exit;
}
$mes = e107::getMessage();
$tp = e107::getParser();
/*
if($_GET['mode']=="process")
{
session_write_close(); // allow other scripts to run in parallel.
header('Content-Encoding: none');
ignore_user_abort(true);
set_time_limit(0);
header("Content-Length: $size");
header('Connection: close');
$mailManager = new e107MailManager();
$mailManager->doEmailTask(999999);
echo "Completed Mailout ID: ".$_GET['id'];
exit;
}
*/
class mailout_admin extends e_admin_dispatcher
{
protected $modes = array(
'main' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'saved' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'pending' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'held' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'sent' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'prefs' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'maint' => array(
'controller' => 'mailout_main_ui',
'path' => null,
'ui' => 'mailout_admin_form_ui',
'uipath' => null
),
'recipients' => array(
'controller' => 'mailout_recipients_ui',
'path' => null,
'ui' => 'mailout_recipients_form_ui',
'uipath' => null
)
);
protected $adminMenu = array(
// 'makemail/makemail' => array('caption'=> LAN_MAILOUT_190, 'perm' => 'W', 'url'=>e_SELF),
'main/list' => array('caption'=> LAN_MANAGE, 'perm'=> 'W'),
'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'W'),
'recipients/list' => array('caption'=> "Recipients", 'perm' => 'W'),
// 'main/send' => array('caption'=> "Send", 'perm' => 'W'),
'other' => array('divider'=> true),
// 'saved/list' => array('caption'=> LAN_MAILOUT_191, 'perm' => 'W'),
'pending/list' => array('caption'=> LAN_MAILOUT_193, 'perm' => 'W'),
'held/list' => array('caption'=> LAN_MAILOUT_194, 'perm' => 'W'),
'sent/list' => array('caption'=> LAN_MAILOUT_192, 'perm' => 'W'),
'other2' => array('divider'=> true),
'prefs/prefs' => array('caption'=> LAN_PREFS, 'perm' => '0'),
'maint/maint' => array('caption'=> ADLAN_40, 'perm' => '0'),
'main/templates' => array('caption'=> 'Template Preview', 'perm' => '0'),
);
protected $adminMenuAliases = array(
'main/send' => 'main/create',
);
protected $menuTitle = LAN_MAILOUT_15;
}
class mailout_main_ui extends e_admin_ui
{
//TODO Move to Class above.
protected $pluginTitle = LAN_MAILOUT_15;
protected $pluginName = LAN_MAILOUT_15;
protected $table = "mail_content";
// protected $listQry = null;
// protected $editQry = "SELECT * FROM #mail_content WHERE cust_id = {ID}";
protected $pid = "mail_source_id";
protected $perPage = 10;
protected $listOrder = "mail_source_id desc";
protected $batchDelete = true;
protected $batchCopy = true;
protected $tabs = array(LAN_BASIC,LAN_ADVANCED);
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'mail_source_id' => array('title' => LAN_MAILOUT_137, 'width' =>'5%', 'thclass' => 'center', 'class'=>'center', 'forced' => TRUE),
'mail_selectors' => array('title' => LAN_MAILOUT_03, 'type'=>'method', 'data'=>false, 'nolist' => true, 'writeParms'=>'nolabel=0'),
'mail_title' => array('title' => LAN_TITLE, 'type'=>'text', 'forced' => TRUE, 'data'=>'str', 'inline'=>true, 'writeParms'=>'size=xxlarge&required=1', 'help'=>''),
'mail_sender_name' => array('title' => LAN_MAILOUT_150, 'type'=>'method', 'data'=>false),
'mail_sender_email' => array('title' => LAN_MAILOUT_149,'type'=>'method','data'=>false),
'mail_copy_to' => array('title' => LAN_MAILOUT_151,'tab'=>1, 'type'=>'method','data'=>false),
'mail_bcopy_to' => array('title' => LAN_MAILOUT_152,'tab'=>1, 'type'=>'method','data'=>false),
'mail_subject' => array('title' => LAN_MAILOUT_06, 'type'=>'text', 'forced' => TRUE,'data'=>'str', 'inline'=>true, 'writeParms'=>'size=xxlarge&required=1'),
'mail_content_status' => array('title' => LAN_MAILOUT_136, 'tab'=>1, 'type'=> 'dropdown', 'data'=>'int', 'filter'=>false, 'inline'=>false, 'thclass' => 'left', 'class'=>'left'),
'mail_total_count' => array('title' => "Total Recipients", 'noedit'=>true, 'type'=>'number'),
'mail_sent_count' => array('title' => LAN_MAILOUT_82, 'noedit'=>true, 'type'=>'number'),
'mail_togo_count' => array('title' => LAN_MAILOUT_83, 'noedit'=>true, 'type'=>'number'),
'mail_fail_count' => array('title' => LAN_MAILOUT_128, 'noedit'=>true, 'type'=>'number'),
'mail_bounce_count' => array('title' => LAN_MAILOUT_144, 'noedit'=>true, 'type'=>'number'),
'mail_start_send' => array('title' => LAN_MAILOUT_131,'noedit'=>true, 'type'=>'datestamp'),
'mail_end_send' => array('title' => LAN_MAILOUT_132, 'noedit'=>true, 'type'=>'datestamp'),
'mail_create_date' => array('title' => LAN_MAILOUT_130, 'type'=>null, 'noedit'=>true, 'data'=>'int'),
'mail_creator' => array('title' => LAN_MAILOUT_85, 'type'=>null, 'noedit'=>true, 'data'=>'int'),
'mail_create_app' => array('title' => LAN_MAILOUT_133, 'type'=>null, 'noedit'=>true,'data'=>'str'),
'mail_e107_priority' => array('title' => LAN_MAILOUT_134, 'noedit'=>true),
'mail_notify_complete' => array('title' => LAN_MAILOUT_243, 'noedit'=>true, 'nolist' => true),
'mail_last_date' => array('title' => LAN_MAILOUT_129, 'noedit'=>true, 'type'=>'int', 'proc' => 'sdatetime'),
'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)
);
protected $fieldpref = array('checkboxes', 'mail_source_id', 'mail_title', 'mail_subject', 'mail_content_status', 'options');
// optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName);
protected $prefs = array(
// 'after_submit' => array('title'=> 'Custom After Submit Text:', 'type'=>'bbarea')
// 'submit_question' => array('title'=> 'Allow submitting of Questions by:', 'type'=>'userclass'),
// 'classic_look' => array('title'=> 'Use Classic Layout', 'type'=>'boolean')
);
public $mailAdmin = null;
private $selectFields = array('email_to',
'extended_1_name','extended_1_value',
'extended_2_name', 'extended_2_value',
'user_search_name', 'user_search_value',
'last_visit_match', 'last_visit_date'
);
private $mailOtherFields = array(
'mail_sender_email',
'mail_sender_name',
'mail_copy_to',
'mail_bcopy_to',
'mail_attach',
'mail_send_style', // HTML, text, template name etc
'mail_selectors', // Only used internally
'mail_include_images', // Used to determine whether to embed images, or link to them
'mail_body_alt' , // If non-empty, use for alternate email text (generally the 'plain text' alternative)
'mail_overrides'
);
function afterDelete($del_data,$id)
{
$result = e107::getDb()->delete('mail_recipients', 'mail_detail_id = '.intval($id));
// $this->getModel()->addMessageDebug("Deleted ".$result." recipients from the deleted email #".$id);
// e107::getMessage()->addDebug("Deleted ".$result." recipients from the deleted email #".$id, 'default', true);
}
function init()
{
$action = varset($_GET['mode'], 'main');
$this->mailAdmin = new mailoutAdminClass($action);
if($_GET['action'] == 'preview')
{
echo $this->previewPage($_GET['id'], $_GET['user']);
exit;
}
if ($this->mailAdmin->loadMailHandlers() == 0)
{
e107::getMessage()->addDebug('No mail handlers loaded!!');
}
/*
define('MAIL_STATUS_SENT', 0); // Mail sent. Email handler happy, but may have bounced (or may be yet to bounce)
define('MAIL_STATUS_BOUNCED', 1);
define('MAIL_STATUS_CANCELLED', 2);
define('MAIL_STATUS_PARTIAL', 3); // A run which was abandoned - errors, out of time etc
define('MAIL_STATUS_FAILED', 5); // Failure on initial send - rejected by selected email handler
// This must be the numerically highest 'processing complete' code
define('MAIL_STATUS_PENDING', 10); // Mail which is in the sending list (even if outside valid sending window)
// This must be the numerically lowest 'not sent' code
// E107_EMAIL_MAX_TRIES values used in here for retry counting
define('MAIL_STATUS_MAX_ACTIVE', 19); // Highest allowable 'not sent or processed' code
define('MAIL_STATUS_SAVED', 20); // Identifies an email which is just saved (or in process of update)
define('MAIL_STATUS_HELD',21); // Held pending release
define('MAIL_STATUS_TEMP', 22); // Tags entries which aren't yet in any list
*/
$types = array(10=>'Pending',20=>"Saved", 21=>"Held", 0=>'Sent', 1=>'Bounced', 2=>'Cancelled', 3=> 'Partial', 5=>'Failed', 19 => "Max Active", 22=>"Temp");
$qr = array('saved'=>20,'pending'=>10,'held'=>21,'sent'=>0);
if($action !== 'main' )
{
$this->listQry = "SELECT * FROM `#mail_content` WHERE mail_content_status = ".varset($qr[$action],20);
}
else
{
$this->listQry = "SELECT * FROM `#mail_content` WHERE (mail_content_status = ".MAIL_STATUS_TEMP ." OR mail_content_status = ".MAIL_STATUS_SAVED.")";
}
if($action == 'sent' || $action == 'pending' || $action == 'held')
{
$this->fieldpref = array('checkboxes', 'mail_source_id', 'mail_title', 'mail_subject','mail_total_count', 'mail_togo_count', 'mail_sent_count', 'mail_fail_count', 'mail_bounce_count', 'options');
}
$this->fields['mail_content_status']['writeParms'] = $types;
$this->processSendActions();
$mes = e107::getMessage();
if (getperms('0'))
{
if (isset($_POST['testemail']))
{
$this->sendTestEmail(); // Send test email - uses standard 'single email' handler
}
if(!empty($_POST['send_bounce_test']))
{
$this->sendTestBounce();
}
elseif (isset($_POST['updateprefs']))
{
$this->saveMailPrefs($mes); // TODO check if functional, $emessage -> $mes
}
elseif(!empty($_POST['DKIM_generate']))
{
$this->generateDKIM();
}
}
}
/**
*
* https://www.mail-tester.com/spf-dkim-check
* http://dkimvalidator.com/
* @return bool
*/
private function generateDKIM()
{
$privatekeyfile = e_SYSTEM.'dkim_private.key';
$tp = e107::getParser();
if(file_exists($privatekeyfile))
{
e107::getMessage()->addInfo("DKIM keys already exists (".$privatekeyfile.")");
$text = $this->getDKIMPublicKey();
e107::getMessage()->addInfo("Add the following to your ".e_DOMAIN." DNS Zone records:".print_a($text,true));
e107::getMessage()->addinfo("Consider testing it using this website: http://dkimvalidator.com");
return false;
}
$keyLength = 1024; // Any higher and cPanel < 11.50 will refuse it.
$pk = openssl_pkey_new(
array(
"digest_alg" => "sha1",
'private_key_bits' => $keyLength, // (2048 bits is the recommended minimum key length - gmail won't accept less than 1024 bits)
'private_key_type' => OPENSSL_KEYTYPE_RSA
)
);
openssl_pkey_export_to_file($pk, $privatekeyfile);
// $contents = file_get_contents($privatekeyfile);
$tmp = openssl_pkey_get_details($pk);
$pubKey = $tmp['key'];
file_put_contents( e_SYSTEM."dkim_public.key",$pubKey);
// e107::getMessage()->addInfo(nl2br($pubKey));
$pubString = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\n"),"",$pubKey);
// $dnsEntry = 'phpmailer._domainkey IN TXT "v=DKIM1; k=rsa; g=*; s=email; h=sha1; t=s; p=[x];"';
$dnsEntry = 'phpmailer._domainkey IN TXT "v=DKIM1; k=rsa; p=[x];"';
$text = $tp->lanVars($dnsEntry, $pubString);
e107::getMessage()->addInfo("Add the following ".$keyLength." bit key to your ".e_DOMAIN." DNS Zone records:".print_a($text,true));
e107::getMessage()->addinfo("Consider testing it using this website: http://dkimvalidator.com");
}
private function getDKIMPublicKey()
{
$pubKey = file_get_contents( e_SYSTEM."dkim_public.key");
$pubString = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\n"),"",$pubKey);
// $dnsEntry = 'phpmailer._domainkey IN TXT "v=DKIM1; k=rsa; g=*; s=email; h=sha1; t=s; p=[x];"';
$dnsEntry = 'phpmailer._domainkey IN TXT "v=DKIM1; k=rsa; p=[x];"';
return e107::getParser()->lanVars($dnsEntry, $pubString);
}
private function sendTestBounce()
{
$mes = e107::getMessage();
$pref = e107::getPref();
$sendto = $pref['mail_bounce_email'];
$eml = array('subject'=>'Test Bounce', 'body' => 'Test Bounce Email address','e107_header'=>99999999, 'extra_header' => 'X-Bounce-Test: true');
if(e107::getEmail()->sendEmail($sendto, 'Bounce handler', $eml))
{
$mes->addSuccess('Test Bounce sent to '.$sendto);
}
else
{
$mes->addError('Failed Bounce email sent to '.$sendto);
}
}
private function sendTestEmail()
{
$mes = e107::getMessage();
$pref = e107::getPref();
if(trim($_POST['testaddress']) == '')
{
$mes->addError(LAN_MAILOUT_19);
$subAction = 'error';
}
else
{
$add = ($pref['mailer']) ? " (".strtoupper($pref['mailer']).") " : ' (PHP)';
if($pref['mailer'] == 'smtp')
{
$add .= "Port: ".varset($pref['smtp_port'],25);
$add .= " - ".str_replace("secure=", "", $pref['smtp_options']);
}
$sendto = trim($_POST['testaddress']);
$subjectSitename = ($_POST['testtemplate'] == 'textonly') ? SITENAME : '';
$eml = array(
'e107_header' => USERID,
'subject' => LAN_MAILOUT_113." ".$subjectSitename.$add,
'body' => str_replace("[br]", "\n", LAN_MAILOUT_114),
'template' => vartrue($_POST['testtemplate'],null),
'shortcodes' => $this->getExampleShortcodes(),
'media' => array(
0 => array('path' => '{e_PLUGIN}gallery/images/butterfly.jpg'),
1 => array('path' => 'h-v880sXEOQ.youtube'),
)
);
if(E107_DEBUG_LEVEL > 0)
{
$eml['SMTPDebug'] = true;
}
if (!e107::getEmail()->sendEmail($sendto, LAN_MAILOUT_189, $eml))
{
$mes->addError(($pref['mailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106);
}
else
{
$mes->addSuccess(LAN_MAILOUT_81. ' ('.$sendto.')');
e107::getAdminLog()->log_event('MAIL_01', $sendto, E_LOG_INFORMATIVE,'');
}
}
}
public function beforeCreate($new_data, $old_data)
{
$ret = $this->processData($new_data);
$ret['mail_create_date'] = time();
$ret['mail_creator'] = USERID;
$ret['mail_create_app'] = 'core';
$ret['mail_content_status'] = MAIL_STATUS_TEMP;
return $ret;
}
public function beforeUpdate($new_data, $old_data, $id)
{
$ret = $this->processData($new_data);
$ret['mail_content_status'] = MAIL_STATUS_TEMP;
return $ret;
}
function afterCopy($firstInsert, $copied)
{
$num = array();
$count = 0;
foreach($copied as $tmp)
{
$num[] = ($firstInsert + $count);
$count ++;
}
if(!empty($firstInsert))
{
$update = array(
'mail_content_status' => MAIL_STATUS_TEMP,
'mail_total_count' => 0,
'mail_togo_count' => 0,
'mail_sent_count' => 0,
'mail_fail_count' => 0,
'mail_bounce_count' => 0,
'mail_start_send' => '',
'mail_end_send' => '',
'mail_create_date' => time(),
'WHERE' => "mail_source_id IN (".implode(",",$num).")" // FIXME Currently modifies the original instead of the copy.
);
if(!e107::getDb()->update('mail_content',$update))
{
e107::getMessage()->addDebug(print_a($update,true));
}
}
}
private function processSendActions()
{
if((vartrue($_POST['email_send']) || vartrue($_POST['email_hold']) || vartrue($_POST['email_cancel'])) && !vartrue($_POST['email_id']))
{
e107::getMessage()->addError("No Message ID submitted");
return;
}
$id = intval($_POST['email_id']);
if(vartrue($_POST['email_send']))
{
$this->emailSend($id);
}
if(vartrue($_POST['email_hold']))
{
$this->emailHold($id);
}
if(vartrue($_POST['email_cancel']))
{
$this->emailCancel($id);
}
}
private function emailSendNow($id)
{
}
private function emailSend($mailId)
{
$log = e107::getAdminLog();
$notify = isset($_POST['mail_notify_complete']) ? 3 : 2;
$first = 0;
$last = 0; // Set defaults for earliest and latest send times.
if (isset($_POST['mail_earliest_time']))
{
$first = e107::getDateConvert()->decodeDateTime($_POST['mail_earliest_time'], 'datetime', CORE_DATE_ORDER, FALSE);
}
if (isset($_POST['mail_latest_time']))
{
$last = e107::getDateConvert()->decodeDateTime($_POST['mail_earliest_time'], 'datetime', CORE_DATE_ORDER, TRUE);
}
if ($this->mailAdmin->activateEmail($mailId, FALSE, $notify, $first, $last))
{
e107::getMessage()->addSuccess(LAN_MAILOUT_185);
$log->log_event('MAIL_06','ID: '.$mailId,E_LOG_INFORMATIVE,'');
}
else
{
$errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_188);
}
}
private function emailHold($mailId)
{
if ($this->mailAdmin->activateEmail($mailId, TRUE))
{
e107::getMessage()->addSuccess(str_replace('--ID--', $mailId, LAN_MAILOUT_187));
}
else
{
$errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_166);
}
}
private function emailCancel($mailId)
{
if ($this->mailAdmin->cancelEmail($mailId))
{
e107::getMessage()->addSuccess(str_replace('--ID--', $mailId, LAN_MAILOUT_220));
}
else
{
$errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_221);
}
}
/**
* Preview the Email.
*/
function previewPage($id='', $user=null)
{
if(is_numeric($id))
{
$mailData = e107::getDb()->retrieve('mail_content','*','mail_source_id='.intval($id)." LIMIT 1");
$shortcodes = array(
'USERNAME'=>'John Example',
'DISPLAYNAME'=> 'John Example',
'USERID'=>'555', 'MAILREF'=>$_GET['id'],
'LOGINNAME' => 'johnE',
'ACTIVATION_LINK' => SITEURL.'signup.php?testing-activation',
'PASSWORD' => 'MyPass123',
'NEWSLETTER'=>SITEURL."newsletter/?id=example1234567",
'UNSUBSCRIBE'=>SITEURL."unsubscribe/?id=example1234567");
if(!empty($user))
{
$userData = e107::getDb()->retrieve('mail_recipients','*', 'mail_detail_id = '.intval($id).' AND mail_recipient_id = '.intval($user).' LIMIT 1');
$shortcodes = e107::unserialize(stripslashes($userData['mail_target_info']));
}
$data = $this->mailAdmin->dbToMail($mailData);
$eml = array(
'subject' => $data['mail_subject'],
'body' => $data['mail_body'],
'template' => $data['mail_send_style'],
'shortcodes' => $shortcodes,
'media' => $data['mail_media'],
);
// return print_a($data,true);
}
else
{
// e107::coreLan('signup');
$tp = e107::getParser();
$eml = array(
'subject' => 'Test Subject',
'body' => "This is the body text of your email. Included are example media attachments such as images and video thumbnails.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquam volutpat risus, a efficitur ex dignissim ac. Phasellus ornare tortor est, a elementum orci finibus non! Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce feugiat bibendum venenatis. Ut sit amet purus id magna consequat euismod vitae ac elit. Maecenas rutrum nisi metus, sed pulvinar velit fermentum eu? Aliquam erat volutpat.
Ut risus massa, consequat et gravida vitae, tincidunt in metus. Nam sodales felis non tortor faucibus lacinia! Integer neque libero, maximus eu cursus nec, fringilla varius erat. Phasellus elementum scelerisque mauris at fermentum. Aliquam erat volutpat. Aliquam sit amet placerat leo, vitae mollis purus. Nulla laoreet nulla pretium risus placerat, a luctus risus pulvinar. Duis ut dolor sed arcu aliquam dictum sed auctor magna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam eleifend in mi lobortis blandit. Aliquam vestibulum rhoncus vestibulum. Cras metus.",
'template' => $id,
'shortcodes' => $this->getExampleShortcodes(),
'media' => array(
0 => array('path' => '{e_PLUGIN}gallery/images/butterfly.jpg'),
1 => array('path' => 'h-v880sXEOQ.youtube'),
2 => array('path' => '_j0b9syAuIk.youtube'),
3 => array('path' => '{e_PLUGIN}gallery/images/horse.jpg'),
4 => array('path' => '{e_PLUGIN}gallery/images/lake-and-forest.jpg'),
)
);
}
return e107::getEmail()->preview($eml);
exit;
}
function getExampleShortcodes()
{
$tp = e107::getParser();
return array(
'USERNAME' =>'test-username',
'EMAIL' => 'test@email.com',
'DISPLAYNAME' => 'John Example',
'USERID' =>'555',
'MAILREF' => '123',
'NEWSLETTER' => SITEURL."newsletter/?id=example1234567",
'UNSUBSCRIBE' => SITEURL."unsubscribe.php?id=example1234567",
'UNSUBSCRIBE_MESSAGE'=> "This email was sent to test@email.com. If you don't want to receive these emails in the future, please unsubscribe. ",
'ACTIVATION_LINK' => "http://whereever.to.activate.com/",
'USERURL' => "www.user-website.com",
'PASSWORD' => "test-password",
'LOGINNAME' => "test-loginname",
'SUBJECT' => "Test Subject",
'DATE_SHORT' => $tp->toDate(time(),'short'),
'DATE_LONG' => $tp->toDate(time(),'long')
);
}
function templatesPage()
{
$templates = e107::getCoreTemplate('email',null,'front');
$tab = array();
foreach($templates as $k=>$layout)
{
$caption = $k;
$text = "";
$tab[$k] = array('caption'=>$caption, 'text'=>$text);
}
return e107::getForm()->tabs($tab);
}
/**
* Process Posted Data
*/
private function processData($new_data)
{
$other = array();
$ret = $new_data;
foreach($new_data as $k=>$v)
{
if(in_array($k, $this->mailOtherFields))
{
$other[$k] = $v;
unset($ret[$k]);
}
}
$other['mail_selectors'] = $this->mailAdmin->getAllSelectors();
$ret['mail_attach'] = trim($new_data['mail_attach']);
$ret['mail_send_style'] = varset($new_data['mail_send_style'],'textonly');
$ret['mail_include_images'] = (isset($new_data['mail_include_images']) ? 1 : 0);
$ret['mail_other'] = $other; // type is set to 'array' in $fields.
// e107::getMessage()->addInfo(print_a($ret,true));
return $ret;
}
/*
function createPage()
{
if (!isset($mailData) || !is_array($mailData))
{
$mailData = array(); // Empty array just in case
}
if($id = $this->getId())
{
$mailData = e107::getDB()->retrieve('mail_content','*','mail_source_id='.$id);
}
return $this->mailAdmin->show_mailform($mailData);
}
*/
function sendnowPage()
{
$id = $this->getId();
$this->getResponse()->setTitle(LAN_MAILOUT_15.SEP.'Process Mail Queue #'.$id);
e107::getDb()->update('mail_content', 'mail_content_status='.MAIL_STATUS_PENDING.' WHERE mail_source_id = '.intval($id));
e107::getDb()->update('mail_recipients', 'mail_status='.MAIL_STATUS_PENDING.' WHERE mail_detail_id = '.intval($id));
if(E107_DEBUG_LEVEL > 0)
{
echo "
".LAN_MAILOUT_20.": |