Framework  3.9
html_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2007-2010 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
39 
47 {
48  var $colspan = 2;
49  var $hideStyleBar = false;
50  var $width = "540px";
51  var $height = "200px";
53  var $rootBlock = "p";
54  var $baseURL = null;
55  var $convertURLs = false;
56 
57  static $_includedRTEScript = false;
58 
59  public static $actionFilter = null;
60 
61  var $rteParams= array();
62 
64  {
65  $this->FieldRenderer($parent);
66  $this->hideStyleBar = $parent->HTMLEditorHideStyleBar;
67  $this->width = $parent->HTMLEditorDefaultWidth;
68  $this->height = $parent->HTMLEditorDefaultHeight;
69  $this->annotateBefore = true;
70  }
71 
72  function setRTEParam($key, $value)
73  {
74  $this->rteParams[$key] = $value;
75  }
76 
77  function getRTEParam($key)
78  {
79  return $this->rteParams[$key];
80  }
81 
82  function renderScript($field)
83  {
84  global $config;
85 
86  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field)
87  || array_key_exists($field, $this->parent->hidden)) return "";
88 
89  global $tiny_mce_application_plugins;
90  global $tiny_mce_application_toolbar_section;
91  global $tiny_mce_application_context_menu_section;
92  global $tiny_mce_content_css;
93  global $tiny_mce_body_class;
94 
95  $plugins = "advlist,lists,code,visualblocks,table,charmap,paste,contextmenu,searchreplace,fullscreen";
96  if ($tiny_mce_application_plugins) $plugins .= ",".$tiny_mce_application_plugins;
97  $contextMenu = "cut copy paste pastetext searchreplace removeformat | {$tiny_mce_application_context_menu_section} inserttable cell row column deletetable";
98  $toolbar = "undo redo | cut copy paste pastetext searchreplace | styleselect | bold italic removeformat | bullist numlist outdent indent | table charmap | {$tiny_mce_application_toolbar_section} code visualblocks fullscreen";
99 
100  if (is_callable(HTMLFieldRenderer::$actionFilter))
101  {
102  $contextMenu = (HTMLFieldRenderer::$actionFilter)($contextMenu);
103  $toolbar = (HTMLFieldRenderer::$actionFilter)($toolbar);
104  }
105 
106  $https = Fakoli::checkSSL();
107 
108  $protocol = $https ? "https" : "http";
109 
110  $rootBlock = "";
111 
112  if ($this->rootBlock != "p")
113  {
114  if (!$this->rootBlock)
115  {
116  $this->setRTEParam("forced_root_block", false);
117  }
118  else
119  {
120  $this->setRTEParam("forced_root_block", $this->rootBlock);
121  }
122  }
123 
124  $baseURL = ($this->baseURL !== null) ? $this->baseURL : "{$protocol}://{$config['http_host']}";
125  if (isset($config["convertURLs"]))
126  {
127  $convertURLs = $config["convertURLs"] ? true : false;
128  }
129  else
130  {
131  $convertURLs = ($this->convertURLs) ? true : false;
132  }
133 
135  {
136 ?>
137 
138  <script type='text/javascript'>
139  tinymce.baseURL = "<?echo $protocol?>://<?echo $config['http_host']?>/fakoli/tinymce/";
140  </script>
141 <?
143  }
144 
145  $cssFiles = explode("\n", str_replace("\r", "", $tiny_mce_content_css));
146  if (count($cssFiles) > 0)
147  {
148  $this->setRTEParam("content_css", $cssFiles);
149  }
150  else
151  {
152  $this->setRTEParam("content_css", "");
153  }
154 
155  if (endsWith($this->width, "px"))
156  {
157  $w = substr($this->width, 0, -2);
158 
159  $this->setRTEParam("width", $w);
160  }
161 
162  if (endsWith($this->height, "px"))
163  {
164  $h = substr($this->height, 0, -2);
165  $this->setRTEParam("height", $h);
166  }
167 
168  $this->setRTEParam("valid_elements", '*[*]');
169  $this->setRTEParam("selector", "#{$this->parent->id}_{$field}");
170  $this->setRTEParam("plugins", $plugins);
171  $this->setRTEParam("contextmenu", $contextMenu);
172  $this->setRTEParam("skin", 'fakoli');
173  $this->setRTEParam("body_class", $tiny_mce_body_class);
174  $this->setRTEParam("relative_urls", false);
175  $this->setRTEParam("convert_urls", $convertURLs);
176  $this->setRTEParam("document_base_url", $baseURL);
177  $this->setRTEParam("menubar", false);
178  $this->setRTEParam("toolbar", $toolbar);
179  $this->setRTEParam("tools", 'inserttable');
180 
181  if ($this->customConfig) call_user_func($this->customConfig, $this);
182 ?>
183  <script type='text/javascript'>
184  tinymce.init(
185  {
186 <?
187  echo $this->renderParameters();
188 ?>
189  });
190  </script>
191 <?
192  }
193 
194  private function renderParameters()
195  {
196  $params = array();
197  foreach($this->rteParams as $key => $value)
198  {
199  if (is_array($value))
200  {
201  $v = "['".implode("','", $value)."']";
202  $params[] = "\t\t\t$key: $v";
203  }
204  else if (is_bool($value))
205  {
206  $v = $value ? "true" : "false";
207  $params[] = "\t\t\t$key: $v";
208  }
209  else if (is_numeric($value))
210  {
211  $params[] = "\t\t\t$key: $value";
212  }
213  else
214  {
215  $params[] = "\t\t\t$key: '$value'";
216  }
217  }
218 
219  return implode(",\n", $params);
220  }
221 
222  function addEditorButton($editor, $button)
223  {
224  if ($button['url'])
225  {
226  echo "theEditors.$editor.addToolbarButton('{$button['name']}', '{$button['image']}', '{$button['tooltip']}', '{$button['url']}', '{$button['width']}', '{$button['height']}');\n";
227  }
228  else
229  {
230  echo "theEditors.$editor.addToolbarButton('{$button['name']}', '{$button['image']}', '{$button['tooltip']}', {$button['handler']});\n";
231  }
232  }
233 
234  function overrideEditorButton($editor, $button)
235  {
236  echo "theEditors.$editor.overrideToolbarButton('{$button['name']}', {$button['handler']});\n";
237  }
238 
239  function renderField($field)
240  {
241  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field) || array_key_exists($field, $this->parent->hidden)) return "";
242  echo "<div id='{$field}_container'></div>";
243 
244  $this->_startField($field);
245 
246  echo "<textarea id='{$this->parent->id}_{$field}' name='{$field}' style='width: {$this->width}; height: {$this->height}' class='richtext'>".htmlSafe($this->parent->data->get($field))."</textarea>\n";
247 
248  $this->_endField($field);
249  }
250 
251  function renderReadOnly($field)
252  {
253  $this->_startField($field);
254 
255  echo $this->parent->data->get($field);
256 
257  $this->_endField($field);
258  }
259 
260  function renderSearchField($field, $mode = "equal")
261  {
262  // AJG - Override default colspan when rendering in a search form
263  $this->colspan = 1;
264 
265  if ($mode == "range")
266  {
267  $from = $this->parent->params->get($field, "from");
268  $to = $this->parent->params->get($field, "to");
269 
270  echo "<tr>\n";
271  $this->_printLabel($field);
272  echo "<td>From <input type='text' name='$field:from' value='{$from}' size='25'> to <input type='text' name='$field:to' value='{$to}' size='25'></td>\n";
273  echo "</tr>\n";
274  }
275  else
276  {
277  $value = $this->parent->params->get($field, $mode);
278  echo "<tr>\n";
279  $this->_printLabel($field);
280  echo "<td><input type='text' name='$field:$mode' value='{$value}' size='50'></td>\n";
281  echo "</tr>\n";
282  }
283  }
284 
285  function renderOnSubmitHandler($field)
286  {
287  // JDG 3/2/2011., no js for readonly field
288  if ($this->parent->isReadOnly($field)) return "";
289 
290  $editor = $field."_editor";
291 
292  //echo "\ttheEditors.$editor.prepareForSubmit();\n";
293  }
294 }
295 ?>
FieldRenderer is the abstract base class for all FieldRenderers.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
_printLabel($field, $colspan=1, $styles="", $annotation="")
Internal method to generate the HTML for the field label.
FieldRenderer($parent)
Constructor.
Field renderer for HTML data fields.
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
addEditorButton($editor, $button)
renderSearchField($field, $mode="equal")
FieldRenderers must override this method to provide the HTML implementation of the control displayed ...
renderOnSubmitHandler($field)
FieldRenderers can override this method to provide any Javascript that must be executed when the form...
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
setRTEParam($key, $value)
overrideEditorButton($editor, $button)
endsWith($text, $end)
Tests whether a string ends with the given sub-string.
Definition: functions.inc:1481