<?php
/**
 * Eppe View Helper FormWysiwyg
 * @author wojbach
 *
 */
class Eppe_View_Helper_FormWysiwyg extends Zend_View_Helper_FormTextarea {
	protected $_wysiwyg;

	public function FormWysiwyg($name, $value = null, $attribs = null) {
		$info = $this->_getInfo($name, $value, $attribs);
		extract($info); // name, value, attribs, options, listsep, disable

		$disabled = '';
		if ($disable) {
			$disabled = ' disabled="disabled"';
		}

		if (empty($attribs['rows'])) {
			$attribs['rows'] = (int) $this->rows;
		}
		if (empty($attribs['cols'])) {
			$attribs['cols'] = (int) $this->cols;
		}

		if (isset($attribs['editorOptions'])) {
			if ($attribs['editorOptions'] instanceof Zend_Config) {
				$attribs['editorOptions'] = $attribs['editorOptions']->toArray();
			}
			$this->view->wysiwyg()->setOptions($attribs['editorOptions']);
			unset($attribs['editorOptions']);
		}
		$this->view->wysiwyg()->render();

		$xhtml = '<textarea mce_editable="true" name="' . $this->view->escape($name) . '"'
			. ' id="' . $this->view->escape($id) . '"'
			. $disabled
			. $this->_htmlAttribs($attribs) . '>'
			. $this->view->escape($value) . '</textarea>';

		return $xhtml;
	}

}
