XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
youtube.php
Go to the documentation of this file.
1 <?php
22 {
23  function encode($textarea_id)
24  {
25  $config = parent::loadConfig( dirname(__FILE__) );
26  $code = "<img src='{$this->image_path}/youtube.gif' alt='" . _XOOPS_FORM_ALTYOUTUBE . "' onclick='xoopsCodeYoutube(\"{$textarea_id}\",\"" . htmlspecialchars(_XOOPS_FORM_ENTERYOUTUBEURL, ENT_QUOTES) . "\",\"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERHEIGHT, ENT_QUOTES) . "\",\"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;";
27  $javascript = <<<EOH
28  function xoopsCodeYoutube(id, enterFlashPhrase, enterFlashHeightPhrase, enterFlashWidthPhrase)
29  {
30  var selection = xoopsGetSelect(id);
31  if (selection.length > 0) {
32  var text = selection;
33  } else {
34  var text = prompt(enterFlashPhrase, "");
35  }
36  var domobj = xoopsGetElementById(id);
37  if ( text.length > 0 ) {
38  var text2 = prompt(enterFlashWidthPhrase, "425");
39  var text3 = prompt(enterFlashHeightPhrase, "350");
40  var result = "[youtube="+text2+","+text3+"]" + text + "[/youtube]";
41  xoopsInsertText(domobj, result);
42  }
43  domobj.focus();
44  }
45 EOH;
46 
47  return array($code, $javascript);
48  }
49 
50  function load(&$ts)
51  {
52  $ts->patterns[] = "/\[youtube=(['\"]?)([^\"']*),([^\"']*)\\1]([^\"]*)\[\/youtube\]/esU";
53  $ts->replacements[] = __CLASS__ . "::decode( '\\4', '\\2', '\\3' )";
54  }
55 
56  function decode($url, $width, $height)
57  {
58  if (!preg_match("/^http:\/\/(www\.)?youtube\.com\/watch\?v=(.*)/i", $url, $matches)) {
59  trigger_error("Not matched: {$url} {$width} {$height}", E_USER_WARNING);
60  return "";
61  }
62  $src = "http://www.youtube.com/v/" . $matches[2];
63  if (empty($width) || empty($height)) {
64  if (!$dimension = @getimagesize($src) ) {
65  return "";
66  }
67  if (!empty($width)) {
68  $height = $dimension[1] * $width / $dimension[0];
69  } else if (!empty($height)) {
70  $width = $dimension[0] * $height / $dimension[1];
71  } else {
72  list($width, $height) = array($dimension[0], $dimension[1]);
73  }
74  }
75  $code = "<object width='{$width}' height='{$height}'><param name='movie' value='{$src}'></param>" .
76  "<param name='wmode' value='transparent'></param>" .
77  "<embed src='{$src}' type='application/x-shockwave-flash' wmode='transparent' width='425' height='350'></embed>" .
78  "</object>";
79  return $code;
80  }
81 }
82 ?>