/** * Method to validate one ore more email addresses * * @access public * * @param array $cid Subscriber/Test-recipient IDs * @param boolean $showProgress * @return array $res associative array of result data */ public function validate_mail($cid = array(), $showProgress = false) { $_db = $this->_db; $query = $_db->getQuery(true); $config = Jfactory::getConfig(); $validator = new emailValidation(); $tmp = explode('@', $config->get('mailfrom')); $mailuser = $tmp[0]; $mailserver = $tmp[1]; $validator->timeout = 5; $validator->data_timeout = 0; $validator->localuser = $mailuser; $validator->localhost = $mailserver; $validator->debug = 0; $validator->html_debug = 1; $validator->exclude_address = ""; $query->select('*'); $query->from($_db->quoteName('#__bwpostman_subscribers')); $query->where($_db->quoteName('id') . ' IN (' . implode(',', $cid) . ')'); // $query->order($_db->escape($listOrdering).' '.$listDirn); $_db->setQuery($query); $subscribers = $_db->loadObjectList(); // After the validation process we want to show the results // --> therefore we store the results into an array $res = array(); $i = 0; foreach ($subscribers as $subscriber) { if ($showProgress) { echo "\n<br>{$subscriber->email} ... "; ob_flush(); flush(); } $res[$i]['id'] = $subscriber->id; $res[$i]['email'] = $subscriber->email; $res[$i]['name'] = $subscriber->name; $res[$i]['firstname'] = $subscriber->firstname; // Skip confirmed email address if they still passed the confirmation process and where identified as invalid if (strstr($subscriber->name, 'INVALID_')) { // Skipped $res[$i]['result'] = 2; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATION_SKIPPED'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATION_SKIPPED'); ob_flush(); flush(); } continue; } $result = $validator->ValidateEmailBox($subscriber->email); if ($result === -1) { // Unable to validate the address with this host $res[$i]['result'] = -1; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_HOST'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_HOST'); ob_flush(); flush(); } } elseif ($result) { // The host is able to receive email. The address could be valid. $res[$i]['result'] = 1; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_VALIDATING_EMAIL'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_VALIDATING_EMAIL'); ob_flush(); flush(); } // Activate this account $date = JFactory::getDate(); $time = $date->toSql(); $user = JFactory::getUser(); $query = $_db->getQuery(true); $query->update($_db->quoteName('#__bwpostman_subscribers')); $query->set($_db->quoteName('status') . " = " . (int) 1); $query->set($_db->quoteName('confirmation_date') . " = " . $_db->Quote($time, false)); $query->set($_db->quoteName('confirmed_by') . " = " . (int) $user->get('id')); $query->where($_db->quoteName('id') . ' = ' . (int) $subscriber->id); $_db->setQuery($query); if (!$_db->query()) { $this->setError($_db->getErrorMsg()); return false; } } else { // The host can\'t receive email or this mailbox doesn\'t exist. The address is NOT valid. $res[$i]['result'] = 0; $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_EMAIL'); $i++; if ($showProgress) { echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_EMAIL'); ob_flush(); flush(); } // Prepend an INVALID_ to the subscriber name $query = $_db->getQuery(true); $query->update($_db->quoteName('#__bwpostman_subscribers')); $query->set($_db->quoteName('name') . " = " . $_db->Quote('INVALID_' . $subscriber->name)); $query->where($_db->quoteName('id') . ' = ' . (int) $subscriber->id); $_db->setQuery($query); if (!$_db->query()) { $this->setError($_db->getErrorMsg()); return false; } } } return $res; }
/** * returns default values for params * * @return string Json-encoded default values for params */ private function _setDefaultParams() { $css_styles = "\r\n body\t{\r\n\tfont-family: Tahoma, Arial, Helvetica, Univers, sans-serif;\r\n\tfont-size: 15px;\r\n\tbackground:#E9EDF0;\r\n\tpadding:0px;\r\n\tmargin:0px;\r\n\tpadding-bottom:40px;\r\n\tcolor: #3F3F3F;\r\n}\r\n\r\n.outer\t{\r\n\tmargin: 0 auto;\r\n}\r\n\r\n.header\t{\r\n\tpadding: 10px auto;\r\n\tborder-bottom: 5px solid #599DCA;\r\n\ttext-align: center;\r\n\twidth: 100%;\r\n}\r\n\r\n.logo\t{\r\n\tmax-width: 100%;\r\n}\r\n\r\n.content-outer\t{\r\n\tmax-width: 1000px;\r\n\tmargin: 10px auto;\r\n}\r\n\r\n.content\t{\r\n\ttext-align: left;\r\n\tbackground: #E9EDF0;\r\n\tborder-radius: 8px 8px 8px 8px;\r\n\tbox-shadow: 1px 1px 3px 2px #599DCA;\r\n\tmargin: 0 5px;\r\n\tpadding: 0;\r\n}\r\n\r\n.content-inner\t{\r\n\tpadding: 20px 15px;\r\n}\r\n\r\nH1\t{\r\n\tcolor: #fff;\r\n\tbackground: #599DCA;\r\n\tborder-radius: 8px 8px 0 0;\r\n\tfont-size: 16px;\r\n\tfont-weight: bold;\r\n\ttext-align: center;\r\n\tpadding: 10px 0;\r\n}\r\n\r\nH2\t{\r\n\tborder-radius: 8px 8px 8px 8px;\r\n\tbox-shadow: 1px 1px 3px 2px #599DCA;\r\n\tcolor: #3061AF;\r\n\tpadding: 5px;\r\n}\r\n\r\n.footer-outer\t{\r\n\tmax-width: 1000px;\r\n\tmargin: 10px auto;\r\n}\r\n\r\n.footer-inner\t{\r\n\tmargin: 0 5px;\r\n}\r\n"; $params_default = array(); $config = Jfactory::getConfig(); $params_default['default_from_name'] = $config->get('fromname'); $params_default['default_from_email'] = $config->get('mailfrom'); $params_default['default_reply_email'] = $config->get('mailfrom'); $params_default['default_mails_per_pageload'] = "100"; $params_default['use_css_for_html_newsletter'] = "1"; $params_default['css_for_html_newsletter'] = $css_styles; $params_default['newsletter_show_author'] = "1"; $params_default['newsletter_show_createdate'] = "1"; $params_default['show_name_field'] = "1"; $params_default['show_firstname_field'] = "1"; $params_default['name_field_obligation'] = "1"; $params_default['firstname_field_obligation'] = "1"; $params_default['show_emailformat'] = "1"; $params_default['default_emailformat'] = "1"; $params_default['disclaimer'] = "0"; $params_default['disclaimer_link'] = "http://www.disclaimer.de/disclaimer.htm"; $params_default['disclaimer_target'] = "0"; $params_default['use_captcha'] = "0"; $params_default['pretext'] = ""; $params = json_encode($params_default); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->update($db->quoteName('#__extensions')); $query->set($db->quoteName('params') . " = " . $db->quote($params)); $query->where($db->quoteName('element') . " = " . $db->quote('com_bwpostman')); $db->SetQuery($query); $db->execute(); }
/** * Method to get the record form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * @since 1.0.1 */ public function getForm($data = array(), $loadData = true) { JForm::addFieldPath('JPATH_ADMINISTRATOR/components/com_bwpostman/models/fields'); $params = JComponentHelper::getParams('com_bwpostman'); $config = Jfactory::getConfig(); $user = JFactory::getUser(); $form = $this->loadForm('com_bwpostman.newsletter', 'newsletter', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } $jinput = JFactory::getApplication()->input; $id = $jinput->get('id', 0); // predefine some values if (!$form->getValue('from_name')) { if ($params->get('default_from_name') && !$form->getValue('from_name')) { $form->setValue('from_name', '', $params->get('default_from_name')); } else { $form->setValue('from_name', '', $config->get('fromname')); } } if (!$form->getValue('from_email')) { if ($params->get('default_from_email')) { $form->setValue('from_email', '', $params->get('default_from_email')); } else { $form->setValue('from_email', '', $config->get('mailfrom')); } } if (!$form->getValue('reply_email')) { if ($params->get('default_reply_email')) { $form->setValue('reply_email', '', $params->get('default_reply_email')); } else { $form->setValue('reply_email', '', $config->get('mailfrom')); } } // Check for existing newsletter. // Modify the form based on Edit State access controls. if ($id != 0 && !$user->authorise('core.edit.state', 'com_bwpostman.newsletter.' . (int) $id) || $id == 0 && !$user->authorise('core.edit.state', 'com_bwpostman')) { // Disable fields for display. $form->setFieldAttribute('published', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is an newsletter you can edit. $form->setFieldAttribute('state', 'filter', 'unset'); } // Check to show created data $c_date = $form->getValue('created_date'); if ($c_date == '0000-00-00 00:00:00') { $form->setFieldAttribute('created_date', 'type', 'hidden'); $form->setFieldAttribute('created_by', 'type', 'hidden'); } // Check to show modified data $m_date = $form->getValue('modified_time'); if ($m_date == '0000-00-00 00:00:00') { $form->setFieldAttribute('modified_time', 'type', 'hidden'); $form->setFieldAttribute('modified_by', 'type', 'hidden'); } // Check to show mailing data $s_date = $form->getValue('mailing_date'); if ($s_date == '0000-00-00 00:00:00') { $form->setFieldAttribute('mailing_date', 'type', 'hidden'); } // Hide published on tab edit_basic if ($jinput->get('layout') == 'edit_basic') { $form->setFieldAttribute('published', 'type', 'hidden'); } return $form; }