protected static function get_images($artist_name) { $images = array(); if (AmpConfig::get('echonest_api_key')) { $echonest = new EchoNest_Client(new EchoNest_HttpClient_Requests()); $echonest->authenticate(AmpConfig::get('echonest_api_key')); try { $images = $echonest->getArtistApi()->setName($artist_name)->getImages(); } catch (Exception $e) { debug_event('echonest', 'EchoNest artist images error: ' . $e->getMessage(), '1'); } } foreach (Plugin::get_plugins('get_photos') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $images += $plugin->_plugin->get_photos($artist_name); } } return $images; }
* along with this program. If not, see <http://www.gnu.org/licenses/>. * */ $last_seen = $client->last_seen ? date("m\\/d\\/y - H:i", $client->last_seen) : T_('Never'); $create_date = $client->create_date ? date("m\\/d\\/y - H:i", $client->create_date) : T_('Unknown'); $client->format(); UI::show_box_top($client->f_name); ?> <div class="user_avatar"> <?php if ($client->f_avatar) { echo $client->f_avatar . "<br /><br />"; } if (AmpConfig::get('sociable')) { echo $client->get_display_follow(); $plugins = Plugin::get_plugins('display_user_field'); ?> <ul id="plugins_user_field"> <?php foreach ($plugins as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($client)) { ?> <li><?php $plugin->_plugin->display_user_field(); ?> </li> <?php } } ?>
public static function display_ui_links($object_type, $object_id) { echo "<ul>"; echo "<li><a onclick=\"handleShareAction('" . AmpConfig::get('web_path') . "/share.php?action=show_create&type=" . $object_type . "&id=" . $object_id . "')\">" . UI::get_icon('share', T_('Advanced Share')) . " " . T_('Advanced Share') . "</a></li>"; if (AmpConfig::get('download')) { $dllink = ""; if ($object_type == "song" || $object_type == "video") { $dllink = AmpConfig::get('web_path') . "/play/index.php?action=download&type=" . $object_type . "&oid=" . $object_id . "&uid=-1"; } else { if (Access::check_function('batch_download') && check_can_zip($object_type)) { $dllink = AmpConfig::get('web_path') . "/batch.php?action=" . $object_type . "&id=" . $object_id; } } if (!empty($dllink)) { if (AmpConfig::get('require_session')) { // Add session information to the link to avoid authentication $dllink .= "&ssid=" . Stream::get_session(); } echo "<li><a rel=\"nohtml\" href=\"" . $dllink . "\">" . UI::get_icon('download', T_('Temporary direct link')) . " " . T_('Temporary direct link') . "</a></li>"; } } echo "<li style='padding-top: 8px; text-align: right;'>"; $plugins = Plugin::get_plugins('external_share'); foreach ($plugins as $plugin_name) { echo "<a onclick=\"handleShareAction('" . AmpConfig::get('web_path') . "/share.php?action=external_share&plugin=" . $plugin_name . "&type=" . $object_type . "&id=" . $object_id . "')\" target=\"_blank\">" . UI::get_icon('share_' . strtolower($plugin_name), $plugin_name) . "</a> "; } echo "</li>"; echo "</ul>"; }
/** * Load wanted release data. * @param boolean $track_details */ public function load_all($track_details = true) { $mb = new MusicBrainz(new RequestsHttpAdapter()); $this->songs = array(); try { $group = $mb->lookup('release-group', $this->mbid, array('releases')); // Set fresh data $this->name = $group->title; $this->year = date("Y", strtotime($group->{'first-release-date'})); // Load from database if already cached $this->songs = Song_preview::get_song_previews($this->mbid); if (count($group->releases) > 0) { $this->release_mbid = $group->releases[0]->id; if ($track_details && count($this->songs) == 0) { // Use the first release as reference for track content $release = $mb->lookup('release', $this->release_mbid, array('recordings')); foreach ($release->media as $media) { foreach ($media->tracks as $track) { $song = array(); $song['disk'] = $media->position; $song['track'] = $track->number; $song['title'] = $track->title; $song['mbid'] = $track->id; if ($this->artist) { $song['artist'] = $this->artist; } $song['artist_mbid'] = $this->artist_mbid; $song['session'] = session_id(); $song['album_mbid'] = $this->mbid; if ($this->artist) { $artist = new Artist($this->artist); $artist_name = $artist->name; } else { $wartist = Wanted::get_missing_artist($this->artist_mbid); $artist_name = $wartist['name']; } $song['file'] = null; foreach (Plugin::get_plugins('get_song_preview') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $song['file'] = $plugin->_plugin->get_song_preview($track->id, $artist_name, $track->title); if ($song['file'] != null) { break; } } } if ($song != null) { $this->songs[] = new Song_Preview(Song_preview::insert($song)); } } } } } } catch (Exception $e) { $this->songs = array(); } foreach ($this->songs as $song) { $song->f_album = $this->name; $song->format(); } }
} else { $GLOBALS['user']->upload_avatar(); //$_REQUEST['action'] = 'confirm'; $title = T_('Updated'); $text = T_('Your Account has been updated'); $next_url = AmpConfig::get('web_path') . '/preferences.php?tab=account'; } $notification_text = T_('User updated successfully'); break; case 'grant': // Make sure we're a user and they came from the form if (!Access::check('interface', '25') && $GLOBALS['user']->id > 0) { UI::access_denied(); exit; } if ($_REQUEST['token'] && in_array($_REQUEST['plugin'], Plugin::get_plugins('save_mediaplay'))) { // we receive a token for a valid plugin, have to call getSession and obtain a session key if ($plugin = new Plugin($_REQUEST['plugin'])) { $plugin->load($GLOBALS['user']); if ($plugin->_plugin->get_session($GLOBALS['user']->id, $_REQUEST['token'])) { $title = T_('Updated'); $text = T_('Your Account has been updated') . ' : ' . $_REQUEST['plugin']; $next_url = AmpConfig::get('web_path') . '/preferences.php?tab=plugins'; } else { $title = T_('Error'); $text = T_('Your Account has not been updated') . ' : ' . $_REQUEST['plugin']; $next_url = AmpConfig::get('web_path') . '/preferences.php?tab=plugins'; } } } $fullname = $GLOBALS['user']->fullname;
if (!defined('AJAX_INCLUDE')) { exit; } $results = array(); switch ($_REQUEST['action']) { case 'geolocation': if (AmpConfig::get('geolocation')) { if ($GLOBALS['user']->id) { $latitude = floatval($_REQUEST['latitude']); $longitude = floatval($_REQUEST['longitude']); $name = $_REQUEST['name']; if (empty($name)) { // First try to get from local cache (avoid external api requests) $name = Stats::get_cached_place_name($latitude, $longitude); if (empty($name)) { foreach (Plugin::get_plugins('get_location_name') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $name = $plugin->_plugin->get_location_name($latitude, $longitude); if (!empty($name)) { break; } } } } } // Better to check for bugged values here and keep previous user good location // Someone listing music at 0.0,0.0 location would need a waterproof music player btw if ($latitude > 0 && $longitude > 0) { Session::update_geolocation(session_id(), $latitude, $longitude, $name); }
/** * Get lyrics. * @return array */ public function get_lyrics() { if ($this->lyrics) { return array('text' => $this->lyrics); } foreach (Plugin::get_plugins('get_lyrics') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $lyrics = $plugin->_plugin->get_lyrics($this); if ($lyrics != false) { return $lyrics; } } } return null; }
/** * set_rating * This function sets the rating for the current object. * If no userid is passed in, we use the currently logged in user. */ public function set_rating($rating, $user_id = null) { if (is_null($user_id)) { $user_id = $GLOBALS['user']->id; } $user_id = intval($user_id); debug_event('Rating', "Setting rating for {$this->type} {$this->id} to {$rating}", 5); // If score is -1, then remove rating if ($rating == '-1') { $sql = "DELETE FROM `rating` WHERE " . "`object_id` = ? AND " . "`object_type` = ? AND " . "`user` = ?"; $params = array($this->id, $this->type, $user_id); } else { $sql = "REPLACE INTO `rating` " . "(`object_id`, `object_type`, `rating`, `user`) " . "VALUES (?, ?, ?, ?)"; $params = array($this->id, $this->type, $rating, $user_id); } Dba::write($sql, $params); parent::add_to_cache('rating_' . $this->type . '_user' . $user_id, $this->id, $rating); foreach (Plugin::get_plugins('save_rating') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $plugin->_plugin->save_rating($this, $rating); } } return true; }
/** * show_footer * * Shows the footer template and possibly profiling info. */ public static function show_footer() { if (!defined("TABLE_RENDERED")) { show_table_render(); } $plugins = Plugin::get_plugins('display_on_footer'); foreach ($plugins as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $plugin->_plugin->display_on_footer(); } } require_once AmpConfig::get('prefix') . UI::find_template('footer.inc.php'); if (isset($_REQUEST['profiling'])) { Dba::show_profile(); } }
* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License v2 * as published by the Free Software Foundation. * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ foreach (Plugin::get_plugins('display_home') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $plugin->_plugin->display_home(); } } if (AmpConfig::get('home_now_playing')) { ?> <div id="now_playing"> <?php show_now_playing(); ?> </div> <!-- Close Now Playing Div --> <?php } ?>
/** * _get_plugin_tags * * Get additional metadata from plugins */ private function _get_plugin_tags() { $tag_order = $this->get_metadata_order(); if (!is_array($tag_order)) { $tag_order = array($tag_order); } $plugin_names = Plugin::get_plugins('get_metadata'); foreach ($tag_order as $tag_source) { if (in_array($tag_source, $plugin_names)) { $plugin = new Plugin($tag_source); $installed_version = Plugin::get_plugin_version($plugin->_plugin->name); if ($installed_version) { if ($plugin->load($GLOBALS['user'])) { $this->tags[$tag_source] = $plugin->_plugin->get_metadata($this->gather_types, self::clean_tag_info($this->tags, self::get_tag_type($this->tags, $this->get_metadata_order_key()), $this->filename)); } } } } }
/** * set_flag * This function sets the user flag for the current object. * If no userid is passed in, we use the currently logged in user. */ public function set_flag($flagged, $user_id = null) { if ($user_id === null) { $user_id = $GLOBALS['user']->id; } $user_id = intval($user_id); debug_event('Userflag', "Setting userflag for {$this->type} {$this->id} to {$flagged}", 5); if (!$flagged) { $sql = "DELETE FROM `user_flag` WHERE " . "`object_id` = ? AND " . "`object_type` = ? AND " . "`user` = ?"; $params = array($this->id, $this->type, $user_id); } else { $sql = "REPLACE INTO `user_flag` " . "(`object_id`, `object_type`, `user`, `date`) " . "VALUES (?, ?, ?, ?)"; $params = array($this->id, $this->type, $user_id, time()); Useractivity::post_activity($user_id, 'userflag', $this->type, $this->id); } Dba::write($sql, $params); parent::add_to_cache('userflag_' . $this->type . '_user' . $user_id, $this->id, $flagged); // Forward flag to last.fm and Libre.fm (song only) if ($this->type == 'song') { $user = new User($user_id); $song = new Song($this->id); if ($song) { $song->format(); foreach (Plugin::get_plugins('save_mediaplay') as $plugin_name) { try { $plugin = new Plugin($plugin_name); if ($plugin->load($user)) { $plugin->_plugin->set_flag($song, $flagged); } } catch (Exception $e) { debug_event('user.class.php', 'Stats plugin error: ' . $e->getMessage(), '1'); } } } } return true; }
/* Verify that this plugin exists */ $plugins = Plugin::get_plugins(); if (!array_key_exists($_REQUEST['plugin'], $plugins)) { debug_event('plugins', 'Error: Invalid Plugin: ' . $_REQUEST['plugin'] . ' selected', '1'); break; } $plugin = new Plugin($_REQUEST['plugin']); $plugin->upgrade(); User::rebuild_all_preferences(); $url = AmpConfig::get('web_path') . '/admin/modules.php?action=show_plugins'; $title = T_('Plugin Upgraded'); $body = ''; show_confirmation($title, $body, $url); break; case 'show_plugins': $plugins = Plugin::get_plugins(); UI::show_box_top(T_('Plugins'), 'box box_localplay_plugins'); require_once AmpConfig::get('prefix') . '/templates/show_plugins.inc.php'; UI::show_box_bottom(); break; case 'show_localplay': $controllers = Localplay::get_controllers(); UI::show_box_top(T_('Localplay Controllers'), 'box box_localplay_controllers'); require_once AmpConfig::get('prefix') . '/templates/show_localplay_controllers.inc.php'; UI::show_box_bottom(); break; case 'show_catalog_types': $catalogs = Catalog::get_catalog_types(); UI::show_box_top(T_('Catalog Types'), 'box box_catalog_types'); require_once AmpConfig::get('prefix') . '/templates/show_catalog_types.inc.php'; UI::show_box_bottom();
/** * stream_control * Check all stream control plugins * @param array $media_ids * @param User $user * @return boolean */ public static function stream_control($media_ids, User $user = null) { if ($user == null) { $user = $GLOBALS['user']; } foreach (Plugin::get_plugins('stream_control') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($user)) { if (!$plugin->_plugin->stream_control($media_ids)) { return false; } } } return true; }
public function display_map($user = 0, $object_type = null, $object_id = 0, $start_date = null, $end_date = null, $zoom = 'day') { $pts = $this->get_geolocation_pts($user, $object_type, $object_id, $start_date, $end_date, $zoom); foreach (Plugin::get_plugins('display_map') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { if ($plugin->_plugin->display_map($pts)) { break; } } } }
public function stream() { $data = null; foreach (Plugin::get_plugins('stream_song_preview') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { if ($plugin->_plugin->stream_song_preview($this->file)) { break; } } } return $data; }
public function accept() { if ($GLOBALS['user']->has_access('75')) { $sql = "UPDATE `wanted` SET `accepted` = '1' WHERE `mbid` = ?"; Dba::write($sql, array($this->mbid)); $this->accepted = 1; foreach (Plugin::get_plugins('process_wanted') as $plugin_name) { debug_event('wanted', 'Using Wanted Process plugin: ' . $plugin_name, '5'); $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $plugin->_plugin->process_wanted($this); } } } }
/** * gather * This tries to get the art in question * @param array $options * @param int $limit * @return array */ public function gather($options = array(), $limit = 0) { // Define vars $results = array(); $type = $this->type; if (isset($options['type'])) { $type = $options['type']; } if (count($options) == 0) { debug_event('Art', 'No options for art search, skipped.', 3); return array(); } $config = AmpConfig::get('art_order'); $methods = get_class_methods('Art'); /* If it's not set */ if (empty($config)) { // They don't want art! debug_event('Art', 'art_order is empty, skipping art gathering', 3); return array(); } elseif (!is_array($config)) { $config = array($config); } debug_event('Art', 'Searching using:' . json_encode($config), 3); $plugin_names = Plugin::get_plugins('gather_arts'); foreach ($config as $method) { $method_name = "gather_" . $method; $data = array(); if (in_array($method, $plugin_names)) { $plugin = new Plugin($method); $installed_version = Plugin::get_plugin_version($plugin->_plugin->name); if ($installed_version) { if ($plugin->load($GLOBALS['user'])) { $data = $plugin->_plugin->gather_arts($type, $options, $limit); } } } else { if (in_array($method_name, $methods)) { debug_event('Art', "Method used: {$method_name}", 3); // Some of these take options! switch ($method_name) { case 'gather_lastfm': $data = $this->{$method_name}($limit, $options); break; case 'gather_google': $data = $this->{$method_name}($limit, $options); break; default: $data = $this->{$method_name}($limit); break; } } else { debug_event("Art", $method_name . " not defined", 1); } } // Add the results we got to the current set $results = array_merge($results, (array) $data); if ($limit && count($results) >= $limit) { return array_slice($results, 0, $limit); } } // end foreach return $results; }
/** * get_avatar * Get the user avatar */ public function get_avatar() { $avatar = array(); $avatar['title'] = T_('User avatar'); $upavatar = new Art($this->id, 'user'); if ($upavatar->get_db()) { $avatar['url'] = AmpConfig::get('web_path') . '/image.php?object_type=user&id=' . $this->id; $avatar['url_mini'] = $avatar['url']; $avatar['url_medium'] = $avatar['url']; $avatar['url'] .= '&thumb=3'; $avatar['url_mini'] .= '&thumb=5'; $avatar['url_medium'] .= '&thumb=3'; } else { foreach (Plugin::get_plugins('get_avatar_url') as $plugin_name) { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $avatar['url'] = $plugin->_plugin->get_avatar_url($this); if (!empty($avatar['url'])) { $avatar['url_mini'] = $plugin->_plugin->get_avatar_url($this, 32); $avatar['url_medium'] = $plugin->_plugin->get_avatar_url($this, 64); $avatar['title'] .= ' (' . $plugin->_plugin->name . ')'; break; } } } } return $avatar; }