Archived
Spotify embed
This commit is contained in:
1 parent
13eb63c8b2
commit
1090921648
2 files changed
+265
No files matched your search
@@ -0,0 +1,144 @@
|
||||
=== Spotify Embed ===
|
||||
Contributors: ocean90
|
||||
Tags: Spotify, WP Embed, Embed, Music, Spotfiy Play Button
|
||||
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VR8YU922B7K46
|
||||
Requires at least: 2.9
|
||||
Tested up to: 3.5
|
||||
Stable tag: 0.2.1
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Easily embed Spotify playlists, albums and tracks into your posts through the new Spotify Play Button.
|
||||
|
||||
== Description ==
|
||||
|
||||
Spotify Embed is based on the new [API by Spotify](https://developer.spotify.com/technologies/spotify-play-button/), better known as the Spotify Play Button.
|
||||
With Spotify Embed you can easily share your favored music tracks, albums and playlists with other Spotify users.
|
||||
|
||||
= What's your part? =
|
||||
Just place a Spotify link into your posts. It can be a link to your favored track or album, but also music playlists are possible.
|
||||
**By default no shortcodes are necessary, just a link!**
|
||||
And that was about your part. Easy, isn't it?
|
||||
|
||||
= What does the plugin? =
|
||||
The plugin will fetch your links of your music and will convert it to a sexy Spotify Play Button.
|
||||
|
||||
= Some usage examples =
|
||||
To embed a simple Track just embed a link like this:
|
||||
`https://open.spotify.com/track/4IJUii1lg0IRLBs0yG1w2p`
|
||||
|
||||
To embed an album just embed a link like this:
|
||||
`http://open.spotify.com/album/4pT0rlFvHYc46KyEhmCy88`
|
||||
|
||||
Or to embed a complete playlist just embed a link like this:
|
||||
`http://open.spotify.com/user/sonymusic/playlist/1BVPSd4dynzdlIWehjvkPj`
|
||||
|
||||
For more examples please vist the [FAQ section](http://wordpress.org/extend/plugins/spotify-embed/faq/).
|
||||
|
||||
**Sounds pretty good? Install now!**
|
||||
|
||||
= Coming soon =
|
||||
* Support for Spotify URLs like `spotify:album:4pT0rlFvHYc46KyEhmCy88`.
|
||||
|
||||
|
||||
*Spotify Embed is not associated in any way with Spotify by Spotify Ltd.*
|
||||
|
||||
|
||||
= Feedback =
|
||||
If you want, you can drop me a line @[ocean90](http://twitter.com/ocean90) on Twitter or @[Dominik Schilling](https://plus.google.com/101675293278434581718/) on Google+.
|
||||
|
||||
|
||||
|
||||
= More =
|
||||
If you want, you can try also some of my [other plugins](http://profiles.wordpress.org/users/ocean90) or visit my site [wpGrafie.de](http://wpgrafie.de/).
|
||||
|
||||
|
||||
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Can I embed the light theme instead of the dark theme? =
|
||||
Yes, you can. Just wrap your link into the `[embed][/embed]` shortcode and add the keyword 'light'.
|
||||
Example:
|
||||
`[embed light]http://open.spotify.com/user/spotify/playlist/3Yrvm5lBgnhzTYTXx2l55x[/embed]`
|
||||
|
||||
|
||||
= I want to show the cover art, is that possible? =
|
||||
Yes. Just wrap your link into the `[embed][/embed]` shortcode and add the keyword 'coverart'.
|
||||
Example:
|
||||
`[embed coverart]http://open.spotify.com/user/spotify/playlist/3Yrvm5lBgnhzTYTXx2l55x[/embed]`
|
||||
|
||||
|
||||
= Where does the plugin get it's default height and width settings? =
|
||||
Therefor take a look at the Media settings under `Settings > Media > Embed`.
|
||||
|
||||
|
||||
= Can I customize the size of the embed box? =
|
||||
Yes. Just wrap your link into the `[embed][/embed]` shortcode and add the keywords 'height' and/or 'width'.
|
||||
(Note: Take also a look at the [Spotify documentation](https://developer.spotify.com/technologies/spotify-play-button/documentation/))
|
||||
Example:
|
||||
`[embed height="600" width="450"]http://open.spotify.com/user/spotify/playlist/3Yrvm5lBgnhzTYTXx2l55x[/embed]`
|
||||
|
||||
Another option is the use of the `size` keyword. You can use `size="compact"` (80x250px) or `size="large"` (720x640px).
|
||||
Example:
|
||||
`[embed size="compact"]http://open.spotify.com/user/spotify/playlist/3Yrvm5lBgnhzTYTXx2l55x[/embed]`
|
||||
|
||||
|
||||
= Can I combine all these keywords? =
|
||||
Yes. (But don't try to combine the size keywords, or the sky will fall on your head)
|
||||
|
||||
|
||||
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. An example of an embed track.
|
||||
2. Here you can get the HTML link of your track, album or playlist, which you can insert into your content.
|
||||
|
||||
|
||||
|
||||
|
||||
== Installation ==
|
||||
|
||||
Note: There will be NO settings page.
|
||||
|
||||
For an automatic installation through WordPress:
|
||||
|
||||
1. Go to the 'Add New' plugins screen in your WordPress admin area
|
||||
1. Search for 'Spotify Embed'
|
||||
1. Click 'Install Now' and activate the plugin
|
||||
|
||||
|
||||
For a manual installation via FTP:
|
||||
|
||||
1. Upload the `spotify-embed` directory to the `/wp-content/plugins/` directory
|
||||
1. Activate the plugin through the 'Plugins' screen in your WordPress admin area
|
||||
|
||||
|
||||
To upload the plugin through WordPress, instead of FTP:
|
||||
|
||||
1. Upload the downloaded zip file on the 'Add New' plugins screen (see the 'Upload' tab) in your WordPress admin area and activate.
|
||||
|
||||
|
||||
|
||||
|
||||
== Changelog ==
|
||||
= 0.2.1 =
|
||||
* Removes one unused matching group to increase performance, thanks to Sergej Müller.
|
||||
|
||||
= 0.2.0 =
|
||||
* Performance boost by reducing to only one regular expression, thanks to Jens Tautenhahn.
|
||||
* New keyword: `size`. (Use `size="compact"` or `size="large"`.)
|
||||
|
||||
= 0.1.0 =
|
||||
* First release.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 0.2 =
|
||||
Performance boost and a new keyword for default size. You can use size="compact" or size="large" now.
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Spotify Embed
|
||||
* Version: 0.2.1
|
||||
* Description: Just add Spotify links into your posts and the plugin will add the embed code for you.
|
||||
* Author: Dominik Schilling
|
||||
* Author URI: http://wphelper.de/
|
||||
* Plugin URI: http://wpgrafie.de/wp-plugins/spotify-embed/en/
|
||||
*
|
||||
* License: GPLv2 or later
|
||||
*
|
||||
* Copyright (C) 2011-2012 Dominik Schilling
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Don't call this file directly.
|
||||
*/
|
||||
if ( ! class_exists( 'WP' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* The class.
|
||||
*/
|
||||
final class DS_Spotify_Embed {
|
||||
/**
|
||||
* The Spotify API URL.
|
||||
*/
|
||||
private static $spotify_embed_url = 'https://embed.spotify.com/';
|
||||
|
||||
/**
|
||||
* Register the embed handler.
|
||||
*/
|
||||
public static function init() {
|
||||
wp_embed_register_handler(
|
||||
'spotify',
|
||||
'#https?:\/\/open\.spotify\.com\/(track|album|user\/.+?\/playlist)\/([a-z0-9]{22})\/?#i',
|
||||
array( __CLASS__, 'embed_handler_spotify' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for the spotify embeds. Prints the HTML embed code.
|
||||
*
|
||||
* @param mixed $matches Matches through the regex search.
|
||||
* $matches[0] The Spotify URL.
|
||||
* $matches[1] The type of embed music (album, track or playlist).
|
||||
* $matches[2] The Spotify ID.
|
||||
* @param array $attr Custom attributes from the [embed][/embed] shortcut
|
||||
* @param string $url The matched URL.
|
||||
* @param array $rawattr Includes the height and width from media settings
|
||||
*
|
||||
* @return string The HTML embed code.
|
||||
*/
|
||||
public static function embed_handler_spotify( $matches, $attr, $url, $rawattr ) {
|
||||
if ( empty( $matches ) )
|
||||
return;
|
||||
|
||||
$type = str_replace( '/', ':', $matches[1] );
|
||||
$id = $matches[2];
|
||||
|
||||
// Set the size of the embed iframe
|
||||
if ( ! empty( $attr['size'] ) && 'compact' == $attr['size'] ) {
|
||||
$width = 250;
|
||||
$height = 80;
|
||||
} elseif ( ! empty( $attr['size'] ) && 'large' == $attr['size'] ) {
|
||||
$width = 640;
|
||||
$height = 720;
|
||||
} else {
|
||||
if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
|
||||
$width = $rawattr['width'];
|
||||
$height = $rawattr['height'];
|
||||
} else {
|
||||
list( $width, $height ) = wp_expand_dimensions( 300, 380, $attr['width'], $attr['height'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the base embed source
|
||||
$embed_src = sprintf(
|
||||
'%s?uri=spotify:%s:%s',
|
||||
self::$spotify_embed_url,
|
||||
$type,
|
||||
$id
|
||||
);
|
||||
|
||||
// Check for custom settings
|
||||
if ( in_array( 'coverart', $attr ) )
|
||||
$embed_src = add_query_arg( 'view', 'coverart', $embed_src );
|
||||
|
||||
if ( in_array( 'light', $attr ) )
|
||||
$embed_src = add_query_arg( 'theme', 'white', $embed_src );
|
||||
/* Ninja in more sensible defaults */
|
||||
$width = 300;
|
||||
$height = 380;
|
||||
|
||||
// The embed code
|
||||
return sprintf(
|
||||
'<iframe src="%s" width="%d" height="%d" frameborder="0" allowTransparency="true"></iframe>',
|
||||
esc_url( $embed_src ),
|
||||
(int) $width,
|
||||
(int) $height
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Gogogo.
|
||||
add_action( 'plugins_loaded', array( 'DS_Spotify_Embed', 'init' ) );
|
||||
Reference in new issue
Block a user