/app/code/Ecart/Cms/controllers/ViewController.php
PHP | 149 lines | 97 code | 20 blank | 32 comment | 8 complexity | b46bda440db0a9a2e456b803fc6dba4f 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_ViewController extends Ecart_Core_Controller_Front
- {
- public function viewPageAction()
- {
- $link = $this->_getParam('page');
- $pageId = Ecart::single('cms/page')->getPageIdByLink($link);
- $rowPage = Ecart::single('cms/page')
- ->find($pageId)
- ->current();
-
- if (!$rowPage || !$rowPage->is_active) {
- return $this->_forward('not-found', 'Error', 'Ecart_Core');
- }
-
- $content = $rowPage->getContent();
-
- $this->view->page = array();
- $this->view->pageTitle = $content['title'];
- $this->view->crumbs()->add(
- Ecart::translate('cms')->__('Pages'),
- '/pages'
- );
-
- $categories = Ecart::single('cms/category')
- ->cache()
- ->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['id'] = $rowPage->id;
- $this->view->page['content'] = $content['content'];
- $this->view->page['is_commented'] = $rowPage->comment;
-
- if ($rowPage->comment) {
- // get all comments
- $comments = $rowPage->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++;
- }
-
- // create comment form
- $this->view->formComment =
- Ecart::model('cms/form_comment', array('pageId' => $rowPage->id));
- }
- $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($rowPage->layout, strpos($rowPage->layout, '_'));
- $this->_helper->layout->setLayout('layout' . $layout);
- $this->render();
- }
-
- public function viewCategoryAction()
- {
- $modelCategory = Ecart::single('cms/category')->cache();
- $categoryId = $modelCategory->getCategoryIdByLink(
- $this->_getParam('cat')
- );
- $currentCategory = $modelCategory->find($categoryId)->current();
-
- if (!$currentCategory || !$currentCategory->is_active) {
- return $this->_forward('not-found', 'Error', 'Ecart_Core');
- }
-
- $content = $currentCategory->getContent();
-
- $this->view->category = array();
- $title = empty($content['title']) ?
- $this->_getParam('cat') : $content['title'];
- $this->view->pageTitle = Ecart::translate('cms')->__($title);
- $this->view->crumbs()->add(
- Ecart::translate('cms')->__('Pages'),
- '/pages'
- );
- $categories = $modelCategory->getParentCategory($categoryId);
-
- array_pop($categories);
- foreach ($categories as $category) {
- $this->view->crumbs()->add(
- empty($category['title']) ? $category['link'] : $category['title'],
- $this->view->href('/cat/' . $category['link'])
- );
- }
-
- $metaTitle = $content['meta_title'] == '' ?
- $content['title'] : $content['meta_title'];
- $metaDescription = $content['meta_description'] == '' ?
- $content['description'] : $content['meta_description'];
- $this->view->meta()
- ->setTitle($metaTitle, 'cms_category', $categoryId)
- ->setDescription($metaDescription)
- ->setKeywords($content['meta_keyword']);
-
- $this->view->category['description'] = $content['description'];
- $this->view->category['childs'] = $currentCategory->getChilds();
- $this->view->category['pages'] = $currentCategory->getPages();
-
- $this->render();
- }
- }