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

/components/CmsPageViewFilter.php

https://bitbucket.org/Crisu83/nordcms
PHP | 41 lines | 18 code | 5 blank | 18 comment | 4 complexity | d09740f900a60f9edb50458027472bce MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, Apache-2.0, GPL-3.0
  1. <?php
  2. /**
  3. * CmsNodeFilter class file.
  4. * @author Christoffer Niska <christoffer.niska@nordsoftware.com>
  5. * @copyright Copyright &copy; 2011, Nord Software Ltd
  6. * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  7. * @package cms.components
  8. */
  9. /**
  10. * Filter that ensures that the page is published and issues a 301 redirect to the correct URL
  11. * in case an incorrect page URL was requested.
  12. */
  13. class CmsPageViewFilter extends CFilter
  14. {
  15. /**
  16. * Performs the pre-action filtering.
  17. * @param CFilterChain $filterChain the filter chain that the filter is on
  18. * @return boolean whether the filtering process should continue and the action should be executed
  19. * @throws CHttpException if the page isn't published
  20. */
  21. protected function preFilter($filterChain)
  22. {
  23. $controller = $filterChain->controller;
  24. if (isset($_GET['id']) && method_exists($controller, 'loadModel'))
  25. {
  26. $model = $controller->loadModel($_GET['id']);
  27. // Prevent accessing of unpublished pages.
  28. if (!$model->published)
  29. throw new CHttpException(404, Yii::t('CmsModule.core', 'The requested page does not exist.'));
  30. $url = $model->getUrl();
  31. if (strpos(Yii::app()->request->getRequestUri(), $url) === false)
  32. $controller->redirect($url, true, 301);
  33. }
  34. return parent::preFilter($filterChain);
  35. }
  36. }