diff --git a/wp-content/plugins/soundcloud-shortcode/phpunit.xml b/wp-content/plugins/soundcloud-shortcode/phpunit.xml new file mode 100644 index 0000000000000000000000000000000000000000..b966a93f11b16e11caf11b23e5aad89e933d4486 --- /dev/null +++ b/wp-content/plugins/soundcloud-shortcode/phpunit.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit backupGlobals="false" + backupStaticAttributes="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false" + syntaxCheck="false" +> + <testsuites> + <testsuite name='Name your suite'> + <directory suffix='.php'>./tests</directory> + </testsuite> + </testsuites> +</phpunit> diff --git a/wp-content/plugins/soundcloud-shortcode/readme.txt b/wp-content/plugins/soundcloud-shortcode/readme.txt index de1196bf710b69e7f699c7e900f522454198af6a..a30ee8b32d6fe3460c202f003570b9e44a2355d8 100644 --- a/wp-content/plugins/soundcloud-shortcode/readme.txt +++ b/wp-content/plugins/soundcloud-shortcode/readme.txt @@ -1,16 +1,15 @@ === SoundCloud Shortcode === -Contributors: jowagener, theophani, por -Donate link: http://soundcloud.com +Contributors: jowagener, theophani, por_ Tags: soundcloud, html5, flash, player, shortcode, -Requires at least: 2.5.0 -Tested up to: 3.3.1 +Requires at least: 3.1.0 +Tested up to: 3.4.0 Stable tag: trunk The SoundCloud Shortcode plugin allows you to integrate a player widget from SoundCloud into your Wordpress Blog by using a Wordpress shortcodes. == Description == -The SoundCloud Shortcode plugin allows you to easily integrate a player widget for a track, set or group from SoundCloud into your Wordpress Blog by using a Wordpress shortcode. +The SoundCloud Shortcode plugin allows you to easily integrate a player widget for a track, set or group from SoundCloud into your Wordpress Blog by using a Wordpress shortcode. Use it like that in your blog post: `[soundcloud]http://soundcloud.com/LINK_TO_TRACK_SET_OR_GROUP[/soundcloud]` It also supports these optional parameters: width, height and params. The "params" parameter will pass the given options on to the player widget. @@ -24,23 +23,19 @@ Our player accepts the following parameter options: Examples: `[soundcloud params="auto_play=true&show_comments=false"]http://soundcloud.com/forss/flickermood[/soundcloud]` -Embed a track player which starts playing automaticly and won't show any comments. +Embed a track player which starts playing automatically and won't show any comments. -`[soundcloud params="color=33e040&theme_color=80e4a0"]http://soundcloud.com/forss/sets/live-4[/soundcloud]` +`[soundcloud params="color=33e040&theme_color=80e4a0"]https://soundcloud.com/forss/sets/soulhack[/soundcloud]` Embeds a set player with a green theme. -`[soundcloud width="250"]http://soundcloud.com/groups/experimental[/soundcloud]` -Embeds a group player with 250px width. +`[soundcloud width="250"]http://soundcloud.com/groups/experimental[/soundcloud]` +Embeds a group player with 250px width. When posting the standard SoundCloud embed code, the plugin tries to use the new HTML5 player, but falls back to the Flash Player for legacy URL formats. -== Installation == - - +== Installation == == Frequently Asked Questions == - - == Screenshots == 1. This is how the Flash player looks, which is still available as an option. It is also the fallback for legacy URL formats. @@ -48,16 +43,26 @@ When posting the standard SoundCloud embed code, the plugin tries to use the new 2. This is how the default player looks, which uses HTML5. == Changelog == += 2.3 = +* Don’t use oEmbed anymore because of various bugs. +* Standard http://soundcloud.com/<user> permalinks will always return the flash widget. Use the widget generator on the website to get an API url. + += 2.2 = +* Improved default options support + += 2.1 = +* Integrate oEmbed + = 2.0 = * HTML5 Player added as the default player, with Flash as an option and fallback for legacy URL formats. = 1.2.1 = * Removed flash fallback HTML -= 1.2 = += 1.2 = * Added options page to allow blog-wide global default settings. -= 1.1.9 = += 1.1.9 = * Fix to support resources from api.soundcloud.com * Security enhancement. Only support players from player.soundcloud.com, player.sandbox-soundcloud.com and player.staging-soundcloud.com @@ -65,4 +70,4 @@ When posting the standard SoundCloud embed code, the plugin tries to use the new Bugfix to use correct SoundCloud player host = 1.0 = -* First version \ No newline at end of file +* First version diff --git a/wp-content/plugins/soundcloud-shortcode/screenshot-1.png b/wp-content/plugins/soundcloud-shortcode/screenshot-1.png index 9763f083d654bc558334edd25e5d4a6ec5d0ca4c..45f89320e113e76f53621bc3398626406ecbcc55 100644 Binary files a/wp-content/plugins/soundcloud-shortcode/screenshot-1.png and b/wp-content/plugins/soundcloud-shortcode/screenshot-1.png differ diff --git a/wp-content/plugins/soundcloud-shortcode/screenshot-2.png b/wp-content/plugins/soundcloud-shortcode/screenshot-2.png new file mode 100644 index 0000000000000000000000000000000000000000..9763f083d654bc558334edd25e5d4a6ec5d0ca4c Binary files /dev/null and b/wp-content/plugins/soundcloud-shortcode/screenshot-2.png differ diff --git a/wp-content/plugins/soundcloud-shortcode/soundcloud-shortcode.php b/wp-content/plugins/soundcloud-shortcode/soundcloud-shortcode.php index 0dc2b57e677860c9e9290ec3075fbaf0ce8daa5f..533ef558a388aa02dab064f296472af0584ca4ff 100644 --- a/wp-content/plugins/soundcloud-shortcode/soundcloud-shortcode.php +++ b/wp-content/plugins/soundcloud-shortcode/soundcloud-shortcode.php @@ -1,230 +1,243 @@ <?php /* Plugin Name: SoundCloud Shortcode -Plugin URI: http://www.soundcloud.com -Description: SoundCloud Shortcode. Usage in your posts: [soundcloud]http://soundcloud.com/TRACK_PERMALINK[/soundcloud] . Works also with set or group instead of track. You can provide optional parameters height/width/params as follows [soundcloud height="166" params="auto_play=true"]http.... -Version: 2.0 -Author: Johannes Wagener <johannes@soundcloud.com> -Author URI: http://johannes.wagener.cc +Plugin URI: http://wordpress.org/extend/plugins/soundcloud-shortcode/ +Description: Converts SoundCloud WordPress shortcodes to a SoundCloud widget. Example: [soundcloud]http://soundcloud.com/forss/flickermood[/soundcloud] +Version: 2.3 +Author: SoundCloud Inc. +Author URI: http://soundcloud.com +License: GPLv2 + +Original version: Johannes Wagener <johannes@soundcloud.com> +Options support: Tiffany Conroy <tiffany@soundcloud.com> +HTML5 & oEmbed support: Tim Bormans <tim@soundcloud.com> */ -/* -SoundCloud Shortcode (Wordpress Plugin) -Copyright (C) 2009 Johannes Wagener -Options support added by Tiffany Conroy <tif@tif.ca> - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ -add_shortcode( "soundcloud", "soundcloud_shortcode" ); - -function soundcloud_shortcode($attributes, $content=null) { - return SoundcloudShortcode::parse($attributes, $content); -} +/* Register oEmbed provider + -------------------------------------------------------------------------- */ -class SoundcloudShortcode { +wp_oembed_add_provider('#https?://(?:api\.)?soundcloud\.com/.*#i', 'http://soundcloud.com/oembed', true); - const IFRAME_HEIGHT = '166'; - const IFRAME_TRACKLIST_HEIGHT = '450'; - const IFRAME_WIDTH = '100%'; - const FLASH_HEIGHT = '81'; - const FLASH_TRACKLIST_HEIGHT = '255'; - const FLASH_WIDTH = '100%'; +/* Register SoundCloud shortcode + -------------------------------------------------------------------------- */ - // set to true when we deprecate the flash player - const DEFAULT_TO_IFRAME = false; +add_shortcode("soundcloud", "soundcloud_shortcode"); - public function parse($attributes, $content=null) { - extract(shortcode_atts(array( - 'url' => $content, - 'iframe' => self::getDefaultIframePreference(), - 'params' => self::getDefaultQuery(), - 'height' => '', - 'width' => '' - ), $attributes)); +/** + * SoundCloud shortcode handler + * @param {string|array} $atts The attributes passed to the shortcode like [soundcloud attr1="value" /]. + * Is an empty string when no arguments are given. + * @param {string} $content The content between non-self closing [soundcloud]…[/soundcloud] tags. + * @return {string} Widget embed code HTML + */ +function soundcloud_shortcode($atts, $content = null) { - $iframe = self::booleanize($iframe); + // Custom shortcode options + $shortcode_options = array_merge(array('url' => trim($content)), is_array($atts) ? $atts : array()); - // The HTML5 widget doesn't support http://soundcloud.com/<username> - // style urls yet. So we force the old Flash widget for now. - if (self::isLegacyURL($url)) { - $iframe = false; - } - - $type = self::getType($url); - $width = self::getWidth($width, $iframe, $type); - $height = self::getHeight($height, $iframe, $type); - - return self::getHTML($url, $iframe, $params, $width, $height); + // Turn shortcode option "param" (param=value¶m2=value) into array + $shortcode_params = array(); + if (isset($shortcode_options['params'])) { + parse_str(html_entity_decode($shortcode_options['params']), $shortcode_params); } - - public function getDefaultQuery() { - $options = array( - 'auto_play', - 'show_comments', - 'color', - 'theme_color' - ); - $params = array(); - foreach ($options as &$option) { - $value = get_option('soundcloud_' . $option, ''); - if (!empty($value)) { - $params[$option] = $value; - } - } - return http_build_query($params); + $shortcode_options['params'] = $shortcode_params; + + // User preference options + $plugin_options = array_filter(array( + 'iframe' => soundcloud_get_option('player_iframe', true), + 'width' => soundcloud_get_option('player_width'), + 'height' => soundcloud_url_has_tracklist($shortcode_options['url']) ? soundcloud_get_option('player_height_multi') : soundcloud_get_option('player_height'), + 'params' => array_filter(array( + 'auto_play' => soundcloud_get_option('auto_play'), + 'show_comments' => soundcloud_get_option('show_comments'), + 'color' => soundcloud_get_option('color'), + 'theme_color' => soundcloud_get_option('theme_color'), + )), + )); + // Needs to be an array + if (!isset($plugin_options['params'])) { $plugin_options['params'] = array(); } + + // plugin options < shortcode options + $options = array_merge( + $plugin_options, + $shortcode_options + ); + + // plugin params < shortcode params + $options['params'] = array_merge( + $plugin_options['params'], + $shortcode_options['params'] + ); + + // The "url" option is required + if (!isset($options['url'])) { + return ''; + } else { + $options['url'] = trim($options['url']); } - public function getDefaultIframePreference() { - $pref = get_option('soundcloud_player_iframe'); - return ($pref === '') ? DEFAULT_TO_IFRAME : self::booleanize($pref); + // Both "width" and "height" need to be integers + if (isset($options['width']) && !preg_match('/^\d+$/', $options['width'])) { + // set to 0 so oEmbed will use the default 100% and WordPress themes will leave it alone + $options['width'] = 0; } - - private function booleanize($value) { - if ($value && strtolower($value) !== "false") { - return true; - } else { - return false; - } + if (isset($options['height']) && !preg_match('/^\d+$/', $options['height'])) { unset($options['height']); } + + // The "iframe" option must be true to load the iframe widget + $iframe = soundcloud_booleanize($options['iframe']) + // Default to flash widget for permalink urls (e.g. http://soundcloud.com/{username}) + // because HTML5 widget doesn’t support those yet + ? preg_match('/api.soundcloud.com/i', $options['url']) + : false; + + // Return html embed code + if ($iframe) { + return soundcloud_iframe_widget($options); + } else { + return soundcloud_flash_widget($options); } - private function isLegacyURL($url) { - return !preg_match("/api.soundcloud.com/i", $url); - } +} - private function getWidth($width, $iframe, $type) { - if (empty($width)) { - $default = ($iframe) ? self::IFRAME_WIDTH : self::FLASH_WIDTH; - $width = get_option('soundcloud_player_width'); - $width = $width === '' ? $default : $width; - } - return $width; - } +/** + * Plugin options getter + * @param {string|array} $option Option name + * @param {mixed} $default Default value + * @return {mixed} Option value + */ +function soundcloud_get_option($option, $default = false) { + $value = get_option('soundcloud_' . $option); + return $value === '' ? $default : $value; +} - private function getHeight($height, $iframe, $type) { - switch ($type) { - case 'groups': - case 'sets': - case 'playlists': - $default = ($iframe) ? self::IFRAME_TRACKLIST_HEIGHT : self::FLASH_TRACKLIST_HEIGHT; - $height = (empty($height)) ? get_option('soundcloud_player_height_multi') : $height; - $height = (empty($height)) ? $default : $height; - if ($iframe) { - $height = self::fixHeight($height, $default); - } - break; - default: - $default = ($iframe) ? self::IFRAME_HEIGHT : self::FLASH_HEIGHT; - $height = (empty($height)) ? get_option('soundcloud_player_height') : $height; - $height = (empty($height)) ? $default : $height; - if ($iframe) { - $height = self::fixHeight($height, $default); - } - // sounds can only be default height - //$height = ($iframe) ? self::IFRAME_HEIGHT : self::FLASH_HEIGHT; - break; - } - return $height; - } +/** + * Booleanize a value + * @param {boolean|string} $value + * @return {boolean} + */ +function soundcloud_booleanize($value) { + return is_bool($value) ? $value : $value === 'true' ? true : false; +} - private function fixHeight($height, $min_height) { - if (!preg_match("/[0-9]+%/", $height) && intval($height) < $min_height) { - $height = $min_height; - } - return $height; - } +/** + * Decide if a url has a tracklist + * @param {string} $url + * @return {boolean} + */ +function soundcloud_url_has_tracklist($url) { + return preg_match('/^(.+?)\/(sets|groups|playlists)\/(.+?)$/', $url); +} - private function getType($url) { - if (empty($url)) { - return false; - } - if ($url = parse_url($url)) { - $splitted_url = split( "/", $url['path'] ); - $media_type = $splitted_url[count($splitted_url) - 2]; - return $media_type; - } - } +/** + * Parameterize url + * @param {array} $match Matched regex + * @return {string} Parameterized url + */ +function soundcloud_oembed_params_callback($match) { + global $soundcloud_oembed_params; + + // Convert URL to array + $url = parse_url(urldecode($match[1])); + // Convert URL query to array + parse_str($url['query'], $query_array); + // Build new query string + $query = http_build_query(array_merge($query_array, $soundcloud_oembed_params)); + + return 'src="' . $url['scheme'] . '://' . $url['host'] . $url['path'] . '?' . $query; +} - private function getHTML($url, $iframe, $params, $width, $height) { - - $encoded_url = urlencode($url); - $parsed_url = parse_url($url); - - if ($iframe) { - $player_host = 'w.soundcloud.com'; - $player_params = 'url=' . $encoded_url . '&' . $params; - $player_src = 'http://' . $player_host . '/player/?' . $player_params; - } else { - $player_host = preg_replace('/(.+\.)?(((staging|sandbox)-)?soundcloud\.com)/', 'player.$2', $parsed_url['host']); - $player_params = 'url=' . $encoded_url . '&g=1&' . $params; - $player_src = 'http://' . $player_host . '/player.swf?' . $player_params; - } - - $width = esc_attr($width); - $height = esc_attr($height); - $player_src = esc_attr($player_src); - - if ($iframe) { - $html = '<iframe width="' . $width . '" height="' . $height . '" scrolling="no" frameborder="no" src="' . $player_src . '"></iframe>'; - } else { - $html = '<object height="' . $height . '" width="' . $width . '"><param name="movie" value="' . $player_src . '"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="' . $height . '" src="' . $player_src . '" type="application/x-shockwave-flash" width="' . $width . '"></embed></object>'; - } - return $html; - } +/** + * Iframe widget embed code + * @param {array} $options Parameters + * @return {string} Iframe embed code + */ +function soundcloud_iframe_widget($options) { + + // Merge in "url" value + $options['params'] = array_merge(array( + 'url' => $options['url'] + ), $options['params']); + + // Build URL + $url = 'http://w.soundcloud.com/player?' . http_build_query($options['params']); + // Set default width if not defined + $width = isset($options['width']) && $options['width'] !== 0 ? $options['width'] : '100%'; + // Set default height if not defined + $height = isset($options['height']) && $options['height'] !== 0 ? $options['height'] : (soundcloud_url_has_tracklist($options['url']) ? '450' : '166'); + + return sprintf('<iframe width="%s" height="%s" scrolling="no" frameborder="no" src="%s"></iframe>', $width, $height, $url); +} +/** + * Legacy Flash widget embed code + * @param {array} $options Parameters + * @return {string} Flash embed code + */ +function soundcloud_flash_widget($options) { + + // Merge in "url" value + $options['params'] = array_merge(array( + 'url' => $options['url'] + ), $options['params']); + + // Build URL + $url = 'http://player.soundcloud.com/player.swf?' . http_build_query($options['params']); + // Set default width if not defined + $width = isset($options['width']) && $options['width'] !== 0 ? $options['width'] : '100%'; + // Set default height if not defined + $height = isset($options['height']) && $options['height'] !== 0 ? $options['height'] : (soundcloud_url_has_tracklist($options['url']) ? '255' : '81'); + + return preg_replace('/\s\s+/', "", sprintf('<object width="%s" height="%s"> + <param name="movie" value="%s"></param> + <param name="allowscriptaccess" value="always"></param> + <embed width="%s" height="%s" src="%s" allowscriptaccess="always" type="application/x-shockwave-flash"></embed> + </object>', $width, $height, $url, $width, $height, $url)); } -// Add settings link on plugin page -add_filter("plugin_action_links_".plugin_basename(__FILE__), 'soundcloud_settings_link' ); + + +/* Settings + -------------------------------------------------------------------------- */ + +/* Add settings link on plugin page */ +add_filter("plugin_action_links_" . plugin_basename(__FILE__), 'soundcloud_settings_link'); + function soundcloud_settings_link($links) { $settings_link = '<a href="options-general.php?page=soundcloud-shortcode">Settings</a>'; array_unshift($links, $settings_link); return $links; } -// Add admin menu +/* Add admin menu */ add_action('admin_menu', 'soundcloud_shortcode_options_menu'); function soundcloud_shortcode_options_menu() { add_options_page('SoundCloud Options', 'SoundCloud', 'manage_options', 'soundcloud-shortcode', 'soundcloud_shortcode_options'); - add_action( 'admin_init', 'register_soundcloud_settings' ); + add_action('admin_init', 'register_soundcloud_settings'); } function register_soundcloud_settings() { - // register our settings - register_setting( 'soundcloud-settings', 'soundcloud_player_height' ); - register_setting( 'soundcloud-settings', 'soundcloud_player_height_multi' ); - register_setting( 'soundcloud-settings', 'soundcloud_player_width ' ); - register_setting( 'soundcloud-settings', 'soundcloud_player_iframe' ); - register_setting( 'soundcloud-settings', 'soundcloud_auto_play' ); - register_setting( 'soundcloud-settings', 'soundcloud_show_comments ' ); - register_setting( 'soundcloud-settings', 'soundcloud_color' ); - register_setting( 'soundcloud-settings', 'soundcloud_theme_color' ); + register_setting('soundcloud-settings', 'soundcloud_player_height'); + register_setting('soundcloud-settings', 'soundcloud_player_height_multi'); + register_setting('soundcloud-settings', 'soundcloud_player_width '); + register_setting('soundcloud-settings', 'soundcloud_player_iframe'); + register_setting('soundcloud-settings', 'soundcloud_auto_play'); + register_setting('soundcloud-settings', 'soundcloud_show_comments'); + register_setting('soundcloud-settings', 'soundcloud_color'); + register_setting('soundcloud-settings', 'soundcloud_theme_color'); } - function soundcloud_shortcode_options() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } - ?> <div class="wrap"> <h2>SoundCloud Shortcode Default Settings</h2> <p>These settings will become the new defaults used by the SoundCloud Shortcode throughout your blog.</p> - <p>You can always override these settings on a per-shortcode basis. Setting the 'params' attribute in a shortcode overrides all these defaults combined.</p> + <p>You can always override these settings on a per-shortcode basis. Setting the 'params' attribute in a shortcode overrides these defaults individually.</p> <form method="post" action="options.php"> <?php settings_fields( 'soundcloud-settings' ); ?> @@ -233,8 +246,10 @@ function soundcloud_shortcode_options() { <tr valign="top"> <th scope="row">Widget Type</th> <td> - <label for="player_iframe_true" style="margin-right: 1em;"><input type="radio" id="player_iframe_true" name="soundcloud_player_iframe" value="true" <?php if (SoundcloudShortcode::getDefaultIframePreference() == true) echo 'checked'; ?> />HTML5</label> - <label for="player_iframe_false" style="margin-right: 1em;"><input type="radio" id="player_iframe_false" name="soundcloud_player_iframe" value="false" <?php if (SoundcloudShortcode::getDefaultIframePreference() == false) echo 'checked'; ?> />Flash</label> + <input type="radio" id="player_iframe_true" name="soundcloud_player_iframe" value="true" <?php if (strtolower(get_option('soundcloud_player_iframe')) === 'true') echo 'checked'; ?> /> + <label for="player_iframe_true" style="margin-right: 1em;">HTML5</label> + <input type="radio" id="player_iframe_false" name="soundcloud_player_iframe" value="false" <?php if (strtolower(get_option('soundcloud_player_iframe')) === 'false') echo 'checked'; ?> /> + <label for="player_iframe_false" style="margin-right: 1em;">Flash</label> </td> </tr> @@ -242,7 +257,7 @@ function soundcloud_shortcode_options() { <th scope="row">Player Height for Tracks</th> <td> <input type="text" name="soundcloud_player_height" value="<?php echo get_option('soundcloud_player_height'); ?>" /> (no unit, or %)<br /> - Leave blank to use the default, 81 (pixels). + Leave blank to use the default. </td> </tr> @@ -250,7 +265,7 @@ function soundcloud_shortcode_options() { <th scope="row">Player Height for Groups/Sets</th> <td> <input type="text" name="soundcloud_player_height_multi" value="<?php echo get_option('soundcloud_player_height_multi'); ?>" /> (no unit, or %)<br /> - Leave blank to use the default, 225 (pixels). + Leave blank to use the default. </td> </tr> @@ -258,32 +273,43 @@ function soundcloud_shortcode_options() { <th scope="row">Player Width</th> <td> <input type="text" name="soundcloud_player_width" value="<?php echo get_option('soundcloud_player_width'); ?>" /> (no unit, or %)<br /> - Leave blank to use the default, 100%. + Leave blank to use the default. </td> </tr> <tr valign="top"> <th scope="row">Current Default 'params'</th> <td> - <?php echo SoundcloudShortcode::getDefaultQuery(); ?> + <?php echo http_build_query(array_filter(array( + 'auto_play' => get_option('soundcloud_auto_play'), + 'show_comments' => get_option('soundcloud_show_comments'), + 'color' => get_option('soundcloud_color'), + 'theme_color' => get_option('soundcloud_theme_color'), + ))) ?> </td> </tr> <tr valign="top"> <th scope="row">Auto Play</th> <td> - <label for="auto_play_none" style="margin-right: 1em;"><input type="radio" id="auto_play_none" name="soundcloud_auto_play" value="" <?php if (get_option('soundcloud_auto_play') == '') echo 'checked'; ?> />Default</label> - <label for="auto_play_true" style="margin-right: 1em;"><input type="radio" id="auto_play_true" name="soundcloud_auto_play" value="true" <?php if (get_option('soundcloud_auto_play') == 'true') echo 'checked'; ?> />True</label> - <label for="auto_play_false" style="margin-right: 1em;"><input type="radio" id="auto_play_false" name="soundcloud_auto_play" value="false" <?php if (get_option('soundcloud_auto_play') == 'false') echo 'checked'; ?> />False</label> + <input type="radio" id="auto_play_none" name="soundcloud_auto_play" value=""<?php if (get_option('soundcloud_auto_play') == '') echo 'checked'; ?> /> + <label for="auto_play_none" style="margin-right: 1em;">Default</label> + <input type="radio" id="auto_play_true" name="soundcloud_auto_play" value="true"<?php if (get_option('soundcloud_auto_play') == 'true') echo 'checked'; ?> /> + <label for="auto_play_true" style="margin-right: 1em;">True</label> + <input type="radio" id="auto_play_false" name="soundcloud_auto_play" value="false" <?php if (get_option('soundcloud_auto_play') == 'false') echo 'checked'; ?> /> + <label for="auto_play_false" style="margin-right: 1em;">False</label> </td> </tr> <tr valign="top"> <th scope="row">Show Comments</th> <td> - <label for="show_comments_none" style="margin-right: 1em;"><input type="radio" id="show_comments_none" name="soundcloud_show_comments" value="" <?php if (get_option('soundcloud_show_comments') == '') echo 'checked'; ?> />Default</label> - <label for="show_comments_true" style="margin-right: 1em;"><input type="radio" id="show_comments_true" name="soundcloud_show_comments" value="true" <?php if (get_option('soundcloud_show_comments') == 'true') echo 'checked'; ?> />True</label> - <label for="show_comments_false" style="margin-right: 1em;"><input type="radio" id="show_comments_false" name="soundcloud_show_comments" value="false" <?php if (get_option('soundcloud_show_comments') == 'false') echo 'checked'; ?> />False</label> + <input type="radio" id="show_comments_none" name="soundcloud_show_comments" value=""<?php if (get_option('soundcloud_show_comments') == '') echo 'checked'; ?> /> + <label for="show_comments_none" style="margin-right: 1em;">Default</label> + <input type="radio" id="show_comments_true" name="soundcloud_show_comments" value="true"<?php if (get_option('soundcloud_show_comments') == 'true') echo 'checked'; ?> /> + <label for="show_comments_true" style="margin-right: 1em;">True</label> + <input type="radio" id="show_comments_false" name="soundcloud_show_comments" value="false" <?php if (get_option('soundcloud_show_comments') == 'false') echo 'checked'; ?> /> + <label for="show_comments_false" style="margin-right: 1em;">False</label> </td> </tr> @@ -313,4 +339,4 @@ function soundcloud_shortcode_options() { </div> <?php } -?> \ No newline at end of file +?> diff --git a/wp-content/plugins/soundcloud-shortcode/tests/soundcloud-shortcode-test.php b/wp-content/plugins/soundcloud-shortcode/tests/soundcloud-shortcode-test.php new file mode 100644 index 0000000000000000000000000000000000000000..655627e693f11591568c9f1df4153cbf04d4f7ec --- /dev/null +++ b/wp-content/plugins/soundcloud-shortcode/tests/soundcloud-shortcode-test.php @@ -0,0 +1,179 @@ +<?php + +/** + * Mocks + */ + +function wp_oembed_add_provider() { return; } +function add_shortcode() { return; } +function add_filter() { return; } +function plugin_basename() { return; } +function add_action() { return; } +function get_option($name) { + switch ($name) { + case 'soundcloud_player_iframe': + return ''; + case 'soundcloud_player_width': + return '100%'; + case 'soundcloud_player_height': + return '100%'; + case 'soundcloud_auto_play': + case 'soundcloud_show_comments': + case 'soundcloud_theme_color': + default: + return ''; + } + +} + + +require_once('./soundcloud-shortcode.php'); + +class SC_Widget_Test extends PHPUnit_Framework_TestCase { + + /** + * Basic soundcloud_shortcode() tests + */ + public function testShortcode() { + + $expected = '<iframe width="500" height="200" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></iframe>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'iframe' => true, + 'width' => 500, + 'height' => 200 + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Simple HTML5 widget'); + + $expected = '<object width="500" height="200"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fforss%2Fflickermood"></param><param name="allowscriptaccess" value="always"></param><embed width="500" height="200" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fforss%2Fflickermood" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://soundcloud.com/forss/flickermood', + 'iframe' => false, + 'width' => 500, + 'height' => 200 + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Simple Flash widget'); + + $expected = '<iframe width="500" height="200" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054&color=ff0000"></iframe>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'iframe' => true, + 'width' => 500, + 'height' => 200, + 'params' => 'color=ff0000' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'HTML5 Widget with extra parameters'); + + $expected = '<object width="300" height="300"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F45036121&auto_play=false&player_type=artwork&color=00ff3b"></param><param name="allowscriptaccess" value="always"></param><embed width="300" height="300" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F45036121&auto_play=false&player_type=artwork&color=00ff3b" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/45036121', + 'iframe' => false, + 'width' => 300, + 'height' => 300, + 'params' => 'auto_play=false&player_type=artwork&color=00ff3b' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Flash Widget with extra parameters'); + + $expected = '<object width="300" height="300"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F41770793&auto_play=false&player_type=artwork&color=ff7700"></param><param name="allowscriptaccess" value="always"></param><embed width="300" height="300" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F41770793&auto_play=false&player_type=artwork&color=ff7700" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/41770793', + 'iframe' => 'false', + 'params' => 'auto_play=false&player_type=artwork&color=ff7700', + 'width' => '300', + 'height' => '300', + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Classic Flash artwork player'); + } + + /** + * Default values tests + */ + public function testShortcodeDefaults() { + + $expected = '<iframe width="500" height="200" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></iframe>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'width' => 500, + 'height' => 200 + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Check if HTML5 widget is the default'); + + $expected = '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></iframe>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Default height and width for HTML5 widget'); + + $expected = '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1815863"></iframe>'; + $params = array( + 'url' => 'https://api.soundcloud.com/playlists/1815863' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Default height and width for HTML5 playlist widget'); + + $expected = '<object width="100%" height="81"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></param><param name="allowscriptaccess" value="always"></param><embed width="100%" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'iframe' => false + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Default height and width for Flash widget'); + + $expected = '<object width="100%" height="255"><param name="movie" value="http://player.soundcloud.com/player.swf?url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1815863"></param><param name="allowscriptaccess" value="always"></param><embed width="100%" height="255" src="http://player.soundcloud.com/player.swf?url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1815863" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'https://api.soundcloud.com/playlists/1815863', + 'iframe' => false + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Default height and width for Flash playlist widget'); + + $expected = '<object width="100%" height="81"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fforss%2Fflickermood"></param><param name="allowscriptaccess" value="always"></param><embed width="100%" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fforss%2Fflickermood" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://soundcloud.com/forss/flickermood', + 'iframe' => true + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Override HTML5 widget default with non-API urls (it doesn’t support those yet)'); + } + + /** + * Bad values tests + */ + public function testShortcodeBadValues() { + + $expected = '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></iframe>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'width' => '', + 'height' => 'onebillionpixels!' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Check bad input'); + + $expected = '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></iframe>'; + $params = array( + 'url' => ' http://api.soundcloud.com/tracks/38987054', + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Trim whitespace'); + + $expected = '<object width="100%" height="81"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fvincewatson%2Fvince-watson-live-subclub"></param><param name="allowscriptaccess" value="always"></param><embed width="100%" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fvincewatson%2Fvince-watson-live-subclub" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://soundcloud.com/vincewatson/vince-watson-live-subclub', + 'iframe' => 'true' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Fall back on Flash widget for permalinks'); + + $expected = '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></iframe>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'iframe' => 'true' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Check iframe true as string'); + + $expected = '<object width="100%" height="81"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054"></param><param name="allowscriptaccess" value="always"></param><embed width="100%" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F38987054" allowscriptaccess="always" type="application/x-shockwave-flash"></embed></object>'; + $params = array( + 'url' => 'http://api.soundcloud.com/tracks/38987054', + 'iframe' => 'false' + ); + $this->assertEquals($expected, soundcloud_shortcode($params), 'Check iframe false as string'); + + } + +} + +?>