Source for file HtmlTextArea.class.php

Documentation is available at HtmlTextArea.class.php

  1. <?php
  2. /**
  3. * @since 9/5/07
  4. * @package polyphony.wizard
  5. *
  6. * @copyright Copyright &copy; 2007, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: HtmlTextArea.class.php,v 1.4 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. require_once(dirname(__FILE__)."/FckTextArea.class.php");
  13.  
  14. /**
  15. * The HtmlTextArea is a text input block that allows the user to use one of several
  16. * editing interfaces to aid in the entry of HTML text. Some of the editing interfaces
  17. * may be WYSIWYG editors, while others may simply supply shortcut buttons for
  18. * entering HTML markup.
  19. *
  20. * @since 9/5/07
  21. * @package polyphony.wizard
  22. *
  23. * @copyright Copyright &copy; 2007, Middlebury College
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  25. *
  26. * @version $Id: HtmlTextArea.class.php,v 1.4 2007/09/19 14:04:51 adamfranco Exp $
  27. */
  28. class HtmlTextArea
  29. extends WTextArea
  30. {
  31. /**
  32. * Virtual Constructor
  33. * @param integer $rows
  34. * @param integer $cols
  35. * @access public
  36. * @return ref object
  37. * @static
  38. */
  39. public static function withRowsAndColumns ($rows, $cols, $class = 'HtmlTextArea') {
  40. return parent::withRowsAndColumns($rows, $cols, $class);
  41. }
  42. /**
  43. * @var object $editorChoice; A slect field for the editor choice
  44. * @access private
  45. * @since 9/5/07
  46. */
  47. private $editorChoice;
  48. /**
  49. * @var array $editors;
  50. * @access private
  51. * @since 9/5/07
  52. */
  53. private $editors = array();
  54. /**
  55. * Constructor
  56. *
  57. * @return void
  58. * @access public
  59. * @since 9/5/07
  60. */
  61. public function __construct () {
  62. parent::__construct();
  63. $this->editorChoice = new WSelectList;
  64. $this->editorChoice->addOnChange('this.form.submit();');
  65. $this->addEditor('none', _('None'), new WTextArea);
  66. $this->addEditor('fck', _('FCK Editor'), new FckTextarea);
  67. $this->chooseEditor('none');
  68. }
  69. /**
  70. * Add a new editor to those supported
  71. *
  72. * @param string $name
  73. * @param string $displayName
  74. * @param object WTextArea $editor
  75. * @return void
  76. * @access public
  77. * @since 9/5/07
  78. */
  79. public function addEditor ($name, $displayName, WTextArea $editor) {
  80. if (!$name)
  81. throw new Exception("Name must be a non-zero-length string. '$name' is invalid.");
  82. if (!$displayName)
  83. throw new Exception("DisplayName must be a non-zero-length string. '$displayName' is invalid.");
  84. $this->editorChoice->addOption($name, $displayName);
  85. $this->editors[$name] = $editor;
  86. }
  87. /**
  88. * Choose an editor.
  89. *
  90. * @param string $name
  91. * @return void
  92. * @access public
  93. * @since 9/5/07
  94. */
  95. public function chooseEditor ($name) {
  96. if (!isset($this->editors[$name]))
  97. throw new Exception("Unknown editor, '$name'.");
  98. $this->editorChoice->setValue($name);
  99. $editor = $this->getCurrentEditor();
  100. $editor->setRows($this->_rows);
  101. $editor->setColumns($this->_cols);
  102. $editor->setValue($this->_value);
  103. $editor->setStartingDisplayText($this->_startingDisplay);
  104. $editor->setStyle($this->_style);
  105. $editor->_onchange = $this->_onchange;
  106. }
  107. /**
  108. * Answer an editor so that it may be configured
  109. *
  110. * @param string $name
  111. * @return void
  112. * @access public
  113. * @since 9/5/07
  114. */
  115. public function getEditor ($name) {
  116. if (!isset($this->editors[$name]))
  117. throw new Exception("Unknown editor, '$name'.");
  118. return $this->editors[$name];
  119. }
  120. /**
  121. * Answer the current Editor
  122. *
  123. * @return object WTextArea
  124. * @access public
  125. * @since 9/5/07
  126. */
  127. public function getCurrentEditor () {
  128. if (!$this->editorChoice->getAllValues())
  129. throw new Exception("No current editor set.");
  130. if (!isset($this->editors[$this->editorChoice->getAllValues()]))
  131. throw new Exception("Current editor object is missing.");
  132. return $this->editors[$this->editorChoice->getAllValues()];
  133. }
  134. /**
  135. * Sets the number of visible rows in this textarea.
  136. * @param integer $rows
  137. * @access public
  138. * @return void
  139. */
  140. public function setRows ($rows) {
  141. parent::setRows($rows);
  142. $this->getCurrentEditor()->setRows($rows);
  143. }
  144. /**
  145. * Sets the number of visible columns in this textarea.
  146. * @param integer $cols
  147. * @access public
  148. * @return void
  149. */
  150. public function setColumns ($cols) {
  151. parent::setColumns($cols);
  152. $this->getCurrentEditor()->setColumns($cols);
  153. }
  154. /**
  155. * Sets the text of the field to display until the user enters the field.
  156. * @param string $text
  157. * @access public
  158. * @return void
  159. */
  160. function setStartingDisplayText ($text) {
  161. parent::setStartingDisplayText($text);
  162. $this->getCurrentEditor()->setStartingDisplayText($text);
  163. }
  164. /**
  165. * Sets the CSS style of this field.
  166. * @param string $style
  167. * @access public
  168. * @return void
  169. */
  170. function setStyle ($style) {
  171. parent::setStyle($style);
  172. $this->getCurrentEditor()->setStyle($style);
  173. }
  174. /**
  175. * Add commands to the javascript onchange attribute.
  176. * @param string $commands
  177. * @access public
  178. * @return void
  179. */
  180. function addOnChange($commands) {
  181. parent::addOnChange($commands);
  182. $this->getCurrentEditor()->addOnChange($commands);
  183. }
  184. /**
  185. * Returns true if this component (and all child components if applicable) have valid values.
  186. * By default, this will just return TRUE.
  187. * @access public
  188. * @return boolean
  189. */
  190. function validate () {
  191. return $this->getCurrentEditor()->validate();
  192. }
  193. /**
  194. * Tells the wizard component to update itself - this may include getting
  195. * form post data or validation - whatever this particular component wants to
  196. * do every pageload.
  197. * @param string $fieldName The field name to use when outputting form data or
  198. * similar parameters/information.
  199. * @access public
  200. * @return boolean - TRUE if everything is OK
  201. */
  202. function update ($fieldName) {
  203. $this->getCurrentEditor()->update($fieldName);
  204. $this->_value = $this->getCurrentEditor()->getAllValues();
  205. $oldEditor = $this->editorChoice->getAllValues();
  206. $this->editorChoice->update($fieldName.'_choice');
  207. if ($oldEditor != $this->editorChoice->getAllValues())
  208. $this->chooseEditor($this->editorChoice->getAllValues());
  209. }
  210. /**
  211. * Sets the value of this text field.
  212. * @param string $value
  213. * @access public
  214. * @return void
  215. */
  216. function setValue ($value) {
  217. parent::setValue($value);
  218. $this->getCurrentEditor()->setValue($value);
  219. }
  220. /**
  221. * Returns a block of XHTML-valid code that contains markup for this specific
  222. * component.
  223. * @param string $fieldName The field name to use when outputting form data or
  224. * similar parameters/information.
  225. * @access public
  226. * @return string
  227. */
  228. public function getMarkup ($fieldName) {
  229. ob_start();
  230. print "\n<div class='Wizard_HtmlTextArea_choice'>";
  231. print _("Choose editor: ");
  232. print $this->editorChoice->getMarkup($fieldName.'_choice');
  233. print "\n</div>";
  234. print $this->getCurrentEditor()->getMarkup($fieldName);
  235. return ob_get_clean();
  236. }
  237. }
  238.  
  239. ?>

Documentation generated on Wed, 19 Sep 2007 10:24:35 -0400 by phpDocumentor 1.3.0RC3