Skip to content

Commit

Permalink
- removed simplexml from youtube block, now using another parsing lib…
Browse files Browse the repository at this point in the history
…rary
  • Loading branch information
luizlaydner committed Aug 13, 2007
1 parent b4191a3 commit d4c603d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 21 additions & 17 deletions blocks/tag_youtube/block_tag_youtube.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


require_once($CFG->dirroot.'/tag/lib.php'); require_once($CFG->dirroot.'/tag/lib.php');
require_once($CFG->libdir . '/magpie/rss_cache.inc'); require_once($CFG->libdir . '/magpie/rss_cache.inc');
require_once($CFG->libdir . '/phpxml/xml.php');


define('YOUTUBE_DEV_KEY', 'PGm8FdJXS8Q'); define('YOUTUBE_DEV_KEY', 'PGm8FdJXS8Q');
define('DEFAULT_NUMBER_OF_VIDEOS', 5); define('DEFAULT_NUMBER_OF_VIDEOS', 5);
Expand Down Expand Up @@ -115,21 +116,22 @@ function get_videos_by_tag_and_category(){
$request .= "&page=1"; $request .= "&page=1";
$request .= "&per_page={$numberofvideos}"; $request .= "&per_page={$numberofvideos}";


return $this->fetch_request($request); return $this->fetch_request($request);
} }


function fetch_request($request){ function fetch_request($request){

global $CFG; global $CFG;

$cache = new RSSCache($CFG->dataroot . '/cache',YOUTUBE_CACHE_EXPIRATION); $cache = new RSSCache($CFG->dataroot . '/cache',YOUTUBE_CACHE_EXPIRATION);
$cache_status = $cache->check_cache( $request); $cache_status = $cache->check_cache( $request);


if ( $cache_status == 'HIT' ) { if ( $cache_status == 'HIT' ) {
$cached_response = $cache->get( $request ); $cached_response = $cache->get( $request );


$simplexmlobj = new SimpleXMLElement($cached_response); $xmlobj = XML_unserialize($cached_response);
return $this->render_video_list($simplexmlobj); return $this->render_video_list($xmlobj);

} }


if ( $cache_status == 'STALE' ) { if ( $cache_status == 'STALE' ) {
Expand All @@ -142,30 +144,32 @@ function fetch_request($request){
$response = $cached_response; $response = $cached_response;
} }
else{ else{
$cache->set($request, $response); $cache->set($request, $response);
} }


$simplexmlobj = new SimpleXMLElement($response); $xmlobj = XML_unserialize($response);
return $this->render_video_list($simplexmlobj); return $this->render_video_list($xmlobj);
} }

function render_video_list($simplexmlobj){ function render_video_list($xmlobj){


$text = ''; $text = '';
$text .= '<table class="yt-video-entry">'; $text .= '<table class="yt-video-entry">';
foreach($simplexmlobj->video_list->video as $video){ $videos = $xmlobj['ut_response']['video_list']['video'];

foreach($videos as $video){
$text .= '<tr>'; $text .= '<tr>';
$text .= '<td>'; $text .= '<td>';
$text .= '<a href="'. $video->url . '">'; $text .= '<a href="'. $video['url'] . '">';
$text .= '<img class="youtube-thumb" title="'.$video->title.'" style="padding:3px;" src="' . $video->thumbnail_url . '"/>' ; $text .= '<img class="youtube-thumb" title="'.$video['title'].'" style="padding:3px;" src="' . $video['thumbnail_url'] . '"/>' ;
$text .= "</a>"; $text .= "</a>";
$text .= "</td>"; $text .= "</td>";
$text .= '<td>'; $text .= '<td>';
$text .= '<a href="'. $video->url . '">'.$video->title. '</a>'; $text .= '<a href="'. $video['url'] . '">'.$video['title']. '</a>';
$text .= '<br/>'; $text .= '<br/>';
$text .= format_time($video->length_seconds); $text .= format_time($video['length_seconds']);
$text .= '<br/>'; $text .= '<br/>';
$text .= 'views: ' . $video->view_count ; $text .= 'views: ' . $video['view_count'] ;
$text .= '</td>'; $text .= '</td>';
$text .= '</tr>'; $text .= '</tr>';
} }
Expand Down
2 changes: 1 addition & 1 deletion blocks/tag_youtube/config_instance.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
<td colspan="3" align="center"> <td colspan="3" align="center">
<input type="submit" value="<?php print_string('savechanges') ?>" /></td> <input type="submit" value="<?php print_string('savechanges') ?>" /></td>
</tr> </tr>
</table> </table>

0 comments on commit d4c603d

Please sign in to comment.