PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/Ecart/Cms/controllers/ViewController.php

https://code.google.com/p/ecartcommerce/
PHP | 149 lines | 97 code | 20 blank | 32 comment | 8 complexity | b46bda440db0a9a2e456b803fc6dba4f MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Ecart
  4. *
  5. * This file is part of Ecart.
  6. *
  7. * Ecart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Ecart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Ecart
  21. * @package Ecart_Cms
  22. * @copyright Copyright 2008-2009 E-Cart LLC
  23. * @license GNU Public License V3.0
  24. */
  25. /**
  26. *
  27. * @category Ecart
  28. * @package Ecart_Cms
  29. * @subpackage Controller
  30. * @author Ecart Core Team <core@ecartcommerce.com>
  31. */
  32. class Ecart_Cms_ViewController extends Ecart_Core_Controller_Front
  33. {
  34. public function viewPageAction()
  35. {
  36. $link = $this->_getParam('page');
  37. $pageId = Ecart::single('cms/page')->getPageIdByLink($link);
  38. $rowPage = Ecart::single('cms/page')
  39. ->find($pageId)
  40. ->current();
  41. if (!$rowPage || !$rowPage->is_active) {
  42. return $this->_forward('not-found', 'Error', 'Ecart_Core');
  43. }
  44. $content = $rowPage->getContent();
  45. $this->view->page = array();
  46. $this->view->pageTitle = $content['title'];
  47. $this->view->crumbs()->add(
  48. Ecart::translate('cms')->__('Pages'),
  49. '/pages'
  50. );
  51. $categories = Ecart::single('cms/category')
  52. ->cache()
  53. ->getParentCategory($pageId, true);
  54. foreach ($categories as $category) {
  55. $this->view->crumbs()->add(
  56. empty($category['title']) ? $category['link'] : $category['title'],
  57. $this->view->href('/cat/' . $category['link'])
  58. );
  59. }
  60. $this->view->page['id'] = $rowPage->id;
  61. $this->view->page['content'] = $content['content'];
  62. $this->view->page['is_commented'] = $rowPage->comment;
  63. if ($rowPage->comment) {
  64. // get all comments
  65. $comments = $rowPage->cache()->getComments();
  66. $i = 0;
  67. foreach ($comments as $comment) {
  68. $this->view->page['comment'][$i]['author'] = $comment['author'];
  69. $this->view->page['comment'][$i]['content'] = $comment['content'];
  70. $this->view->page['comment'][$i]['created_on'] = $comment['created_on'];
  71. $this->view->page['comment'][$i]['modified_on'] = $comment['modified_on'];
  72. $this->view->page['comment'][$i]['status'] = $comment['status'];
  73. $i++;
  74. }
  75. // create comment form
  76. $this->view->formComment =
  77. Ecart::model('cms/form_comment', array('pageId' => $rowPage->id));
  78. }
  79. $metaTitle = $content['meta_title'] == '' ?
  80. $content['title'] : $content['meta_title'];
  81. $this->view->meta()
  82. ->setTitle($metaTitle, 'cms_page', $pageId)
  83. ->setDescription($content['meta_description'])
  84. ->setKeywords($content['meta_keyword']);
  85. $layout = substr($rowPage->layout, strpos($rowPage->layout, '_'));
  86. $this->_helper->layout->setLayout('layout' . $layout);
  87. $this->render();
  88. }
  89. public function viewCategoryAction()
  90. {
  91. $modelCategory = Ecart::single('cms/category')->cache();
  92. $categoryId = $modelCategory->getCategoryIdByLink(
  93. $this->_getParam('cat')
  94. );
  95. $currentCategory = $modelCategory->find($categoryId)->current();
  96. if (!$currentCategory || !$currentCategory->is_active) {
  97. return $this->_forward('not-found', 'Error', 'Ecart_Core');
  98. }
  99. $content = $currentCategory->getContent();
  100. $this->view->category = array();
  101. $title = empty($content['title']) ?
  102. $this->_getParam('cat') : $content['title'];
  103. $this->view->pageTitle = Ecart::translate('cms')->__($title);
  104. $this->view->crumbs()->add(
  105. Ecart::translate('cms')->__('Pages'),
  106. '/pages'
  107. );
  108. $categories = $modelCategory->getParentCategory($categoryId);
  109. array_pop($categories);
  110. foreach ($categories as $category) {
  111. $this->view->crumbs()->add(
  112. empty($category['title']) ? $category['link'] : $category['title'],
  113. $this->view->href('/cat/' . $category['link'])
  114. );
  115. }
  116. $metaTitle = $content['meta_title'] == '' ?
  117. $content['title'] : $content['meta_title'];
  118. $metaDescription = $content['meta_description'] == '' ?
  119. $content['description'] : $content['meta_description'];
  120. $this->view->meta()
  121. ->setTitle($metaTitle, 'cms_category', $categoryId)
  122. ->setDescription($metaDescription)
  123. ->setKeywords($content['meta_keyword']);
  124. $this->view->category['description'] = $content['description'];
  125. $this->view->category['childs'] = $currentCategory->getChilds();
  126. $this->view->category['pages'] = $currentCategory->getPages();
  127. $this->render();
  128. }
  129. }