From d8d8614313f5ce90173f5c0674b04f4fa406c689 Mon Sep 17 00:00:00 2001 From: Oreolek Date: Sun, 2 Feb 2014 15:49:39 +0700 Subject: [PATCH] Pages --- .gitmodules | 3 + README.md | 2 +- application/bootstrap.php | 1 + application/classes/Controller/Page.php | 73 ++++++------------------- application/config/cache.php | 8 +++ application/i18n/ru.php | 8 ++- modules/cache | 1 + 7 files changed, 39 insertions(+), 57 deletions(-) create mode 100644 application/config/cache.php create mode 160000 modules/cache diff --git a/.gitmodules b/.gitmodules index a933823..1e71b55 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,6 @@ [submodule "modules/config-writer"] path = modules/config-writer url = https://github.com/ppx17/kohana-config-file-writer.git +[submodule "modules/cache"] + path = modules/cache + url = git@github.com:Oreolek/cache.git diff --git a/README.md b/README.md index 9fa4ffc..2729a66 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ License is [AGPL 3.0](http://www.tldrlegal.com/l/AGPL3) Kohana 3.3 (I recommend using 3.4 unstable git branch, it has MySQLi driver) MySQL or MariaDB -PHP 5 with enabled OpenSSL +PHP 5 with enabled OpenSSL and APCu ## Notes ### Config Writer diff --git a/application/bootstrap.php b/application/bootstrap.php index 600be5d..1b99441 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -115,6 +115,7 @@ Kohana::modules(array( 'email' => MODPATH.'email', // Electronic mail class 'minion' => MODPATH.'minion', // CLI framework 'config-writer' => MODPATH.'config-writer', // Write to PHP configs + 'cache' => MODPATH.'cache', // Object caching )); /** diff --git a/application/classes/Controller/Page.php b/application/classes/Controller/Page.php index e0deeb2..edd8f2d 100644 --- a/application/classes/Controller/Page.php +++ b/application/classes/Controller/Page.php @@ -4,6 +4,10 @@ class Controller_Page extends Controller_Layout { protected $secure_actions = array( 'drafts', 'create', 'edit', 'delete' ); + protected $controls = array( + 'name' => 'input', + 'content' => 'textarea', + ); /** * View a page. **/ @@ -41,10 +45,10 @@ class Controller_Page extends Controller_Layout { } $this->template = new View_Page_View; $this->template->title = $page->name; - $this->template->content = Markdown::instance()->transform($page->content); + $this->template->content = $page->content; if ($page->is_draft) { - $this->template->title .= ' (черновик)'; + $this->template->title .= ' ('.__('draft').')'; } $renderer = Kostache_Layout::factory('layout'); $body = $renderer->render($this->template, $this->template->_view); @@ -61,25 +65,13 @@ class Controller_Page extends Controller_Layout { public function action_index() { $this->template = new View_Index; - $this->template->title = 'Содержание'; + $this->template->title = __('Page index'); $this->template->show_date = FALSE; - $page_size = Kohana::$config->load('common.page_size'); - $current_page = (int) $this->request->param('page') - 1; - if ($current_page < 0) - { - $current_page = 0; - } - $first_item = $page_size * $current_page; $this->template->items = ORM::factory('Page') ->where('is_draft', '=', '0') ->order_by('name', 'ASC') - ->offset($first_item) - ->limit($page_size) + ->filter_by_page($this->request->param('page')) ->find_all(); - $this->template->item_count = ORM::factory('Page') - ->where('is_draft', '=', '0') - ->count_all(); - } public function action_delete() { @@ -90,9 +82,9 @@ class Controller_Page extends Controller_Layout { { $this->redirect('error/404'); } - $this->template->title = 'Удаление страницы'; + $this->template->title = __('Delete page'); $this->template->content_title = $page->name; - $this->template->content = Markdown::instance()->transform($page->content); + $this->template->content = $page->content; $confirmation = $this->request->post('confirmation'); if ($confirmation === 'yes') { @@ -106,10 +98,10 @@ class Controller_Page extends Controller_Layout { public function action_create() { $this->template = new View_Edit; - $this->template->title = 'Новая страница'; + $this->template->title = __('New page'); $this->template->errors = array(); - $page = ORM::factory('Page'); - $this->edit_page($page); + $this->template->model = ORM::factory('Page'); + $this->_edit($this->template->model); } /** * Edit a page (for admin) @@ -117,43 +109,14 @@ class Controller_Page extends Controller_Layout { public function action_edit() { $this->template = new View_Page_Edit; - $this->template->title = 'Редактирование страницы'; + $this->template->title = __('Edit page'); $id = $this->request->param('id'); - $page = ORM::factory('Page', $id); - if (!$page->loaded()) + $this->template->model = ORM::factory('Page', $id); + if (!$this->template->model->loaded()) { $this->redirect('error/404'); } - $this->edit_page($page); - } - - /** - * Edit or create page. - * Page model should be initialized with empty page (create) or existing one (update). - **/ - protected function edit_page($page) - { - $this->template->errors = array(); - if ($this->request->method() === HTTP_Request::POST) { - $page->content = $this->request->post('content'); - $page->name = $this->request->post('name'); - $page->is_draft = $this->request->post('is_draft'); - try { - if ($page->check()) - { - $page->save(); - } - } - catch (ORM_Validation_Exception $e) - { - $this->template->errors = $e->errors(''); - } - if (empty($this->template->errors)) - { - $this->redirect('page/view/' . $page->id); - } - } - $this->template->model = $page; + $this->_edit($this->template->model); } /** @@ -162,7 +125,7 @@ class Controller_Page extends Controller_Layout { public function action_drafts() { $this->template = new View_Index; - $this->template->title = 'Содержание (черновики)'; + $this->template->title = __('Page drafts'); $this->template->show_date = FALSE; $this->template->items = ORM::factory('Page') ->where('is_draft', '=', '1') diff --git a/application/config/cache.php b/application/config/cache.php new file mode 100644 index 0000000..364e673 --- /dev/null +++ b/application/config/cache.php @@ -0,0 +1,8 @@ + array( + 'driver' => 'apcu', + 'default_expire' => 3600, + ) +); diff --git a/application/i18n/ru.php b/application/i18n/ru.php index 354604e..3a8bfa3 100644 --- a/application/i18n/ru.php +++ b/application/i18n/ru.php @@ -44,5 +44,11 @@ return array( 'Edit client info' => 'Редактировать информацию о подписчике', 'Delete client' => 'Удалить клиента', 'Submit' => 'Отправить', - 'Search' => 'Искать' + 'Search' => 'Искать', + 'draft' => 'черновик', + 'New page' => 'Новая страница', + 'Edit page' => 'Редактировать страницу', + 'Page drafts' => 'Черновики страниц', + 'Page index' => 'Список страниц', + 'Delete page' => 'Удалить страницу' ); diff --git a/modules/cache b/modules/cache new file mode 160000 index 0000000..3b384fe --- /dev/null +++ b/modules/cache @@ -0,0 +1 @@ +Subproject commit 3b384fed3c4896910471895d9ec51dc4893d0e9a