function slashStrip($input) { if (is_array($input)) { foreach ($input as $key => $value) { $input[$key] = PommoHelper::slashStrip($value); } return $input; } else { return stripslashes($input); } }
function check_notifyMails($value, $empty, &$params, &$formvars) { $mails = PommoHelper::trimArray(explode(',', $value)); $ret = true; foreach ($mails as $mail) { if (!empty($mail) && !PommoHelper::isEmail($mail)) { $ret = false; } } return $ret; }
function PommoTemplate() { global $pommo; // set theme -- TODO; extend this to the theme selector $this->_pommoTheme = 'default'; // set smarty directories $this->_themeDir = $pommo->_baseDir . 'themes/'; $this->template_dir = $this->_themeDir . $this->_pommoTheme; $this->config_dir = $this->template_dir . '/inc/config'; $this->cache_dir = $pommo->_workDir . '/pommo/smarty'; $this->compile_dir = $pommo->_workDir . '/pommo/smarty'; $this->plugins_dir = array('plugins', $pommo->_baseDir . 'inc/lib/smarty-plugins/gettext', $pommo->_baseDir . 'inc/lib/smarty-plugins/pommo'); // set base/core variables available to all template $this->assign('url', array('theme' => array('shared' => $pommo->_baseUrl . 'themes/shared/', 'this' => $pommo->_baseUrl . 'themes/' . $this->_pommoTheme . '/'), 'base' => $pommo->_baseUrl, 'http' => $pommo->_http)); $this->assign('config', @array('app' => array('path' => $pommo->_baseDir, 'weblink' => '<a href="http://pommo.sourceforge.net/">' . Pommo::_T('poMMo Website') . '</a>', 'dateformat' => PommoHelper::timeGetFormat()), 'site_name' => $pommo->_config['site_name'], 'site_url' => $pommo->_config['site_url'], 'list_name' => $pommo->_config['list_name'], 'admin_email' => $pommo->_config['admin_email'], 'demo_mode' => $pommo->_config['demo_mode'])); // set gettext overload functions (see block.t.php...) $this->_gettext_func = array('Pommo', '_T'); // calls Pommo::_T($str) $this->_gettext_plural_func = array('Pommo', '_TP'); // assign page title $this->assign('title', '. ..poMMo.. .'); // assign section (used for sidebar template) $this->assign('section', $pommo->_section); }
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; }
function preInit() { Pommo::requireOnce($this->_baseDir . 'inc/classes/log.php'); Pommo::requireOnce($this->_baseDir . 'inc/lib/safesql/SafeSQL.class.php'); Pommo::requireOnce($this->_baseDir . 'inc/classes/db.php'); Pommo::requireOnce($this->_baseDir . 'inc/classes/auth.php'); // initialize logger $this->_logger = new PommoLog(); // NOTE -> this clears messages that may have been retained (not outputted) from logger. // read in config.php (configured by user) // TODO -> write a web-based frontend to config.php creation $config = PommoHelper::parseConfig($this->_baseDir . 'config.php'); // check to see if config.php was "properly" loaded if (count($config) < 5) { Pommo::kill('Could not read config.php'); } $this->_workDir = empty($config['workDir']) ? $this->_baseDir . 'cache' : $config['workDir']; $this->_debug = strtolower($config['debug']) != 'on' ? false : true; $this->_default_subscriber_sort = empty($config['default_subscriber_sort']) ? 'email' : $config['default_subscriber_sort']; $this->_verbosity = empty($config['verbosity']) ? 3 : $config['verbosity']; $this->_logger->_verbosity = $this->_verbosity; $this->_dateformat = $config['date_format'] >= 1 && $cofig['date_format'] <= 3 ? intval($config['date_format']) : 1; // the regex strips port info from hostname $this->_hostname = empty($config['hostname']) ? preg_replace('/:\\d+$/i', '', $_SERVER['HTTP_HOST']) : $config['hostname']; $this->_hostport = empty($config['hostport']) ? $_SERVER['SERVER_PORT'] : $config['hostport']; $this->_ssl = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? false : true; $this->_http = ($this->_ssl ? 'https://' : 'http://') . $this->_hostname; if ($this->_hostport != 80 && $this->_hostport != 443) { $this->_http .= ':' . $this->_hostport; } $this->_language = empty($config['lang']) ? 'en' : strtolower($config['lang']); $this->_slanguage = defined('_poMMo_lang') ? _poMMo_lang : false; // include translation (l10n) methods if language is not English $this->_l10n = FALSE; if ($this->_language != 'en') { $this->_l10n = TRUE; Pommo::requireOnce($this->_baseDir . 'inc/helpers/l10n.php'); PommoHelperL10n::init($this->_language, $this->_baseDir); } // set base URL (e.g. http://mysite.com/news/pommo => 'news/pommo/') // TODO -> provide validation of baseURL ? if (isset($config['baseURL'])) { $this->_baseUrl = $config['baseURL']; } else { // If we're called from an outside (embedded) script, read baseURL from "last known good". // Else, set it based off of REQUEST if (defined('_poMMo_embed')) { Pommo::requireOnce($this->_baseDir . 'inc/helpers/maintenance.php'); $this->_baseUrl = PommoHelperMaintenance::rememberBaseURL(); } else { $baseUrl = preg_replace('@/(inc|setup|user|install|support(/tests)?|admin(/subscribers|/user|/mailings|/setup)?(/ajax|/mailing|/config)?)$@i', '', dirname($_SERVER['PHP_SELF'])); $this->_baseUrl = $baseUrl == '/' ? $baseUrl : $baseUrl . '/'; } } // make sure workDir is writable if (!is_dir($this->_workDir . '/pommo/smarty')) { $wd = $this->_workDir; $this->_workDir = null; if (!is_dir($wd)) { Pommo::kill(sprintf(Pommo::_T('Work Directory (%s) not found! Make sure it exists and the webserver can write to it. You can change its location from the config.php file.'), $wd)); } if (!is_writable($wd)) { Pommo::kill(sprintf(Pommo::_T('Cannot write to Work Directory (%s). Make sure it has the proper permissions.'), $wd)); } if (ini_get('safe_mode') == "1") { Pommo::kill(sprintf(Pommo::_T('Working Directory (%s) cannot be created under PHP SAFE MODE. See Documentation, or disable SAFE MODE.'), $wd)); } if (!is_dir($wd . '/pommo')) { if (!mkdir($wd . '/pommo')) { Pommo::kill(Pommo::_T('Could not create directory') . ' ' . $wd . '/pommo'); } } if (!mkdir($wd . '/pommo/smarty')) { Pommo::kill(Pommo::_T('Could not create directory') . ' ' . $wd . '/pommo/smarty'); } $this->_workdir = $wd; } // set the current "section" -- should be "user" for /user/* files, "mailings" for /admin/mailings/* files, etc. etc. $this->_section = preg_replace('@^admin/?@i', '', str_replace($this->_baseUrl, '', dirname($_SERVER['PHP_SELF']))); // initialize database link $this->_dbo = @new PommoDB($config['db_username'], $config['db_password'], $config['db_database'], $config['db_hostname'], $config['db_prefix']); // turn off debugging if in user area if ($this->_section == 'user') { $this->_debug = false; $this->_dbo->debug(FALSE); } // if debugging is set in config.php, enable debugging on the database. if ($this->_debug) { // don't enable debugging in ajax requests unless verbosity is < 3 if (PommoHelper::isAjax() && $this->_verbosity > 2) { $this->_debug = false; } else { $this->_dbo->debug(TRUE); } } }
function optionAdd(&$field, $value) { global $pommo; $dbo =& $pommo->_dbo; $logger =& $pommo->_logger; $value = PommoHelper::trimArray(explode(',', $value)); // add value to the array $field['array'] = array_unique(array_merge($field['array'], $value)); $o = serialize($field['array']); $query = "\n\t\t\tUPDATE " . $dbo->table['fields'] . "\n\t\t\tSET field_array='%s'\n\t\t\tWHERE field_id=%i"; $query = $dbo->prepare($query, array($o, $field['id'])); return $dbo->affected($query) > 0 ? $field['array'] : FALSE; }
function addFieldRule(&$group, &$field, &$logic, &$values, $type = 0) { global $pommo; $dbo =& $pommo->_dbo; $type = $type == 'or' ? 1 : 0; // remove previous filters PommoRules::deleteRule($group, $field, $logic); // get the field Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/fields.php'); $field = current(PommoField::get(array('id' => $field))); foreach ($values as $value) { // if this is a date type field, convert the values from human readable date // strings to timestamps appropriate for matching if ($field['type'] == 'date') { $value = PommoHelper::timeFromStr($value); } $v[] = $dbo->prepare("(%i,%i,'%s','%s',%i)", array($group, $field['id'], $logic, $value, $type)); } $query = "\n\t\t\tINSERT INTO " . $dbo->table['group_rules'] . "\n\t\t\t(group_id, field_id, logic, value, type)\n\t\t\tVALUES " . implode(',', $v); return $dbo->affected($query); }
function rememberBaseURL() { global $pommo; $config = PommoHelper::parseConfig($pommo->_workDir . '/maintenance.php'); return $config['baseURL']; }
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; }
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; }
$box = true; } if (is_resource($fp)) { if ($_POST['type'] == 'txt') { // list of emails $a = array(); while (($data = fgetcsv($fp, 2048, ',', '"')) !== FALSE) { foreach ($data as $email) { if (PommoHelper::isEmail($email)) { array_push($a, $email); } } } // remove dupes $includeUnsubscribed = isset($_REQUEST['excludeUnsubscribed']) ? false : true; $dupes =& PommoHelper::isDupe($a, $includeUnsubscribed); if (!$dupes) { $dupes = array(); } $emails = array_diff($a, $dupes); $pommo->set(array('emails' => $emails, 'dupes' => count($dupes))); Pommo::redirect('import_txt.php'); } elseif ($_POST['type'] == 'csv') { // csv of subscriber data, store first 10 for preview $a = array(); $i = 1; while (($data = fgetcsv($fp, 2048, ',', '"')) !== FALSE) { array_push($a, $data); if ($i > 9) { // only get first 10 lines -- move file break;
if ($logger->isErr() || !PommoValidate::subscriberData($subscriber['data'], array('active' => FALSE))) { $smarty->assign('back', TRUE); $smarty->display('user/process.tpl'); Pommo::kill(); } $comments = isset($_POST['comments']) ? substr($_POST['comments'], 0, 255) : false; /********************************** ADD SUBSCRIBER *********************************/ $config = PommoAPI::configGet(array('site_success', 'site_confirm', 'list_confirm', 'notices')); $notices = unserialize($config['notices']); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/messages.php'); if ($config['list_confirm'] == 'on') { // email confirmation required. // add user as "pending" $subscriber['pending_code'] = PommoHelper::makeCode(); $subscriber['pending_type'] = 'add'; $subscriber['status'] = 2; $id = PommoSubscriber::add($subscriber); if (!$id) { $logger->addErr('Error adding subscriber! Please contact the administrator.'); $smarty->assign('back', TRUE); } else { $logger->addMsg(Pommo::_T('Subscription request received.')); // send confirmation message. if (PommoHelperMessages::sendMessage(array('to' => $subscriber['email'], 'code' => $subscriber['pending_code'], 'type' => 'confirm'))) { $subscriber['registered'] = date("F j, Y, g:i a", $subscriber['registered']); if ($comments || isset($notices['pending']) && $notices['pending'] == 'on') { PommoHelperMessages::notify($notices, $subscriber, 'pending', $comments); } if ($config['site_confirm']) {
} // [RELEASE] // Include core components require dirname(__FILE__) . '/inc/helpers/common.php'; // base helper functions require dirname(__FILE__) . '/inc/classes/api.php'; // base API require dirname(__FILE__) . '/inc/classes/pommo.php'; // base object // Setup the core global. All utility is tucked away within this global to reduce namespace // pollution and possible collissions when poMMo is embedded in another application. $GLOBALS['pommo'] = new Pommo(dirname(__FILE__) . '/'); /* * Disable session.use_trans_sid to mitigate performance-penalty * (do it before any output is started) [from gallery2] */ if (!defined('SID')) { @ini_set('session.use_trans_sid', 0); } // soft turn off magic quotes -- NOTE; this may break embedded scripts? // clean user input of slashes added by magic quotes. TODO; optimize this. if (get_magic_quotes_gpc()) { $_REQUEST = PommoHelper::slashStrip($_REQUEST); $_GET = PommoHelper::slashStrip($_GET); $_POST = PommoHelper::slashStrip($_POST); } // disable escaping from DB ini_set("magic_quotes_runtime", 0); // Assign alias to the core global which can be used by the script calling bootstrap.php $pommo =& $GLOBALS['pommo']; $pommo->preinit();
} // 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: die('invalid request passed to ' . __FILE__); break; } $json->success();
Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $group = current(PommoGroup::get(array('id' => $state['group']))); if (empty($group)) { die('invalid input'); } if ($_REQUEST['ruleType'] == 'field') { $field = current(PommoField::get(array('id' => $_REQUEST['fieldID']))); $logic = isset($_REQUEST['logic']) && $_REQUEST['logic'] != "0" ? $_REQUEST['logic'] : false; $type = $_REQUEST['type'] == 'or' ? 'or' : 'and'; $values = array(); // check to see if we're editing [logic is passed *only* when edit button is clicked] if ($logic) { foreach ($group['rules'] as $rule) { if ($rule['logic'] == $logic && $rule['field_id'] == $_REQUEST['fieldID']) { $values[] = $field['type'] == 'date' ? PommoHelper::timeFromStr($rule['value']) : $rule['value']; } } } $firstVal = empty($values) ? false : array_shift($values); $logic = $logic ? PommoRules::getEnglish(array($logic)) : PommoRules::getEnglish(end(PommoRules::getLegal($group, array($field)))); $smarty->assign('type', $type); $smarty->assign('field', $field); $smarty->assign('logic', $logic); $smarty->assign('values', $values); $smarty->assign('firstVal', $firstVal); $smarty->display('admin/subscribers/ajax/rule.field.tpl'); Pommo::kill(); } elseif ($_REQUEST['ruleType'] == 'group') { $match = PommoGroup::getNames($_REQUEST['fieldID']); $key = key($match);
function &get($p = array(), $search = array('field' => null, 'string' => null)) { $defaults = array('status' => 'all', 'email' => null, 'sort' => null, 'order' => null, 'limit' => null, 'offset' => null, 'id' => null); $p = PommoAPI::getParams($defaults, $p); global $pommo; $dbo =& $pommo->_dbo; if ($p['status'] == 'all') { $p['status'] = null; } if (is_numeric($p['limit']) && !is_numeric($p['offset'])) { $p['offset'] = 0; } $o = array(); $query = "\n\t\t\tSELECT\n\t\t\t\ts.subscriber_id,\n\t\t\t\ts.email,\n\t\t\t\ts.time_touched,\n\t\t\t\ts.time_registered,\n\t\t\t\ts.flag,\n\t\t\t\tINET_NTOA(s.ip) ip,\n\t\t\t\ts.status,\n\t\t\t\tp.pending_code,\n\t\t\t\tp.pending_array,\n\t\t\t\tp.pending_type" . (is_numeric($p['sort']) ? ", d.value" : '') . (is_numeric($search['field']) ? ", search.value" : '') . " FROM " . $dbo->table['subscribers'] . " s\n\t\t\tLEFT JOIN " . $dbo->table['subscriber_pending'] . " p ON (s.subscriber_id = p.subscriber_id) " . (is_numeric($p['sort']) ? "LEFT JOIN (SELECT * FROM " . $dbo->table['subscriber_data'] . " WHERE field_id = " . (int) $p['sort'] . " ) AS d" . " ON (s.subscriber_id = d.subscriber_id)" : '') . (is_numeric($search['field']) ? "LEFT JOIN (SELECT value FROM " . $dbo->table['subscriber_data'] . " WHERE field_id = " . (int) $search['field'] . " ) AS search" . " ON (s.subscriber_id = search.subscriber_id)" : '') . " WHERE\n\t\t\t\t1\n\t\t\t\t[AND s.subscriber_id IN(%C)]\n\t\t\t\t[AND s.status=%I]\n\t\t\t\t[AND s.email IN (%Q)]\n\t\t\t\t[AND %S LIKE '%%S%']\n\t\t\t\t[ORDER BY %S] [%S]\n\t\t\t\t[LIMIT %I, %I]"; // Check if we're sorting against a field. // If so, sort against the "value" column select. // If it's a numeric field, cast the value (string) as an Integer by the DBE for proper sorting. if (is_numeric($p['sort'])) { Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/fields.php'); $numericFields = PommoField::getByType(array('date', 'number')); $p['sort'] = in_array($p['sort'], $numericFields) ? 'CAST(value as SIGNED)' : 'value'; } // If we're searching/filtering, generate the proper SQL $searchSQL = NULL; if (!empty($search['field']) && !empty($search['string'])) { // make MySQL LIKE() compliant $search['string'] = addcslashes($search['string'], '%_'); $search['field'] = is_numeric($search['field']) ? 'search.value' : 's.' . $search['field']; } $query = $dbo->prepare($query, array($p['id'], $p['status'], $p['email'], $search['field'], $search['string'], $p['sort'], $p['order'], $p['offset'], $p['limit'])); while ($row = $dbo->getRows($query)) { $o[$row['subscriber_id']] = empty($row['pending_code']) ? PommoSubscriber::makeDB($row) : PommoSubscriber::makeDB($row, TRUE); } // fetch data if (!empty($o)) { // get any date fields for conversion. We can't use the MySQL 4.1/5 // engine, as it doesn't support negative timestamps... !!! Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/fields.php'); $dates = PommoField::getByType('date'); $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tfield_id,\n\t\t\t\t\tvalue,\n\t\t\t\t\tsubscriber_id\n\t\t\t\tFROM\n\t\t\t\t\t" . $dbo->table['subscriber_data'] . "\n\t\t\t\tWHERE\n\t\t\t\t\tsubscriber_id IN(%c)"; $query = $dbo->prepare($query, array(array_keys($o))); while ($row = $dbo->getRows($query)) { $o[$row['subscriber_id']]['data'][$row['field_id']] = in_array($row['field_id'], $dates) ? PommoHelper::timeToStr($row['value']) : $row['value']; } } return $o; }
SmartyValidate::register_validator('email', 'Email', 'isEmail', false, false, 'trim'); $formError = array(); $formError['email'] = Pommo::_T('Invalid email address'); $smarty->assign('formError', $formError); // Assign email to form if pre-provided if (isset($_REQUEST['Email'])) { $smarty->assign('Email', $_REQUEST['Email']); } elseif (isset($_REQUEST['email'])) { $smarty->assign('Email', $_REQUEST['email']); } } else { // ___ USER HAS SENT FORM ___ SmartyValidate::connect($smarty); if (SmartyValidate::is_valid($_POST)) { // __ FORM IS VALID __ if (PommoHelper::isDupe($_POST['Email'])) { if (PommoPending::isEmailPending($_POST['Email'])) { $input = urlencode(serialize(array('Email' => $_POST['Email']))); SmartyValidate::disconnect(); Pommo::redirect('pending.php?input=' . $input); } else { // __ EMAIL IN SUBSCRIBERS TABLE, REDIRECT SmartyValidate::disconnect(); Pommo::redirect('activate.php?email=' . $_POST['Email']); } } else { // __ REPORT STATUS $logger->addMsg(Pommo::_T('Email address not found! Please try again.')); $logger->addMsg(sprintf(Pommo::_T('To subscribe, %sclick here%s'), '<a href="' . $pommo->_baseUrl . 'user/subscribe.php?Email=' . $_POST['Email'] . '">', '</a>')); } }
function &stateInit($name = 'default', $defaults = array(), $source = array()) { global $pommo; if (empty($pommo->_session['state'][$name])) { $pommo->_session['state'][$name] = $defaults; } $state =& $pommo->_session['state'][$name]; if (empty($defaults)) { return $state; } foreach (array_keys($state) as $key) { if (array_key_exists($key, $source)) { $state[$key] = $source[$key]; } } // normalize the page state if (count($state) > count($defaults)) { $state = PommoHelper::arrayIntersect($state, $defaults); } return $state; }
function validate() { if (empty($this->_fromname)) { $this->logger->addMsg("Name cannot be blank."); return false; } if (!PommoHelper::isEmail($this->_fromemail)) { $this->logger->addMsg("From email must be a valid email address."); return false; } if (!PommoHelper::isEmail($this->_frombounce)) { $this->logger->addMsg("Bounce email must be a valid email address."); return false; } if (empty($this->_subject)) { $this->logger->addMsg("Subject cannot be blank."); return false; } if (empty($this->_body)) { $this->logger->addMsg("Message content cannot be blank."); return false; } return true; }
$table = $dbo->table[$key]; $sql = 'DROP TABLE IF EXISTS ' . $table; $dbo->query($sql); } if (isset($_REQUEST['debugInstall'])) { $dbo->debug(TRUE); } $install = PommoInstall::parseSQL(); if ($install) { // installation of DB went OK, set configuration values to user supplied ones $pass = $_POST['admin_password']; // install configuration $_POST['admin_password'] = md5($_POST['admin_password']); PommoAPI::configUpdate($_POST); // generate key to uniquely identify this installation $key = PommoHelper::makeCode(6); PommoAPI::configUpdate(array('key' => $key), TRUE); $pommo->reloadConfig(); // load configuration [depricated?], set message defaults, load templates Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/messages.php'); PommoHelperMessages::resetDefault('all'); // install templates $file = $pommo->_baseDir . "install/sql.templates.php"; if (!PommoInstall::parseSQL(false, $file)) { $logger->addErr('Error Loading Default Mailing Templates.'); } // serialize the latest updates $GLOBALS['pommoFakeUpgrade'] = true; Pommo::requireOnce($pommo->_baseDir . 'install/helper.upgrade.php'); PommoUpgrade(); $logger->addMsg(Pommo::_T('Installation Complete! You may now login and setup poMMo.'));
$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'; $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.'));
function smarty_modifier_pommoDateFormat($int) { return PommoHelper::timeToStr($int); }
foreach ($row as $key => $col) { $fid =& $_POST['f'][$key]; if (is_numeric($fid)) { $subscriber['data'][$fid] = $col; } 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++; } } }
function notify(&$notices, &$sub, $type, $comments = false) { global $pommo; Pommo::requireOnce($pommo->_baseDir . 'inc/classes/mailer.php'); $mails = PommoHelper::trimArray(explode(',', $notices['email'])); if (empty($mails[0])) { $mails = array($pommo->_config['admin_email']); } $subject = $notices['subject'] . ' '; $body = sprintf(Pommo::_T('poMMo %s Notice'), $type); $body .= " [" . date("F j, Y, g:i a") . "]\n\n"; $body .= "EMAIL: " . $sub['email'] . "\n"; $body .= "IP: " . $sub['ip'] . "\n"; $body .= "REGISTERED: " . $sub['registered'] . "\n\n"; if ($comments) { $body .= "COMMENTS: {$comments} \n\n"; } $body .= "DATA:\n"; Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/fields.php'); $fields = PommoField::getNames(); foreach ($sub['data'] as $fid => $v) { $body .= "\t" . $fields[$fid] . ": {$v}\n"; } switch ($type) { case 'subscribe': $subject .= Pommo::_T('new subscriber!'); break; case 'unsubscribe': $subject .= Pommo::_T('user unsubscribed.'); break; case 'pending': $subject .= Pommo::_T('new pending!'); break; case 'update': $subject .= Pommo::_T('subscriber updated.'); break; } $mail = new PommoMailer(); // allow mail to be sent, even if demo mode is on $mail->toggleDemoMode("off"); // send the confirmation mail $mail->prepareMail($subject, $body); foreach ($mails as $to) { $mail->bmSendmail($to); } // reset demo mode to default $mail->toggleDemoMode(); return; }
$pommo->init(); Pommo::requireOnce($pommo->_baseDir . 'inc/classes/mailctl.php'); echo 'Merci de patienter quelques secondes...'; ob_flush(); flush(); $code = PommoHelper::makeCode(); if (!PommoMailCtl::spawn($pommo->_baseUrl . 'support/tests/mailing.test2.php?code=' . $code, true)) { Pommo::kill('Echec du déclenchement du mécanisme. Vous devez corriger ce problème pour que poMMo puisse envoyer des e-mails.'); } sleep(6); if (!is_file($pommo->_workDir . '/mailing.test.php')) { // make sure we can write to the file if (!($handle = fopen($pommo->_workDir . '/mailing.test.php', 'w'))) { die('Impossible d\'écrire dans le fichier de test.'); } fclose($handle); unlink($pommo->_workDir . '/mailing.test.php'); Pommo::kill('Echec du déclenchement du mécanisme (problème d\'écriture au niveau du fichier de test). Vous devez corriger ce problème pour que poMMo puisse envoyer des e-mails.'); } $o = PommoHelper::parseConfig($pommo->_workDir . '/mailing.test.php'); unlink($pommo->_workDir . '/mailing.test.php') or die('impossible de supprimer mailing.test.php'); if (isset($o['error'])) { Pommo::kill('UNE ERREUR A ETE TROUVEE. MERCI DE VERIFIER LE RESULTAT DE \'MAILING_TEST\' DANS LE REPERTOIRE DE TRAVAIL'); } if (!isset($o['code']) || $o['code'] != $code) { Pommo::kill('Le test a échoué. Certains codes ne correspondent pas.'); } if (!isset($o['spawn']) || $o['spawn'] == 0) { Pommo::kill('Déclenchement réussi mais échec des envois à répétition.'); } Pommo::kill('Déclenchement réussi. Envois à répétition réussis. La fonction d\'envoi massif est opérationnelle.');
} $config = PommoAPI::configGet(array('notices')); $notices = unserialize($config['notices']); if (!isset($_POST['d'])) { $smarty->assign('d', $subscriber['data']); } // check for an update + validate new subscriber info (also converts dates to ints) if (!empty($_POST['update']) && PommoValidate::subscriberData($_POST['d'])) { $newsub = array('id' => $subscriber['id'], 'email' => $subscriber['email'], 'data' => $_POST['d']); if (!empty($_POST['newemail'])) { // if change in email, validate and send confirmation of update if ($_POST['newemail'] != $_POST['newemail2']) { $logger->addErr(Pommo::_T('Emails must match.')); } elseif (!PommoHelper::isEmail($_POST['newemail'])) { $logger->addErr(Pommo::_T('Invalid Email Address')); } elseif (PommoHelper::isDupe($_POST['newemail'])) { $logger->addMsg(Pommo::_T('Email address already exists. Duplicates are not allowed.')); } else { $newsub['email'] = $_POST['newemail']; $code = PommoPending::add($newsub, 'change'); if (!$code) { die('Failed to Generate Pending Subscriber Code'); } Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/messages.php'); PommoHelperMessages::sendMessage(array('to' => $newsub['email'], 'code' => $code, 'type' => 'update')); if (isset($notices['update']) && $notices['update'] == 'on') { PommoHelperMessages::notify($notices, $newsub, 'update'); } } } elseif (!PommoSubscriber::update($newsub, 'REPLACE_ACTIVE')) { $logger->addErr('Error updating subscriber.');