1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-06-16 15:01:09 +03:00

Email module

This commit is contained in:
Alexander Yakovlev 2014-01-29 17:41:25 +07:00
parent bb0ce9bcbc
commit 0f6ddf60f8
9 changed files with 40 additions and 16 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
application/config/database.php
application/config/stats.php
application/config/email.php
application/config/sphinxql.php
application/cache
application/logs

3
.gitmodules vendored
View file

@ -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

View file

@ -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
));
/**

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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')),
);

View file

@ -0,0 +1,12 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
return array(
'driver' => 'smtp',
'sender' => array('sender@example.com', 'Sender Name'),
'options' => array(
'hostname' => '',
'username' => '',
'password' => '',
'port' => '465',
'encryption' => 'tls'
),
);

View file

@ -32,5 +32,6 @@ return array(
'New letter' => 'Новое письмо',
'Letter editing' => 'Редактирование письма',
'Delete letter' => 'Удалить письмо',
'View' => 'Просмотреть'
'View' => 'Просмотреть',
'Message subject' => 'Тема письма',
);

1
modules/email Submodule

@ -0,0 +1 @@
Subproject commit 6005b3965b395b7fae5ac50e9fa58452bfcf6453