Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merging in fix for bug 3478

  • Loading branch information...
commit 40c61f1f0198a2dc8ca5e20efb6dc6b5a0b10d13 1 parent 14f03b6
dhawes authored
View
75 blocks/rss_client/block_rss_client.php
@@ -1,5 +1,20 @@
<?php //$Id$
+/*******************************************************************
+* This file contains one class which...
+*
+* @todo Finish documenting this file
+* @author Daryl Hawes
+* @version $Id$
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+* @package base
+******************************************************************/
+
+/**
+ * This class is for a block which....
+ * @todo Finish documenting this class
+ */
+
// 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', true);
@@ -36,11 +51,11 @@ function get_content() {
}
$this->content = new stdClass;
+ $this->content->text = '';
$this->content->footer = '';
if (empty($this->instance)) {
// We're being asked for content without an associated instance
- $this->content->text = '';
return $this->content;
}
@@ -90,11 +105,11 @@ function get_content() {
$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
if (isset($this->config)) {
// this instance is configured - show Add/Edit feeds link
- $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'managefeeds'));
+ $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $this->courseid));
$output .= '<div align="center"><a title="'. get_string('feedsaddedit', 'block_rss_client') .'" href="'. $script .'">'. get_string('feedsaddedit', 'block_rss_client') .'</a></div>';
} else {
// this instance has not been configured yet - show configure link
- $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'configblock'));
+ $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $this->courseid));
$output .= '<div align="center"><a title="'. get_string('feedsconfigurenewinstance', 'block_rss_client') .'" href="'. $script.'">'. get_string('feedsconfigurenewinstance', 'block_rss_client') .'</a></div>';
}
}
@@ -198,32 +213,36 @@ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle
$formatoptions->para = false;
- if(!empty($rss->items)) {
- foreach ($rss->items as $item) {
- $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) . '...';
- } else {
- $item['title'] = break_up_long_words($item['title'], 30);
- }
+ // 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 '';
+ }
- if ($item['link'] == '') {
- $item['link'] = $item['guid'];
- }
-
- $item['link'] = str_replace('&', '&amp;', $item['link']);
-
- $returnstring .= '<div class="link"><a href="'. $item['link'] .'" target="_blank">'. $item['title'] . '</a></div>' ."\n";
-
-
- if ($display_description && !empty($item['description'])) {
- $item['description'] = break_up_long_words($item['description'], 30);
- $returnstring .= '<div class="description">'.
- format_text($item['description'], FORMAT_MOODLE, $formatoptions, $this->courseid) .
- '</div>' ."\n";
- }
+ foreach ($rss->items as $item) {
+ $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) . '...';
+ } else {
+ $item['title'] = break_up_long_words($item['title'], 30);
+ }
+
+ if ($item['link'] == '') {
+ $item['link'] = $item['guid'];
+ }
+
+ $item['link'] = str_replace('&', '&amp;', $item['link']);
+
+ $returnstring .= '<div class="link"><a href="'. $item['link'] .'" target="_blank">'. $item['title'] . '</a></div>' ."\n";
+
+
+ if ($display_description && !empty($item['description'])) {
+ $item['description'] = break_up_long_words($item['description'], 30);
+ $returnstring .= '<div class="description">'.
+ format_text($item['description'], FORMAT_MOODLE, $formatoptions, $this->courseid) .
+ '</div>' ."\n";
}
}
View
81 blocks/rss_client/block_rss_client_action.php
@@ -1,5 +1,14 @@
<?php //$Id$
+/*******************************************************************
+* This file contains one class which...
+*
+* @author Daryl Hawes
+* @version $Id$
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+* @package base
+******************************************************************/
+
require_once('../../config.php');
require_once($CFG->libdir .'/rsslib.php');
require_once(MAGPIE_DIR .'rss_fetch.inc');
@@ -17,19 +26,21 @@
error(get_string('noguestpost', 'forum'), $referrer);
}
- optional_variable($act, 'none');
- optional_variable($rssid, 'none');
- $courseid = optional_param('courseid', 0, PARAM_INT);
- optional_variable($url);
- optional_variable($preferredtitle, '');
- optional_variable($item);
+ $act = optional_param('act', 'none' );
+ $rssid = optional_param('rssid', 'none' );
+ $id = optional_param('id', SITEID, PARAM_INT);
+ $url = optional_param('url');
+ $preferredtitle = optional_param('preferredtitle', '');
+ $item = optional_param('item');
if (!defined('MAGPIE_OUTPUT_ENCODING')) {
define('MAGPIE_OUTPUT_ENCODING', get_string('thischarset')); // see bug 3107
}
- if (!empty($courseid)) {
- $course = get_record('course', 'id', $courseid, '', '', '', '', 'shortname');
+ if (!empty($id)) {
+ // we get the complete $course object here because print_header assumes this is
+ // a complete object (needed for proper course theme settings)
+ $course = get_record('course', 'id', $id);
}
$straddedit = get_string('feedsaddedit', 'block_rss_client');
@@ -39,7 +50,7 @@
$navigation = "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradmin</a> -> ".
"<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $straddedit";
} else if (!empty($course)) {
- $navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> -> $straddedit";
+ $navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$id\">$course->shortname</a> -> $straddedit";
} else {
$navigation = $straddedit;
}
@@ -52,28 +63,37 @@
$submitters = $CFG->block_rss_client_submitters;
$isteacher = false;
if (!empty($course)) {
- $isteacher = isteacher($course->id);
+ $isteacher = isteacher($id);
}
+ $rss_record = get_record('block_rss_client', 'id', $rssid);
+
//if the user is an admin or course teacher then allow the user to
//assign categories to other uses than personal
- if (!( isadmin() || $submitters == SUBMITTERS_ALL_ACCOUNT_HOLDERS || ($submitters == SUBMITTERS_ADMIN_AND_TEACHER && $isteacher) ) ) {
- error(get_string('noguestpost', 'forum'), $referrer);
+ if (!( isadmin() || $submitters == SUBMITTERS_ALL_ACCOUNT_HOLDERS ||
+ ($submitters == SUBMITTERS_ADMIN_AND_TEACHER && $isteacher) ||
+ ( ($act == 'rss_edit' || $act == 'delfeed') && $USER->id == $rss_record->userid) ) ) {
+ error(get_string('noguestpost', 'forum').' You are not allowed to make modifications to this RSS feed at this time.', $referrer);
}
if ($act == 'none') {
- rss_display_feeds();
- rss_get_form($act, $url, $rssid, $preferredtitle);
+ rss_display_feeds($id);
+ rss_print_form($act, $url, $rssid, $preferredtitle, $id);
} else if ($act == 'updfeed') {
- require_variable($url);
+ 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;
@@ -92,13 +112,14 @@
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 .= '<br />'. get_string('feedupdated', 'block_rss_client');
+ redirect($referrer, $message);
+
} else if ($act == 'addfeed' ) {
- require_variable($url);
+ if (empty($url)) {
+ error('url not defined for rss feed');
+ }
$dataobject->userid = $USER->id;
$dataobject->description = '';
$dataobject->title = '';
@@ -113,9 +134,12 @@
// 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) {
@@ -132,7 +156,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 .= '<br />'. get_string('feedadded', 'block_rss_client');
}
redirect($referrer, $message);
/*
@@ -141,14 +165,13 @@
*/
} else if ( $act == 'rss_edit') {
- $rss_record = get_record('block_rss_client', 'id', $rssid);
$preferredtitle = stripslashes_safe($rss_record->preferredtitle);
if (empty($preferredtitle)) {
$preferredtitle = stripslashes_safe($rss_record->title);
}
$url = stripslashes_safe($rss_record->url);
- rss_display_feeds('', $rssid);
- rss_get_form($act, $url, $rssid, $preferredtitle);
+ rss_display_feeds($id, '', $rssid);
+ rss_print_form($act, $url, $rssid, $preferredtitle, $id);
} else if ($act == 'delfeed') {
@@ -170,7 +193,6 @@
} else if ($act == 'view') {
// echo $sql; //debug
// print_object($res); //debug
- $rss_record = get_record('block_rss_client', 'id', $rssid);
if (!$rss_record->id) {
print '<strong>'. get_string('couldnotfindfeed', 'block_rss_client') .': '. $rssid .'</strong>';
} else {
@@ -179,7 +201,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)) {
@@ -219,8 +240,8 @@
print '</table>'."\n";
}
} else {
- rss_display_feeds();
- rss_get_form($act, $url, $rssid, $preferredtitle);
+ rss_display_feeds($id);
+ rss_print_form($act, $url, $rssid, $preferredtitle, $id);
}
print_footer();
View
2  blocks/rss_client/block_rss_client_error.php
@@ -2,7 +2,7 @@
require_once('../../config.php');
- require_variable($error);
+ $error = required_param('error',PARAM_CLEAN);
print_header(get_string('error'),
get_string('error'),
View
8 blocks/rss_client/config_instance.html
@@ -1,11 +1,13 @@
<?php
require_once($CFG->libdir .'/rsslib.php');
+$id = optional_param('id', SITEID, PARAM_INT);
+
//create a page object for url_get_full()
$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
/// Print tabs at top
-global $currentaction;
+$currentaction = optional_param( 'currentaction','',PARAM_ALPHA );
if (empty($currentaction) || $currentaction == 'configblock') {
$currentaction = 'configblock';
} else {
@@ -147,8 +149,8 @@
global $act, $url, $rssid, $preferredtitle;
print '<table cellpadding="9" cellspacing="0" class="blockconfigtable">';
print '<tr valign="top"><td>';
- rss_display_feeds();
+ rss_display_feeds($id);
print '</form>'; //not sure that this is needed
- rss_get_form($act, $url, $rssid, $preferredtitle);
+ rss_print_form($act, $url, $rssid, $preferredtitle, $id);
print '</td></tr></table>';
} ?>
View
4 blocks/rss_client/config_instance_tabs.php
@@ -5,11 +5,11 @@
global $USER;
$tabs = $row = array();
- $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'configblock'));
+ $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $id));
$row[] = new tabobject('configblock', $script,
get_string('configblock', 'block_rss_client'));
- $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'managefeeds'));
+ $script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id));
$row[] = new tabobject('managefeeds', $script,
get_string('managefeeds', 'block_rss_client'));
View
41 lib/rsslib.php
@@ -344,10 +344,11 @@ function rss_full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) {
define('SUBMITTERS_ADMIN_AND_TEACHER', 2);
/**
+ * @param int $courseid The id of the course the user is currently viewing
* @param int $userid If present only entries added by this userid will be displayed
* @param int $rssid If present the rss entry matching this id alone will be displayed
*/
-function rss_display_feeds($userid='', $rssid='') {
+function rss_display_feeds($courseid='', $userid='', $rssid='') {
global $db, $USER, $CFG;
global $blogid; //hackish, but if there is a blogid it would be good to preserve it
@@ -356,12 +357,12 @@ function rss_display_feeds($userid='', $rssid='') {
$select = '';
if (!isadmin()) {
- $userid = $USER->id;
+ $userid = $USER->id;
}
if ($userid != '' && is_numeric($userid)) {
- // if a user is specified and not an admin then only show their own feeds
- $select = 'userid='. $userid;
+ // if a user is specified and not an admin then only show their own feeds
+ $select = 'userid='. $userid;
} else if ($rssid != ''){
$select = 'id='. $rssid;
}
@@ -392,17 +393,18 @@ function rss_display_feeds($userid='', $rssid='') {
if ($feed->userid == $USER->id || isadmin()) {
- $feedicons = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=rss_edit&amp;rssid='. $feed->id .'&blogid='. $blogid .'">'.
+ $feedicons = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $courseid .'&amp;act=rss_edit&amp;rssid='. $feed->id .'&blogid='. $blogid .'">'.
'<img src="'. $CFG->pixpath .'/t/edit.gif" alt="'. get_string('edit').'" title="'. get_string('edit') .'" /></a>&nbsp;'.
- '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=delfeed&amp;rssid='. $feed->id.'&amp;blogid='. $blogid .'" onclick="return confirm(\''. get_string('deletefeedconfirm', 'block_rss_client') .'\');">'.
+ '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $courseid .'&amp;act=delfeed&amp;rssid='. $feed->id.'&amp;blogid='. $blogid .'"
+ onclick="return confirm(\''. get_string('deletefeedconfirm', 'block_rss_client') .'\');">'.
'<img src="'. $CFG->pixpath .'/t/delete.gif" alt="'. get_string('delete').'" title="'. get_string('delete') .'" /></a>';
}
else {
$feedicons = '';
}
- $feedinfo = '<div class="title"><a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=view&rssid='.$feed->id .'&blogid='. $blogid .'">'
+ $feedinfo = '<div class="title"><a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $courseid .'&amp;act=view&rssid='.$feed->id .'&blogid='. $blogid .'">'
.$feedtitle .'</a></div><div class="url"><a href="'. $feed->url .'">'. $feed->url .'</a></div><div class="description">'.$feed->description.'</div>';
$table->add_data(array($feedinfo, $feedicons));
@@ -426,13 +428,19 @@ function rss_unhtmlentities($string) {
}
/**
+*/
+function rss_print_form($act='none', $url='', $rssid='', $preferredtitle='', $courseid='') {
+ print rss_get_form($act, $url, $rssid, $preferredtitle, $courseid);
+}
+/**
* Prints or returns a form for managing rss feed entries.
- * @param string $act .
- * @param string $url .
- * @param int $rssid .
- * @param bool $printnow True if the generated form should be printed out, false if the string should be returned from this function quietly
+ * @param string $act The current action. If "rss_edit" then and "update" button is used, otherwise "add" is used.
+ * @param string $url The url of the feed that is being updated or NULL
+ * @param int $rssid The dataabse id of the feed that is being updated or NULL
+ * @param int $id The id of the course that is currently being viewed if applicable
+ * @return string Either the form is printed directly and nothing is returned or the form is returned as a string
*/
-function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $printnow=true) {
+function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $courseid='') {
global $USER, $CFG, $_SERVER, $blockid, $blockaction;
global $blogid; //hackish, but if there is a blogid it would be good to preserve it
$stredit = get_string('edit');
@@ -441,20 +449,23 @@ function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $prin
$straddfeed = get_string('addfeed', 'block_rss_client');
$returnstring = '<table align="center"><tbody><tr><td>'."\n";
-
$returnstring .= '<form action="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php" method="POST" name="block_rss">'."\n";
+
if ($act == 'rss_edit') {
$returnstring .= $strupdatefeed;
} else {
$returnstring .= $straddfeed;
}
+
$returnstring .= "\n".'<br /><input type="text" size="60" maxlength="256" name="url" value="';
if ($act == 'rss_edit') {
$returnstring .= $url;
}
+
$returnstring .= '" />'."\n";
$returnstring .= '<br />'. get_string('customtitlelabel', 'block_rss_client');
$returnstring .= '<br /><input type="text" size="60" maxlength="64" name="preferredtitle" value="';
+
if ($act == 'rss_edit') {
$returnstring .= $preferredtitle;
}
@@ -470,6 +481,8 @@ function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $prin
if ($act == 'rss_edit') {
$returnstring .= '<input type="hidden" name="rssid" value="'. $rssid .'" />'. "\n";
}
+
+ $returnstring .= '<input type="hidden" name="id" value="'. $courseid .'" />'."\n";
$returnstring .= '<input type="hidden" name="blogid" value="'. $blogid .'" />'."\n";
$returnstring .= '<input type="hidden" name="user" value="'. $USER->id .'" />'."\n";
$returnstring .= '<br /><input type="submit" value="';
@@ -488,4 +501,4 @@ function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $prin
}
return $returnstring;
}
-?>
+?>

0 comments on commit 40c61f1

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