diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-03-15 23:40:34 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-03-15 23:40:34 +0000 |
commit | cc36557ebd32a41a9b31d21611b5a1f731b96efa (patch) | |
tree | 7dfe8beb9a72a71edadc794a42edc7d55242e74e | |
parent | 62fa1b6da6139b3d8c77f10db75d8e6ead259310 (diff) | |
download | ampache-cc36557ebd32a41a9b31d21611b5a1f731b96efa.tar.gz ampache-cc36557ebd32a41a9b31d21611b5a1f731b96efa.tar.bz2 ampache-cc36557ebd32a41a9b31d21611b5a1f731b96efa.zip |
add in the democratic methods (untested)
-rwxr-xr-x | docs/CHANGELOG | 5 | ||||
-rw-r--r-- | lib/class/xmldata.class.php | 59 | ||||
-rw-r--r-- | server/xml.server.php | 36 | ||||
-rw-r--r-- | templates/show_democratic_playlist.inc.php | 2 |
4 files changed, 97 insertions, 5 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index de157c3b..a5409d26 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -3,7 +3,10 @@ -------------------------------------------------------------------------- -------------------------------------------------------------------------- - v.3.5-Alpha3 + v.3.5-Beta1 + - Add democratic methods to api, can now vote, devote, get url + and the current democratic playlist through the api + - Revert to old Random Play method - Added proxy use for xmlrpcclient - Added Configuration 'Wizard' for democratic play - Fixed interface feedback issues with democratic play actions diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index c25a5560..db704ad2 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -362,12 +362,12 @@ class xmlData { $video->format(); $string .= "<video id=\"$video->id\">\n" . - "\t<title><![CDATA[$video->title]]</title>\n" . - "\t<mime><![CDATA[$video->mime]]</mime>\n" . + "\t<title><![CDATA[$video->title]]></title>\n" . + "\t<mime><![CDATA[$video->mime]]></mime>\n" . "\t<resolution>$this->f_resolution</resolution>\n" . "\t<size>$this->size</size>\n" . self::tags_string($video->tags,'video',$video->id) . - "\t<url><![CDATA[" . Video::play_url($video->id) . "]]</url>\n" . + "\t<url><![CDATA[" . Video::play_url($video->id) . "]]></url>\n" . "</video>\n"; } // end foreach @@ -380,6 +380,59 @@ class xmlData { } // videos /** + * democratic + * This handles creating an xml document for democratic items, this can be a little complicated + * due to the votes and all of that + */ + public static function democratic($object_ids=array()) { + + if (!is_array($object_ids)) { $object_ids = array(); } + + $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_string = ''; + + $tag = new Tag($song->tags['0']); + $song->genre = $tag->id; + $song->f_genre = $tag->name; + + $tag_string = self::tags_string($song->tags,'song',$song->id); + + $rating = new Rating($song_id,'song'); + + $art_url = Album::get_art_url($song->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->preciserating . "</preciserating>\n" . + "\t<rating>" . $rating->rating . "</rating>\n" . + "\t<vote>" . $democratic->get_vote($row_id) . "</vote>\n" . + "</song>\n"; + + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // democratic + + /** * rss_feed */ public static function rss_feed($data,$title,$description,$date) { diff --git a/server/xml.server.php b/server/xml.server.php index 7f777f84..45570dda 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -355,9 +355,45 @@ switch ($_REQUEST['action']) { switch ($_REQUEST['method']) { case 'vote': + $type = 'song'; + $media = new $type($_REQUEST['oid']); + if (!$media->id) { + echo xmlData::error('400',_('Media Object Invalid or Not Specified')); + break; + } + Democratic::vote(array($media->id)); + + // If everything was ok + $xml_array = array('action'=>$_REQUEST['action'],'method'=>$_REQUEST['method'],'result'=>true); + echo xmlData::build_from_array($xml_array); + break; case 'devote': + $type = 'song'; + $media = new $type($_REQUEST['oid']); + if (!$media->id) { + echo xmlData::error('400',_('Media Object Invalid or Not Specified')); + } + + Democratic::remove_vote(array($media->id)); + + // Everything was ok + $xml_array = array('action'=>$_REQUEST['action'],'method'=>$_REQUEST['method'],'result'=>true); + echo xmlData::build_from_array($xml_array); + break; case 'playlist': + $objects = $democratic->get_items(); + Song::build_cache($democratic->object_ids); + Democratic::build_vote_cache($democratic->vote_ids); + xmlData::democratic($objects); + break; case 'play': + $url = $democratic->play_url(); + $xml_array = array('url'=>$url); + echo xmlData::build_from_array($xml_array); + break; + default: + echo xmlData::error('405',_('Invalid Request')); + break; } // switch on method diff --git a/templates/show_democratic_playlist.inc.php b/templates/show_democratic_playlist.inc.php index d19b0dba..dee57b8f 100644 --- a/templates/show_democratic_playlist.inc.php +++ b/templates/show_democratic_playlist.inc.php @@ -76,7 +76,7 @@ foreach($object_ids as $row_id=>$data) { <?php echo Ajax::button('?page=democratic&action=add_vote&object_id=' . $media->id . '&type=' . scrub_out($data['object_type']),'tick',_('Add Vote'),'remove_vote_' . $row_id); ?> <?php } ?> </td> - <td class="cel_votes" >(<?php echo scrub_out($democratic->get_vote($row_id)); ?>)</td> + <td class="cel_votes" ><?php echo scrub_out($democratic->get_vote($row_id)); ?></td> <td class="cel_title"><?php echo $media->f_link; ?></td> <td class="cel_album"><?php echo $media->f_album_link; ?></td> <td class="cel_artist"><?php echo $media->f_artist_link; ?></td> |