XOOPS  2.6.0
youtube.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
25 {
30  public function encode($textarea_id)
31  {
32  $code = "<img src='{$this->image_path}/youtube.gif' alt='" . XoopsLocale::YOUTUBE . "' onclick='xoopsCodeYoutube(\"{$textarea_id}\",\"" . htmlspecialchars(XoopsLocale::YOUTUBE_URL, ENT_QUOTES) . "\",\"" . htmlspecialchars(XoopsLocale::HEIGHT, ENT_QUOTES) . "\",\"" . htmlspecialchars(XoopsLocale::WIDTH, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;";
33  $javascript = <<<EOH
34  function xoopsCodeYoutube(id, enterFlashPhrase, enterFlashHeightPhrase, enterFlashWidthPhrase)
35  {
36  var selection = xoopsGetSelect(id);
37  if (selection.length > 0) {
38  var text = selection;
39  } else {
40  var text = prompt(enterFlashPhrase, "");
41  }
42  var domobj = xoopsGetElementById(id);
43  if ( text.length > 0 ) {
44  var text2 = prompt(enterFlashWidthPhrase, "425");
45  var text3 = prompt(enterFlashHeightPhrase, "350");
46  var result = "[youtube="+text2+","+text3+"]" + text + "[/youtube]";
47  xoopsInsertText(domobj, result);
48  }
49  domobj.focus();
50  }
51 EOH;
52 
53  return array($code, $javascript);
54  }
55 
56 static function myCallback($match) {
57  return self::decode( $match[4], $match[2], $match[3] );
58 }
59 
64  public function load(MyTextSanitizer &$ts)
65  {
66 // $ts->patterns[] = "/\[youtube=(['\"]?)([^\"']*),([^\"']*)\\1]([^\"]*)\[\/youtube\]/esU";
67 // $ts->replacements[] = __CLASS__ . "::decode( '\\4', '\\2', '\\3' )";
68 
69 //mb------------------------------
70  $ts->callbackPatterns[] = "/\[youtube=(['\"]?)([^\"']*),([^\"']*)\\1]([^\"]*)\[\/youtube\]/sU";
71  $ts->callbacks[] = __CLASS__ . "::myCallback";
72 //mb------------------------------
73 
74  }
75 
82  public static function decode($url, $width, $height)
83  {
84  if (!preg_match("/^http[s]?:\/\/(www\.)?youtube\.com\/watch\?v=(.*)/i", $url, $matches)) {
85  trigger_error("Not matched: {$url} {$width} {$height}", E_USER_WARNING);
86  return "";
87  }
88  $src = "http://www.youtube.com/v/" . $matches[2];
89  if (empty($width) || empty($height)) {
90  if (!$dimension = @getimagesize($src)) {
91  return "";
92  }
93  if (!empty($width)) {
94  $height = $dimension[1] * $width / $dimension[0];
95  } else {
96  if (!empty($height)) {
97  $width = $dimension[0] * $height / $dimension[1];
98  } else {
99  list($width, $height) = array($dimension[0], $dimension[1]);
100  }
101  }
102  }
103  $code = "<object width='{$width}' height='{$height}'><param name='movie' value='{$src}'></param>" . "<param name='wmode' value='transparent'></param>" . "<embed src='{$src}' type='application/x-shockwave-flash' wmode='transparent' width='425' height='350'></embed>" . "</object>";
104  return $code;
105  }
106 }
static myCallback($match)
Definition: youtube.php:56
const YOUTUBE_URL
Definition: en_US.php:1109
encode($textarea_id)
Definition: youtube.php:30
static decode($url, $width, $height)
Definition: youtube.php:82
$height
$url
Definition: register.php:72
$width
const HEIGHT
Definition: en_US.php:459
load(MyTextSanitizer &$ts)
Definition: youtube.php:64
$code
Definition: lostpass.php:48