Skip to content
Browse files

new instance config option to display feed's url if present

  • Loading branch information...
1 parent f51f486 commit 81610483fd2a5a4c7e9179556fa3abcd28712b85 dhawes committed Jan 29, 2005
Showing with 53 additions and 24 deletions.
  1. +27 −14 blocks/rss_client/block_rss_client.php
  2. +26 −10 blocks/rss_client/config_instance.html
View
41 blocks/rss_client/block_rss_client.php
@@ -1,5 +1,9 @@
<?php //$Id$
+// Developer's debug assistant - if true then the display string will not cache, only
+// the magpie object's built in caching will be used
+define('BLOCK_RSS_SECONDARY_CACHE_ENABLED', false);
+
class block_rss_client extends block_base {
function init() {
@@ -71,7 +75,7 @@ function get_content() {
$courseid = $this->instance->pageid;
}
- //if the user is an admin, course teacher, or all user are allowed -
+ //if the user is an admin, course teacher, or all users are allowed
// then allow the user to add rss feeds
if ( !isguest() && (isadmin() || $submitters == SUBMITTERS_ALL_ACCOUNT_HOLDERS || ($submitters == SUBMITTERS_ADMIN_AND_TEACHER && $isteacher)) ) {
$output .= '<div align="center"><a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?courseid='. $courseid .'">'. get_string('block_rss_feeds_add_edit', 'block_rss_client') .'</a></div><br />';
@@ -86,7 +90,7 @@ function get_content() {
foreach ($rssidarray as $rssid) {
$rssfeedstring = $this->get_rss_by_id($rssid, $display_description, $shownumentries, ($numids > 1) ? true : false);
$output .= format_text($rssfeedstring);
- if ($numids > 1 && $count != $numids -1) {
+ if ($numids > 1 && $count != $numids -1 && !empty($rssfeedstring)) {
$output .= '<hr width="80%" />';
}
$count ++;
@@ -124,9 +128,10 @@ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle
require_once(MAGPIE_DIR .'rss_fetch.inc');
// Check if there is a cached string which has not timed out.
- if (isset($this->config->{'rssid'. $rssid}) &&
- isset($this->config->{'rssid'. $rssid .'timestamp'}) &&
- $this->config->{'rssid'. $rssid .'timestamp'} >= $now - $CFG->block_rss_timeout * 60) {
+ if (BLOCK_RSS_SECONDARY_CACHE_ENABLED &&
+ isset($this->config->{'rssid'. $rssid}) &&
+ isset($this->config->{'rssid'. $rssid .'timestamp'}) &&
+ $this->config->{'rssid'. $rssid .'timestamp'} >= $now - $CFG->block_rss_timeout * 60) {
// If the cached string is not too stale
// use it rather than going any further
return stripslashes_safe($this->config->{'rssid'. $rssid});
@@ -138,17 +143,18 @@ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle
// 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.
- ob_start();
+
+ error_reporting(E_USER_NOTICE);
+ //ob_start();
$rss = fetch_rss($rss_record->url);
- $rsserror = ob_get_contents();
- ob_end_clean();
-
+ //$rsserror = ob_get_contents();
+ //ob_end_clean();
+
if ($rss === false) {
if ($CFG->debug && !empty($rsserror)) {
// There was a failure in loading the rss feed, print link to full error text
- print '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_error.php?error='. urlencode($rsserror) .'">Error loading a feed.</a><br />'; //Daryl Hawes note: localize this line
+ return '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_error.php?error='. urlencode($rsserror) .'">Error loading a feed.</a><br />'; //Daryl Hawes note: localize this line
}
- return;
}
if ($shownumentries > 0 && $shownumentries < count($rss->items) ) {
@@ -159,8 +165,15 @@ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle
$feedtitle = stripslashes_safe(rss_unhtmlentities($rss->channel['title']));
} else {
$feedtitle = stripslashes_safe($rss_record->preferredtitle);
- }
-
+ }
+// print_object($rss);
+ if (isset($this->config) &&
+ isset($this->config->block_rss_client_show_channel_image) &&
+ $this->config->block_rss_client_show_channel_image &&
+ isset($rss->image) && isset($rss->image['link']) && isset($rss->image['title']) && isset($rss->image['url']) ) {
+ $returnstring .= '<div class="rssclientimage"><a href="'. $rss->image['link'] .'"><img src="'. $rss->image['url'] .'" alt="'. $rss->image['title'] .'"/></a></div><br />';
+ }
+
if ($showtitle) {
$returnstring .= '<div class="rssclienttitle">'. $feedtitle .'</div><br /><br />';
}
@@ -169,6 +182,7 @@ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle
$item['title'] = stripslashes_safe(rss_unhtmlentities($item['title']));
$item['description'] = stripslashes_safe(rss_unhtmlentities($item['description']));
if ($item['title'] == '') {
+ // no title present, use portion of description
$item['title'] = substr(strip_tags($item['description']), 0, 20) . '...';
}
@@ -198,7 +212,6 @@ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle
if (!empty($feedtitle) and ($feedtitle != '<a href="'. $rss->channel['link'] .'"></a>')) {
$this->title = $feedtitle;
}
- $returnstring .= '<br />';
// store config setting for this rssid so we do not need to read from file each time
$this->config->{'rssid'. $rssid} = addslashes($returnstring);
View
36 blocks/rss_client/config_instance.html
@@ -1,7 +1,7 @@
<table cellpadding="9" cellspacing="0">
<tr valign="top">
<td align="right">
- <?php print_string('block_rss_display_description_label', 'block_rss_client') ?>
+ <p><?php print_string('block_rss_display_description_label', 'block_rss_client') ?></p>
</td>
<td>
<?php
@@ -20,7 +20,7 @@
</tr>
<tr valign="top">
<td align="right">
- <?php print_string('block_rss_shownumentries_label', 'block_rss_client') ?>
+ <p><?php print_string('block_rss_shownumentries_label', 'block_rss_client') ?></p>
</td>
<td>
<input name="shownumentries" type="text" size="5" value="<?php
@@ -38,7 +38,7 @@
</tr>
<tr valign="top">
<td align="right">
- <?php print_string('block_rss_choose_feed_label', 'block_rss_client') ?>
+ <p><?php print_string('block_rss_choose_feed_label', 'block_rss_client') ?></p>
</td>
<td>
<?php
@@ -55,9 +55,9 @@
if ($rssfeeds = get_records('block_rss_client')) {
foreach($rssfeeds as $rssfeed){
if (!empty($rssfeed->preferredtitle)) {
- $feedtitle = $rssfeed->preferredtitle;
+ $feedtitle = stripslashes_safe($rssfeed->preferredtitle);
} else {
- $feedtitle = $rssfeed->title;
+ $feedtitle = stripslashes_safe($rssfeed->title);
}
$feedoptions[$rssfeed->id] = $feedtitle;
}
@@ -90,7 +90,7 @@
</td>
</tr>
<tr valign="top">
- <td align="right"><p><?php print_string('uploadlabel'); ?></td>
+ <td align="right"><p><?php print_string('uploadlabel'); ?></p></td>
<?php
$title = '';
if (!empty($this->config) && !empty($this->config->title)) {
@@ -101,13 +101,13 @@
</td>
</tr>
<tr valign="top">
- <td align="right"><p><?php print_string('block_rss_client_show_channel_link_label', 'block_rss_client'); ?></td>
+ <td align="right"><p><?php print_string('block_rss_client_show_channel_link_label', 'block_rss_client'); ?></p></td>
<td>
- <?php if (isset($CFG->block_rss_client_show_channel_link)) {
- $selected = $CFG->block_rss_client_show_channel_link;
+ <?php
+ if (isset($this->config) && isset($this->config->block_rss_client_show_channel_link)) {
+ $selected = $this->config->block_rss_client_show_channel_link;
} else {
$selected = '0';
- $CFG->block_rss_client_show_channel_link = 0;
}
$options = array ( '0' => get_string('no'),
'1' => get_string('yes') );
@@ -116,6 +116,22 @@
?>
</td>
</tr>
+<tr valign="top">
+ <td align="right"><p><?php print_string('block_rss_client_show_image_label', 'block_rss_client'); ?></p></td>
+ <td>
+ <?php
+ if (isset($this->config) && isset($this->config->block_rss_client_show_channel_image)) {
+ $selected = $this->config->block_rss_client_show_channel_image;
+ } else {
+ $selected = '0';
+ }
+ $options = array ( '0' => get_string('no'),
+ '1' => get_string('yes') );
+
+ choose_from_menu ($options, 'block_rss_client_show_channel_image', $selected);
+ ?>
+ </td>
+</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="<?php print_string('savechanges') ?>">

0 comments on commit 8161048

Please sign in to comment.
Something went wrong with that request. Please try again.