2
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
5
* LICENSE: GNU General Public License, version 2 (GPLv2)
6
* Copyright 2001 - 2013 Ampache.org
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License
10
* as published by the Free Software Foundation; version 2
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35
* This takes a flagged.id and then pulls in the information for said flag entry
37
public function __construct($type) {
39
$this->type = self::validate_type($type);
45
* This returns the xmldocument for the current rss type, it calls a sub function that gathers the data
46
* and then uses the xmlDATA class to build the document
48
public function get_xml() {
51
$data_function = 'load_' . $this->type;
52
$pub_date_function = 'pubdate_' . $this->type;
54
$data = call_user_func(array('Ampache_RSS',$data_function));
55
$pub_date = call_user_func(array('Ampache_RSS',$pub_date_function));
57
XML_Data::set_type('rss');
58
$xml_document = XML_Data::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date);
66
* This returns the standardized title for the rss feed based on this->type
68
public function get_title() {
70
$titles = array('now_playing' => T_('Now Playing'),
71
'recently_played' => T_('Recently Played'),
72
'latest_album' => T_('Newest Albums'),
73
'latest_artist' => T_('Newest Artists'));
75
return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type];
81
* This returns the standardized description for the rss feed based on this->type
83
public function get_description() {
85
//FIXME: For now don't do any kind of translating
86
return 'Ampache RSS Feeds';
92
* this returns a valid type for an rss feed, if the specified type is invalid it returns a default value
94
public static function validate_type($type) {
96
$valid_types = array('now_playing','recently_played','latest_album','latest_artist','latest_song',
97
'popular_song','popular_album','popular_artist');
99
if (!in_array($type,$valid_types)) {
100
return 'now_playing';
109
* This dumps out some html and an icon for the type of rss that we specify
111
public static function get_display($type='now_playing') {
113
// Default to now playing
114
$type = self::validate_type($type);
116
$string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . UI::get_icon('feed', T_('RSS Feed')) . '</a>';
122
// type specific functions below, these are called semi-dynamically based on the current type //
126
* This loads in the now playing information. This is just the raw data with key=>value pairs that could be turned
127
* into an xml document if we so wished
129
public static function load_now_playing() {
131
$data = Stream::get_now_playing();
134
$format = Config::get('rss_format') ?: '%t - %a - %A';
140
foreach ($data as $element) {
141
$song = $element['media'];
142
$client = $element['user'];
144
$description = $format;
145
foreach($string_map as $search => $replace) {
146
$trep = 'f_' . $replace;
147
$drep = 'f_' . $replace . '_full';
148
$title = str_replace($search, $song->$trep, $title);
149
$description = str_replace($search, $song->$drep, $description);
153
'link' => $song->link,
154
'description' => $description,
155
'comments' => $client->fullname . ' - ' . $element['agent'],
156
'pubDate' => date('r', $element['expire'])
158
$results[] = $xml_array;
163
} // load_now_playing
166
* pubdate_now_playing
167
* this is the pub date we should use for the now playing information,
168
* this is a little specific as it uses the 'newest' expire we can find
170
public static function pubdate_now_playing() {
172
// Little redundent, should be fixed by an improvement in the get_now_playing stuff
173
$data = Stream::get_now_playing();
175
$element = array_shift($data);
177
return $element['expire'];
179
} // pubdate_now_playing
182
* load_recently_played
183
* This loads in the recently played information and formats it up real nice like
185
public static function load_recently_played() {
187
//FIXME: The time stuff should be centralized, it's currently in two places, lame
189
$time_unit = array('', T_('seconds ago'), T_('minutes ago'), T_('hours ago'), T_('days ago'), T_('weeks ago'), T_('months ago'), T_('years ago'));
190
$data = Song::get_recently_played();
194
foreach ($data as $item) {
195
$client = new User($item['user']);
196
$song = new Song($item['object_id']);
198
$amount = intval(time() - $item['date']+2);
200
while ($amount >= 1) {
203
if ($time_place <= 2) {
204
$amount = floor($amount/60);
206
if ($time_place == '3') {
207
$amount = floor($amount/24);
209
if ($time_place == '4') {
210
$amount = floor($amount/7);
212
if ($time_place == '5') {
213
$amount = floor($amount/4);
215
if ($time_place == '6') {
216
$amount = floor ($amount/12);
218
if ($time_place > '6') {
219
$final = $amount . '+';
224
$time_string = $final . ' ' . $time_unit[$time_place];
226
$xml_array = array('title'=>$song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album,
227
'link'=>str_replace('&', '&', $song->link),
228
'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string,
229
'comments'=>$client->username,
230
'pubDate'=>date("r",$item['date']));
231
$results[] = $xml_array;
237
} // load_recently_played
240
* pubdate_recently_played
241
* This just returns the 'newest' recently played entry
243
public static function pubdate_recently_played() {
245
$data = Song::get_recently_played();
247
$element = array_shift($data);
249
return $element['date'];
251
} // pubdate_recently_played
253
} // end Ampache_RSS class