Пример #1
0
 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;
 }
Пример #2
0
 function subscriberData(&$in, $p = array())
 {
     $defaults = array('prune' => true, 'active' => true, 'log' => true, 'ignore' => false, 'ignoreInactive' => true, 'skipReq' => false);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $pommo->requireOnce($GLOBALS['pommo']->_baseDir . 'inc/helpers/fields.php');
     $logger =& $pommo->_logger;
     $fields = PommoField::get(array('active' => $p['active']));
     $valid = true;
     foreach ($fields as $id => $field) {
         $inactive = $field['active'] == 'on' ? false : true;
         if (!isset($in[$id]) && $p['skipReq']) {
             continue;
         }
         $in[$id] = @trim($in[$id]);
         if (empty($in[$id])) {
             unset($in[$id]);
             // don't include blank values
             if ($field['required'] == 'on') {
                 if ($p['log']) {
                     $logger->addErr(sprintf(Pommo::_T('%s is a required field.'), $field['prompt']));
                 }
                 $valid = false;
             }
             continue;
         }
         // shorten
         $in[$id] = substr($in[$id], 0, 255);
         switch ($field['type']) {
             case "checkbox":
                 if (strtolower($in[$id]) == 'true') {
                     $in[$id] = 'on';
                 }
                 if (strtolower($in[$id]) == 'false') {
                     $in[$id] = '';
                 }
                 if ($in[$id] != 'on' && $in[$id] != '') {
                     if ($p['ignore'] || $inactive && $p['ignoreInactive']) {
                         unset($in[$id]);
                         break;
                     }
                     if ($p['log']) {
                         $logger->addErr(sprintf(Pommo::_T('Illegal input for field %s.'), $field['prompt']));
                     }
                     $valid = false;
                 }
                 break;
             case "multiple":
                 if (is_array($in[$id])) {
                     foreach ($in[$id] as $key => $val) {
                         if (!in_array($val, $field['array'])) {
                             if ($p['ignore'] || $inactive && $p['ignoreInactive']) {
                                 unset($in[$id]);
                                 break;
                             }
                             if ($p['log']) {
                                 $logger->addErr(sprintf(Pommo::_T('Illegal input for field %s.'), $field['prompt']));
                             }
                             $valid = false;
                         }
                     }
                 } elseif (!in_array($in[$id], $field['array'])) {
                     if ($p['ignore'] || $inactive && $p['ignoreInactive']) {
                         unset($in[$id]);
                         break;
                     }
                     if ($p['log']) {
                         $logger->addErr(sprintf(Pommo::_T('Illegal input for field %s.'), $field['prompt']));
                     }
                     $valid = false;
                 }
                 break;
             case "date":
                 // convert date to timestamp [float; using adodb time library]
                 if (is_numeric($in[$id])) {
                     $in[$id] = PommoHelper::timeToStr($in[$id]);
                 }
                 $in[$id] = PommoHelper::timeFromStr($in[$id]);
                 if (!$in[$id]) {
                     if ($p['ignore'] || $inactive && $p['ignoreInactive']) {
                         unset($in[$id]);
                         break;
                     }
                     if ($p['log']) {
                         $logger->addErr(sprintf(Pommo::_T('Field (%s) must be a date ('), $field['prompt']));
                     }
                     $valid = false;
                 }
                 break;
             case "number":
                 if (!is_numeric($in[$id])) {
                     if ($p['ignore'] || $inactive && $p['ignoreInactive']) {
                         unset($in[$id]);
                         break;
                     }
                     if ($p['log']) {
                         $logger->addErr(sprintf(Pommo::_T('Field (%s) must be a number.'), $field['prompt']));
                     }
                     $valid = false;
                 }
                 break;
         }
     }
     // prune
     if ($p['prune']) {
         $in = PommoHelper::arrayIntersect($in, $fields);
     }
     return $valid;
 }
Пример #3
0
 function &get($p = array())
 {
     $defaults = array('id' => null);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $dbo =& $pommo->_dbo;
     $o = array();
     $query = "\n\t\t\tSELECT g.group_id, g.group_name, c.rule_id, c.field_id, c.logic, c.value, c.type\n\t\t\tFROM " . $dbo->table['groups'] . " g\n\t\t\tLEFT JOIN " . $dbo->table['group_rules'] . " c \n\t\t\t\tON (g.group_id = c.group_id)\n\t\t\tWHERE\n\t\t\t\t1\n\t\t\t\t[AND g.group_id IN(%C)]\n\t\t\tORDER BY g.group_name";
     $query = $dbo->prepare($query, array($p['id']));
     while ($row = $dbo->getRows($query)) {
         if (empty($o[$row['group_id']])) {
             $o[$row['group_id']] = PommoGroup::makeDB($row);
         }
         if (!empty($row['rule_id'])) {
             $c = array('field_id' => $row['field_id'], 'logic' => $row['logic'], 'value' => $row['value'], 'or' => $row['type'] == 0 ? false : true);
             $o[$row['group_id']]['rules'][$row['rule_id']] = $c;
         }
     }
     return $o;
 }
Пример #4
0
 function &makeDB(&$row)
 {
     $in = @array('id' => $row['pending_id'], 'subscriber_id' => $row['subscriber_id'], 'code' => $row['pending_code'], 'array' => unserialize($row['pending_array']), 'type' => $row['pending_type']);
     $o = PommoType::pending();
     return PommoAPI::getParams($o, $in);
 }
Пример #5
0
 /** 
  * init -> called by page to load page state, populate config, and track authentication. 
  *	valid args [ passed as Pommo::init(array('arg' => val, 'arg2' => val)) ] ->
  *		authLevel	:	check that authenticated permission level is at least authLevel (non authenticated == 0). exit if not high enough. [default: 1]
  *		keep		:	keep data stored in session. [default: false]
  *		session		:	explicity set session name. [default: null]
  * 		install		:	bypass loading of config/version checking [default: false]
  */
 function init($args = array())
 {
     $defaults = array('authLevel' => 1, 'keep' => FALSE, 'noSession' => FALSE, 'sessionID' => NULL, 'install' => FALSE);
     // merge submitted parameters
     $p = PommoAPI::getParams($defaults, $args);
     // Bypass Reading of Config, SESSION creation, and authentication checks and return
     //  if 'install' passed
     if ($p['install']) {
         return;
     }
     // load configuration data
     // note; cannot save in session, as session needs unique key -- this is simplest method.
     $this->_config = PommoAPI::configGetBase();
     // check current ("file") revision against database ("last") revision
     $revision = isset($this->_config['revision']) ? $this->_config['revision'] : false;
     if (!defined('_poMMo_support')) {
         if (!$revision) {
             $this->kill(sprintf(Pommo::_T('Error loading configuration. Has poMMo been installed? %sClick Here%s to install.'), '<a href="' . $this->_baseUrl . 'install/install.php">', '</a>'));
         } elseif ($this->_revision != $revision) {
             $this->kill(sprintf(Pommo::_T('Version Mismatch. %sClick Here%s to upgrade.'), '<a href="' . $this->_baseUrl . 'install/upgrade.php">', '</a>'));
         }
     }
     // toggle DB debugging
     if ($this->_debug) {
         $this->_dbo->debug(TRUE);
     }
     // Bypass SESSION creation, reading of config, authentication checks and return
     //  if 'noSession' passed
     if ($p['noSession']) {
         return;
     }
     // start the session
     if (!empty($p['sessionID'])) {
         session_id($p['sessionID']);
     }
     $this->startSession();
     // check for "session" language -- user defined language on the fly.
     if ($this->_slanguage) {
         $this->_session['slanguage'] = $this->_slanguage;
     }
     if (isset($this->_session['slanguage'])) {
         if ($this->_session['slanguage'] == 'en') {
             $this->_l10n = FALSE;
         } else {
             $this->_l10n = TRUE;
             Pommo::requireOnce($this->_baseDir . 'inc/helpers/l10n.php');
             PommoHelperL10n::init($this->_session['slanguage'], $this->_baseDir);
         }
         $this->_slanguage = $this->_session['slanguage'];
     }
     // if authLevel == '*' || _poMMo_support (0 if poMMo not installed, 1 if installed)
     if (defined('_poMMo_support')) {
         Pommo::requireOnce($this->_baseDir . 'inc/classes/install.php');
         $p['authLevel'] = PommoInstall::verify() ? 1 : 0;
     }
     // check authentication levels
     $this->_auth = new PommoAuth(array('requiredLevel' => $p['authLevel']));
     // clear SESSION 'data' unless keep is passed.
     // TODO --> phase this out in favor of page state system?
     // -- add "persistent" flag & complicate state initilization...
     if (!$p['keep']) {
         $this->_session['data'] = array();
     }
 }
Пример #6
0
 function &get($p = array())
 {
     $defaults = array('active' => false, 'id' => null, 'byName' => true);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $dbo =& $pommo->_dbo;
     $p['active'] = $p['active'] ? 'on' : null;
     $p['byName'] = $p['byName'] ? 'field_name' : 'field_ordering';
     $o = array();
     $query = "\n\t\t\tSELECT *\n\t\t\tFROM " . $dbo->table['fields'] . "\n\t\t\tWHERE\n\t\t\t\t1\n\t\t\t\t[AND field_active='%S']\n\t\t\t\t[AND field_id IN(%C)]\n\t\t\tORDER BY " . $p['byName'];
     $query = $dbo->prepare($query, array($p['active'], $p['id']));
     while ($row = $dbo->getRows($query)) {
         $o[$row['field_id']] = PommoField::makeDB($row);
     }
     return $o;
 }
Пример #7
0
 function &get($p = array())
 {
     $defaults = array('active' => false, 'noBody' => false, 'id' => null, 'code' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $dbo =& $pommo->_dbo;
     $p['active'] = $p['active'] ? 1 : null;
     if (is_numeric($p['limit']) && !is_numeric($p['offset'])) {
         $p['offset'] = 0;
     }
     $o = array();
     $select = "mailing_id, fromname, fromemail, frombounce, subject, ishtml, mailgroup, subscriberCount, started, finished, sent, charset, status, c.*";
     if (!$p['noBody']) {
         $select .= ", body, altbody";
     }
     $query = "\n\t\t\tSELECT {$select}\n\t\t\tFROM \n\t\t\t\t" . $dbo->table['mailings'] . " m\n\t\t\t\tLEFT JOIN " . $dbo->table['mailing_current'] . " c ON (m.mailing_id = c.current_id)\n\t\t\tWHERE\n\t\t\t\t1\n\t\t\t\t[AND m.status=%I]\n\t\t\t\t[AND m.mailing_id IN(%C)]\n\t\t\t\t[AND c.securityCode='%S'] \n\t\t\t\t[ORDER BY %S] [%S] \n\t\t\t\t[LIMIT %I, %I]";
     $query = $dbo->prepare($query, array($p['active'], $p['id'], $p['code'], $p['sort'], $p['order'], $p['offset'], $p['limit']));
     while ($row = $dbo->getRows($query)) {
         $o[$row['mailing_id']] = PommoMailing::makeDB($row);
     }
     return $o;
 }
Пример #8
0
 function &getEmail($p = array())
 {
     $defaults = array('status' => 'all', 'id' => null);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $dbo =& $pommo->_dbo;
     if ($p['status'] == 'all') {
         $p['status'] = null;
     }
     $o = array();
     $query = "\n\t\t\tSELECT\n\t\t\t\tsubscriber_id,\n\t\t\t\temail\n\t\t\tFROM \n\t\t\t\t" . $dbo->table['subscribers'] . "\n\t\t\tWHERE\n\t\t\t\t1\n\t\t\t\t[AND subscriber_id IN(%C)]\n\t\t\t\t[AND status=%I]";
     $query = $dbo->prepare($query, array($p['id'], $p['status']));
     while ($row = $dbo->getRows($query)) {
         $o[$row['subscriber_id']] = $row['email'];
     }
     return $o;
 }
Пример #9
0
 function &getDescriptions($p = array())
 {
     $defaults = array('id' => null, 'name' => null);
     $p = PommoAPI::getParams($defaults, $p);
     global $pommo;
     $dbo =& $pommo->_dbo;
     $o = array();
     $query = "\n\t\t\tSELECT template_id, description\n\t\t\tFROM " . $dbo->table['templates'] . "\n\t\t\tWHERE\n\t\t\t\t1\n\t\t\t\t[AND name='%S']\n\t\t\t\t[AND template_id IN(%C)]\n\t\t\tORDER BY name";
     $query = $dbo->prepare($query, array($p['name'], $p['id']));
     while ($row = $dbo->getRows($query)) {
         $o[$row['template_id']] = $row['description'];
     }
     return $o;
 }