textarea.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * HTML class for a textarea type field
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  17. * @author Bertrand Mansion <bmansion@mamasam.com>
  18. * @copyright 2001-2009 The PHP Group
  19. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  20. * @version CVS: $Id: textarea.php,v 1.13 2009/04/04 21:34:04 avb Exp $
  21. * @link http://pear.php.net/package/HTML_QuickForm
  22. */
  23. /**
  24. * HTML class for a textarea type field
  25. *
  26. * @category HTML
  27. * @package HTML_QuickForm
  28. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  29. * @author Bertrand Mansion <bmansion@mamasam.com>
  30. * @version Release: 3.2.11
  31. * @since 1.0
  32. */
  33. class HTML_QuickForm_textarea extends HTML_QuickForm_element
  34. {
  35. // {{{ properties
  36. /**
  37. * Field value
  38. * @var string
  39. * @since 1.0
  40. * @access private
  41. */
  42. public $_value = null;
  43. // }}}
  44. // {{{ constructor
  45. /**
  46. * Class constructor
  47. *
  48. * @param string Input field name attribute
  49. * @param mixed Label(s) for a field
  50. * @param mixed Either a typical HTML attribute string or an associative array
  51. * @since 1.0
  52. * @access public
  53. * @return void
  54. */
  55. public function __construct($elementName=null, $elementLabel=null, $attributes=null)
  56. {
  57. $attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'form-control';
  58. parent::__construct($elementName, $elementLabel, $attributes);
  59. $this->_persistantFreeze = true;
  60. $this->_type = 'textarea';
  61. } //end constructor
  62. // }}}
  63. // {{{ setName()
  64. /**
  65. * Sets the input field name
  66. *
  67. * @param string $name Input field name attribute
  68. * @since 1.0
  69. * @access public
  70. * @return void
  71. */
  72. function setName($name)
  73. {
  74. $this->updateAttributes(array('name'=>$name));
  75. } //end func setName
  76. // }}}
  77. // {{{ getName()
  78. /**
  79. * Returns the element name
  80. *
  81. * @since 1.0
  82. * @access public
  83. * @return string
  84. */
  85. function getName()
  86. {
  87. return $this->getAttribute('name');
  88. } //end func getName
  89. // }}}
  90. // {{{ setValue()
  91. /**
  92. * Sets value for textarea element
  93. *
  94. * @param string $value Value for textarea element
  95. * @since 1.0
  96. * @access public
  97. * @return void
  98. */
  99. function setValue($value)
  100. {
  101. $this->_value = $value;
  102. } //end func setValue
  103. // }}}
  104. // {{{ getValue()
  105. /**
  106. * Returns the value of the form element
  107. *
  108. * @since 1.0
  109. * @access public
  110. * @return string
  111. */
  112. function getValue()
  113. {
  114. return $this->_value;
  115. } // end func getValue
  116. // }}}
  117. // {{{ setWrap()
  118. /**
  119. * Sets wrap type for textarea element
  120. *
  121. * @param string $wrap Wrap type
  122. * @since 1.0
  123. * @access public
  124. * @return void
  125. */
  126. function setWrap($wrap)
  127. {
  128. $this->updateAttributes(array('wrap' => $wrap));
  129. } //end func setWrap
  130. // }}}
  131. // {{{ setRows()
  132. /**
  133. * Sets height in rows for textarea element
  134. *
  135. * @param string $rows Height expressed in rows
  136. * @since 1.0
  137. * @access public
  138. * @return void
  139. */
  140. function setRows($rows)
  141. {
  142. $this->updateAttributes(array('rows' => $rows));
  143. } //end func setRows
  144. // }}}
  145. // {{{ setCols()
  146. /**
  147. * Sets width in cols for textarea element
  148. *
  149. * @param string $cols Width expressed in cols
  150. * @since 1.0
  151. * @access public
  152. * @return void
  153. */
  154. function setCols($cols)
  155. {
  156. $this->updateAttributes(array('cols' => $cols));
  157. } //end func setCols
  158. // }}}
  159. // {{{ toHtml()
  160. /**
  161. * Returns the textarea element in HTML
  162. *
  163. * @since 1.0
  164. * @access public
  165. * @return string
  166. */
  167. public function toHtml()
  168. {
  169. if ($this->_flagFrozen) {
  170. return $this->getFrozenHtml();
  171. } else {
  172. return $this->_getTabs() .
  173. '<textarea' . $this->_getAttrString($this->_attributes) . '>' .
  174. // because we wrap the form later we don't want the text indented
  175. // Modified by Ivan Tcholakov, 16-MAR-2010.
  176. //preg_replace("/(\r\n|\n|\r)/", '&#010;', htmlspecialchars($this->_value)) .
  177. preg_replace("/(\r\n|\n|\r)/", '&#010;', @htmlspecialchars($this->_value, ENT_COMPAT, HTML_Common::charset())) .
  178. //
  179. '</textarea>';
  180. }
  181. }
  182. /**
  183. * Returns the value of field without HTML tags (in this case, value is changed to a mask)
  184. *
  185. * @since 1.0
  186. * @access public
  187. * @return string
  188. */
  189. public function getFrozenHtml()
  190. {
  191. // Modified by Ivan Tcholakov, 16-MAR-2010.
  192. //$value = htmlspecialchars($this->getValue());
  193. $value = @htmlspecialchars($this->getValue(), ENT_COMPAT, HTML_Common::charset());
  194. //
  195. if ($this->getAttribute('wrap') == 'off') {
  196. $html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
  197. } else {
  198. $html = nl2br($value)."\n";
  199. }
  200. return $html . $this->_getPersistantData();
  201. }
  202. }