<commit_before><?php

require_once 'Swat/SwatUI.php';
require_once 'Swat/SwatString.php';
require_once 'Site/SiteMultipartMailMessage.php';
require_once 'Site/pages/SiteEditPage.php';

/**
 *
 * @package   Site
 * @copyright 2006-2009 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 */
class SiteContactPage extends SiteEditPage
{
	// {{{ protected function getUiXml()

	protected function getUiXml()
	{
		return 'Site/pages/contact.xml';
	}

	// }}}
	// {{{ protected function getSubjects()

	protected function getSubjects()
	{
		$subjects = array(
			'general'  => Site::_('General Question'),
			'website'  => Site::_('Website'),
			'privacy'  => Site::_('Privacy'),
		);

		return $subjects;
	}

	// }}}

	// process phase
	// {{{ protected function save()

	protected function save(SwatForm $form)
	{
		$this->sendEmail();
	}

	// }}}
	// {{{ protected function relocate()

	protected function relocate(SwatForm $form)
	{
		if (!$this->app->session->isActive() ||
			count($this->app->messages) === 0) {
			$this->app->relocate($this->source.'/thankyou');
		}
	}

	// }}}
	// {{{ protected function sendEmail()

	protected function sendEmail()
	{
		$message = $this->getMessage();

		try {
			$message->send();
		} catch (SiteMailException $e) {
			if (!$this->app->session->isActive())
				$this->app->session->activate();

			$message = new SwatMessage(<commit_msg>Fix an edge-case bug caused by bad robots trying to submit the contact form without all the required POST data.<commit_after><?php

require_once 'Swat/SwatUI.php';
require_once 'Swat/SwatString.php';
require_once 'Site/SiteMultipartMailMessage.php';
require_once 'Site/pages/SiteEditPage.php';

/**
 *
 * @package   Site
 * @copyright 2006-2010 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 */
class SiteContactPage extends SiteEditPage
{
	// {{{ protected function getUiXml()

	protected function getUiXml()
	{
		return 'Site/pages/contact.xml';
	}

	// }}}
	// {{{ protected function getSubjects()

	protected function getSubjects()
	{
		$subjects = array(
			'general'  => Site::_('General Question'),
			'website'  => Site::_('Website'),
			'privacy'  => Site::_('Privacy'),
		);

		return $subjects;
	}

	// }}}

	// process phase
	// {{{ protected function save()

	protected function save(SwatForm $form)
	{
		$this->sendEmail();
	}

	// }}}
	// {{{ protected function validate()

	protected function validate(SwatForm $form)
	{
		parent::validate($form);

		// Ensure a subject is set. Some robots try to submit the contact form
		// and omit HTTP POST data for the subject field. Due to Swat's
		// architecture, the widget will not raise its own validation error if
		// no POST data exists for the subject flydown. We check for a null
		// value here and explicitly add a validation message.
		$subject = $this->ui->getWidget('subject');
		if ($subject->value === null) {
			$message = new SwatMessage(
				Site::_('The <strong>%s<strong> field is required.'));

			$message->content_type = 'text/xml';
			$subject->addMessage($message);
		}
	}

	// }}}
	// {{{ protected function relocate()

	protected function relocate(SwatForm $form)
	{
		if (!$this->app->session->isActive() ||
			count($this->app->messages) === 0) {
			$this->app->relocate($this->source.'/thankyou');
		}
	}

	// }}}
	// {{{ protected function sendEmail()

	protected function sendEmail()
	{
		$message = $this->getMessage();

		try {
			$message->send();
		} catch (SiteMailException $e) {
			if (!$this->app->session->isActive())
				$this->app->session->activate();

			$message = new SwatMessage(
{'fraction_non_alphanumeric': 0.17198679141441936, 'fraction_numerical': 0.006053935057787562, 'mean_word_length': 3.654289372599232, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '792190', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1180, 'n_words': 277}