Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
htmlarea.php
Go to the documentation of this file.
1 <?php
2 /*******************************************************************************
3  * File: HTML/QuickForm/htmlarea.php
4  * Author: Steve Hannah <shannah@sfu.ca>
5  * Created: September 1, 2005
6  * Description:
7  * HMTL Quickform widget to edit HTML. Uses the FCKEditor
8  ******************************************************************************/
9 
10 
11 require_once 'HTML/QuickForm/textarea.php';
12 
13 
14 $GLOBALS['HTML_QuickForm_htmlarea'] = array(
15  'FCKeditor_BasePath' => ( isset($GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath']) ? $GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath'] : './lib/FCKeditor'),
16  'TinyMCE_BasePath' => (isset($GLOBALS['HTML_QuickForm_htmlarea']['TinyMCE_BasePath']) ? $GLOBALS['HTML_QuickForm_htmlarea']['TinyMCE_BasePath'] : './lib/tiny_mce')
17  );
18 
19 
28 class HTML_QuickForm_htmlarea extends HTML_QuickForm_textarea {
29 
30  var $_basePath = '.';
31 
32  // added to support multiple types of editors
33  var $editorName = 'FCKEditor';
34  var $tinyMCE_atts = array(
35  'theme','plugins','language','ask','docs_language','debug','focus_alert','directionality','auto_resize','browsers','dialog_type','accessibility_warnings','accessibility_focus','event_elements','table_inline_editing','object_resizing','custom_shortcuts','convert_urls','relative_urls','remove_script_host','document_base_url','content_css','popups_css','editor_css','width','height','visual','visual_table_class','cleanup','valid_elements','extended_valid_elements','invalid_elements','verify_css_classes','verify_html','preformatted','encoding','cleanup_on_startup','fix_content_duplication','inline_styles','convert_newlines_to_brs','force_br_newlines','force_p_newlines','entities','entity_encoding','remove_linebreaks','convert_fonts_to_spans','font_size_classes','font_size_style_values','merge_styles_invalid_parents','force_hex_style_colors','apply_source_formatting','trim_span_elements','doctype','fix_list_elements','fix_table_elements','theme_advanced_toolbar_location','theme_advanced_resizing','theme_advanced_buttons1_add_before','theme_advanced_buttons1_add','theme_advanced_buttons2_add','theme_advanced_buttons2_add_before','theme_advanced_buttons3_add_before','theme_advanced_buttons3_add','theme_advanced_toolbar_location','theme_advanced_toolbar_align','theme_advanced_path_location'
36  );
37  var $wysiwygOptions = array();
38 
39  function HTML_QuickForm_htmlarea($elementName=null, $elementLabel=null, $attributes=null)
40  {
41  HTML_QuickForm_textarea::HTML_QuickForm_textarea($elementName, $elementLabel, $attributes);
42  $this->_type = 'htmlarea';
43  } //end constructor
44 
45 
49  function setWysiwygOptions($atts){
50  foreach ($this->tinyMCE_atts as $option){
51  if ( isset( $atts[$option] ) ){
52  if ( is_array($atts[$option]) ){
53  $this->wysiwygOptions[$option] = implode(',',$atts[$option]);
54  } else {
55  $this->wysiwygOptions[$option] = $atts[$option];
56  }
57  }
58  }
59 
60  }
61 
62 
70  function toHtml()
71  {
72  if ($this->_flagFrozen) {
73  return $this->getFrozenHtml();
74  } else {
75  switch (strtolower($this->editorName)){
76 
77  case 'nicedit':
78  ob_start();
79  if ( !defined('HTML_QuickForm_htmlarea_nicEdit_loaded') ){
80  define('HTML_QuickForm_htmlarea_nicEdit_loaded',1);
81  echo '<script language="javascript" type="text/javascript" src="'.DATAFACE_URL.'/js/nicEdit/nicEdit.js"></script>';
82  }
83  echo '<script language="javascript">
84  //<![CDATA[
85  bkLib.onDomLoaded(function(){
86  new nicEditor({fullPanel: true, iconsPath: \''.DATAFACE_URL.'/js/nicEdit/nicEditorIcons.gif\'}).panelInstance(\''.$this->getAttribute('id').'\');
87  });
88  //]]></script>';
89  $html = ob_get_contents();
90  ob_end_clean();
91  return $html."\n".parent::toHtml();
92 
93  case 'fckeditor':
94  require_once 'FCKeditor/fckeditor.php';
95  $editor = new FCKEditor($this->getName());
96  $editor->BasePath = $GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath'];
97  $editor->Value = $this->_value;
98  $editor->Width = '100%';
99  $editor->Height = '480';
100  ob_start();
101  $editor->Create();
102  $html = ob_get_contents();
103  ob_end_clean();
104  return $html;
105 
106  case 'tinymce':
107  ob_start();
108  if ( !defined('HTML_QuickForm_htmlarea_TinyMCE_loaded') ){
109  define('HTML_QuickForm_htmlarea_TinyMCE_loaded', true);
110  echo '<script language="javascript" type="text/javascript" src="'.$GLOBALS['HTML_QuickForm_htmlarea']['TinyMCE_BasePath'].'/tiny_mce.js"></script>';
111  }
112  echo '
113 
114  <script language="javascript" type="text/javascript">
115  tinyMCE.init({
116  editor_selector : "mceEditor",
117  mode : "exact",
118  elements : "'.$this->getAttribute('id').'"';
119  foreach ($this->wysiwygOptions as $key=>$value){
120  echo ',
121  '.$key.' : "'.$value.'"';
122  }
123  echo '
124  });
125 
126  </script>
127  ';
128  $out = ob_get_contents();
129  ob_end_clean();
130 
131  // now we can just call textarea's tohtml method.
132  return $out.parent::toHtml();
133 
134 
135 
136 
137 
138  }
139 
140  }
141 
142 
143  } //end func toHtml
144 
145 
153  function getFrozenHtml()
154  {
155  $value = $this->getValue();
156  $html = '<div style="border: 1px solid #ccc; padding: 1em">'.$value.'</div>';
157 
158  return $html . $this->_getPersistantData();
159  } //end func getFrozenHtml
160 
161 
162 
163 }