19 include_once($ROOT_PATH.
'wysiwyg_plugin.inc');
46 wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
47 $this->
_add_button(
'matrixembedyoutube',
'MatrixEmbedYouTube',
'Embed YouTube',
'false',
'67');
48 $this->_img_url = $wysiwyg->web_path.
'plugins/'.$this->
get_popup_href(
'embedded_object.gif');
62 <script type=
"text/javascript" language=
"Javascript">
64 HTMLArea.prototype._matrixEmbedYouTube =
function() {
67 var sel = this._getSelection();
68 var range = this._createRange(sel);
75 var full_screen =
"1";
87 if (HTMLArea.is_gecko) {
88 var fragment = this._doc.createDocumentFragment();
89 var div = this._doc.createElement(
"div");
90 div.innerHTML = this.getSelectedHTML();
91 while (div.firstChild) {
92 if (div.firstChild.tagName ==
"IMG" && div.firstChild.getAttribute(
'sq_youtube_embeded') ==
"1") {
94 var embed_tag = div.firstChild;
98 fragment.appendChild(div.firstChild);
100 }
else if (HTMLArea.is_ie) {
102 if (range.item(0).tagName ==
"IMG" && range.item(0).getAttribute(
'sq_youtube_embeded') ==
"1") {
104 var embed_tag = range.item(0);
110 if (is_file && embed_tag) {
111 vid = embed_tag.getAttribute(
'vid');
112 video_url = embed_tag.getAttribute(
'video_url');
113 auto_start = embed_tag.getAttribute(
'auto_start');
114 loop = embed_tag.getAttribute(
'loop');
115 full_screen = embed_tag.getAttribute(
'full_screen');
116 show_border = embed_tag.getAttribute(
'show_border');
117 colour1 = embed_tag.getAttribute(
'colour1');
118 colour2 = embed_tag.getAttribute(
'colour2');
119 width = embed_tag.getAttribute(
'width');
120 height = embed_tag.getAttribute(
'height');
121 rel = embed_tag.getAttribute(
'rel');
122 egm = embed_tag.getAttribute(
'egm');
123 enable_js = embed_tag.getAttribute(
'enable_js');
126 width = parseInt(width);
127 height = parseInt(height);
130 if (!width) { width =
"" }
131 if (!height) { height =
"" }
136 if (this._inPopup ==
true) { in_popup =
'1'; }
138 editor_<?php echo $this->
wysiwyg->name?>._object =
this;
139 strPage =
"<?php echo $this->get_popup_href('embed_youtube_frames.php')?>?f_vid=" + escape(vid) +
"&f_video_url=" + escape(video_url) +
"&f_width=" + escape(width) +
"&f_height=" + escape(height) +
"&f_auto_start=" + escape(auto_start) +
"&f_loop=" + escape(loop) +
"&f_full_screen=" + escape(full_screen) +
"&f_show_border=" + escape(show_border) +
"&f_colour1=" + escape(colour1) +
"&f_colour2=" + escape(colour2) +
"&f_rel=" + escape(rel) +
"&f_egm=" + escape(egm) +
"&f_enable_js=" + escape(enable_js) +
"&editor_name=" + escape(
"<?php echo $this->wysiwyg->name; ?>") +
"&in_popup=" + escape(in_popup);
141 var popup_height = 300;
144 if (HTMLArea.is_safari) popup_height += 15;
146 this._popupDialog(
"matrixEmbedYouTube", strPage, 780, popup_height,
true,
function(param) {
151 var html =
'<img sq_youtube_embeded="1" src="<?php echo $this->_img_url; ?>"';
152 html +=
' style="width: ' + param[
"f_width"] +
'px; height: ' + param[
"f_height"] +
'px; border: 2px dashed black;"';
153 html +=
' width="' + param[
"f_width"] +
'"';
154 html +=
' height="' + param[
"f_height"] +
'"';
155 html +=
' auto_start="' + param[
"f_auto_start"] +
'"';
156 html +=
' loop="' + param[
"f_loop"] +
'"';
157 html +=
' full_screen="' + param[
"f_full_screen"] +
'"';
158 html +=
' vid="' + param[
"f_vid"] +
'"';
159 html +=
' video_url="' + param[
"f_video_url"] +
'"';
160 html +=
' show_border="' + param[
"f_show_border"] +
'"';
161 html +=
' colour1="' + param[
"f_colour1"] +
'"';
162 html +=
' colour2="' + param[
"f_colour2"] +
'"';
163 html +=
' rel="' + param[
"f_rel"] +
'"';
164 html +=
' egm="' + param[
"f_egm"] +
'"';
165 html +=
' enable_js="' + param[
"f_enable_js"] +
'"';
167 html = editor.make_absolute_urls(html);
169 if (!is_file || HTMLArea.is_gecko) {
171 editor.insertHTML(html, range);
174 embed_tag.outerHTML = html;
194 case "matrixembedyoutube":
195 this._matrixEmbedYouTube();
214 preg_match_all(
'|(<img[^>]+sq_youtube_embeded="1"([^>]+)?>)|i', $html, $matches);
216 foreach ($matches[1] as $match) {
220 $match = substr($match, 4);
221 $match = substr($match, 0, -1);
222 $match = str_replace(
'src="'.$this->_img_url.
'"',
'', $match);
223 $match = preg_replace(
'/style="(.*?("))/im ',
'', $match);
226 $match = preg_replace(
'/ height=([0-9]+)/',
' height="$1"', $match);
227 $match = preg_replace(
'/ width=([0-9]+)/',
' width="$1"', $match);
230 preg_match_all(
'|\s+([^=]+)="([^"]+)"|', $match, $pieces);
233 $movie_vars = Array();
234 for (reset($pieces[1]); NULL !== ($k = key($pieces[1])); next($pieces[1])) {
235 $var_name = trim($pieces[1][$k]);
236 $var_value = trim($pieces[2][$k]);
237 $movie_vars[$var_name] = $var_value;
239 if (array_key_exists(
'video_url', $movie_vars) === TRUE) {
240 $movie_vars[
'video_url'] = $movie_vars[
'video_url'].
'&';
244 $movie_url_prefix =
'http://www.youtube.com/v/';
246 $add_suffix_vars = TRUE;
247 if (isset($movie_vars[
'video_url']) && !empty($movie_vars[
'video_url'])) {
248 if (preg_match(
'/youtu(\.?)be(.*)(v?)[\/|=](.+?)&/', $movie_vars[
'video_url'], $v_match)) {
249 if (isset($v_match[4]) && !empty($v_match[4])) {
251 $movie_url = $movie_url_prefix.$v_match[4];
254 $movie_url = $movie_vars[
'video_url'];
257 $movie_url = $movie_vars[
'video_url'];
261 if (isset($movie_vars[
'vid']) && !empty($movie_vars[
'vid'])) {
262 $movie_url = $movie_url_prefix.$movie_vars[
'vid'];
270 if (isset($movie_vars[
'width'])) {
271 $width =
'width="'.str_replace(
'px',
'',$movie_vars[
'width']).
'"';
274 if (empty($height)) {
275 if (isset($movie_vars[
'height'])) {
276 $height =
'height="'.str_replace(
'px',
'',$movie_vars[
'height']).
'"';
280 $movie_url_vars =
'&playerapiid=matrixytplayer';
281 foreach($movie_vars as $var_name => $var_value) {
284 if (!empty($var_value)) {
285 $colour = str_replace(
'#',
'', $var_value);
286 $colour = strtolower($colour);
287 $movie_url_vars .=
'&color1=0x'.$colour;
291 if (!empty($var_value)) {
292 $colour = str_replace(
'#',
'', $var_value);
293 $colour = strtolower($colour);
294 $movie_url_vars .=
'&color2=0x'.$colour;
298 if ($var_value ==
'1') {
299 $movie_url_vars .=
'&rel='.$var_value;
301 $movie_url_vars .=
'&rel=0';
305 if ($var_value ==
'1') {
306 $movie_url_vars .=
'&autoplay='.$var_value;
308 $movie_url_vars .=
'&autoplay=0';
312 if ($var_value ==
'1') {
313 $movie_url_vars .=
'&loop='.$var_value;
315 $movie_url_vars .=
'&loop=0';
319 if ($var_value ==
'1') {
320 $movie_url_vars .=
'&egm='.$var_value;
322 $movie_url_vars .=
'&egm=0';
326 if ($var_value ==
'1') {
327 $movie_url_vars .=
'&border='.$var_value;
329 $movie_url_vars .=
'&border=0';
333 if ($var_value ==
'1') {
334 $movie_url_vars .=
'&fs='.$var_value;
336 $movie_url_vars .=
'&fs=0';
340 if ($var_value ==
'1') {
341 $movie_url_vars .=
'&enablejsapi='.$var_value;
343 $movie_url_vars .=
'&enablejsapi=0';
348 $movie_url_vars = htmlentities($movie_url_vars, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
353 <sq_wysiwyg_embed_youtube <?php echo $match; ?>>
354 <script src=
"http://swfobject.googlecode.com/svn/tags/rc3/swfobject/src/swfobject.js" type=
"text/javascript"></script>
358 <?php echo $width; ?> <?php echo $height; ?>>
359 <param name=
"movie" value=
"<?php echo $movie_url.$movie_url_vars; ?>">
360 <param name=
"allowfullscreen" value=
"<?php echo ($movie_vars['full_screen']) ? 'true' : 'false';?>">
361 <embed type=
"application/x-shockwave-flash"
362 src=
"<?php echo $movie_url.$movie_url_vars; ?>"
363 name=
"matrixytplayer"
364 allowfullscreen=
"<?php echo ($movie_vars['full_screen']) ? 'true' : 'false'; ?>"
365 <?php echo $width; ?>
366 <?php echo $height; ?>
369 </sq_wysiwyg_embed_youtube>
371 $new_html = ob_get_contents();
374 $html = str_replace($old_html, $new_html, $html);
381 $html_tidy->new_inline_tag(
'sq_wysiwyg_embed_youtube');
398 $contents = preg_replace(
'|(<sq_wysiwyg_embed_youtube([^>]*)?>)(.*?)(</sq_wysiwyg_embed_youtube>)|si',
'<IMG src="'.$this->_img_url.
'" $2>', $contents);
399 $contents = preg_replace(
'|\s+|',
' ', $contents);