ThemeView.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.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.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. * @todo Make theme path building respect $cached parameter.
  49. */
  50. protected function _paths($plugin = null, $cached = true) {
  51. $paths = parent::_paths($plugin, $cached);
  52. $themePaths = array();
  53. if (!empty($this->theme)) {
  54. $count = count($paths);
  55. for ($i = 0; $i < $count; $i++) {
  56. if (strpos($paths[$i], DS . 'Plugins' . DS) === false
  57. && strpos($paths[$i], DS . 'Cake' . DS . 'View') === false) {
  58. if ($plugin) {
  59. $themePaths[] = $paths[$i] . 'Themed'. DS . $this->theme . DS . 'Plugins' . DS . $plugin . DS;
  60. }
  61. $themePaths[] = $paths[$i] . 'Themed'. DS . $this->theme . DS;
  62. }
  63. }
  64. $paths = array_merge($themePaths, $paths);
  65. }
  66. return $paths;
  67. }
  68. }