XOOPS  2.6.0
soundcloud.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 
24 {
25  public function encode($textarea_id)
26  {
27  $config = parent::loadConfig(__DIR__);
28  $alttxt = htmlspecialchars(XoopsLocale::SOUNDCLOUD, ENT_QUOTES);
29  $prompt = htmlspecialchars(XoopsLocale::SOUNDCLOUD_URL, ENT_QUOTES);
30  $code = "<img src='{$this->image_path}/soundcloud.png' "
31  . " alt='{$alttxt}' title='{$alttxt}' "
32  . " onclick='xoopsCodeSoundCloud(\"{$textarea_id}\",\"{$prompt}\");' "
33  . " onmouseover='style.cursor=\"hand\"'/>&nbsp;";
34  $javascript = <<<EOH
35  function xoopsCodeSoundCloud(id, enterSoundCloud)
36  {
37  var selection = xoopsGetSelect(id);
38  if (selection.length > 0) {
39  var text = selection;
40  } else {
41  var text = prompt(enterSoundCloud, "");
42  }
43 
44  var domobj = xoopsGetElementById(id);
45  if (text.length > 0) {
46  xoopsInsertText(domobj, "[soundcloud]"+text+"[/soundcloud]");
47  }
48  domobj.focus();
49  }
50 EOH;
51 
52  return array($code, $javascript);
53  }
54 
55  public function load(&$ts)
56  {
57  $ts->callbackPatterns[] = "/\[soundcloud\](http[s]?:\/\/[^\"'<>]*)(.*)\[\/soundcloud\]/sU";
58  $ts->callbacks[] = __CLASS__ . "::myCallback";
59  }
60 
61  public static function myCallback($match)
62  {
63  $url = $match[1] . $match[2];
64  $config = parent::loadConfig(__DIR__);
65  if (!preg_match("/^http[s]?:\/\/(www\.)?soundcloud\.com\/(.*)/i", $url, $matches)) {
66  trigger_error("Not matched: {$url}", E_USER_WARNING);
67 
68  return "";
69  }
70 
71  $code = '<object height="81" width="100%"><param name="movie" '
72  . 'value="http://player.soundcloud.com/player.swf?url='.$url.'&amp;g=bb">'
73  . '</param><param name="allowscriptaccess" value="always"></param>'
74  . '<embed allowscriptaccess="always" height="81" '
75  . 'src="http://player.soundcloud.com/player.swf?url=' . $url
76  . '&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed></object>'
77  . '<a href="'.$url.'">'.$url.'</a>';
78 
79  return $code;
80  }
81 }
const SOUNDCLOUD
Definition: en_US.php:1011
const SOUNDCLOUD_URL
Definition: en_US.php:1012
encode($textarea_id)
Definition: soundcloud.php:25
$url
Definition: register.php:72
static myCallback($match)
Definition: soundcloud.php:61
$code
Definition: lostpass.php:48