function PommoMTA($args = array()) { $defaults = array('queueSize' => 100, 'maxRunTime' => 80, 'skipSecurity' => false, 'start' => time(), 'serial' => false, 'spawn' => 1); $p = PommoAPI::getParams($defaults, $args); foreach ($p as $k => $v) { $this->{'_' . $k} = $v; } // protect against safe mode timeouts if (ini_get('safe_mode')) { $this->_maxRunTime = ini_get('max_execution_time') - 10; } else { set_time_limit(0); } // protect against user (client) abort ignore_user_abort(true); // register shutdown method register_shutdown_function(array(&$this, "shutdown")); // set parameters from URL $this->_code = empty($_GET['code']) ? 'invalid' : $_GET['code']; $this->_test = isset($_GET['test']); $this->_id = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : false; // verify and initialize the current mailing $p = array('active' => true, 'code' => $this->_skipSecurity ? null : $this->_code, 'id' => $this->_id ? $this->_id : null); $this->_mailing = current(PommoMailing::get($p)); if (!is_numeric($this->_mailing['id'])) { $this->shutdown('Unable to initialize mailing.'); } $this->_id = $this->_mailing['id']; // make sure the $_GET global holds the mailing id (used in personalizations, etc.) $_GET['id'] = $this->_id; // security routines if ($this->_mailing['end'] > 0) { $this->shutdown(Pommo::_T('Mailing Complete.')); } if (empty($this->_mailing['serial'])) { if (!PommoMailCtl::mark($this->_serial, $this->_id)) { $this->shutdown('Unable to serialize mailing (ID: ' . $this->_id . ' SERIAL: ' . $this->_serial . ')'); } } if ($this->_maxRunTime < 15) { $this->shutdown('Max Runtime must be at least 15 seconds!'); } $this->_queue = $this->_sent = $this->_failed = array(); return; }
} else { // temp subscriber created $state['tally'] = 1; $state['group'] = Pommo::_T('Test Mailing'); if ($state['ishtml'] == 'off') { $state['body'] = $state['altbody']; $state['altbody'] = ''; } // create mailing $mailing = PommoMailing::make(array(), TRUE); $state['status'] = 1; $state['current_status'] = 'stopped'; $state['command'] = 'restart'; $state['charset'] = $state['list_charset']; $mailing = PommoHelper::arrayIntersect($state, $mailing); $code = PommoMailing::add($mailing); // populate queue $queue = array($key); if (!PommoMailCtl::queueMake($queue)) { $logger->addErr('Unable to Populate Queue'); } else { if (!PommoMailCtl::spawn($pommo->_baseUrl . 'admin/mailings/mailings_send4.php?test=TRUE&code=' . $code)) { $logger->addErr('Unable to spawn background mailer'); } else { $smarty->assign('sent', $_POST['email']); } } } } elseif ($current) { $logger->addMsg(Pommo::_T('A mailing is currently taking place. Please try again later.')); $smarty->assign($_POST);
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ /********************************** INITIALIZATION METHODS *********************************/ require '../../bootstrap.php'; Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/mailings.php'); $config = PommoAPI::configGet('public_history'); if ($config['public_history'] == 'on') { $pommo->init(array('authLevel' => 0)); } else { Pommo::redirect('login.php'); } $logger =& $pommo->_logger; $dbo =& $pommo->_dbo; if (isset($_REQUEST['mailings'])) { if (is_array($_REQUEST['mailings'])) { $_REQUEST['mailings'] = $_REQUEST['mailings'][0]; } $mailing = current(PommoMailing::get(array('id' => $_REQUEST['mailings']))); } else { die; } /********************************** SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->assign($mailing); $smarty->display('inc/mailing.tpl'); Pommo::kill();
if (!empty($_REQUEST['sord']) && ($_REQUEST['sord'] == 'asc' || $_REQUEST['sord'] == 'desc')) { $state['order'] = $_REQUEST['sord']; } // Calculate the offset $start = $state['limit'] * $state['page'] - $state['limit']; if ($start < 0) { $start = 0; } /********************************** RECORD RETREVIAL *********************************/ // normalize sort to database column if ($state['sort'] == 'start') { $state['sort'] = 'started'; } // Fetch Mailings for this Page $mailings = PommoMailing::get(array('noBody' => TRUE, 'sort' => $state['sort'], 'order' => $state['order'], 'limit' => $state['limit'], 'offset' => $start)); /********************************** OUTPUT FORMATTING *********************************/ $records = array(); foreach ($mailings as $o) { $row = array('id' => $o['id'], 'subject' => $o['subject'], 'start' => $o['start']); if ($o['status'] == 0) { // only return "complete" mailings array_push($records, $row); } } // format for JSON output to jqGrid $json->add(array('page' => $state['page'], 'total' => $state['pages'], 'records' => PommoMailing::tally(), 'rows' => $records)); $json->serve();
/********************************** INITIALIZATION METHODS *********************************/ require '../../../bootstrap.php'; Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/mailings.php'); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/groups.php'); $pommo->init(); $logger =& $pommo->_logger; $dbo =& $pommo->_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->prepareForForm(); if (PommoMailing::isCurrent()) { Pommo::kill(sprintf(Pommo::_T('A Mailing is currently processing. Visit the %sStatus%s page to check its progress.'), '<a href="mailing_status.php">', '</a>')); } $dbvalues = PommoAPI::configGet(array('list_fromname', 'list_fromemail', 'list_frombounce', 'list_charset', 'list_wysiwyg')); // Initialize page state with default values overriden by those held in $_REQUEST $state =& PommoAPI::stateInit('mailing', array('fromname' => $dbvalues['list_fromname'], 'fromemail' => $dbvalues['list_fromemail'], 'frombounce' => $dbvalues['list_frombounce'], 'list_charset' => $dbvalues['list_charset'], 'wysiwyg' => $dbvalues['list_wysiwyg'], 'mailgroup' => 'all', 'subject' => '', 'body' => '', 'altbody' => ''), $_POST); // SmartyValidate Custom Validation Function function check_charset($value, $empty, &$params, &$formvars) { $validCharsets = array('UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-7', 'ISO-8859-15', 'cp1251', 'KOI8-R', 'GB2312', 'EUC-JP', 'ISO-2022-JP'); return in_array($value, $validCharsets); } if (!SmartyValidate::is_registered_form() || empty($_POST)) { // ___ USER HAS NOT SENT FORM ___ SmartyValidate::connect($smarty, true); // register custom criteria
$mailing = current(PommoMailing::get(array('id' => $_REQUEST['mailings']))); // change group name to ID $groups = PommoGroup::getNames(); $gid = 'all'; foreach ($groups as $group) { if ($group['name'] == $mailing['group']) { $gid = $group['id']; } } PommoAPI::stateReset(array('mailing')); // if this is a plain text mailing, switch body + altbody. if ($mailing['ishtml'] == 'off') { $mailing['altbody'] = $mailing['body']; $mailing['body'] = null; } // Initialize page state with default values overriden by those held in $_REQUEST $state =& PommoAPI::stateInit('mailing', array('fromname' => $mailing['fromname'], 'fromemail' => $mailing['fromemail'], 'frombounce' => $mailing['frombounce'], 'list_charset' => $mailing['charset'], 'mailgroup' => $gid, 'subject' => $mailing['subject'], 'body' => $mailing['body'], 'altbody' => $mailing['altbody'])); Pommo::redirect($pommo->_baseUrl . 'admin/mailings/mailings_start.php'); break; case 'delete': $deleted = PommoMailing::delete($mailingIDS); $logger->addMsg(Pommo::_T('Please Wait') . '...'); $params = $json->encode(array('ids' => $mailingIDS)); $smarty->assign('callbackFunction', 'deleteMailing'); $smarty->assign('callbackParams', $params); break; default: $logger->AddErr('invalid call'); break; } $smarty->display('admin/rpc.tpl');
$output['statusText'] = $statusText[$output['status']]; // get last 50 unique notices $mailingNotices = PommoMailing::getNotices($mailing['id'], 50, true); $newNotices = array(); foreach ($mailingNotices as $time => $arr) { if (!isset($state['notices'][$time])) { $newNotices = array_merge($newNotices, $arr); continue; } foreach ($arr as $notice) { if (array_search($notice, $arr) === false) { $newNotices[] = $notice; } } } $state['notices'] = $mailingNotices; $output['notices'] = array_reverse($newNotices); // calculate sent if ($output['status'] == 4) { $output['sent'] = PommoMailing::getSent($mailing['id']); } else { $query = "SELECT count(subscriber_id) FROM {$dbo->table['queue']} WHERE status > 0"; $output['sent'] = $dbo->query($query, 0); } // cleanup session if frozen or finished. if ($output['status'] > 2) { PommoAPI::stateInit('subscribers_manage'); } $output['percent'] = $output['status'] == 4 ? 100 : round($output['sent'] * (100 / $mailing['tally'])); $json->add($output); $json->serve();
$input['subject'] = PommoHelperPersonalizeTitle::replace($input['subject'], $subscriber, $pSubject); } } $smarty->assign($input); $smarty->display('inc/mailing.tpl'); Pommo::kill(); } } /********************************** VALIDATION ROUTINES *********************************/ if (!is_numeric($state['limit']) || $state['limit'] < 10 || $state['limit'] > 200) { $state['limit'] = 100; } if ($state['order'] != 'asc' && $state['order'] != 'desc') { $state['order'] = 'asc'; } if ($state['sort'] != 'start' && $state['sort'] != 'subject') { $state['sort'] = 'start'; } /********************************** DISPLAY METHODS *********************************/ // Calculate and Remember number of pages $tally = PommoMailing::tally(); $state['pages'] = is_numeric($tally) && $tally > 0 ? ceil($tally / $state['limit']) : 0; $smarty->assign('state', $state); $smarty->assign('tally', $tally); $smarty->assign('mailings', $mailings); $smarty->display('user/mailings.tpl'); Pommo::kill();
function add(&$in) { global $pommo; $dbo =& $pommo->_dbo; // set the start time if not provided if (empty($in['start'])) { $in['start'] = time(); } if (empty($in['sent'])) { $in['sent'] = 0; } if (!PommoMailing::validate($in)) { return false; } $query = "\n\t\t\tINSERT INTO " . $dbo->table['mailings'] . "\n\t\t\tSET\n\t\t\t[fromname='%S',]\n\t\t\t[fromemail='%S',]\n\t\t\t[frombounce='%S',]\n\t\t\t[subject='%S',]\n\t\t\t[body='%S',]\n\t\t\t[altbody='%S',]\n\t\t\t[ishtml='%S',]\n\t\t\t[mailgroup='%S',]\n\t\t\t[subscriberCount=%I,]\n\t\t\t[finished=FROM_UNIXTIME(%I),]\n\t\t\t[sent=%I,]\n\t\t\t[charset='%S',]\n\t\t\t[status=%I,]\n\t\t\tstarted=FROM_UNIXTIME(%i)"; $query = $dbo->prepare($query, @array($in['fromname'], $in['fromemail'], $in['frombounce'], $in['subject'], $in['body'], $in['altbody'], $in['ishtml'], $in['group'], $in['tally'], $in['end'], $in['sent'], $in['charset'], $in['status'], $in['start'])); // fetch new subscriber's ID $id = $dbo->lastId($query); if (!$id) { return false; } // insert current if applicable if (!empty($in['status']) && $in['status'] == 1) { if (empty($in['code'])) { $in['code'] = PommoHelper::makeCode(); } $query = "\n\t\t\tINSERT INTO " . $dbo->table['mailing_current'] . "\n\t\t\tSET\n\t\t\t[command='%S',]\n\t\t\t[serial=%I,]\n\t\t\t[securityCode='%S',]\n\t\t\t[current_status='%S',]\n\t\t\tcurrent_id=%i"; $query = $dbo->prepare($query, @array($in['command'], $in['serial'], $in['code'], $in['current_status'], $id)); if (!$dbo->query($query)) { return false; } return $in['code']; } return $id; }
* poMMo is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2, or any later version. * * poMMo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with program; see the file docs/LICENSE. If not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ // Progress bar modified from the works of Juha Suni <*****@*****.**> /********************************** INITIALIZATION METHODS *********************************/ require '../../bootstrap.php'; Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/mailings.php'); $pommo->init(); $logger =& $pommo->_logger; $dbo =& $pommo->_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $mailing = current(PommoMailing::get(array('active' => TRUE))); $smarty->assign('mailing', $mailing); $smarty->display('admin/mailings/mailing_status.tpl'); Pommo::kill();