/** * Overloaded check method to ensure data integrity of a subscriber * * @access public * @return boolean True on success */ public function check() { //Initialize jimport('joomla.mail.helper'); $params = JComponentHelper::getParams('com_bwpostman'); $app = JFactory::getApplication(); $import = $app->getUserState('com_bwpostman.subscriber.import', false); $data = $app->getUserState('com_bwpostman.subscriber.register.data', array()); $session = JFactory::getSession(); $err = $session->get('session_error'); $fault = false; $_db = $this->_db; $query = $_db->getQuery(true); $tester = false; $format_txt = array(0 => 'Text', 1 => 'HTML'); if ($xtest = !'9') { $tester = true; } if ($import && $this->status == '9') { $tester = true; } // Remove all HTML tags from the name, firstname, email and special $filter = new JFilterInput(array(), array(), 0, 0); $this->name = $filter->clean($this->name); $this->firstname = $filter->clean($this->firstname); $this->email = $filter->clean($this->email); $this->special = $filter->clean($this->special); if (!$import) { // Check for valid firstname if ($data['show_firstname_field'] && $data['firstname_field_obligation']) { if (trim($this->firstname) == '') { $app->enqueueMessage(JText::_('COM_BWPOSTMAN_SUB_ERROR_FIRSTNAME'), 'error'); $fault = true; } } // Check for valid name if ($data['show_name_field'] && $data['name_field_obligation']) { if (trim($this->name) == '') { $app->enqueueMessage(JText::_('COM_BWPOSTMAN_SUB_ERROR_NAME'), 'error'); $fault = true; } } // Check for valid additional field if ($data['show_special'] && $data['special_field_obligation']) { if (trim($this->special) == '') { $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_SPECIAL', JText::_($params->get('special_label'))), 'error'); $fault = true; } } } // Check for valid email address if (trim($this->email) == '') { $app->enqueueMessage(JText::_('COM_BWPOSTMAN_SUB_ERROR_EMAIL'), 'error'); $fault = true; } elseif (!JMailHelper::isEmailAddress(trim($this->email))) { $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_EMAIL_INVALID', $this->email), 'error'); $fault = true; } if ($app->isSite() && !$this->id) { // Check if any mailinglist is checked if (!$data['mailinglists']) { $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_LISTCHECK'), 'error'); $fault = true; } // agreecheck if (JComponentHelper::getParams('com_bwpostman')->get('disclaimer') == 1) { if (!isset($data['agreecheck']) && !isset($data['agreecheck_mod'])) { $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_AGREECHECK'), 'error'); $fault = true; } } // Spamcheck 1 // Set error message if a not visible (top: -5000px) inputfield is empty if ($data['falle'] != '') { // input wrong - set error $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_SPAMCHECK'), 'error'); $fault = true; } // Spamcheck 2 // Set error message if check of a dynamic time variable failed if (!isset($data['bwp-' . BwPostmanHelper::getCaptcha(1)]) && !isset($data['bwp-' . BwPostmanHelper::getCaptcha(2)])) { // input wrong - set error $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_SPAMCHECK2'), 'error'); $fault = true; } // Captchacheck 1 // Set error message if captchatest failed if (JComponentHelper::getParams('com_bwpostman')->get('use_captcha') == 1) { // start check if (trim($data['stringQuestion']) != trim(JComponentHelper::getParams('com_bwpostman')->get('security_answer'))) { // input wrong - set error $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_CAPTCHA'), 'error'); $fault = true; } } // Captchacheck 2 if (JComponentHelper::getParams('com_bwpostman')->get('use_captcha') == 2) { // Temp folder of captcha-images $captchaDir = JPATH_COMPONENT_SITE . '/assets/capimgdir/'; // del old images after ? minutes $delFile = 10; // start check $resultCaptcha = BwPostmanHelper::CheckCaptcha($data['codeCaptcha'], $data['stringCaptcha'], $captchaDir, $delFile); if (!$resultCaptcha) { // input wrong - set error $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_CAPTCHA'), 'error'); $fault = true; } } } if ($fault) { $app->setUserState('com_bwpostman.edit.subscriber.data', $this); // $app->setUserState('com_bwpostman.edit.subscriber.register.errors', $err); $session->set('session_error', $err); // $session->close(); return false; } // Check for existing email $query->select($_db->quoteName('id')); $query->from($_db->quoteName('#__bwpostman_subscribers')); $query->where($_db->quoteName('email') . ' = ' . $_db->Quote($this->email)); if (!$tester) { $query->where($_db->quoteName('status') . ' != ' . (int) 9); } $_db->setQuery($query); $_db->query(); if (!$tester) { $xid = intval($this->_db->loadResult()); } else { $xids = $this->_db->loadColumn(); } //Test-recipient may have multiple entries, but may not be archived if ($tester) { foreach ($xids as $xid) { $xid = intval($xid); if ($xid && $xid != intval($this->id)) { $query = $_db->getQuery(true); $query->select($_db->quoteName('id')); $query->select($_db->quoteName('emailformat')); $query->select($_db->quoteName('archive_flag')); $query->from($_db->quoteName('#__bwpostman_subscribers')); $query->where($_db->quoteName('id') . ' = ' . (int) $xid); $this->_db->setQuery($query); $testrecipient = $this->_db->loadObject(); // Account with this emailformat already exists if ($testrecipient->archive_flag == 0 && $testrecipient->emailformat == $this->emailformat) { $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTEXISTS', $this->email, $format_txt[$this->emailformat], $testrecipient->id), 'error'); $err['err_code'] = 409; $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTEXISTS', $this->email, $format_txt[$this->emailformat], $testrecipient->id); $err['err_id'] = $xid; $app->setUserState('com_bwpostman.subscriber.register.error', $err); $this->setError(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTEXISTS', $this->email, $format_txt[$this->emailformat], $testrecipient->id)); $session->set('session_error', $err); return false; } // Account is archived if ($testrecipient->archive_flag == 1 && $testrecipient->emailformat == $this->emailformat) { $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTARCHIVED', $this->email, $format_txt[$this->emailformat], $testrecipient->id), 'error'); $err['err_code'] = 410; $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTARCHIVED', $this->email, $format_txt[$this->emailformat], $testrecipient->id); $err['err_id'] = $xid; $app->setUserState('com_bwpostman.subscriber.register.error', $err); $this->setError(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTARCHIVED', $this->email, $format_txt[$this->emailformat], $testrecipient->id)); $session->set('session_error', $err); return false; } } } } else { if ($xid && $xid != intval($this->id)) { $query = $_db->getQuery(true); $query->select($_db->quoteName('id')); $query->select($_db->quoteName('status')); $query->select($_db->quoteName('archive_flag')); $query->select($_db->quoteName('archived_by')); $query->from($_db->quoteName('#__bwpostman_subscribers')); $query->where($_db->quoteName('id') . ' = ' . (int) $xid); $_db->setQuery($query); $_db->query(); $subscriber = $this->_db->loadObject(); // Account is blocked by system/administrator if ($subscriber->archive_flag == 1 && $subscriber->archived_by > 0) { $err['err_code'] = 405; $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTBLOCKED_BY_SYSTEM', $this->email, $xid); $err['err_id'] = $xid; $err['err_email'] = $this->email; $app->setUserState('com_bwpostman.subscriber.register.error', $err); $this->setError(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTBLOCKED_BY_SYSTEM', $this->email, $xid)); $session->set('session_error', $err); return false; } // Account is not activated if ($subscriber->status == 0) { $err['err_code'] = 406; $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTNOTACTIVATED', $this->email, $xid); $err['err_id'] = $xid; $err['err_email'] = $this->email; $app->setUserState('com_bwpostman.subscriber.register.error', $err); $this->setError(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTNOTACTIVATED', $this->email, $xid)); $session->set('session_error', $err); return false; } // Account already exists if ($subscriber->status == 1 && $subscriber->archive_flag != 1) { $err['err_code'] = 407; $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTEXISTS', $this->email, JRoute::_('index.php?option=com_bwpostman&view=edit')); $err['err_id'] = $xid; $err['err_email'] = $this->email; $app->setUserState('com_bwpostman.subscriber.register.error', $err); $this->setError(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTEXISTS', $this->email, JRoute::_('index.php?option=com_bwpostman&view=edit'))); $session->set('session_error', $err); return false; } } } return true; }