From 0f6ddf60f8547063fca45244c78c2ffc10856e09 Mon Sep 17 00:00:00 2001 From: Oreolek Date: Wed, 29 Jan 2014 17:41:25 +0700 Subject: [PATCH] Email module --- .gitignore | 1 + .gitmodules | 3 +++ application/bootstrap.php | 1 + application/classes/Controller/Letter.php | 15 +-------------- application/classes/Model/Letter.php | 18 ++++++++++++++++++ application/classes/View/Letter/Index.php | 2 +- application/config/email.php.example | 12 ++++++++++++ application/i18n/ru.php | 3 ++- modules/email | 1 + 9 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 application/config/email.php.example create mode 160000 modules/email diff --git a/.gitignore b/.gitignore index 39994f5..b6deaac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ application/config/database.php application/config/stats.php +application/config/email.php application/config/sphinxql.php application/cache application/logs diff --git a/.gitmodules b/.gitmodules index f269e81..8b62fba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "modules/kostache"] path = modules/kostache url = git://github.com/zombor/KOstache.git +[submodule "modules/email"] + path = modules/email + url = git@github.com:shadowhand/email.git diff --git a/application/bootstrap.php b/application/bootstrap.php index da58a33..ddd90d8 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -112,6 +112,7 @@ Kohana::modules(array( 'less' => MODPATH.'less', // LEaner CSS 'debug-toolbar' => MODPATH.'debug-toolbar', // Debug toolbar 'kostache' => MODPATH.'kostache', // Logic-less Mustache views + 'email' => MODPATH.'email', // Electronic mail class )); /** diff --git a/application/classes/Controller/Letter.php b/application/classes/Controller/Letter.php index 53c14af..2acfb3a 100644 --- a/application/classes/Controller/Letter.php +++ b/application/classes/Controller/Letter.php @@ -8,6 +8,7 @@ class Controller_Letter extends Controller_Layout { 'index','create', 'edit', 'delete' ); protected $controls = array( + 'subject' => 'input', 'text' => 'textarea', 'order' => 'input', ); @@ -57,18 +58,4 @@ class Controller_Letter extends Controller_Layout { $this->redirect('/'); } } - public function action_view() - { - $this->template = new View_Letter_Index; - $id = $this->request->param('id'); - $model = ORM::factory('Subscription', $id)->with('letters'); - if (!$model->loaded()) - { - $this->redirect('error/404'); - } - $this->template->title = __('Subscription').' '.$model->title; - $this->template->items = $model->letters - ->filter_by_page($this->request->param('page')) - ->find_all(); - } } diff --git a/application/classes/Model/Letter.php b/application/classes/Model/Letter.php index 9f6727e..24b8e60 100644 --- a/application/classes/Model/Letter.php +++ b/application/classes/Model/Letter.php @@ -16,6 +16,10 @@ class Model_Letter extends ORM { public function rules() { return array( + 'subject' => array( + array('not_empty'), + array('max_length', array(':value', 128)), + ), 'text' => array( array('not_empty'), array('min_length', array(':value', 20)), @@ -32,6 +36,7 @@ class Model_Letter extends ORM { **/ protected $_labels = array( 'text' => 'Message text', + 'subject' => 'Message subject', 'order' => 'Message order' ); @@ -43,4 +48,17 @@ class Model_Letter extends ORM { } } + /** + * Function to send a email to a specified address. + * Not suitable for a large-scale use. + * @param email $address email address + * TODO: render text in HTML template + **/ + public function send($address) + { + $sender = Kohana::$config->load('email')->get('sender'); + $email = Email::factory($this->subject, $this->text)->to($address)->from($sender); + return $email->send(); + } + } diff --git a/application/classes/View/Letter/Index.php b/application/classes/View/Letter/Index.php index 995e73e..a0cfda1 100644 --- a/application/classes/View/Letter/Index.php +++ b/application/classes/View/Letter/Index.php @@ -22,7 +22,7 @@ class View_Letter_Index extends View_Index { $output = array( 'description' => $item->text, - 'view_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'view','id' => $item->id)),__('View'), array('class' => 'link_view')), + 'view_link' => $item->subject,//HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'view','id' => $item->id)), $item->subject, array('class' => 'link_view')), 'edit_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'edit','id' => $item->id)), __('Edit'), array('class' => 'link_edit')), 'delete_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'delete','id' => $item->id)), __('Delete'), array('class' => 'link_delete')), ); diff --git a/application/config/email.php.example b/application/config/email.php.example new file mode 100644 index 0000000..95abb06 --- /dev/null +++ b/application/config/email.php.example @@ -0,0 +1,12 @@ + 'smtp', + 'sender' => array('sender@example.com', 'Sender Name'), + 'options' => array( + 'hostname' => '', + 'username' => '', + 'password' => '', + 'port' => '465', + 'encryption' => 'tls' + ), + ); diff --git a/application/i18n/ru.php b/application/i18n/ru.php index 74a8571..1150a66 100644 --- a/application/i18n/ru.php +++ b/application/i18n/ru.php @@ -32,5 +32,6 @@ return array( 'New letter' => 'Новое письмо', 'Letter editing' => 'Редактирование письма', 'Delete letter' => 'Удалить письмо', - 'View' => 'Просмотреть' + 'View' => 'Просмотреть', + 'Message subject' => 'Тема письма', ); diff --git a/modules/email b/modules/email new file mode 160000 index 0000000..6005b39 --- /dev/null +++ b/modules/email @@ -0,0 +1 @@ +Subproject commit 6005b3965b395b7fae5ac50e9fa58452bfcf6453