diff options
author | Brion Vibber <brion@pobox.com> | 2010-09-15 14:09:23 -0700 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-09-15 14:10:18 -0700 |
commit | 95b534c5cee56602dffcc11121908c0f518cab6d (patch) | |
tree | 0a6a3cab7b1f6f881c51101bff7742dcb1d05cb6 /plugins/SpotifyPlugin.php | |
parent | 2d4c0f9a47f6534c578a37abe79670cec699caae (diff) |
Move standalone plugin files into subdirectories so they can have locale data, etc added to them at leisure.
Diffstat (limited to 'plugins/SpotifyPlugin.php')
-rw-r--r-- | plugins/SpotifyPlugin.php | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/plugins/SpotifyPlugin.php b/plugins/SpotifyPlugin.php deleted file mode 100644 index e7a5a5382..000000000 --- a/plugins/SpotifyPlugin.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php -/** - * StatusNet, the distributed open-source microblogging tool - * - * Plugin to create pretty Spotify URLs - * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @category Plugin - * @package StatusNet - * @author Nick Holliday <n.g.holliday@gmail.com> - * @copyright Nick Holliday - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - * - * @see Event - */ -if (!defined('STATUSNET')) { - exit(1); -} -define('SPOTIFYPLUGIN_VERSION', '0.1'); - -/** - * Plugin to create pretty Spotify URLs - * - * The Spotify API is called before the notice is saved to gather artist and track information. - * - * @category Plugin - * @package StatusNet - * @author Nick Holliday <n.g.holliday@gmail.com> - * @copyright Nick Holliday - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - * - * @see Event - */ - -class SpotifyPlugin extends Plugin -{ - - function __construct() - { - parent::__construct(); - } - - function onStartNoticeSave($notice) - { - $notice->rendered = preg_replace_callback('/spotify:[a-z]{5,6}:[a-z0-9]{22}/i', - "renderSpotifyURILink", - $notice->rendered); - - $notice->rendered = preg_replace_callback('/<a href="http:\/\/open.spotify.com\/[a-z]{5,6}\/[a-z0-9]{22}" title="http:\/\/open.spotify.com\/[a-z]{5,6}\/[a-z0-9]{22}" rel="external">http:\/\/open.spotify.com\/[a-z]{5,6}\/[a-z0-9]{22}<\/a>/i', - "renderSpotifyHTTPLink", - $notice->rendered); - - return true; - } - - function userAgent() - { - return 'SpotifyPlugin/'.SPOTIFYPLUGIN_VERSION . - ' StatusNet/' . STATUSNET_VERSION; - } -} - -function doSpotifyLookup($uri, $isArtist) -{ - $request = HTTPClient::start(); - $response = $request->get('http://ws.spotify.com/lookup/1/?uri=' . $uri); - if ($response->isOk()) { - $xml = simplexml_load_string($response->getBody()); - - if($isArtist) - return $xml->name; - else - return $xml->artist->name . ' - ' . $xml->name; - } -} - -function renderSpotifyURILink($match) -{ - $isArtist = false; - if(preg_match('/artist/', $match[0]) > 0) $isArtist = true; - - $name = doSpotifyLookup($match[0], $isArtist); - return "<a href=\"{$match[0]}\">" . $name . "</a>"; -} - -function renderSpotifyHTTPLink($match) -{ - $match[0] = preg_replace('/<a href="http:\/\/open.spotify.com\/[a-z]{5,6}\/[a-z0-9]{22}" title="http:\/\/open.spotify.com\/[a-z]{5,6}\/[a-z0-9]{22}" rel="external">http:\/\/open.spotify.com\//i', 'spotify:', $match[0]); - $match[0] = preg_replace('/<\/a>/', '', $match[0]); - $match[0] = preg_replace('/\//', ':', $match[0]); - - $isArtist = false; - if(preg_match('/artist/', $match[0]) > 0) $isArtist = true; - - $name = doSpotifyLookup($match[0], $isArtist); - return "<a href=\"{$match[0]}\">" . $name . "</a>"; -} |