/** * load_latest_shout * This loads in the latest added shouts * @return array */ public static function load_latest_shout() { $ids = Shoutbox::get_top(10); $results = array(); foreach ($ids as $id) { $shout = new Shoutbox($id); $shout->format(); $object = Shoutbox::get_object($shout->object_type, $shout->object_id); $object->format(); $user = new User($shout->user); $user->format(); $xml_array = array('title' => $user->username . ' ' . T_('on') . ' ' . $object->get_fullname(), 'link' => $object->link, 'description' => $shout->text, 'image' => Art::url($shout->object_id, $shout->object_type, null, 2), 'comments' => '', 'pubDate' => date("c", $shout->date)); $results[] = $xml_array; } // end foreach return $results; }
/** * get_artist_info * Returns artist information */ public static function get_artist_info($artist_id, $fullname = '') { $artist = null; if ($artist_id) { $artist = new Artist($artist_id); $artist->format(); $fullname = $artist->f_full_name; // Data newer than 6 months, use it if ($artist->last_update + 15768000 > time()) { $results = array(); $results['summary'] = $artist->summary; $results['placeformed'] = $artist->placeformed; $results['yearformed'] = $artist->yearformed; $results['largephoto'] = Art::url($artist->id, 'artist'); $results['megaphoto'] = $results['largephoto']; return $results; } } $query = 'artist=' . rawurlencode($fullname); $xml = self::get_lastfm_results('artist.getinfo', $query); $results = array(); $results['summary'] = strip_tags(preg_replace("#<a href=([^<]*)Last\\.fm</a>.#", "", (string) $xml->artist->bio->summary)); $results['placeformed'] = (string) $xml->artist->bio->placeformed; $results['yearformed'] = (string) $xml->artist->bio->yearformed; $results['largephoto'] = $xml->artist->image[2]; $results['megaphoto'] = $xml->artist->image[4]; if ($artist) { if (!empty($results['summary']) || !empty($results['megaphoto'])) { $artist->update_artist_info($results['summary'], $results['placeformed'], $results['yearformed']); $image = Art::get_from_source(array('url' => $results['megaphoto']), 'artist'); $rurl = pathinfo($results['megaphoto']); $mime = 'image/' . $rurl['extension']; $art = new Art($artist->id, 'artist'); $art->reset(); $art->insert($image, $mime); $results['largephoto'] = Art::url($artist->id, 'artist'); $results['megaphoto'] = $results['largephoto']; } } return $results; }
$results[] = array('type' => T_('Playlists'), 'link' => $playlist->link, 'label' => $playlist->name, 'value' => $playlist->name, 'rels' => '', 'image' => ''); } } if (($target == 'anywhere' || $target == 'label') && AmpConfig::get('label')) { $searchreq = array('limit' => $limit, 'type' => 'label', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'name'); $sres = Search::run($searchreq); // Litmit not reach, new search with another operator if (count($sres) < $limit) { $searchreq['limit'] = $limit - count($sres); $searchreq['rule_1_operator'] = '0'; $sres = array_unique(array_merge($sres, Search::run($searchreq))); } foreach ($sres as $id) { $label = new Label($id); $label->format(false); $results[] = array('type' => T_('Labels'), 'link' => $label->link, 'label' => $label->name, 'value' => $label->name, 'rels' => '', 'image' => Art::url($label->id, 'label', null, 10)); } } if ($target == 'missing_artist' && AmpConfig::get('wanted')) { $sres = Wanted::search_missing_artists($search); $i = 0; foreach ($sres as $r) { $results[] = array('type' => T_('Missing Artists'), 'link' => AmpConfig::get('web_path') . '/artists.php?action=show_missing&mbid=' . $r['mbid'], 'label' => $r['name'], 'value' => $r['name'], 'rels' => '', 'image' => ''); $i++; if ($i >= $limit) { break; } } } if ($target == 'user' && AmpConfig::get('sociable')) { $searchreq = array('limit' => $limit, 'type' => 'user', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'username');
private static function _itemVideo($video, $parent) { $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false; $art_url = Art::url($video->id, 'video', $api_session); $fileTypesByExt = self::_getFileTypes(); $arrFileType = $fileTypesByExt[$video->type]; return array('id' => $parent . '/' . $video->id, 'parentID' => $parent, 'restricted' => '1', 'dc:title' => self::_replaceSpecialSymbols($video->f_title), 'upnp:class' => isset($arrFileType['class']) ? $arrFileType['class'] : 'object.item.unknownItem', 'upnp:albumArtURI' => $art_url, 'upnp:genre' => Tag::get_display($video->tags, false, 'video'), 'res' => Video::play_url($video->id, '', 'api'), 'protocolInfo' => $arrFileType['mime'], 'size' => $video->size, 'duration' => $video->f_time_h . '.0'); }
/** * media_to_urlarray * Formats the URL and media information and adds it to the object */ public static function media_to_urlarray($media, $additional_params = '') { $urls = array(); foreach ($media as $medium) { $url = array(); if ($medium['custom_play_action']) { $additional_params .= "&custom_play_action=" . $medium['custom_play_action']; } $type = $medium['object_type']; //$url['object_id'] = $medium['object_id']; $url['type'] = $type; $object = new $type($medium['object_id']); $object->format(); // Don't add disabled media objects to the stream playlist // Playing a disabled media return a 404 error that could make failed the player (mpd ...) if (make_bool($object->enabled)) { //FIXME: play_url shouldn't be static $url['url'] = $type::play_url($object->id, $additional_params); $api_session = AmpConfig::get('require_session') ? Stream::$session : false; // Set a default which can be overridden $url['author'] = 'Ampache'; $url['time'] = $object->time; switch ($type) { case 'song': $url['title'] = $object->title; $url['author'] = $object->f_artist_full; $url['info_url'] = $object->f_link; $url['image_url'] = Art::url($object->album, 'album', $api_session); $url['album'] = $object->f_album_full; break; case 'video': $url['title'] = 'Video - ' . $object->title; $url['author'] = $object->f_artist_full; break; case 'radio': $url['title'] = 'Radio - ' . $object->name; if (!empty($object->site_url)) { $url['title'] .= ' (' . $object->site_url . ')'; } $url['codec'] = $object->codec; break; case 'song_preview': $url['title'] = $object->title; $url['author'] = $object->f_artist_full; break; case 'channel': $url['title'] = $object->name; break; case 'random': $url['title'] = 'Random URL'; break; default: $url['title'] = 'URL-Add'; $url['time'] = -1; break; } $urls[] = new Stream_URL($url); } } return $urls; }
/** * media_object_to_url */ public static function media_object_to_url($object, $additional_params = '', $urltype = 'web') { $surl = null; $url = array(); $type = strtolower(get_class($object)); $url['type'] = $type; // Don't add disabled media objects to the stream playlist // Playing a disabled media return a 404 error that could make failed the player (mpd ...) if (!isset($object->enabled) || make_bool($object->enabled)) { if ($urltype == 'file') { $url['url'] = $object->file; // Relative path if (!empty($additional_params) && strpos($url['url'], $additional_params) === 0) { $url['url'] = substr($url['url'], strlen($additional_params)); if (strlen($url['url']) < 1) { return null; } if ($url['url'][0] == DIRECTORY_SEPARATOR) { $url['url'] = substr($url['url'], 1); } } } else { //FIXME: play_url shouldn't be static $url['url'] = $type::play_url($object->id, $additional_params); } $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false; // Set a default which can be overridden $url['author'] = 'Ampache'; $url['time'] = $object->time; switch ($type) { case 'song': $url['title'] = $object->title; $url['author'] = $object->f_artist_full; $url['info_url'] = $object->f_link; $url['image_url'] = Art::url($object->album, 'album', $api_session, AmpConfig::get('ajax_load') ? 3 : 4); $url['album'] = $object->f_album_full; $url['track_num'] = $object->f_track; break; case 'video': $url['title'] = 'Video - ' . $object->title; $url['author'] = $object->f_artist_full; $url['resolution'] = $object->f_resolution; break; case 'live_stream': $url['title'] = 'Radio - ' . $object->name; if (!empty($object->site_url)) { $url['title'] .= ' (' . $object->site_url . ')'; } $url['codec'] = $object->codec; break; case 'song_preview': $url['title'] = $object->title; $url['author'] = $object->f_artist_full; break; case 'channel': $url['title'] = $object->name; break; case 'random': $url['title'] = 'Random URL'; break; default: $url['title'] = 'URL-Add'; $url['time'] = -1; break; } $surl = new Stream_URL($url); } return $surl; }
public static function podcast(library_item $libitem) { $xml = new SimpleXMLElement('<rss />'); $xml->addAttribute("version", "2.0"); $xml->addAttribute("xmlns:xmlns:atom", "http://www.w3.org/2005/Atom"); $xml->addAttribute("xmlns:xmlns:itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd"); $xchannel = $xml->addChild("channel"); $xchannel->addChild("title", $libitem->get_fullname() . " Podcast"); $xlink = $xchannel->addChild("atom:link"); $xlink->addAttribute("type", "text/html"); $xlink->addAttribute("href", $libitem->link); if (Art::has_db($libitem->id, get_class($libitem))) { $ximg = $xchannel->addChild("xmlns:itunes:image"); $ximg->addAttribute("href", Art::url($libitem->id, get_class($libitem))); } $summary = $libitem->get_description(); if (!empty($summary)) { $xchannel->addChild("xmlns:itunes:summary", $summary); } $xchannel->addChild("xmlns:itunes:category", "Music"); $owner = $libitem->get_user_owner(); if ($owner) { $user_owner = new User($owner); $user_owner->format(); $xowner = $xchannel->addChild("xmlns:itunes:owner"); $xowner->addChild("xmlns:itunes:name", $user_owner->f_name); } $medias = $libitem->get_medias(); foreach ($medias as $media_info) { $media = new $media_info['object_type']($media_info['object_id']); $media->format(); $xitem = $xchannel->addChild("item"); $xitem->addChild("title", $media->get_fullname()); if ($media->f_artist) { $xitem->addChild("xmlns:itunes:author", $media->f_artist); } $xmlink = $xitem->addChild("link"); $xmlink->addAttribute("href", $media->link); $xitem->addChild("guid", $media->link); if ($media->addition_time) { $xitem->addChild("pubDate", date("r", $media->addition_time)); } $description = $media->get_description(); if (!empty($description)) { $xitem->addChild("description", $description); } $xitem->addChild("xmlns:itunes:duration", $media->f_time); $xencl = $xitem->addChild("enclosure"); $xencl->addAttribute("type", $media->mime); $xencl->addAttribute("length", $media->size); $surl = $media_info['object_type']::play_url($media_info['object_id']); $xencl->addAttribute("url", $surl); } $xmlstr = $xml->asXml(); // Format xml output $dom = new DOMDocument(); $dom->loadXML($xmlstr); $dom->formatOutput = true; return $dom->saveXML($dom->documentElement); }
/** * democratic * * This handles creating an xml document for democratic items, this can be a little complicated * due to the votes and all of that * * @param array $object_ids Object IDs * @return string return xml */ public static function democratic($object_ids = array()) { if (!is_array($object_ids)) { $object_ids = array(); } $democratic = Democratic::get_current_playlist(); $string = ''; foreach ($object_ids as $row_id => $data) { $song = new $data['object_type']($data['object_id']); $song->format(); //FIXME: This is duplicate code and so wrong, functions need to be improved $tag = new Tag($song->tags['0']); $song->genre = $tag->id; $song->f_genre = $tag->name; $tag_string = self::tags_string($song->tags); $rating = new Rating($song->id, 'song'); $art_url = Art::url($song->album, 'album', $_REQUEST['auth']); $string .= "<song id=\"" . $song->id . "\">\n" . "\t<title><![CDATA[" . $song->title . "]]></title>\n" . "\t<artist id=\"" . $song->artist . "\"><![CDATA[" . $song->f_artist_full . "]]></artist>\n" . "\t<album id=\"" . $song->album . "\"><![CDATA[" . $song->f_album_full . "]]></album>\n" . "\t<genre id=\"" . $song->genre . "\"><![CDATA[" . $song->f_genre . "]]></genre>\n" . $tag_string . "\t<track>" . $song->track . "</track>\n" . "\t<time>" . $song->time . "</time>\n" . "\t<mime>" . $song->mime . "</mime>\n" . "\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" . "\t<size>" . $song->size . "</size>\n" . "\t<art><![CDATA[" . $art_url . "]]></art>\n" . "\t<preciserating>" . $rating->get_user_rating() . "</preciserating>\n" . "\t<rating>" . $rating->get_user_rating() . "</rating>\n" . "\t<averagerating>" . $rating->get_average_rating() . "</averagerating>\n" . "\t<vote>" . $democratic->get_vote($row_id) . "</vote>\n" . "</song>\n"; } // end foreach $final = self::_header() . $string . self::_footer(); return $final; }
$results[] = array('type' => T_('Albums'), 'link' => $album->f_link_src, 'label' => $a_title, 'value' => $album->f_title, 'rels' => $album->f_artist, 'image' => Art::url($album->id, 'album')); } } if ($target == 'anywhere' || $target == 'title') { $searchreq = array('limit' => $limit, 'type' => 'song', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'title'); $sres = Search::run($searchreq); // Litmit not reach, new search with another operator if (count($sres) < $limit) { $searchreq['limit'] = $limit - count($sres); $searchreq['rule_1_operator'] = '0'; $sres = array_unique(array_merge($sres, Search::run($searchreq))); } foreach ($sres as $id) { $song = new Song($id); $song->format(); $results[] = array('type' => T_('Songs'), 'link' => $song->link, 'label' => $song->f_title_full, 'value' => $song->f_title_full, 'rels' => $song->f_artist_full, 'image' => Art::url($song->album, 'album')); } } if ($target == 'anywhere' || $target == 'playlist') { $searchreq = array('limit' => $limit, 'type' => 'playlist', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'name'); $sres = Search::run($searchreq); // Litmit not reach, new search with another operator if (count($sres) < $limit) { $searchreq['limit'] = $limit - count($sres); $searchreq['rule_1_operator'] = '0'; $sres = array_unique(array_merge($sres, Search::run($searchreq))); } foreach ($sres as $id) { $playlist = new Playlist($id); $playlist->format(); $results[] = array('type' => T_('Playlists'), 'link' => $playlist->f_link, 'label' => $playlist->name, 'value' => $playlist->name, 'rels' => '', 'image' => '');
private static function _itemPodcastEpisode($episode, $parent) { $api_session = AmpConfig::get('require_session') ? Stream::get_session() : false; $art_url = Art::url($episode->podcast, 'podcast', $api_session); $fileTypesByExt = self::_getFileTypes(); $arrFileType = !empty($episode->type) ? $fileTypesByExt[$episode->type] : array(); $ret = array('id' => 'amp://music/podcasts/' . $episode->podcast . '/' . $episode->id, 'parentID' => $parent, 'restricted' => '1', 'dc:title' => self::_replaceSpecialSymbols($episode->f_title), 'upnp:album' => self::_replaceSpecialSymbols($episode->f_podcast), 'upnp:class' => isset($arrFileType['class']) ? $arrFileType['class'] : 'object.item.unknownItem', 'upnp:albumArtURI' => $art_url); if (isset($arrFileType['mime'])) { $ret['res'] = Podcast_Episode::play_url($episode->id, '', 'api'); $ret['protocolInfo'] = $arrFileType['mime']; $ret['size'] = $episode->size; $ret['duration'] = $episode->f_time_h . '.0'; } return $ret; }