From a3e1bf7850a641f0c0c3f5b7d1a755edbb053a6c Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Tue, 10 Mar 2009 00:03:16 +0000 Subject: add video data to the API and add missing count="X" value to tag information --- lib/class/tag.class.php | 2 +- lib/class/video.class.php | 11 ++++++++++ lib/class/xmldata.class.php | 49 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 10 deletions(-) (limited to 'lib/class') diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index 2bc829d7..ae1582f8 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -510,7 +510,7 @@ class Tag extends database_object { */ public static function validate_type($type) { - $valid_array = array('song','artist','album'); + $valid_array = array('song','artist','album','video','playlist','live_stream'); if (in_array($type,$valid_array)) { return $type; } diff --git a/lib/class/video.class.php b/lib/class/video.class.php index 44c7ae4f..ee40e141 100644 --- a/lib/class/video.class.php +++ b/lib/class/video.class.php @@ -25,6 +25,7 @@ class Video extends database_object implements media { public $title; public $enabled; public $file; + public $size; /** * Constructor @@ -49,6 +50,16 @@ class Video extends database_object implements media { */ public static function build_cache($ids=array()) { + if (!is_array($ids) OR !count($ids)) { return false; } + + $idlist = '(' . implode(',',$ids) . ')'; + + $sql = "SELECT * FROM `video` WHERE `video`.`id` IN $idlist"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('video',$row['id'],$row); + } } // build_cache diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index e2a4ef2e..71554464 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -126,13 +126,14 @@ class xmlData { * tags_string * This returns the formated 'tags' string for an xml document */ - private static function tags_string($tags) { + private static function tags_string($tags,$type,$object_id) { $string = ''; foreach ($tags as $tag_id) { $tag = new Tag($tag_id); - $string .= "\tid\">name]]>\n"; + $tag->format($type,$object_id); + $string .= "\tid\" count=\"$tag->weight\">name]]>\n"; } return $string; @@ -188,7 +189,7 @@ class xmlData { $artist->format(); $rating = new Rating($artist_id,'artist'); - $tag_string = self::tags_string($artist->tags); + $tag_string = self::tags_string($artist->tags,'artist',$artist->id); $string .= "id\">\n" . "\tf_full_name]]>\n" . @@ -241,7 +242,7 @@ class xmlData { $string .= "\t$album->year\n" . "\t$album->song_count\n" . "\t$album->disk\n" . - self::tags_string($album->tags) . + self::tags_string($album->tags,'album',$album->id) . "\t\n" . "\t" . $rating->preciserating . "\n" . "\t" . $rating->rating . "\n" . @@ -314,11 +315,7 @@ class xmlData { $song->genre = $tag->id; $song->f_genre = $tag->name; - // Build up the tag's text - foreach ($song->tags as $tag_id) { - $tag = new Tag($tag_id); - $tag_string .= "\tid\">name]]>\n"; - } + $tag_string = self::tags_string($song->tags,'song',$song->id); $rating = new Rating($song_id,'song'); @@ -348,6 +345,40 @@ class xmlData { } // songs + /** + * videos + * This builds the xml document for displaying video objects + */ + public static function videos($videos) { + + if (count($videos) > self::$limit) { + $videos = array_slice($videos,self::$offset,self::$limit); + } + + $string = ''; + + foreach ($videos as $video_id) { + $video = new Video($video_id); + $video->format(); + + $string .= "\n"; + + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + + } // videos + /** * rss_feed */ -- cgit