From 8d914e47c9ecb0c99f63ba50936a09e2184eaf84 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Wed, 21 Nov 2007 06:53:20 +0000 Subject: additional xml methods songs & album_songs, also implemented catalog add speed improvement from Karl Hungus --- lib/class/catalog.class.php | 18 +++++++++++++----- lib/class/xmldata.class.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) (limited to 'lib/class') diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index a6dabbbe..76289677 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -380,6 +380,12 @@ class Catalog { Error::add('catalog_add',_('Error: Unable to open') . ' ' . $path); } + /* Change the dir so is_dir works correctly */ + if (!chdir($path)) { + debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); + Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); + } + /* Recurse through this dir and create the files array */ while ( false !== ( $file = readdir($handle) ) ) { @@ -388,11 +394,6 @@ class Catalog { debug_event('read',"Starting work on $file inside $path",'5','ampache-catalog'); - /* Change the dir so is_dir works correctly */ - if (!chdir($path)) { - debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); - Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); - } /* Create the new path */ $full_file = $path.$slash_type.$file; @@ -411,6 +412,13 @@ class Catalog { /* If it's a dir run this function again! */ if (is_dir($full_file)) { $this->add_files($full_file,$options); + + /* Change the dir so is_dir works correctly */ + if (!chdir($path)) { + debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); + Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); + } + /* Skip to the next file */ continue; } //it's a directory diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index ba1bec3f..d63d9bfc 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -165,6 +165,39 @@ class xmlData { } // genres + /** + * songs + * This returns an xml document from an array of song ids spiffy isn't it! + */ + public static function songs($songs) { + + if (count($songs) > self::$limit) { + $songs = array_slice($songs,0,self::$limit); + } + + // Foreach the ids! + foreach ($songs as $song_id) { + $song = new Song($song_id); + $song->format(); + + $string .= "id\">\n" . + "\t<![CDATA[$song->title]]>\n" . + "\tartist\">f_artist_full]]>\n" . + "\talbum\">f_album_full]]>\n" . + "\tgenre\">genre]]>\n" . + "\t$song->track\n" . + "\t\n" . + "\t\n" . + "\n"; + + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // songs + /** * _header * this returns a standard header, there are a few types -- cgit