Created
December 8, 2010 11:54
-
-
Save sylvinus/733187 to your computer and use it in GitHub Desktop.
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
class Jamendo_ShortCodes { | |
/************************************************************* | |
* Shortcodes | |
*************************************************************/ | |
function _sh_getid($attrs) { | |
if (!empty($attrs[0])) { | |
return intval($attrs[0]); | |
} elseif (!empty($attrs["id"])) { | |
return intval($attrs["id"]); | |
} | |
return false; | |
} | |
function _sh_getwidgetcode($unit,$id) { | |
global $jamendo_bridge_plugin; | |
$code = file_get_contents("http://".$jamendo_bridge_plugin->jamendoDomain."/get2/none/".$unit."/playercode/?id=".$id); | |
//remove the "div align=center" | |
$code = preg_replace("/^\<div .*?\>/","",$code); | |
$code = preg_replace("/\<\/div\>$/","",$code); | |
return $code; | |
} | |
function sh_album($attrs) { | |
$id = $this->_sh_getid($attrs); | |
if (!$id) return ""; | |
return $this->_sh_getwidgetcode("album",$id); | |
} | |
function sh_playlist($attrs) { | |
$id = $this->_sh_getid($attrs); | |
if (!$id) return ""; | |
return $this->_sh_getwidgetcode("playlist",$id); | |
} | |
function sh_track($attrs) { | |
$id = $this->_sh_getid($attrs); | |
if (!$id) return ""; | |
return $this->_sh_getwidgetcode("track",$id); | |
} | |
//Register all sh_* functions as shortcodes | |
function hook() { | |
//todo: introspection code | |
$functions = array("sh_album","sh_playlist","sh_track"); | |
foreach ($functions as $f) { | |
if (substr($f,0,3)=="sh_") { | |
add_shortcode(substr($f,3),array($this,$f)); | |
} | |
} | |
add_filter( 'mce_buttons', array(&$this, 'mce_buttons')); | |
//add_filter( 'mce_buttons_2', array(&$this, 'mce_buttons')); | |
if (is_admin()) { | |
// Register editor button hooks | |
add_action( 'edit_form_advanced', array(&$this, 'AddQuicktagsAndFunctions'),9999 ); | |
add_action( 'edit_page_form', array(&$this, 'AddQuicktagsAndFunctions') ); | |
} | |
} | |
/** tinyMCE plugin code from Viper Video Tags plugin **/ | |
// Add the custom TinyMCE buttons | |
function mce_buttons( $buttons ) { | |
array_push( $buttons, '|' ); | |
array_push( $buttons, 'jamWidget' ); | |
return $buttons; | |
} | |
// WordPress' js_escape() won't allow <, >, or " -- instead it converts it to an HTML entity. This is a "fixed" function that's used when needed. | |
function js_escape($text) { | |
$safe_text = addslashes($text); | |
$safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text)); | |
$safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text)); | |
$safe_text = str_replace('\\\n', '\n', $safe_text); | |
return apply_filters('js_escape', $safe_text, $text); | |
} | |
// Add the old style buttons to the non-TinyMCE editor views and output all of the JS for the button function + dialog box | |
function AddQuicktagsAndFunctions() { | |
$types = array( | |
'jamwidget' => array( | |
__('Jamendo'), | |
__('Embed music from Jamendo'), | |
__('Please enter the URL at which the music can be found on Jamendo.'), | |
"http://www.jamendo.com/album/33</code><br/><code>http://www.jamendo.com/playlist/26</code><br><code>http://www.jamendo.com/track/241", | |
) | |
); | |
$buttonhtml = $datajs = ''; | |
foreach ( $types as $type => $strings ) { | |
// HTML for quicktag button | |
$buttonshtml .= '<input type="button" class="ed_button" onclick="VVQButtonClick(\'' . $type . '\')" title="' . $strings[1] . '" value="' . $strings[0] . '" />'; | |
// Create the data array | |
$datajs .= " VVQData['$type'] = {\n"; | |
$datajs .= ' title: "' . $this->js_escape( ucwords( $strings[1] ) ) . '",' . "\n"; | |
$datajs .= ' instructions: "' . $this->js_escape( $strings[2] ) . '",' . "\n"; | |
$datajs .= ' example: ' . json_encode($strings[3] ). ''; | |
/*if ( !empty($this->settings[$type]['width']) && !empty($this->settings[$type]['height']) ) { | |
$datajs .= ",\n width: " . $this->settings[$type]['width'] . ",\n"; | |
$datajs .= ' height: ' . $this->settings[$type]['height']; | |
}*/ | |
$datajs .= "\n };\n"; | |
} | |
?> | |
<script type="text/javascript"> | |
// <![CDATA[ | |
<?php echo $datajs; ?> | |
jQuery(document).ready(function(){ | |
// Add the buttons to the HTML view | |
jQuery("#ed_toolbar").append('<?php echo $this->js_escape( $buttonshtml ); ?>'); | |
}); | |
// ]]> | |
</script> | |
<?php | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment