function members($p = array(), $filter = array('field' => null, 'string' => null)) { $GLOBALS['pommo']->requireOnce($GLOBALS['pommo']->_baseDir . 'inc/helpers/subscribers.php'); if (is_array($this->_memberIDs)) { $p['id'] =& $this->_memberIDs; } else { // status was already passed when fetching IDs $p['status'] = $this->_status; } return PommoSubscriber::get($p, $filter); }
function replace(&$msg, &$s, &$personalizations) { $subject = $msg; foreach ($personalizations as $p) { // lookup replace string switch (strtolower($p['field'])) { case 'email': $replace = $s['email']; break; case 'ip': $replace = $s['ip']; break; case 'registered': $replace = $s['registered']; break; case '!unsubscribe': $replace = $GLOBALS['pommo']->_http . $GLOBALS['pommo']->_baseUrl . 'user/update.php?email=' . $s['email'] . '&code=' . PommoSubscriber::getActCode($s); break; case '!weblink': $replace = $GLOBALS['pommo']->_http . $GLOBALS['pommo']->_baseUrl . 'user/mailings.php?mail_id=' . $_GET['id'] . '&id=' . $_GET['id'] . '&email=' . $s['email'] . '&code=' . PommoSubscriber::getActCode($s); break; case '!subscriber_id': $replace = $s['id']; break; case '!mailing_id': $replace = $_GET['id']; break; default: if (isset($p['field_id'])) { $replace = $s['data'][$p['field_id']]; } break; } // attempt to add default if replacement is empty if (empty($replace)) { $replace = $p['default']; } $subject = str_replace($p['search'], $replace, $subject); } return $subject; }
$s = array($sub['email']); if (!empty($_POST['registered'])) { $s[] = $sub['registered']; } if (!empty($_POST['ip'])) { $s[] = $sub['ip']; } array_walk($d, 'csvWrap'); array_walk($s, 'csvWrap'); $a = array_merge($s, $d); $o .= implode(',', $a) . "\r\n"; } $size_in_bytes = strlen($o); header("Content-disposition: attachment; filename=poMMo_listing.csv; size={$size_in_bytes}"); print $o; die; } // ====== TXT EXPORT ====== if (!$ids) { $group = new PommoGroup($state['group'], $state['status']); $ids =& $group->_memberIDs; } $emails = PommoSubscriber::getEmail(array('id' => $ids)); $o = ''; foreach ($emails as $e) { $o .= "{$e}\r\n"; } $size_in_bytes = strlen($o); header("Content-disposition: attachment; filename=poMMo_listing.txt; size={$size_in_bytes}"); print $o; die;
$smarty->assign('vMsg', $vMsg); } else { // ___ USER HAS SENT FORM ___ SmartyValidate::connect($smarty); if (SmartyValidate::is_valid($_POST) && !$current) { // __ FORM IS VALID Pommo::requireOnce($pommo->_baseDir . 'inc/classes/mailctl.php'); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/subscribers.php'); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/validate.php'); // get a copy of the message state // composition is valid (via preview.php) $state = $pommo->_session['state']['mailing']; // create temp subscriber $subscriber = array('email' => $_POST['email'], 'registered' => time(), 'ip' => $_SERVER['REMOTE_ADDR'], 'status' => 0, 'data' => $_POST['d']); PommoValidate::subscriberData($subscriber['data'], array('active' => FALSE, 'ignore' => TRUE, 'log' => false)); $key = PommoSubscriber::add($subscriber); if (!$key) { $logger->addErr('Unable to Add Subscriber'); } 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';
$field = current(PommoField::get(array('id' => $_REQUEST['field_id']))); if ($field['id'] != $_REQUEST['field_id']) { die('bad field ID'); } $affected = PommoField::subscribersAffected($field['id'], $_REQUEST['options']); if (count($affected) > 0 && empty($_REQUEST['confirmed'])) { $msg = sprintf(Pommo::_T('Deleting option %1$s will affect %2$s subscribers who have selected this choice. They will be flagged as needing to update their records.'), '<b>' . $_REQUEST['options'] . '</b>', '<em>' . count($affected) . '</em>'); $msg .= "\n " . Pommo::_T('Are you sure?'); $json->add('callbackFunction', 'confirm'); $json->add('callbackParams', $msg); $json->serve(); } else { Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/subscribers.php'); $options = PommoField::optionDel($field, $_REQUEST['options']); if (!options) { $json->fail(Pommo::_T('Error with deletion.')); } // flag subscribers for update if (count($affected) > 0) { PommoSubscriber::flagByID($affected); } $json->add('callbackFunction', 'updateOptions'); $json->add('callbackParams', $options); $json->serve(); } break; default: die('invalid request passed to ' . __FILE__); break; } die;
function perform(&$in) { global $pommo; $dbo =& $pommo->_dbo; $logger =& $pommo->_logger; if (!is_numeric($in['id']) || !is_numeric($in['subscriber_id'])) { $logger->addErr('PommoPending::perform() -> invalid pending object sent.'); return false; } switch ($in['type']) { case 'add': // subscribe $query = "\n\t\t\t\t\tUPDATE " . $dbo->table['subscribers'] . "\n\t\t\t\t\tSET status=1\n\t\t\t\t\tWHERE subscriber_id=%i"; $query = $dbo->prepare($query, array($in['subscriber_id'])); if (!$dbo->query($query)) { $logger->addErr('PommoPending::perform() -> Error updating subscriber.'); return false; } break; case 'change': // update $pommo->requireOnce($pommo->_baseDir . 'inc/helpers/subscribers.php'); $subscriber =& $in['array']; if (!PommoSubscriber::update($subscriber, 'REPLACE_ACTIVE')) { $logger->addErr('PommoPending::perform() -> Error updating subscriber.'); return false; } break; case 'password': // change (admin) password $pommo->requireOnce($pommo->_baseDir . 'inc/helpers/subscribers.php'); $password = PommoHelper::makePassword(); $config = PommoAPI::configGet(array('admin_username', 'admin_email')); if (!PommoAPI::configUpdate(array('admin_password' => md5($password)), TRUE)) { $logger->addMsg('Error updating password.'); return false; } $logger->addErr(sprintf(Pommo::_T('You may now %1$s login %2$s with username: %3$s and password: %4$s '), '<a href="' . $pommo->_baseUrl . 'index.php">', '</a>', '<span style="font-size: 130%">' . $config['admin_username'] . '</span>', '<span style="font-size: 130%">' . $password . '</span>')); break; } $query = "\n\t\t\tDELETE FROM " . $dbo->table['subscriber_pending'] . "\n\t\t\tWHERE pending_id=%i"; $query = $dbo->prepare($query, array($in['id'])); if (!$dbo->query($query)) { $logger->addErr('PommoPending::perform() -> Error removing pending entry.'); return false; } return true; }
SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); // make sure email/login is valid $subscriber = current(PommoSubscriber::get(array('email' => empty($_REQUEST['email']) ? '0' : $_REQUEST['email'], 'status' => 1))); if (empty($subscriber)) { Pommo::redirect('login.php'); } // see if an anctivation email was sent to this subscriber in the last 2 minutes; $query = "\n\tSELECT \n\t\t*\n\tFROM \n\t\t" . $dbo->table['scratch'] . "\n\tWHERE\n\t\t`type`=1\n\t\tAND `int`=%i\n\t\tAND `time` > (NOW() - INTERVAL 2 MINUTE)\n\tLIMIT 1"; $query = $dbo->prepare($query, array($subscriber['id'])); $test = $dbo->query($query, 0); // attempt to send activation code if once has not recently been sent if (empty($test)) { $code = PommoSubscriber::getActCode($subscriber); if (PommoHelperMessages::sendMessage(array('to' => $subscriber['email'], 'code' => $code, 'type' => 'activate'))) { $smarty->assign('sent', true); // timestamp this activation email $query = "\n\t\t\tINSERT INTO " . $dbo->table['scratch'] . "\n\t\t\tSET\n\t\t\t\t`type`=1,\n\t\t\t\t`int`=%i"; $query = $dbo->prepare($query, array($subscriber['id'])); $dbo->query($query); // remove ALL activation email timestamps older than 2 minutes $query = "\n\t\t\tDELETE FROM \n\t\t\t\t" . $dbo->table['scratch'] . "\n\t\t\tWHERE\n\t\t\t\t`type`=1\n\t\t\t\tAND `time` < (NOW() - INTERVAL 2 MINUTE)"; $query = $dbo->prepare($query, array()); $dbo->query($query); } } else { $smarty->assign('sent', false); } $smarty->assign('email', $subscriber['email']);
$smarty = new PommoTemplate(); $smarty->assign('title', $pommo->_config['site_name'] . ' - ' . Pommo::_T('Mailing History')); /** SET PAGE STATE * limit - # of mailings per page * sort - Sorting of Mailings [subject, started] * order - Order Type (ascending - ASC /descending - DESC) */ // Initialize page state with default values overriden by those held in $_REQUEST $state =& PommoAPI::stateInit('mailings_history', array('limit' => 100, 'sort' => 'finished', 'order' => 'asc', 'page' => 1), $_REQUEST); // if mail_id is passed, display the mailing. if (isset($_GET['mail_id']) && is_numeric($_GET['mail_id'])) { $input = current(PommoMailing::get(array('id' => $_GET['mail_id']))); // attempt personalizations of body/subject if (isset($_GET['email']) && isset($_GET['code'])) { $subscriber = current(PommoSubscriber::get(array('email' => $_GET['email'], 'status' => 1))); if ($_GET['code'] == PommoSubscriber::getActCode($subscriber)) { Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/personalize.php'); // require once here so that mailer can use Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/personalizetitle.php'); // title personalization $matches1 = array(); preg_match('/\\[\\[[^\\]]+]]/', $input['body'], $matches1); if (!empty($matches1)) { $pBody = PommoHelperPersonalize::search($input['body']); $input['body'] = PommoHelperPersonalize::replace($input['body'], $subscriber, $pBody); } $matches2 = array(); preg_match('/\\[\\[[^\\]]+]]/', $input['altbody'], $matches2); if (!empty($matches2)) { $pAltBody = PommoHelperPersonalize::search($input['altbody']); $input['altbody'] = PommoHelperPersonalize::replace($input['altbody'], $subscriber, $pAltBody);
} elseif ($fid == 'email' && PommoHelper::isEmail($col)) { $subscriber['email'] = $col; } elseif ($fid == 'registered') { $subscriber['registered'] = PommoHelper::timeFromStr($col); } elseif ($fid == 'ip') { $subscriber['ip'] = $col; } } if ($subscriber['email']) { // check for dupe // TODO -- DO THIS IN BATCH ?? if (PommoHelper::isDupe($subscriber['email'], $includeUnsubscribed)) { $dupes++; continue; } // validate/fix data if (!PommoValidate::subscriberData($subscriber['data'], array('log' => false, 'ignore' => true, 'active' => false))) { $subscriber['flag'] = 9; } // add subscriber if (PommoSubscriber::add($subscriber)) { $tally++; if (isset($subscriber['flag'])) { $flagged++; } } } } unlink($pommo->_workDir . '/import.csv'); echo '<div class="warn"><p>' . sprintf(Pommo::_T('%s subscribers imported! Of these, %s were flagged to update their records.'), $tally, $flagged) . '<p>' . sprintf(Pommo::_T('%s duplicates encountered.'), $dupes) . '</p></div>'; die(Pommo::_T('Complete!') . ' <a href="subscribers_import.php">' . Pommo::_T('Return to') . ' ' . Pommo::_T('Import') . '</a>');
// lookup code $pending = PommoPending::get($_GET['code']); if (!$pending) { $logger->addMsg(Pommo::_T('Invalid code! Make sure you copied it correctly from the email.')); $smarty->display('user/confirm.tpl'); Pommo::kill(); } // Load success messages and redirection URL from config $config = PommoAPI::configGet(array('site_success', 'messages', 'notices')); $messages = unserialize($config['messages']); $notices = unserialize($config['notices']); if (PommoPending::perform($pending)) { Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/messages.php'); // get subscriber info Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/subscribers.php'); $subscriber = current(PommoSubscriber::get(array('id' => $pending['subscriber_id']))); switch ($pending['type']) { case "add": // send/print welcome message PommoHelperMessages::sendMessage(array('to' => $subscriber['email'], 'type' => 'subscribe')); if (isset($notices['subscribe']) && $notices['subscribe'] == 'on') { PommoHelperMessages::notify($notices, $subscriber, 'subscribe'); } if (!empty($config['site_success'])) { Pommo::redirect($config['site_success']); } break; case "change": if (isset($notices['update']) && $notices['update'] == 'on') { PommoHelperMessages::notify($notices, $subscriber, 'update'); }
$validateOptions = array('skipReq' => TRUE, 'active' => FALSE); // check if email is valid if (!PommoHelper::isEmail($subscriber['email'])) { $json->fail(Pommo::_T('Invalid email.')); } // check for dupe $lookupID = current(PommoSubscriber::getIDByEmail($subscriber['email'], array(1, 2))); if ($lookupID && $lookupID != $subscriber['id']) { $json->fail(Pommo::_T('Email address already exists. Duplicates are not allowed.')); } if (!PommoValidate::subscriberData($subscriber['data'], $validateOptions) && !isset($_REQUEST['force'])) { $json->addErr(Pommo::_T('Fields failed validation') . " >>> "); $json->addErr($logger->getAll()); $json->fail(Pommo::_T('Error updating subscriber.')); } if (!PommoSubscriber::update($subscriber, 'REPLACE_ALL')) { $json->fail(Pommo::_T('Error updating subscriber.')); } // subscriber updated successfully, build output $out = array('email' => $subscriber['email'], 'id' => $subscriber['id']); // return human readable date formatting Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/fields.php'); $dateFields = PommoField::getByType('date'); foreach ($subscriber['data'] as $k => $val) { $out['d' . $k] = in_array($k, $dateFields) ? PommoHelper::timeToStr($val) : htmlspecialchars($val); } $json->add('callbackFunction', 'editSubscriber'); $json->add('callbackParams', $out); $json->addMsg(Pommo::_T('Subscriber Updated')); break; default:
function stop($finish = false) { $this->_mailer->SmtpClose(); if ($this->_test) { // don't respawn if this is a test mailing PommoMailCtl::finish($this->_id, TRUE, TRUE); PommoSubscriber::delete(current($this->_hash)); session_destroy(); exit; } if ($finish) { PommoMailCtl::finish($this->_id); $this->shutdown(Pommo::_T('Mailing Complete.')); } // respwn if (!PommoMailCtl::spawn($GLOBALS['pommo']->_baseUrl . 'admin/mailings/mailings_send4.php?' . 'code=' . $this->_code . '&serial=' . $this->_serial . '&id=' . $this->_id)) { $this->shutdown('*** RESPAWN FAILED! ***'); } $this->shutdown(sprintf(Pommo::_T('Runtime (%s seconds) reached, respawning.'), $this->_maxRunTime), false); }
function add(&$in, $id = null) { global $pommo; $dbo =& $pommo->_dbo; // set the registration date if not provided if (empty($in['registered'])) { $in['registered'] = time(); } if (!PommoSubscriber::validate($in)) { return false; } $insert = $id === null ? 'INSERT' : 'REPLACE'; $query = "\n\t\t\t{$insert} INTO " . $dbo->table['subscribers'] . "\n\t\t\tSET\n\t\t\t[subscriber_id=%I,]\n\t\t\temail='%s',\n\t\t\ttime_registered=FROM_UNIXTIME(%i),\n\t\t\tflag=%i,\n\t\t\tip=INET_ATON('%s'),\n\t\t\tstatus=%i"; $query = $dbo->prepare($query, @array($id, $in['email'], $in['registered'], $in['flag'], $in['ip'], $in['status'])); // fetch new subscriber's ID $id = $dbo->lastId($query); if (!$id) { return false; } // insert pending (if exists) if ($in['status'] == 2) { $query = "\n\t\t\tINSERT INTO " . $dbo->table['subscriber_pending'] . "\n\t\t\tSET\n\t\t\t[pending_array='%S',]\n\t\t\tsubscriber_id=%i,\n\t\t\tpending_code='%s',\n\t\t\tpending_type='%s'"; $query = $dbo->prepare($query, @array($in['pending_array'], $id, $in['pending_code'], $in['pending_type'])); if (!$dbo->query($query)) { return false; } } // insert data $values = array(); foreach ($in['data'] as $field_id => $value) { $values[] = $dbo->prepare("(%i,%i,'%s')", array($field_id, $id, $value)); } if (!empty($values)) { $query = "\n\t\t\tINSERT INTO " . $dbo->table['subscriber_data'] . "\n\t\t\t(field_id, subscriber_id, value)\n\t\t\tVALUES " . implode(',', $values); if (!$dbo->query($query)) { return false; } } return $id; }
} } } elseif (!PommoSubscriber::update($newsub, 'REPLACE_ACTIVE')) { $logger->addErr('Error updating subscriber.'); } else { // update successful $logger->addMsg(Pommo::_T('Your records have been updated.')); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/messages.php'); if (isset($notices['update']) && $notices['update'] == 'on') { PommoHelperMessages::notify($notices, $newsub, 'update'); } } } elseif (!empty($_POST['unsubscribe'])) { $comments = isset($_POST['comments']) ? substr($_POST['comments'], 0, 255) : false; $newsub = array('id' => $subscriber['id'], 'status' => 0, 'data' => array()); if (!PommoSubscriber::update($newsub)) { $logger->addErr('Error updating subscriber.'); } else { $dbvalues = PommoAPI::configGet(array('messages')); $messages = unserialize($dbvalues['messages']); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/messages.php'); // send unsubscription email / print unsubscription message PommoHelperMessages::sendMessage(array('to' => $subscriber['email'], 'type' => 'unsubscribe')); if ($comments || isset($notices['unsubscribe']) && $notices['unsubscribe'] == 'on') { PommoHelperMessages::notify($notices, $subscriber, 'unsubscribe', $comments); } $smarty->assign('unsubscribe', TRUE); } } $smarty->assign('email', $subscriber['email']); $smarty->assign('code', $_REQUEST['code']);