Last active
January 4, 2016 21:59
-
-
Save ihackcode/d46633276fe128d1ffc0 to your computer and use it in GitHub Desktop.
File for XOOPS TextSanitizer for SoundCloud BBCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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\"'/> "; | |
$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.'&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.'&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