Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
replace_text.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
33 class Replace_Text extends WYSIWYG_Plugin
34 {
35 
36 
44  function replace_text()
45  {
46  $this->_add_button('replacetext','ReplaceText','Replace Text','false','11');
47 
48  }//end replace_text()
49 
50 
57  function print_plugin_button_click()
58  {
59  ?>
60  case "replacetext":
61  this._popupDialog("ReplaceText", "<?php echo $this->get_popup_href('replace_text.php')?>", 440, 520, true, function(types){
62  if (types == null) return false;
63  var reg = null;
64  var rep = null;
65  var selected_html = types[0];
66  if (types[0] && editor.getSelectedHTML().length != 0) {
67  selected_html = true;
68  var curHTML = editor.getSelectedHTML();
69  // Remove the line breaks in the html content (see bug #5704)
70  if (HTMLArea.is_ie) {
71  curHTML = curHTML.replace(/\r\n/g, "");
72  }
73  } else if (!types[0]) {
74  selected_html = false;
75  var curHTML = editor.getHTML();
76  } else {
77  alert("Selected text is not defined. Replace Text action aborted.");
78  return false;
79  }
80  if (HTMLArea.is_ie) {
81  // IE removes the qoutes from some speical attribute values. Hence we add quotes here to the
82  // unquoted attribute values so that the "replacement text" feature here works expectedly.
83  var tags = curHTML.match(/<(?!\/)[^>]+>/g);
84  for(var i=0; i<tags.length; i++) {
85  var tag = tags[i];
86  curHTML = curHTML.replace(tag, tag.replace(/(\s[^\s<>="'`]+\s*=\s*)([^\s<>"\'`]+)/g, '$1"$2"'));
87  }//end for
88  }
89 
90  var HTMLtags = "!--|a|abbr|above|acronym|address|applet|array|area|b|base|basefont|bdo|bgsound|big|blink|blockquote|body|box|br|blink|button|caption|center|cite|code|col|colgroup|comment|dd|del|dfn|dir|div|dl|dt|em|embed|fieldset|fig|font|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|hr|html|i|id|iframe|ilayer|img|input|ins|isindex|kbd|label|layer|legend|li|link|listing|map|marquee|menu|meta|multicol|nextid|nobr|noframes|nolayer|note|noscript|object|ol|option|keygen|optgroup|p|param|pre|q|quote|range|root|s|samp|script|select|small|sound|spacer|span|sqrt|strike|strong|style|sub|sup|table|tbody|td|text|textarea|tfoot|th|thead|title|tr|tt|u|ul|var|wbr|xmp";
91  var bullet = unescape("%B7");
92  var shy = unescape("%AD");
93  for (var i=1;i<types.length;i++)
94  if (types[i])
95  {
96  // Bug #3204 - Remove Word Document HTML Clipboard Tags, that get pasted through on Firefox 3
97  localreg = new RegExp("<link rel=\"[^\"]*\" href=\"file[^\"]*\">", "gi");
98  localrep = "";
99  curHTML = curHTML.replace(localreg, localrep);
100  wordreg = new RegExp("<w\:[^>]*>(.*?)<\/w\:[^>]*>", "gi");
101 
102  wordrep = "";
103  curHTML = curHTML.replace(wordreg, wordrep);
104  switch (i) {
105  case 1 : {
106  reg = new RegExp("<\/?font ?[^>]*>", "gi");
107  rep = "";
108  break;
109  }
110  case 2 : {
111  //#3827 -- using regexp literal
112  reg = /(\s|&nbsp;){2,}/gi;
113  rep = "$1";
114  break;
115  }
116  case 3 : {
117  reg = new RegExp("<(?!(\/?(" + HTMLtags + ")[> ]))([^>]*)>", "gi");
118  rep = "";
119  break;
120  }
121  case 4 : {
122  reg = new RegExp("<p[^>]*>("+bullet+"|&middot\;)(.*?)<\/p>", "gi");
123  rep = "<li>$2";
124  break;
125  }
126  case 5 : {
127  reg = new RegExp("(&shy;?|"+shy+")", "gi");
128  rep = "";
129  break;
130  }
131  case 6 : {
132  reg = new RegExp(" style=\"?[^\">]*\"?", "gi");
133  rep = "";
134  break;
135  }
136  case 7 : {
137  reg = new RegExp(" class=\"?[^\">]*[\"]?", "gi");
138  rep = "";
139  break;
140  }
141  case 8 : {
142  reg = new RegExp("<(table|/table|tr|tbody|/tbody|td|th) ?[^>]*>", "gi");
143  rep = "";
144  curHTML = curHTML.replace(reg, rep);
145  reg = new RegExp("<(/tr|/td|/th)>", "gi");
146  rep = "<br />";
147  break;
148  }
149  case 9 : {
150  reg = new RegExp("<\/?span( [^>]*>|>)", "gi");
151  rep = "";
152  break;
153  }
154  case 10 : {
155  reg = new RegExp("<([A-Z][A-Z0-9]*)( [^>]*)?>(&nbsp;| |\n|\t)*<\/\\1>", "gi");
156  rep = "";
157  break;
158  }
159  case 11 : {
160  reg = new RegExp('<([^/ >]+)[^>]*?([^>]*?( (src|href)="?[^>"]*"?)[^>]*?)*[^>]*?>', "gi");
161  rep = "<$1$3>";
162  break;
163  }
164  default : return false;
165  }
166  // BUG#928 - special condition to allow empty anchor tag
167  if (i == 10) {
168  reg2 = new RegExp("(<A NAME[^>]*?>)(&nbsp;| |\n|\t)*(</A>)", "gi");
169  rep2 = "$1matrix_anchor_tmp$3"
170  curHTML = curHTML.replace(reg2, rep2);
171  reg2 = new RegExp("(<A ID[^>]*?>)(&nbsp;| |\n|\t)*(</A>)", "gi");
172  rep2 = "$1matrix_anchor_tmp$3"
173  curHTML = curHTML.replace(reg2, rep2);
174  }
175  curHTML = curHTML.replace(reg, rep);
176  if (i == 10) {
177  reg3 = new RegExp("(<A NAME[^>]*?>)matrix_anchor_tmp(</A>)", "gi");
178  rep3 = "$1$2"
179  curHTML = curHTML.replace(reg3, rep3);
180  reg3 = new RegExp("(<A ID[^>]*?>)matrix_anchor_tmp(</A>)", "gi");
181  rep3 = "$1$2"
182  curHTML = curHTML.replace(reg3, rep3);
183  }
184  }
185  if (selected_html) {
186  if (types.length>0) {
187  editor.insertHTML(curHTML);
188  }
189  } else {
190  if (types.length>0) editor.setHTML(curHTML);
191  }
192 
193  }, null);
194  break;
195  <?php
196 
197  }//end print_plugin_button_click()
198 
199 
200 }//end class
201 
202 ?>