Skip to content

Instantly share code, notes, and snippets.

@ihackcode
Last active January 4, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihackcode/d46633276fe128d1ffc0 to your computer and use it in GitHub Desktop.
Save ihackcode/d46633276fe128d1ffc0 to your computer and use it in GitHub Desktop.
File for XOOPS TextSanitizer for SoundCloud BBCode
<?php
//updated version @ https://github.com/XOOPS/XoopsCore/blob/master/htdocs/class/textsanitizer/soundcloud/soundcloud.php
class MytsSoundcloud extends MyTextSanitizerExtension
{
function encode($textarea_id)
{
$config = parent::loadConfig( dirname(__FILE__) );
$code = "<img src='{$this->image_path}/soundcloud.png' alt='SoundCloud' onclick='xoopsCodeSoundCloud(\"{$textarea_id}\",\"" . htmlspecialchars('Enter SoundCloud Profile URL', ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;";
$javascript = <<<EOH
function xoopsCodeSoundCloud(id, enterSoundCloud)
{
var selection = xoopsGetSelect(id);
if (selection.length > 0) {
var text = selection;
} else {
var text = prompt(enterSoundCloud, "");
}
var domobj = xoopsGetElementById(id);
xoopsInsertText(domobj, "[soundcloud]"+text+"[/soundcloud]");
domobj.focus();
}
EOH;
return array($code, $javascript);
}
function load(&$ts)
{
$ts->patterns[] = "/\[soundcloud\](http[s]?:\/\/[^\"'<>]*)(.*)\[\/soundcloud\]/esU";
$ts->replacements[] = __CLASS__ . "::decode('\\1\\2')";
}
function decode($url)
{
$config = parent::loadConfig(dirname(__FILE__));
if (!preg_match("/^http:\/\/(www\.)?soundcloud\.com\/(.*)/i", $url, $matches)) {
trigger_error("Not matched: {$url}", E_USER_WARNING);
return "";
}
$code = '<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url='.$url.'&amp;g=bb">';
$code .= '</param><param name="allowscriptaccess" value="always"></param>';
$code .= '<embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url='.$url.'&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed></object>';
$code .= '<a href="'.$url.'">'.$url.'</a>';
return $code;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment