1 | <?php |
||
35 | class Textarea extends FormElement implements FormElementInterface |
||
36 | { |
||
37 | /** |
||
38 | * Flag variable for the What-You-See-Is-What-You-Get Editor. |
||
39 | * |
||
40 | * There are several different wysiwyg editor formelements available: |
||
41 | * |
||
42 | * 1) Nicedit -> wysiwygnicedit.php |
||
43 | * 2) TinyMCE -> wysiwygtinymce.php |
||
44 | * 3) CKEditor -> wysiwygckeditor.php |
||
45 | * 4) markItUp -> wysiwygmarkItUp.phg |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $editor; |
||
50 | |||
51 | /** |
||
52 | * @var int width of textarea in letters |
||
53 | */ |
||
54 | public $cols = 0; |
||
55 | |||
56 | /** |
||
57 | * @var int height of textarea in rows |
||
58 | */ |
||
59 | public $rows = 0; |
||
60 | |||
61 | /** |
||
62 | * @var object of the wysiwyg editor |
||
63 | */ |
||
64 | private $editorObject; |
||
65 | |||
66 | public function __construct() |
||
72 | |||
73 | public function setEditor($editor = null) |
||
74 | { |
||
75 | /* |
||
76 | * if no editor is given, take the one definied in the general configuration. |
||
77 | * the expected config setting is [editor] type. |
||
78 | * if the configuration value is not given, use "ckeditor" as fallback. |
||
79 | */ |
||
80 | if ($editor === null) { |
||
81 | $config = Clansuite_CMS::getInjector()->instantiate('Koch\Config'); |
||
82 | $editor = isset($config['editor']['type']) ? $config['editor']['type'] : 'ckeditor'; |
||
83 | unset($config); |
||
84 | } |
||
85 | |||
86 | $this->editor = mb_strtolower($editor); |
||
87 | |||
88 | return $this; |
||
89 | } |
||
90 | |||
91 | public function getEditor() |
||
95 | |||
96 | /** |
||
97 | * defines width of textarea. |
||
98 | * |
||
99 | * @param int $cols |
||
100 | */ |
||
101 | public function setCols($cols) |
||
107 | |||
108 | /** |
||
109 | * get defined width of textarea. |
||
110 | */ |
||
111 | public function getCols() |
||
112 | { |
||
113 | return $this->cols; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * define height of textarea in rows. |
||
118 | * |
||
119 | * @param int $rows |
||
120 | */ |
||
121 | public function setRows($rows) |
||
127 | |||
128 | /** |
||
129 | * get defined height of textarea in rows. |
||
130 | */ |
||
131 | public function getRows() |
||
132 | { |
||
133 | return $this->rows; |
||
134 | } |
||
135 | |||
136 | public function setName($name) |
||
142 | |||
143 | public function setEditorFormelement(FormelementInterface $editorObject) |
||
149 | |||
150 | public function getEditorFormelement() |
||
158 | |||
159 | /** |
||
160 | * editorFactory |
||
161 | * loads and instantiates an wysiwyg editor object. |
||
162 | */ |
||
163 | private function editorFactory() |
||
164 | { |
||
165 | // build classname |
||
166 | $name = 'Wysiwyg' . ucfirst($this->getEditor()); |
||
167 | |||
168 | // attach namespace |
||
169 | $classname = 'Koch\Form\Elements\\' . $name; |
||
170 | |||
171 | // load file |
||
172 | if (class_exists($classname, false) === false) { |
||
173 | include __DIR__ . '/' . $name . '.php'; |
||
174 | } |
||
175 | |||
176 | // instantiate |
||
177 | $editor_formelement = new $classname(); |
||
178 | |||
179 | return $editor_formelement; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * At some point in the lifetime of this object |
||
184 | * you decided that this textarea should be a wysiwyg editor. |
||
185 | * The editorFactory will load the file and instantiate the editor object. |
||
186 | * But you already defined some properties like Cols or Rows for this textarea. |
||
187 | * Therefore it's now time to transfer these properties to the editor object. |
||
188 | * Because we don't render this textarea, but the requested wysiwyg editor object. |
||
189 | */ |
||
190 | private function transferPropertiesToEditor() |
||
206 | |||
207 | /** |
||
208 | * Renders a normal html textarea representation when |
||
209 | * no wysiwyg editor object is attached to this textarea object. |
||
210 | * Otherwise the html content of the wysiwyg editor is prepended |
||
211 | * to the textarea html.! |
||
212 | * |
||
213 | * @return $html HTML Representation of an textarea |
||
214 | */ |
||
215 | public function render() |
||
256 | } |
||
257 |