Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
choose_language.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
21 
33 class Choose_Language extends WYSIWYG_Plugin
34 {
35 
36 
42  function Choose_Language(&$wysiwyg)
43  {
45  // WORK OUT THE LOCALE LIST //
47  //require_once dirname(__FILE__).'/../../../../core/include/init.inc';
48 
49 
50  /*$lm = &$GLOBALS['SQ_SYSTEM']->lm;
51  $curr_locale = $lm->getCurrentLocale();
52  if ($curr_locale !== FALSE) {
53 
54  }*/
55  $this->_add_button('chooselang','','','','');
56 
57  }//end constructor
58 
59 
66  function print_plugin_vars()
67  {
68  $common_languages = Array(
69  '' => 'None',
70  'en' => 'English',
71  'es' => 'Spanish',
72  'fr' => 'French',
73  'it' => 'Italian',
74  'pt' => 'Portuguese',
75  'de' => 'German',
76  'ru' => 'Russian',
77  'ar' => 'Arabic',
78  'zh' => 'Chinese',
79  'he' => 'Hebrew',
80  'ja' => 'Japanese',
81  'ko' => 'Korean',
82  'sw' => 'Swahili',
83  'el' => 'Greek',
84  'la' => 'Latin',
85  'he' => 'Hebrew',
86  );
87  ?>
88  this.config.chooselang = {
89  "-- choose language --": "",<?php
90  foreach ($common_languages as $code => $name) {
91  echo '"'.$name.'": "'.$code.'",'."\n";
92  }
93  ?>
94  "---------------------": "",<?php
95  require_once SQ_FUDGE_PATH.'/standards_lists/languages.inc';
96  $count = 1;
97  foreach ($standards_lists_languages as $code => $name) {
98  if (array_key_exists($code, $common_languages)) {
99  $count++;
100  continue;
101  }
102  if ($count == count($standards_lists_languages)) {
103  echo '"'.$name.'": "'.$code.'"'."\n";
104  } else {
105  echo '"'.$name.'": "'.$code.'",'."\n";
106  }
107  $count++;
108  }
109  ?>
110  };
111  <?php
112 
113  }//end print_plugin_vars()
114 
115 
123  {
124  ?>
125  case "chooselang" :
126  options = editor.config[txt];
127  cmd = txt;
128  break;
129  <?php
130 
131  }//end print_plugin_create_select()
132 
133 
141  {
142  ?>
143  case "chooselang" :
144  if (!text) {
145  var options = this.config["chooselang"];
146  var current_span = this.getClosest("span");
147  var found = false;
148  if (current_span) {
149  var value = current_span.lang;
150  var k = 0;
151  for (var j in options) {
152  if (options[j].toLowerCase() == value) {
153  btn.element.selectedIndex = k;
154  found = true;
155  break;
156  }
157  ++k;
158  }
159  }
160  if (!found) {btn.element.selectedIndex = 0; }
161  }
162  break;
163  <?php
164 
165  }//end print_plugin_update_toolbar()
166 
167 
175  {
176  ?>
177  case "chooselang":
178  if (value != null) {
179  var current_span = this.getClosest("span");
180  if (current_span) {
181  if (value == "") {
183  // Remove Lang Tag //
185  var sel = this._getSelection();
186  var range = this._createRange(sel);
187  var span_parent = current_span.parentNode;
188  for (var i = 0; i < span_parent.childNodes.length; i++) {
189  var child_node = span_parent.childNodes[i];
190  if (child_node.tagName == "SPAN") {
191  if (child_node.innerHTML == current_span.innerHTML) {
192  if (HTMLArea.is_gecko) {
193  // Gecko provides a cleaner way
194  if (child_node.attributes.length == 1) {
195  // span tag may have only one attribute, lang. then
196  // we remove the surrounding span tag itself
197  if (child_node.attributes[0].name == "lang") {
198  range.selectNode(child_node);
199  this.insertHTML(child_node.innerHTML, range);
200  }
201  } else if (child_node.attributes.length > 1) {
202  // span tag may have multiple attributes, then
203  // we only remove lang attribute from the tag
204  var attrs = child_node.attributes;
205  var lang_found = false;
206  var xml_lang_found = false;
207  var tmp_span = "<span ";
208  for (var j = 0; j < attrs.length; j++) {
209  if (attrs[j].name == "lang") {
210  lang_found = true;
211  } else if (attrs[j].name == "xml:lang") {
212  xml_lang_found = true;
213  }else {
214  tmp_span = tmp_span + attrs[j].name + "=\"" + attrs[j].value +"\" ";
215  }
216  }
217 
218  if (lang_found && xml_lang_found && attrs.length == 2) {
219  range.selectNode(child_node);
220  this.insertHTML(child_node.innerHTML, range);
221  } else if (lang_found || xml_lang_found) {
222  tmp_span += ">";
223  range.selectNode(child_node);
224  this.insertHTML(tmp_span + child_node.innerHTML + "</span>", range)
225  }
226  }
227  } else if (HTMLArea.is_ie) {
228  var inner_html = child_node.innerHTML
229  var new_child = this._doc.createTextNode('');
230  if (typeof(visual_aid_mode) != 'undefined' && visual_aid_mode) {
231  var e = '<span id=wysiwyg-visual-aid-plugin-lang[^>]*>[^>]*<\/span>';
232  var re = new RegExp(e, "ig");
233  inner_html = inner_html.replace(re, '');
234  }
235  span_parent.replaceChild(new_child, child_node);
236  range.pasteHTML(inner_html);
237  }
238  }
239  }
240  }
241  } else {
243  // Choose The Lang Attribute //
245  this.selectNodeContents(current_span);
246  current_span.lang = value;
247  }
248  } else if (value != "") {
250  // Add The Span Tag With Lang Attr //
252  if (this.getSelectedHTML().length != 0) {
253  this.surroundHTML("<span lang=\"" + value + "\">", "</span>");
254  }
255  }
256  }
257  break;
258  <?php
259 
260  }//end print_plugin_combo_selected()
261 
262 
263 }//end class()
264 
265 ?>