View.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * Abstract master class for extension.
  23. */
  24. require_once 'Zend/View/Abstract.php';
  25. /**
  26. * Concrete class for handling view scripts.
  27. *
  28. * @category Zend
  29. * @package Zend_View
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. *
  33. * Convenience methods for build in helpers (@see __call):
  34. *
  35. * @method string baseUrl($file = null)
  36. * @method string currency($value = null, $currency = null)
  37. * @method Zend_View_Helper_Cycle cycle(array $data = array(), $name = Zend_View_Helper_Cycle::DEFAULT_NAME)
  38. * @method Zend_View_Helper_Doctype doctype($doctype = null)
  39. * @method string fieldset($name, $content, $attribs = null)
  40. * @method string form($name, $attribs = null, $content = false)
  41. * @method string formButton($name, $value = null, $attribs = null)
  42. * @method string formCheckbox($name, $value = null, $attribs = null, array $checkedOptions = null)
  43. * @method string formErrors($errors, array $options = null)
  44. * @method string formFile($name, $attribs = null)
  45. * @method string formHidden($name, $value = null, array $attribs = null)
  46. * @method string formImage($name, $value = null, $attribs = null)
  47. * @method string formLabel($name, $value = null, array $attribs = null)
  48. * @method string formMultiCheckbox($name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n")
  49. * @method string formNote($name, $value = null)
  50. * @method string formPassword($name, $value = null, $attribs = null)
  51. * @method string formRadio($name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n")
  52. * @method string formReset($name = '', $value = 'Reset', $attribs = null)
  53. * @method string formSelect($name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n")
  54. * @method string formSubmit($name, $value = null, $attribs = null)
  55. * @method string formText($name, $value = null, $attribs = null)
  56. * @method string formTextarea($name, $value = null, $attribs = null)
  57. * @method Zend_View_Helper_Gravatar gravatar($email = "", $options = array(), $attribs = array())
  58. * @method Zend_View_Helper_HeadLink headLink(array $attributes = null, $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND)
  59. * @method Zend_View_Helper_HeadMeta headMeta($content = null, $keyValue = null, $keyType = 'name', $modifiers = array(), $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND)
  60. * @method Zend_View_Helper_HeadScript headScript($mode = Zend_View_Helper_HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
  61. * @method Zend_View_Helper_HeadStyle headStyle($content = null, $placement = 'APPEND', $attributes = array())
  62. * @method Zend_View_Helper_HeadTitle headTitle($title = null, $setType = null)
  63. * @method string htmlFlash($data, array $attribs = array(), array $params = array(), $content = null)
  64. * @method string htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
  65. * @method string htmlObject($data, $type, array $attribs = array(), array $params = array(), $content = null)
  66. * @method string htmlPage($data, array $attribs = array(), array $params = array(), $content = null)
  67. * @method string htmlQuicktime($data, array $attribs = array(), array $params = array(), $content = null)
  68. * @method Zend_View_Helper_InlineScript inlineScript($mode = Zend_View_Helper_HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
  69. * @method string|void json($data, $keepLayouts = false, $encodeData = true)
  70. * @method Zend_View_Helper_Layout layout()
  71. * @method Zend_View_Helper_Navigation navigation(Zend_Navigation_Container $container = null)
  72. * @method string paginationControl(Zend_Paginator $paginator = null, $scrollingStyle = null, $partial = null, $params = null)
  73. * @method string partial($name = null, $module = null, $model = null)
  74. * @method string partialLoop($name = null, $module = null, $model = null)
  75. * @method Zend_View_Helper_Placeholder_Container_Abstract placeholder($name)
  76. * @method void renderToPlaceholder($script, $placeholder)
  77. * @method string serverUrl($requestUri = null)
  78. * @method string translate($messageid = null)
  79. * @method string url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
  80. * @method Zend_Http_UserAgent userAgent(Zend_Http_UserAgent $userAgent = null)
  81. */
  82. class Zend_View extends Zend_View_Abstract
  83. {
  84. /**
  85. * Whether or not to use streams to mimic short tags
  86. * @var bool
  87. */
  88. private $_useViewStream = false;
  89. /**
  90. * Whether or not to use stream wrapper if short_open_tag is false
  91. * @var bool
  92. */
  93. private $_useStreamWrapper = false;
  94. /**
  95. * Constructor
  96. *
  97. * Register Zend_View_Stream stream wrapper if short tags are disabled.
  98. *
  99. * @param array $config
  100. * @return void
  101. */
  102. public function __construct($config = array())
  103. {
  104. $this->_useViewStream = (bool) ini_get('short_open_tag') ? false : true;
  105. if ($this->_useViewStream) {
  106. if (!in_array('zend.view', stream_get_wrappers())) {
  107. require_once 'Zend/View/Stream.php';
  108. stream_wrapper_register('zend.view', 'Zend_View_Stream');
  109. }
  110. }
  111. if (array_key_exists('useStreamWrapper', $config)) {
  112. $this->setUseStreamWrapper($config['useStreamWrapper']);
  113. }
  114. parent::__construct($config);
  115. }
  116. /**
  117. * Set flag indicating if stream wrapper should be used if short_open_tag is off
  118. *
  119. * @param bool $flag
  120. * @return Zend_View
  121. */
  122. public function setUseStreamWrapper($flag)
  123. {
  124. $this->_useStreamWrapper = (bool) $flag;
  125. return $this;
  126. }
  127. /**
  128. * Should the stream wrapper be used if short_open_tag is off?
  129. *
  130. * @return bool
  131. */
  132. public function useStreamWrapper()
  133. {
  134. return $this->_useStreamWrapper;
  135. }
  136. /**
  137. * Includes the view script in a scope with only public $this variables.
  138. *
  139. * @param string The view script to execute.
  140. */
  141. protected function _run()
  142. {
  143. if ($this->_useViewStream && $this->useStreamWrapper()) {
  144. include 'zend.view://' . func_get_arg(0);
  145. } else {
  146. include func_get_arg(0);
  147. }
  148. }
  149. }