From 340f81987128bdbaf6cdfeafb0c00af0844fc155 Mon Sep 17 00:00:00 2001 From: dhawes Date: Tue, 28 Jun 2005 21:21:59 +0000 Subject: [PATCH] additional debug output when in debug mode --- blocks/rss_client/block_rss_client.php | 21 +++++++++- blocks/rss_client/block_rss_client_action.php | 40 ++++++++++++------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index 5d520791979..8783009479e 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -1,5 +1,18 @@ content = new stdClass; - $this->content->footer = ''; if (empty($this->instance)) { // We're being asked for content without an associated instance @@ -159,7 +171,6 @@ class block_rss_client extends block_base { $rss_record = get_record('block_rss_client', 'id', $rssid); if (isset($rss_record) && isset($rss_record->id)) { - // By capturing the output from fetch_rss this way // error messages do not display and clutter up the moodle interface // however, we do lose out on seeing helpful messages like "cache hit", etc. @@ -198,6 +209,12 @@ class block_rss_client extends block_base { $formatoptions->para = false; + // first we must verify that the rss feed is loaded + // by checking $rss and $rss->items exist before using them + if (empty($rss) || empty($rss->items)) { + return ''; + } + foreach ($rss->items as $item) { $item['title'] = stripslashes_safe(rss_unhtmlentities($item['title'])); $item['description'] = stripslashes_safe(rss_unhtmlentities($item['description'])); diff --git a/blocks/rss_client/block_rss_client_action.php b/blocks/rss_client/block_rss_client_action.php index 6382731dd32..f0bf3e6b896 100644 --- a/blocks/rss_client/block_rss_client_action.php +++ b/blocks/rss_client/block_rss_client_action.php @@ -1,12 +1,21 @@ libdir .'/rsslib.php'); require_once(MAGPIE_DIR .'rss_fetch.inc'); require_login(); global $USER; - + //ensure that the logged in user is not using the guest account if (isset($_SERVER['HTTP_REFERER'])) { $referrer = $_SERVER['HTTP_REFERER']; @@ -69,13 +78,16 @@ if (empty($url)) { error( 'url not defined for rss feed' ); } - + // By capturing the output from fetch_rss this way // error messages do not display and clutter up the moodle interface // however, we do lose out on seeing helpful messages like "cache hit", etc. + $message = ''; ob_start(); $rss = fetch_rss($url); - $rsserror = ob_get_contents(); + if ($CFG->debug) { + $message .= ob_get_contents(); + } ob_end_clean(); $dataobject->id = $rssid; @@ -94,10 +106,9 @@ error('There was an error trying to update rss feed with id:'. $rssid); } - redirect($referrer, get_string('feedupdated', 'block_rss_client')); -/* rss_display_feeds(); - rss_get_form($act, $dataobject->url, $rssid, $dataobject->preferredtitle); -*/ + $message .= '
'. get_string('feedupdated', 'block_rss_client'); + redirect($referrer, $message); + } else if ($act == 'addfeed' ) { if (empty($url)) { @@ -117,13 +128,16 @@ // By capturing the output from fetch_rss this way // error messages do not display and clutter up the moodle interface // however, we do lose out on seeing helpful messages like "cache hit", etc. + $message = ''; ob_start(); $rss = fetch_rss($url); - $rsserror = ob_get_contents(); + if ($CFG->debug) { + $message .= ob_get_contents(); + } ob_end_clean(); if ($rss === false) { - $message = 'There was an error loading this rss feed. You may want to verify the url you have specified before using it.'; //Daryl Hawes note: localize this line + $message .= '

There was an error loading this rss feed. You may want to verify the url you have specified before using it.'; //Daryl Hawes note: localize this line } else { $dataobject->id = $rssid; @@ -136,7 +150,7 @@ if (!update_record('block_rss_client', $dataobject)) { error('There was an error trying to update rss feed with id:'. $rssid); } - $message = get_string('feedadded', 'block_rss_client'); + $message .= '
'. get_string('feedadded', 'block_rss_client'); } redirect($referrer, $message); /* @@ -168,9 +182,6 @@ redirect($referrer, get_string('feeddeleted', 'block_rss_client') ); -/* rss_display_feeds(); - rss_get_form($act, $url, $rssid, $preferredtitle); -*/ } else if ($act == 'view') { // echo $sql; //debug // print_object($res); //debug @@ -183,7 +194,6 @@ // however, we do lose out on seeing helpful messages like "cache hit", etc. ob_start(); $rss = fetch_rss($rss_record->url); - $rsserror = ob_get_contents(); ob_end_clean(); if (empty($rss_record->preferredtitle)) { @@ -212,7 +222,7 @@ //Blog module is installed - provide "blog this" link print ''."\n"; print ''. get_string('blogthis', 'blog').''."\n"; - print ''. get_string('blogthis', 'blog') .''."\n"; + print ''. get_string('blogthis', 'blog') .''."\n"; } else { print ' '; }