textarea.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. * Base class for form elements
  25. */
  26. require_once 'HTML/QuickForm/element.php';
  27. /**
  28. * HTML class for a textarea type field
  29. *
  30. * @category HTML
  31. * @package HTML_QuickForm
  32. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  33. * @author Bertrand Mansion <bmansion@mamasam.com>
  34. * @version Release: 3.2.11
  35. * @since 1.0
  36. */
  37. class HTML_QuickForm_textarea extends HTML_QuickForm_element
  38. {
  39. // {{{ properties
  40. /**
  41. * Field value
  42. * @var string
  43. * @since 1.0
  44. * @access private
  45. */
  46. var $_value = null;
  47. // }}}
  48. // {{{ constructor
  49. /**
  50. * Class constructor
  51. *
  52. * @param string Input field name attribute
  53. * @param mixed Label(s) for a field
  54. * @param mixed Either a typical HTML attribute string or an associative array
  55. * @since 1.0
  56. * @access public
  57. * @return void
  58. */
  59. function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null)
  60. {
  61. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  62. $this->_persistantFreeze = true;
  63. $this->_type = 'textarea';
  64. } //end constructor
  65. // }}}
  66. // {{{ setName()
  67. /**
  68. * Sets the input field name
  69. *
  70. * @param string $name Input field name attribute
  71. * @since 1.0
  72. * @access public
  73. * @return void
  74. */
  75. function setName($name)
  76. {
  77. $this->updateAttributes(array('name'=>$name));
  78. } //end func setName
  79. // }}}
  80. // {{{ getName()
  81. /**
  82. * Returns the element name
  83. *
  84. * @since 1.0
  85. * @access public
  86. * @return string
  87. */
  88. function getName()
  89. {
  90. return $this->getAttribute('name');
  91. } //end func getName
  92. // }}}
  93. // {{{ setValue()
  94. /**
  95. * Sets value for textarea element
  96. *
  97. * @param string $value Value for textarea element
  98. * @since 1.0
  99. * @access public
  100. * @return void
  101. */
  102. function setValue($value)
  103. {
  104. $this->_value = $value;
  105. } //end func setValue
  106. // }}}
  107. // {{{ getValue()
  108. /**
  109. * Returns the value of the form element
  110. *
  111. * @since 1.0
  112. * @access public
  113. * @return string
  114. */
  115. function getValue()
  116. {
  117. return $this->_value;
  118. } // end func getValue
  119. // }}}
  120. // {{{ setWrap()
  121. /**
  122. * Sets wrap type for textarea element
  123. *
  124. * @param string $wrap Wrap type
  125. * @since 1.0
  126. * @access public
  127. * @return void
  128. */
  129. function setWrap($wrap)
  130. {
  131. $this->updateAttributes(array('wrap' => $wrap));
  132. } //end func setWrap
  133. // }}}
  134. // {{{ setRows()
  135. /**
  136. * Sets height in rows for textarea element
  137. *
  138. * @param string $rows Height expressed in rows
  139. * @since 1.0
  140. * @access public
  141. * @return void
  142. */
  143. function setRows($rows)
  144. {
  145. $this->updateAttributes(array('rows' => $rows));
  146. } //end func setRows
  147. // }}}
  148. // {{{ setCols()
  149. /**
  150. * Sets width in cols for textarea element
  151. *
  152. * @param string $cols Width expressed in cols
  153. * @since 1.0
  154. * @access public
  155. * @return void
  156. */
  157. function setCols($cols)
  158. {
  159. $this->updateAttributes(array('cols' => $cols));
  160. } //end func setCols
  161. // }}}
  162. // {{{ toHtml()
  163. /**
  164. * Returns the textarea element in HTML
  165. *
  166. * @since 1.0
  167. * @access public
  168. * @return string
  169. */
  170. function toHtml()
  171. {
  172. if ($this->_flagFrozen) {
  173. return $this->getFrozenHtml();
  174. } else {
  175. return $this->_getTabs() .
  176. '<textarea' . $this->_getAttrString($this->_attributes) . '>' .
  177. // because we wrap the form later we don't want the text indented
  178. // Modified by Ivan Tcholakov, 16-MAR-2010.
  179. //preg_replace("/(\r\n|\n|\r)/", '&#010;', htmlspecialchars($this->_value)) .
  180. preg_replace("/(\r\n|\n|\r)/", '&#010;', @htmlspecialchars($this->_value, ENT_COMPAT, HTML_Common::charset())) .
  181. //
  182. '</textarea>';
  183. }
  184. } //end func toHtml
  185. // }}}
  186. // {{{ getFrozenHtml()
  187. /**
  188. * Returns the value of field without HTML tags (in this case, value is changed to a mask)
  189. *
  190. * @since 1.0
  191. * @access public
  192. * @return string
  193. */
  194. function getFrozenHtml()
  195. {
  196. // Modified by Ivan Tcholakov, 16-MAR-2010.
  197. //$value = htmlspecialchars($this->getValue());
  198. $value = @htmlspecialchars($this->getValue(), ENT_COMPAT, HTML_Common::charset());
  199. //
  200. if ($this->getAttribute('wrap') == 'off') {
  201. $html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
  202. } else {
  203. $html = nl2br($value)."\n";
  204. }
  205. return $html . $this->_getPersistantData();
  206. } //end func getFrozenHtml
  207. // }}}
  208. } //end class HTML_QuickForm_textarea
  209. ?>