/** * getLovedSongs() * Gets user's loved songs. From cache file or from the feed. * * @return array $songs Returns formatted songs */ public static function getLovedSongs($username = '', $num_songs = 30) { if (!self::isValidUsername($username)) { return array(self::$error); } // Check Feeder and Cache classes are accessible if (!class_exists('Feeder')) { return array('Could not find Feeder.class.php.'); } if (!class_exists('Cache')) { return array('Could not find Cache.class.php.'); } self::$username = $username; self::$num_songs = $num_songs; $cache_filename = self::$username . '-loved-tracks.cache'; $cache_life = 86400; // 1 day Cache::init($cache_filename, $cache_life); if (Cache::cacheFileExists()) { return Cache::getCache(); } $song_data = Feeder::getItems(self::getLovedSongsFeed(), self::$num_songs, array('title', 'link')); if (!is_array($song_data)) { self::$error = "Last.fm loved tracks feed not found"; return array(self::$error); } $songs = self::formatSongData($song_data); Cache::setCache($songs); return $songs; }
/** * getBooksFromShelf() * Gets the array of books from a cache_file if found (and less than a week old). * If no cache_file is found it creates this array of books and adds them to the cache_file - for fast loading next time * * @return array Returns a nicely formatted array of books */ private static function getBooksFromShelf() { $cache_filename = self::$goodreads_id . '-' . self::$shelf . '.cache'; $cache_life = 604800; // 1 week Cache::init($cache_filename, $cache_life); if (Cache::cacheFileExists()) { return Cache::getCache(); } $book_data = Feeder::getItems(self::getGoodreadsFeed(), self::$num_books, array('title', 'author_name')); if (!is_array($book_data)) { self::$error = "Goodreads feed does not exist. Check user: "******" and shelf: '" . self::$shelf . "' exist"; return array(self::$error); } $books = self::formatBookData($book_data); Cache::setCache($books); return $books; }