From 4cc790772830cf8cd347cd9cb5e647f5c36a6c14 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Tue, 27 Apr 2010 17:28:43 +0000 Subject: [PATCH] mailer, some fixes, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@142 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- captcha/Captcha.php | 3 ++ classes/Mailer.class.php | 78 ---------------------------------------------- exception/ErrorHandler.php | 6 ++-- form/Form.php | 8 +++++ mail/Mailer.php | 33 ++++++++++++++++++++ 5 files changed, 47 insertions(+), 81 deletions(-) delete mode 100644 classes/Mailer.class.php create mode 100644 mail/Mailer.php diff --git a/captcha/Captcha.php b/captcha/Captcha.php index b42e0db..919bc9e 100644 --- a/captcha/Captcha.php +++ b/captcha/Captcha.php @@ -72,6 +72,9 @@ class Captcha public function checkCode($token, $code) { if (Session::get('_ctoken') == $token && Session::get('_ccode') == strtoupper($code)){ + // Housekeeping + Session::del('_ccode'); + Session::del('_ctoken'); return true; } return false; diff --git a/classes/Mailer.class.php b/classes/Mailer.class.php deleted file mode 100644 index aaf88a5..0000000 --- a/classes/Mailer.class.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @link http://netmonsters.ru - * @package Core - * @subpackage mail - * @since - * @version SVN: $Id$ - * @filesource $URL$ - */ - -class Mailer -{ - public $template_dir = 'mail'; - public $template = null; - public $templater; - public $headers; - protected $host; - - function __construct($host, $template = null) - { - if ($template !== null) { - $this->templater = Load::templater(ACTION_TPL_PATH . '/' . $this->template_dir); - $this->template = $template; - } - - $this->host = $host; - - $this->headers .= 'From: robot@' . $this->host . "\r\n"; - $this->headers .= 'Date: '. date('r') ."\r\n"; - $this->headers .= "Return-Path: robot@". $this->host ."\r\n"; - $this->headers .= "X-Mailer: PHPMail Tool\r\n"; - $this->headers .= "Reply-To: robot@". $this->host ."\r\n"; - $this->headers .= "X-Priority: 3 (Normal)\r\n"; - $this->headers .= "Message-ID: <". md5(uniqid(time()))."@". $this->host .">\r\n"; - $this->headers .= "MIME-Version: 1.0\r\n"; - $this->headers .= "Content-Type: text/plain; charset=utf-8\r\n"; - $this->headers .= "Content-Transfer-Encoding: 16bit\r\n"; - } - - - /** - * Отправляет письма - * - * @param mixed $mail - * @param mixed $subject - * @param mixed $data - */ - function send ($mail, $subject, $data) - { - $this->headers .= "To: ".$mail."\r\n"; - - foreach ($data as $key => $val) { - $this->templater->assign($key, $val); - } - - $message = $this->templater->fetch($this->template.'.tpl'); - $encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n"; - return mail($mail, $subject, $message, $this->headers); - } - - /** - * Отправка письма с непосредственным указанием контента - * - * @param string $email - * @param string $subject - * @param string $content - * @return bool - */ - public function sendMessage($email, $subject, $content) - { - $encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n"; - return mail($email, $encoded_subject, $content, $this->headers); - } -} -?> \ No newline at end of file diff --git a/exception/ErrorHandler.php b/exception/ErrorHandler.php index 9eeb43b..9f624c6 100644 --- a/exception/ErrorHandler.php +++ b/exception/ErrorHandler.php @@ -51,7 +51,7 @@ class ErrorHandler } $text = ''; foreach ($array as $key => $value) { - if (is_array($value)) { + if (is_array($value) || is_object($value)) { $value = print_r($value, true); } $value = ($value) ? htmlentities($value, ENT_QUOTES, 'UTF-8') : ' '; @@ -79,7 +79,7 @@ class ErrorHandler $source = self::getSource($exception->getFile(), $exception->getLine()); $time = date('r', Env::Server('REQUEST_TIME', time())); - $trace = self::wrapTrace($exception->getTraceAsString()); + $trace = nl2br($exception->getTraceAsString()); $get = self::wrapArray(Env::Get(), 'GET'); $post = self::wrapArray(Env::Post(), 'POST'); @@ -166,7 +166,7 @@ class ErrorHandler

Traceback

-
{$trace}
+
{$trace}
diff --git a/form/Form.php b/form/Form.php index 9d63da6..04e43a3 100644 --- a/form/Form.php +++ b/form/Form.php @@ -66,6 +66,14 @@ abstract class Form return $messages; } + public function getValue($key) + { + if (isset($this->fields[$key])) { + return $this->fields[$key]->getValue(); + } + return false; + } + public function getValues() { $values = array(); diff --git a/mail/Mailer.php b/mail/Mailer.php new file mode 100644 index 0000000..61e2a2e --- /dev/null +++ b/mail/Mailer.php @@ -0,0 +1,33 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage mail + * @since 2010-04-25 + * @version SVN: $Id$ + * @filesource $URL$ + */ + +class Mailer +{ + protected $headers; + + public function __construct($host) + { + $this->headers .= 'From: noreply@' . $host . "\r\n"; + $this->headers .= 'Date: '. date('r') ."\r\n"; + $this->headers .= "Return-Path: noreply@". $host ."\r\n"; + $this->headers .= "X-Priority: 3 (Normal)\r\n"; + $this->headers .= "Message-ID: <". md5(uniqid(time()))."@". $host .">\r\n"; + $this->headers .= "MIME-Version: 1.0\r\n"; + $this->headers .= "Content-Type: text/plain; charset=utf-8\r\n"; + $this->headers .= "Content-Transfer-Encoding: 16bit\r\n"; + } + + public function send($email, $subject, $message) + { + $subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n"; + return mail($email, $subject, $message, $this->headers); + } +} \ No newline at end of file
VariableValue