/app/code/Ecart/Cms/controllers/CommentController.php
PHP | 127 lines | 85 code | 11 blank | 31 comment | 6 complexity | 82646261ec6633b42a0bbf7a577eaa5d MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
- <?php
- /**
- * Ecart
- *
- * This file is part of Ecart.
- *
- * Ecart is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Ecart is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Ecart
- * @package Ecart_Cms
- * @copyright Copyright 2008-2009 E-Cart LLC
- * @license GNU Public License V3.0
- */
- /**
- *
- * @category Ecart
- * @package Ecart_Cms
- * @subpackage Controller
- * @author Ecart Core Team <core@ecartcommerce.com>
- */
- class Ecart_Cms_CommentController extends Ecart_Core_Controller_Front
- {
- public function addAction()
- {
- $pageId = $this->_getParam('page');
- $this->view->page = array();
- $this->view->crumbs()->add(
- Ecart::translate('cms')->__('Pages'), '/pages'
- );
-
- $currentPage = Ecart::single('cms/page')
- ->cache()
- ->find($pageId)
- ->current();
-
- if (!$currentPage) {
- $this->view->pageTitle = Ecart::translate('cms')->__(
- 'Page not found'
- );
- $this->view->meta()->setTitle($this->view->pageTitle);
- $this->render();
- return;
- }
-
- $content = $currentPage->cache()->getContent();
-
- $this->view->page = array();
- $this->view->pageTitle = Ecart::translate('cms')->__($content['title']);
- $categories = Ecart::single('cms/category')
- ->getParentCategory($pageId, true);
- foreach ($categories as $category) {
- $this->view->crumbs()->add(
- empty($category['title']) ?
- $category['link'] : $category['title'],
- $this->view->href('/cat/' . $category['link'])
- );
- }
-
- $this->view->page['content'] = $content['content'];
- $this->view->page['is_commented'] = $currentPage->comment;
-
- if ($currentPage->comment) {
- // get all comments
- $comments = $currentPage->cache()->getComments();
- $i = 0;
- foreach ($comments as $comment) {
- $this->view->page['comment'][$i]['author'] = $comment['author'];
- $this->view->page['comment'][$i]['content'] = $comment['content'];
- $this->view->page['comment'][$i]['created_on'] = $comment['created_on'];
- $this->view->page['comment'][$i]['modified_on'] = $comment['modified_on'];
- $this->view->page['comment'][$i]['status'] = $comment['status'];
- $i++;
- }
-
- $form = Ecart::model('cms/form_comment', array('pageId' => $pageId));
- if ($this->_request->isPost()) {
- $data = $this->_getAllParams();
- if ($form->isValid($data)) {
- Ecart::single('cms/page_comment')->insert(array(
- 'author' => $data['author'],
- 'email' => $data['email'],
- 'status' => 0,
- 'content' => $data['content'],
- 'created_on' => Ecart_Date::now()->toSQLString(),
- 'cms_page_id' => $pageId
- ));
- Ecart::dispatch('cms_comment_add_success', $data);
- Ecart::message()->addSuccess(
- Ecart::translate('cms')->__(
- 'Comment successfully added'
- ));
- $this->_redirect(
- $this->getRequest()->getServer('HTTP_REFERER')
- );
- } else {
- $form->populate($data);
- }
- }
- $this->view->formComment = $form;
- }
- $metaTitle = $content['meta_title'] == '' ?
- $content['title'] : $content['meta_title'];
- $this->view->meta()
- ->setTitle($metaTitle, 'cms_page', $pageId)
- ->setDescription($content['meta_description'])
- ->setKeywords($content['meta_keyword'])
- ;
-
- $layout = substr($currentPage->layout, strpos($currentPage->layout, '_'));
- $this->_helper->layout->setLayout('layout' . $layout);
-
- $this->render();
- }
- }