SoundCloud Shortcode - Version 1.1.9

Version Description

  • 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
Download this release

Release Info

Developer jowagener
Plugin Icon wp plugin SoundCloud Shortcode
Version 1.1.9
Comparing to
See all releases

Version 1.1.9

Files changed (3) hide show
  1. readme.txt +57 -0
  2. screenshot-1.png +0 -0
  3. soundcloud-shortcode.php +85 -0
readme.txt ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === SoundCloud Shortcode ===
2
+ Contributors: jowagener
3
+ Donate link: http://soundcloud.com
4
+ Tags: soundcloud, flash, player, shortcode,
5
+ Requires at least: 2.5.0
6
+ Tested up to: 2.8.1
7
+ Stable tag: trunk
8
+
9
+ The SoundCloud Shortcode plugin allows you to integrate a player widget from SoundCloud into your Wordpress Blog by using a Wordpress shortcodes.
10
+
11
+ == Description ==
12
+
13
+ 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.
14
+ Use it like that in your blog post: `[soundcloud]http://soundcloud.com/LINK_TO_TRACK_SET_OR_GROUP[/soundcloud]`
15
+ It also supports these optional parameters: width, height and params.
16
+ The "params" parameter will pass the given options on to the player widget.
17
+ Our player accepts the following parameter options:
18
+
19
+ * auto_play = (true or false)
20
+ * show_comments = (true or false)
21
+ * color = (color hex code) will paint the play button, waveform and selections in this color
22
+ * theme_color = (color hex code) will set the background color
23
+
24
+ Examples:
25
+
26
+ `[soundcloud params="auto_play=true&show_comments=false"]http://soundcloud.com/forss/flickermood[/soundcloud]`
27
+ Embed a track player which starts playing automaticly and won't show any comments.
28
+
29
+ `[soundcloud params="color=33e040&theme_color=80e4a0"]http://soundcloud.com/forss/sets/live-4[/soundcloud]`
30
+ Embeds a set player with a green theme.
31
+
32
+ `[soundcloud height="150" width="250"]http://soundcloud.com/groups/experimental[/soundcloud]`
33
+ Embeds a group player with 150px height and 250px width.
34
+
35
+
36
+ When posting the standard soundcloud embed code, the plugin tries to replace it with a shortcode.
37
+ == Installation ==
38
+
39
+
40
+
41
+ == Frequently Asked Questions ==
42
+
43
+
44
+ == Screenshots ==
45
+
46
+ 1. This is how the player looks like.
47
+
48
+ == Changelog ==
49
+ = 1.1.9 =
50
+ * Fix to support resources from api.soundcloud.com
51
+ * Security enhancement. Only support players from player.soundcloud.com, player.sandbox-soundcloud.com and player.staging-soundcloud.com
52
+
53
+ = 1.1.8 =
54
+ Bugfix to use correct SoundCloud player host
55
+
56
+ = 1.0 =
57
+ * First version
screenshot-1.png ADDED
Binary file
soundcloud-shortcode.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: SoundCloud Shortcode
4
+ Plugin URI: http://www.soundcloud.com
5
+ 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 like that [soundcloud height="82" params="auto_play=true"]http....
6
+ Version: 1.1.9
7
+ Author: Johannes Wagener <johannes@soundcloud.com>
8
+ Author URI: http://johannes.wagener.cc
9
+ */
10
+
11
+ /*
12
+ SoundCloud Shortcode (Wordpress Plugin)
13
+ Copyright (C) 2009 Johannes Wagener
14
+
15
+ This program is free software: you can redistribute it and/or modify
16
+ it under the terms of the GNU General Public License as published by
17
+ the Free Software Foundation, either version 3 of the License, or
18
+ (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
27
+ */
28
+
29
+ add_filter( "pre_kses", "soundcloud_reverse_shortcode" );
30
+ function soundcloud_reverse_shortcode_preg_replace_callback( $a ){
31
+ $pattern = '/([a-zA-Z0-9\-_%=&]*)&?url=([^&]+)&?([a-zA-Z0-9\-_%&=]*)/';
32
+ preg_match( $pattern, str_replace( "&amp;", "&", $a[3] ), $params );
33
+ return( '[soundcloud width="' . esc_attr( $a[1] ) . '" height="' .
34
+ esc_attr( $a[2] ) . '" params="' . esc_attr( $params[1] . $params[3] )
35
+ . '" url="' . urldecode( $params[2] ) . '"]' );
36
+ }
37
+
38
+ function soundcloud_reverse_shortcode( $content ){
39
+ $pattern = '/<object.*width="([\d]+%?)".*height="([\d]+%?)".*src="http:\/\/.*soundcloud\.com\/player.swf\?(.*)".*<\/object>( <span[^>]*>.*<\/span>|)/U';
40
+ $pattern_ent = htmlspecialchars( $pattern, ENT_NOQUOTES );
41
+ if ( preg_match( $pattern_ent, $content ) )
42
+ return( preg_replace_callback( $pattern_ent,
43
+ 'soundcloud_reverse_shortcode_preg_replace_callback', $content ) );
44
+ else
45
+ return( preg_replace_callback( $pattern,
46
+ 'soundcloud_reverse_shortcode_preg_replace_callback', $content ) );
47
+ }
48
+
49
+ add_shortcode( "soundcloud", "soundcloud_shortcode" );
50
+ function soundcloud_shortcode( $atts,$url='' ) {
51
+ if ( empty( $url ) )
52
+ extract(shortcode_atts( array( 'url' => '', 'params' => '', 'height'
53
+ => '', 'width' => '100%' ), $atts ) );
54
+ else
55
+ extract(shortcode_atts( array( 'params' => '', 'height' => '',
56
+ 'width' => '100%' ), $atts ) );
57
+ $encoded_url = urlencode( $url );
58
+ if ( $url = parse_url( $url ) ){
59
+ $splitted_url = split( "/", $url['path'] );
60
+ $media_type = $splitted_url[count($splitted_url) - 2];
61
+
62
+ if ( $height == "" ){
63
+ if ( $media_type == "groups" || $media_type == "sets" ){
64
+ $height = "225";
65
+ } else {
66
+ $height = "81";
67
+ }
68
+ }
69
+ $player_params = "url=$encoded_url&g=1&$params";
70
+
71
+ preg_match('/(.+\.)?(((staging|sandbox)-)?soundcloud\.com)/', $url['host'], $matches);
72
+ $player_host = "player." . $matches[2];
73
+
74
+ return "<object height=\"" . esc_attr( $height ) . "\" width=\"" .
75
+ esc_attr( $width ) . "\"><param name=\"movie\" value=\"http://" .
76
+ esc_attr( $player_host ) . "/player.swf?" . esc_attr( $player_params )
77
+ . "\"></param><param name=\"allowscriptaccess\"
78
+ value=\"always\"></param><embed allowscriptaccess=\"always\"
79
+ height=\"" . esc_attr( $height ) . "\" src=\"http://" . esc_attr(
80
+ $player_host ) . "/player.swf?" . esc_attr( $player_params ) . "\"
81
+ type=\"application/x-shockwave-flash\" width=\"" . esc_attr( $width )
82
+ . "\"> </embed> </object>";
83
+ }
84
+ }
85
+ ?>