From: luizlaydner Date: Mon, 13 Aug 2007 04:05:55 +0000 (+0000) Subject: - removed simplexml from youtube block, now using another parsing library X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d4c603dbbdf392920e5a5ad5b8f9c9c1178da7af;p=moodle.git - removed simplexml from youtube block, now using another parsing library --- diff --git a/blocks/tag_youtube/block_tag_youtube.php b/blocks/tag_youtube/block_tag_youtube.php index 5061f30796..08110478b0 100644 --- a/blocks/tag_youtube/block_tag_youtube.php +++ b/blocks/tag_youtube/block_tag_youtube.php @@ -2,6 +2,7 @@ require_once($CFG->dirroot.'/tag/lib.php'); require_once($CFG->libdir . '/magpie/rss_cache.inc'); +require_once($CFG->libdir . '/phpxml/xml.php'); define('YOUTUBE_DEV_KEY', 'PGm8FdJXS8Q'); define('DEFAULT_NUMBER_OF_VIDEOS', 5); @@ -115,21 +116,22 @@ class block_tag_youtube extends block_base { $request .= "&page=1"; $request .= "&per_page={$numberofvideos}"; - return $this->fetch_request($request); + return $this->fetch_request($request); } - function fetch_request($request){ - + function fetch_request($request){ + global $CFG; - + $cache = new RSSCache($CFG->dataroot . '/cache',YOUTUBE_CACHE_EXPIRATION); $cache_status = $cache->check_cache( $request); if ( $cache_status == 'HIT' ) { $cached_response = $cache->get( $request ); - $simplexmlobj = new SimpleXMLElement($cached_response); - return $this->render_video_list($simplexmlobj); + $xmlobj = XML_unserialize($cached_response); + return $this->render_video_list($xmlobj); + } if ( $cache_status == 'STALE' ) { @@ -142,30 +144,32 @@ class block_tag_youtube extends block_base { $response = $cached_response; } else{ - $cache->set($request, $response); + $cache->set($request, $response); } - $simplexmlobj = new SimpleXMLElement($response); - return $this->render_video_list($simplexmlobj); + $xmlobj = XML_unserialize($response); + return $this->render_video_list($xmlobj); } - - function render_video_list($simplexmlobj){ + + function render_video_list($xmlobj){ $text = ''; $text .= ''; - foreach($simplexmlobj->video_list->video as $video){ + $videos = $xmlobj['ut_response']['video_list']['video']; + + foreach($videos as $video){ $text .= ''; $text .= '"; $text .= ''; $text .= ''; } diff --git a/blocks/tag_youtube/config_instance.html b/blocks/tag_youtube/config_instance.html index 174425c8df..cf5157f045 100644 --- a/blocks/tag_youtube/config_instance.html +++ b/blocks/tag_youtube/config_instance.html @@ -48,4 +48,4 @@ -
'; - $text .= ''; - $text .= '' ; + $text .= ''; + $text .= '' ; $text .= ""; $text .= "'; - $text .= ''.$video->title. ''; + $text .= ''.$video['title']. ''; $text .= '
'; - $text .= format_time($video->length_seconds); + $text .= format_time($video['length_seconds']); $text .= '
'; - $text .= 'views: ' . $video->view_count ; + $text .= 'views: ' . $video['view_count'] ; $text .= '
+ \ No newline at end of file