ThemeView.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * A custom view class that is used for themeing
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.libs.view
  16. * @since CakePHP(tm) v 0.10.0.1076
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('View', 'View');
  20. /**
  21. * Theme view class
  22. *
  23. * Allows the creation of multiple themes to be used in an app. Theme views are regular view files
  24. * that can provide unique HTML and static assets. If theme views are not found for the current view
  25. * the default app view files will be used. You can set `$this->theme` and `$this->viewClass = 'Theme'`
  26. * in your Controller to use the ThemeView.
  27. *
  28. * Example of theme path with `$this->theme = 'super_hot';` Would be `app/View/Themed/SuperHot/Posts`
  29. *
  30. * @package cake.libs.view
  31. */
  32. class ThemeView extends View {
  33. /**
  34. * Constructor for ThemeView sets $this->theme.
  35. *
  36. * @param Controller $controller Controller object to be rendered.
  37. */
  38. public function __construct($controller) {
  39. parent::__construct($controller);
  40. $this->theme = $controller->theme;
  41. }
  42. /**
  43. * Return all possible paths to find view files in order
  44. *
  45. * @param string $plugin The name of the plugin views are being found for.
  46. * @param boolean $cached Set to true to force dir scan.
  47. * @return array paths
  48. * @access protected
  49. * @todo Make theme path building respect $cached parameter.
  50. */
  51. protected function _paths($plugin = null, $cached = true) {
  52. $paths = parent::_paths($plugin, $cached);
  53. $themePaths = array();
  54. if (!empty($this->theme)) {
  55. $count = count($paths);
  56. for ($i = 0; $i < $count; $i++) {
  57. if (strpos($paths[$i], DS . 'Plugins' . DS) === false
  58. && strpos($paths[$i], DS . 'Cake' . DS . 'View') === false) {
  59. if ($plugin) {
  60. $themePaths[] = $paths[$i] . 'Themed'. DS . $this->theme . DS . 'Plugins' . DS . $plugin . DS;
  61. }
  62. $themePaths[] = $paths[$i] . 'Themed'. DS . $this->theme . DS;
  63. }
  64. }
  65. $paths = array_merge($themePaths, $paths);
  66. }
  67. return $paths;
  68. }
  69. }