PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://code.google.com/p/ecartcommerce/
PHP | 127 lines | 85 code | 11 blank | 31 comment | 6 complexity | 82646261ec6633b42a0bbf7a577eaa5d 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_CommentController extends Ecart_Core_Controller_Front
  33. {
  34. public function addAction()
  35. {
  36. $pageId = $this->_getParam('page');
  37. $this->view->page = array();
  38. $this->view->crumbs()->add(
  39. Ecart::translate('cms')->__('Pages'), '/pages'
  40. );
  41. $currentPage = Ecart::single('cms/page')
  42. ->cache()
  43. ->find($pageId)
  44. ->current();
  45. if (!$currentPage) {
  46. $this->view->pageTitle = Ecart::translate('cms')->__(
  47. 'Page not found'
  48. );
  49. $this->view->meta()->setTitle($this->view->pageTitle);
  50. $this->render();
  51. return;
  52. }
  53. $content = $currentPage->cache()->getContent();
  54. $this->view->page = array();
  55. $this->view->pageTitle = Ecart::translate('cms')->__($content['title']);
  56. $categories = Ecart::single('cms/category')
  57. ->getParentCategory($pageId, true);
  58. foreach ($categories as $category) {
  59. $this->view->crumbs()->add(
  60. empty($category['title']) ?
  61. $category['link'] : $category['title'],
  62. $this->view->href('/cat/' . $category['link'])
  63. );
  64. }
  65. $this->view->page['content'] = $content['content'];
  66. $this->view->page['is_commented'] = $currentPage->comment;
  67. if ($currentPage->comment) {
  68. // get all comments
  69. $comments = $currentPage->cache()->getComments();
  70. $i = 0;
  71. foreach ($comments as $comment) {
  72. $this->view->page['comment'][$i]['author'] = $comment['author'];
  73. $this->view->page['comment'][$i]['content'] = $comment['content'];
  74. $this->view->page['comment'][$i]['created_on'] = $comment['created_on'];
  75. $this->view->page['comment'][$i]['modified_on'] = $comment['modified_on'];
  76. $this->view->page['comment'][$i]['status'] = $comment['status'];
  77. $i++;
  78. }
  79. $form = Ecart::model('cms/form_comment', array('pageId' => $pageId));
  80. if ($this->_request->isPost()) {
  81. $data = $this->_getAllParams();
  82. if ($form->isValid($data)) {
  83. Ecart::single('cms/page_comment')->insert(array(
  84. 'author' => $data['author'],
  85. 'email' => $data['email'],
  86. 'status' => 0,
  87. 'content' => $data['content'],
  88. 'created_on' => Ecart_Date::now()->toSQLString(),
  89. 'cms_page_id' => $pageId
  90. ));
  91. Ecart::dispatch('cms_comment_add_success', $data);
  92. Ecart::message()->addSuccess(
  93. Ecart::translate('cms')->__(
  94. 'Comment successfully added'
  95. ));
  96. $this->_redirect(
  97. $this->getRequest()->getServer('HTTP_REFERER')
  98. );
  99. } else {
  100. $form->populate($data);
  101. }
  102. }
  103. $this->view->formComment = $form;
  104. }
  105. $metaTitle = $content['meta_title'] == '' ?
  106. $content['title'] : $content['meta_title'];
  107. $this->view->meta()
  108. ->setTitle($metaTitle, 'cms_page', $pageId)
  109. ->setDescription($content['meta_description'])
  110. ->setKeywords($content['meta_keyword'])
  111. ;
  112. $layout = substr($currentPage->layout, strpos($currentPage->layout, '_'));
  113. $this->_helper->layout->setLayout('layout' . $layout);
  114. $this->render();
  115. }
  116. }