getParams() public static method

* getParams Merges default and given params
public static getParams ( $defaults, $args )
コード例 #1
0
ファイル: Pommo_Auth.php プロジェクト: soonick/poMMo
 function __construct($args = array())
 {
     $defaults = array('username' => null, 'requiredLevel' => 0);
     $p = Pommo_Api::getParams($defaults, $args);
     if (empty(Pommo::$_session['username'])) {
         Pommo::$_session['username'] = $p['username'];
     }
     $this->_username =& Pommo::$_session['username'];
     $this->_permissionLevel = $this->getPermissionLevel($this->_username);
     if ($p['requiredLevel'] > $this->_permissionLevel) {
         Pommo::kill(sprintf(Pommo::_T('Denied access. You must %slogin%s to' . ' access this page...'), '<a href="' . Pommo::$_baseUrl . 'index.php?referer=' . $_SERVER['PHP_SELF'] . '">', '</a>'));
     }
 }
コード例 #2
0
ファイル: Pommo_Mta.php プロジェクト: soonick/poMMo
 /**
  * Register function that will be called when the script terminates abruptly.
  * Get code, test and id from URL.
  * Retrieve mailing (subject, body, attachments, etc) that will be sent.
  *
  * @param array $args.- Configuration overwrites
  */
 function Pommo_Mta($args = array())
 {
     $defaults = array('queueSize' => 100, 'maxRunTime' => 80, 'skipSecurity' => false, 'start' => time(), 'serial' => false, 'spawn' => 1);
     $p = Pommo_Api::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(Pommo_Mailing::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.) TODO: Find another way to do this
     $_GET['id'] = $this->_id;
     // security routines
     if ($this->_mailing['end'] > 0) {
         $this->shutdown(Pommo::_T('Mailing Complete.'));
     }
     if (empty($this->_mailing['serial'])) {
         if (!Pommo_Mail_Ctl::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();
 }
コード例 #3
0
ファイル: Pommo_Validate.php プロジェクト: systemfirez/poMMo
 function subscriberData(&$in, $p = array())
 {
     $defaults = array('prune' => true, 'active' => true, 'log' => true, 'ignore' => false, 'ignoreInactive' => true, 'skipReq' => false);
     $p = Pommo_Api::getParams($defaults, $p);
     require_once Pommo::$_baseDir . 'classes/Pommo_Fields.php';
     $logger = Pommo::$_logger;
     $fields = Pommo_Fields::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] = Pommo_Helper::timeToStr($in[$id]);
                 }
                 $in[$id] = Pommo_Helper::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 (' . Pommo_Helper::timeGetFormat() . ').'), $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 = Pommo_Helper::arrayIntersect($in, $fields);
     }
     return $valid;
 }
コード例 #4
0
ファイル: Pommo_Groups.php プロジェクト: soonick/poMMo
 static function &get($p = array())
 {
     $defaults = array('id' => null);
     $p = Pommo_Api::getParams($defaults, $p);
     $dbo =& Pommo::$_dbo;
     $o = array();
     $query = "\n            SELECT g.group_id, g.group_name, c.rule_id, c.field_id, c.logic, c.value, c.type\n            FROM " . $dbo->table['groups'] . " g\n            LEFT JOIN " . $dbo->table['group_rules'] . " c\n                ON (g.group_id = c.group_id)\n            WHERE\n                1\n                [AND g.group_id IN(%C)]\n            ORDER 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']] = Pommo_Groups::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;
 }
コード例 #5
0
ファイル: Pommo_Fields.php プロジェクト: soonick/poMMo
 static function get($p = array())
 {
     $defaults = array('active' => false, 'id' => null, 'byName' => false);
     $p = Pommo_Api::getParams($defaults, $p);
     $dbo = Pommo::$_dbo;
     $p['active'] = $p['active'] ? 'on' : null;
     $p['byName'] = $p['byName'] ? 'field_name' : 'field_ordering';
     $o = array();
     $query = "\n            SELECT *\n            FROM " . $dbo->table['fields'] . "\n            WHERE\n                1\n                [AND field_active='%S']\n                [AND field_id IN(%C)]\n            ORDER BY " . $p['byName'];
     $query = $dbo->prepare($query, array($p['active'], $p['id']));
     while ($row = $dbo->getRows($query)) {
         $o[$row['field_id']] = Pommo_Fields::makeDB($row);
     }
     return $o;
 }
コード例 #6
0
ファイル: Pommo_Pending.php プロジェクト: systemfirez/poMMo
 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 = Pommo_Type::pending();
     return Pommo_Api::getParams($o, $in);
 }
コード例 #7
0
ファイル: Pommo.php プロジェクト: soonick/poMMo
 public static function init($args = array())
 {
     $defaults = array('authLevel' => 1, 'keep' => FALSE, 'noSession' => FALSE, 'sessionID' => NULL, 'install' => FALSE);
     // 	merge submitted parameters
     $p = Pommo_Api::getParams($defaults, $args);
     // 	Return if not config.php file present
     if (!self::$_hasConfigFile) {
         return false;
     }
     //	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.
     self::$_config = Pommo_Api::configGetBase();
     //	toggle DB debugging
     if (self::$_debug) {
         self::$_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']);
     }
     self::startSession();
     // check for "session" language -- user defined language on the fly.
     if (self::$_slanguage) {
         self::$_session['slanguage'] = self::$_slanguage;
     }
     if (isset(self::$_session['slanguage'])) {
         if (self::$_session['slanguage'] == 'en') {
             self::$_l10n = FALSE;
         } else {
             self::$_l10n = TRUE;
             require_once self::$_baseDir . 'classes/Pommo_Helper_L10n.php';
             Pommo_Helper_L10n::init(self::$_session['slanguage'], self::$_baseDir);
         }
         self::$_slanguage = self::$_session['slanguage'];
     }
     // 	if authLevel == '*' || _poMMo_support (0 if poMMo not installed,
     //	1 if installed)
     if (defined('_poMMo_support')) {
         require_once self::$_baseDir . 'classes/Pommo_Install.php';
         $p['authLevel'] = Pommo_Install::verify() ? 1 : 0;
     }
     // check authentication levels
     self::$_auth = new Pommo_Auth(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']) {
         self::$_session['data'] = array();
     }
 }
コード例 #8
0
 function &getDescriptions($p = array())
 {
     $defaults = array('id' => null, 'name' => null);
     $p = Pommo_Api::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;
 }
コード例 #9
0
ファイル: Pommo_Mailing.php プロジェクト: soonick/poMMo
 public static function get($p = array())
 {
     $defaults = array('active' => false, 'noBody' => false, 'id' => null, 'code' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null);
     if ($p['forHistory']) {
         $forHistory = 1;
         unset($p['forHistory']);
     }
     $p = Pommo_Api::getParams($defaults, $p);
     $dbo =& Pommo::$_dbo;
     $p['active'] = $p['active'] ? 1 : null;
     if (is_numeric($p['limit']) && !is_numeric($p['offset'])) {
         $p['offset'] = 0;
     }
     $o = array();
     //	We modify the query if the mailings are for the history section
     if (1 == $forHistory) {
         $field = "COUNT(h.subscriber_id) AS hits";
         $join = "LEFT JOIN " . $dbo->table['mailings_hits'] . " h ON (h.mailing_id = m.mailing_id)";
     } else {
         $field = "GROUP_CONCAT(a.file_name) AS file_name";
         $join = "LEFT JOIN " . $dbo->table['mailings_attachments'] . " ma ON (m.mailing_id = ma.mailing_id)\n            LEFT JOIN " . $dbo->table['attachment_files'] . " a ON (ma.file_id = a.file_id)";
     }
     $select = "m.mailing_id,\n                c.command,\n                c.serial,\n                c.securityCode,\n                c.current_status,\n                c.touched,\n                fromname,\n                fromemail,\n                frombounce,\n                subject,\n                ishtml,\n                mailgroup,\n                subscriberCount,\n                started,\n                finished,\n                sent,\n                charset,\n                status,\n                track,\n                " . $field;
     if (!$p['noBody']) {
         $select .= ", body, altbody";
     }
     $query = "SELECT {$select}\n            FROM " . $dbo->table['mailings'] . " m\n            LEFT JOIN " . $dbo->table['mailing_current'] . " c ON (m.mailing_id = c.current_id) " . $join . " WHERE\n                1\n                [AND m.status=%I]\n                [AND m.mailing_id IN(%C)]\n                [AND c.securityCode='%S']\n                GROUP BY mailing_id\n                [ORDER BY %S] [%S]\n                [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']] = Pommo_Mailing::makeDB($row);
     }
     return $o;
 }
コード例 #10
0
ファイル: Pommo_Subscribers.php プロジェクト: soonick/poMMo
 function &getEmail($p = array())
 {
     $defaults = array('status' => 'all', 'id' => null);
     $p = Pommo_Api::getParams($defaults, $p);
     $dbo = Pommo::$_dbo;
     if ($p['status'] == 'all') {
         $p['status'] = null;
     }
     $o = array();
     $query = "\n            SELECT\n                subscriber_id,\n                email\n            FROM\n                " . $dbo->table['subscribers'] . "\n            WHERE\n                1\n                [AND subscriber_id IN(%C)]\n                [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;
 }
コード例 #11
0
ファイル: Pommo_Mailing.php プロジェクト: systemfirez/poMMo
 function &get($p = array())
 {
     $defaults = array('active' => false, 'noBody' => false, 'id' => null, 'code' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null);
     $p = Pommo_Api::getParams($defaults, $p);
     $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']] = Pommo_Mailing::makeDB($row);
     }
     return $o;
 }