Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
matrix_embed_movie.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
34 {
35 
36  var $_img_url = '';
37 
38 
45  function matrix_embed_movie(&$wysiwyg)
46  {
47  wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
48  $this->_add_button('matrixembedmovie','MatrixEmbedMovie','Embed Movie','false','53');
49  $this->_img_url = $wysiwyg->web_path.'plugins/'.$this->get_popup_href('embedded_object.gif');
50 
51  }//end constructor
52 
53 
60  function paint_generic()
61  {
62  ?>
63  <script type="text/javascript" language="Javascript">
64  // Called when the user clicks on "InsertImage" button
65  HTMLArea.prototype._matrixEmbedMovie = function() {
66  var editor = this; // for nested functions
67 
68  var sel = this._getSelection();
69  var range = this._createRange(sel);
70 
71  var style = "";
72  var width = "";
73  var height = "";
74  var fileid = "0";
75  var auto_start = "0";
76  var show_controls = "0";
77  var embed_loop = "0";
78  var is_file = false;
79  var fileurl = '';
80  var fileprotocol = '';
81 
82  // loop through and try and find a selected embed tag
83  if (HTMLArea.is_gecko) {
84  var fragment = this._doc.createDocumentFragment();
85  var div = this._doc.createElement("div");
86  div.innerHTML = this.getSelectedHTML();
87  while (div.firstChild) {
88  if (div.firstChild.tagName == "IMG" && div.firstChild.getAttribute('sq_embeded') == "1") {
89  is_file = true;
90  var embed_tag = div.firstChild;
91  break;
92  }
93  // the following call also removes the node from div
94  fragment.appendChild(div.firstChild);
95  }
96  } else if (HTMLArea.is_ie) {
97  if (range.length) {
98  if (range.item(0).tagName == "IMG" && range.item(0).getAttribute('sq_embeded') == "1") {
99  is_file = true;
100  var embed_tag = range.item(0);
101  }
102  }
103  }
104 
105  // if there is an existing image, get its properties
106  if (is_file && embed_tag) {
107  fileid = embed_tag.getAttribute('fileid');
108  if (fileid != null) {
109  fileurl = './?a=' + fileid;
110  } else {
111  fileparts = embed_tag.getAttribute('fileurl');
112  if (fileparts != null) {
113  if (fileparts.substring(0, 7) == 'http://') {
114  fileprotocol = 'http://';
115  fileurl = fileparts.substring(7);
116  } else if (fileparts.substring(0, 8) == 'https://') {
117  fileprotocol = 'https://';
118  fileurl = fileparts.substring(8);
119  } else if (fileparts.substring(0, 6) == 'ftp://') {
120  fileprotocol = 'ftp://';
121  fileurl = fileparts.substring(6);
122  }
123  }
124  }
125  auto_start = embed_tag.getAttribute('auto_start');
126  show_controls = embed_tag.getAttribute('show_controls');
127  embed_loop = embed_tag.getAttribute('embed_loop');
128 
129  // try getting the width and height from the style
130  style = embed_tag.style;
131  width = style.width;
132  height = style.height;
133 
134  // if that fails, lets try getting them from the tag
135  if (!width) { width = embed_tag.getAttribute('width'); }
136  if (!height) { height = embed_tag.getAttribute('height'); }
137 
138  // make sure they are numbers
139  width = parseInt(width);
140  height = parseInt(height);
141 
142  // failsafe
143  if (!width) { width = "" }
144  if (!height) { height = "" }
145 
146  }
147 
148  var in_popup = '0';
149  if (this._inPopup == true) { in_popup = '1'; }
150 
151  editor_<?php echo $this->wysiwyg->name?>._object = this;
152  strPage = "<?php echo $this->get_popup_href('embed_movie_frames.php')?>?f_fileurl=" + escape(fileurl) + "&f_fileprotocol=" + escape(fileprotocol) + "&f_width=" + escape(width) + "&f_height=" + escape(height) + "&f_auto_start=" + escape(auto_start) + "&f_show_controls=" + escape(show_controls) + "&f_embed_loop=" + escape(embed_loop) + "&editor_name=" + escape("<?php echo $this->wysiwyg->name; ?>") + "&in_popup=" + escape(in_popup);
153 
154  this._popupDialog("matrixEmbedMovie", strPage, 780, 500, true, function(param) {
155  if (!param) {
156  // user must have pressed Cancel
157  return false;
158  }
159  var html = '<img sq_embeded="1" src="<?php echo $this->_img_url; ?>"';
160  html += ' style="width: ' + param["f_width"] + 'px; height: ' + param["f_height"] + 'px; border: 2px dashed black;"';
161  html += ' width="' + param["f_width"] + '"';
162  html += ' height="' + param["f_height"] + '"';
163  if (param["use_external"] == true) {
164  html += ' fileurl="' + param["external_url"] + '"';
165  } else {
166  html += ' fileid="' + param["f_fileid"] + '"';
167  }
168  html += ' auto_start="' + param["f_auto_start"] + '"';
169  html += ' show_controls="' + param["f_show_controls"] + '"';
170  html += ' embed_loop="' + param["f_embed_loop"] + '"';
171  html += '>';
172  html = editor.make_absolute_urls(html);
173 
174  if (!is_file || HTMLArea.is_gecko) {
175  // replace text with new image
176  editor.insertHTML(html, range);
177  } else {
178  // we are replacing an existing image in IE
179  embed_tag.outerHTML = html;
180  }
181 
182  }, null);
183  };
184  </script>
185  <?php
186 
187  }//end paint_generic()
188 
189 
197  {
198  ?>
199  case "matrixembedmovie":
200  this._matrixEmbedMovie();
201  return;
202  break;
203  <?php
204 
205  }//end print_plugin_button_click()
206 
207 
216  function process(&$html)
217  {
218  $matches = Array();
219  preg_match_all('|(<img[^>]+sq_embeded="1"([^>]+)?>)|i', $html, $matches);
220 
221  foreach ($matches[1] as $match) {
222  $old_html = $match;
223 
224  $match = strtolower($match);
225  $match = substr($match, 4);
226  $match = substr($match, 0, -1);
227  $match = str_replace('src="'.$this->_img_url.'"', '', $match);
228 
229  $pieces = Array();
230  preg_match_all('|\s+([^=]+)="([^"]+)"|', $match, $pieces);
231 
232  $movie_vars = Array();
233  for (reset($pieces[1]); NULL !== ($k = key($pieces[1])); next($pieces[1])) {
234  $var_name = trim($pieces[1][$k]);
235  $var_value = trim($pieces[2][$k]);
236  $movie_vars[$var_name] = $var_value;
237  }
238  $movie_url = '';
239  if (isset($movie_vars['fileurl'])) {
240  $filename = $movie_vars['fileurl'];
241  $movie_url = $movie_vars['fileurl'];
242  $movie_url = $filename;
243  } else {
244  if (!isset($movie_vars['fileid'])) continue;
245  $fileid = $movie_vars['fileid'];
246  $file = $GLOBALS['SQ_SYSTEM']->am->getAsset($fileid);
247 
248  if (is_null($file)) continue;
249  if (!($file instanceof File)) {
250  trigger_localised_error('SYS0089', E_USER_WARNING, $file->id, 'File');
251  continue;
252  }
253 
254  $filename = $file->name;
255  $movie_url = './?a='.$fileid;
256  }
257  // first try getting width and height from the style
258  $width = '';
259  $height = '';
260  if (isset($movie_vars['style'])) {
261  $style = $movie_vars['style'];
262  $style_pieces = Array();
263  preg_match_all('|([^\s:]+):\s([^\s;]+);?|i', $style, $style_pieces);
264 
265  $style_vars = Array();
266  for (reset($style_pieces[1]); NULL !== ($k = key($style_pieces[1])); next($style_pieces[1])) {
267  $var_name = trim($style_pieces[1][$k]);
268  $var_value = trim($style_pieces[2][$k]);
269  $style_vars[$var_name] = $var_value;
270  }
271 
272  if (isset($style_vars['width'])) {
273  $width = 'width="'.str_replace('px','',$style_vars['width']).'"';
274  }
275  if (isset($style_vars['height'])) {
276  $height = 'height="'.str_replace('px','',$style_vars['height']).'"';
277  }
278  }
279 
280  // if we didnt get width and height from the style, try the tag
281  if (empty($width)) {
282  if (isset($movie_vars['width'])) {
283  $width = 'width="'.str_replace('px','',$movie_vars['width']).'"';
284  }
285  }
286  if (empty($height)) {
287  if (isset($movie_vars['height'])) {
288  $height = 'height="'.str_replace('px','',$movie_vars['height']).'"';
289  }
290  }
291 
292  ob_start();
293 
294  ?>
295  <sq_wysiwyg_embed_movie <?php echo $match; ?>>
296  <?php
297  switch (strtolower(get_file_type($filename))) {
298 
299  // Quicktime Movie
300  case 'mov' :
301  if (!isset($movie_vars['embed_loop'])) {
302  $movie_vars['embed_loop'] = '0';
303  }
304  if (!isset($movie_vars['show_controls'])) {
305  $movie_vars['show_controls'] = '0';
306  }
307 
308  ?><embed src="<?php echo $movie_url; ?>" controller="<?php echo ($movie_vars['show_controls']) ? 'true' : 'false'?>" cache="true" loop="<?php echo ($movie_vars['embed_loop']) ? 'true' : 'false'; ?>" <?php echo $width; ?> <?php echo $height; ?>><?php
309  break;
310 
311  // Shockwave Flash
312  case 'swf' :
313  ?><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" <?php echo $width; ?> <?php echo $height; ?>>
314  <param name="movie" value="<?php echo $movie_url; ?>">
315  <param name="quality" value="high">
316  <param name="scale" value="exactfit">
317  <embed src="<?php echo $movie_url; ?>" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" <?php echo $width; ?> <?php echo $height; ?> scale="exactfit"></embed>
318  </object><?php
319  break;
320 
321  // Windows Media File
322  case 'wmv' :
323  case 'asf' :
324  case 'asx' :
325  case 'mpeg' :
326  case 'mpg' :
327  if (!isset($movie_vars['embed_loop'])) {
328  $movie_vars['embed_loop'] = '0';
329  }
330  if (!isset($movie_vars['show_controls'])) {
331  $movie_vars['show_controls'] = '0';
332  }
333  if (!isset($movie_vars['auto_start'])) {
334  $movie_vars['auto_start'] = '0';
335  }
336  ?><object id="WinMedia" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
337  codebase= "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
338  <?php echo $width; ?> <?php echo $height; ?>
339  standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">
340  <param name="FileName" value="<?php echo $movie_url; ?>">
341  <param name="AutoStart" value="<?php echo ($movie_vars['auto_start']) ? 'true' : 'false'; ?>">
342  <param name="ShowControls" value="<?php echo ($movie_vars['show_controls']) ? 'true' : 'false'; ?>">
343  <param name="loop" value="<?php echo ($movie_vars['embed_loop']) ? 'true' : 'false';?>">
344  <embed type="application/x-mplayer2"
345  pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
346  src="<?php echo $movie_url; ?>"
347  name="MediaPlayer"
348  AutoStart="<?php echo ($movie_vars['auto_start']) ? 'true' : 'false'; ?>"
349  ShowControls="<?php echo ($movie_vars['show_controls']) ? 'true' : 'false'; ?>"
350  loop="<?php echo ($movie_vars['embed_loop']) ? 'true' : 'false'; ?>"
351  <?php echo $width; ?>
352  <?php echo $height; ?>
353  ></embed>
354  </object><?php
355  break;
356 
357  }//end switch
358 
359  ?></sq_wysiwyg_embed_movie><?php
360  $new_html = ob_get_contents();
361  ob_end_clean();
362 
363  $html = str_replace($old_html, $new_html, $html);
364 
365  }//end foreach $matches
366 
367  // make sure the htmlTidy plugin knows about our special tag
368  if ($this->wysiwyg->plugin_loaded('html_tidy')) {
369  $html_tidy =& $this->wysiwyg->get_plugin('html_tidy');
370  $html_tidy->new_inline_tag('sq_wysiwyg_embed_movie');
371  }
372 
373  }//end process()
374 
375 
384  function set_contents(&$contents)
385  {
386  // replace the special embedded tags with standard img tags
387  $contents = preg_replace('|(<sq_wysiwyg_embed_movie([^>]*)?>)(.*?)(</sq_wysiwyg_embed_movie>)|si', '<IMG src="'.$this->_img_url.'" $2>', $contents);
388  $contents = preg_replace('|\s+|', ' ', $contents);
389 
390  }//end set_contents()
391 
392 
393 }//end class
394 
395 ?>