should be fix for bug 3478

This commit is contained in:
dhawes 2005-08-01 14:02:46 +00:00
parent 6bcfd67887
commit d396889452
6 changed files with 61 additions and 45 deletions

View file

@ -3,6 +3,7 @@
/*******************************************************************
* 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
@ -11,6 +12,7 @@
/**
* 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
@ -103,11 +105,11 @@ class block_rss_client extends block_base {
$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>';
}
}

View file

@ -25,10 +25,10 @@
if (isguest()) {
error(get_string('noguestpost', 'forum'), $referrer);
}
$act = optional_param('act', 'none' );
$rssid = optional_param('rssid', 'none' );
$courseid = optional_param('courseid', SITEID, PARAM_INT);
$id = optional_param('id', SITEID, PARAM_INT);
$url = optional_param('url');
$preferredtitle = optional_param('preferredtitle', '');
$item = optional_param('item');
@ -37,8 +37,10 @@
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');
@ -48,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;
}
@ -61,18 +63,22 @@
$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) ) ) {
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, $courseid);
rss_display_feeds($id);
rss_print_form($act, $url, $rssid, $preferredtitle, $id);
} else if ($act == 'updfeed') {
if (empty($url)) {
@ -154,19 +160,18 @@
}
redirect($referrer, $message);
/*
rss_display_feeds();
rss_get_form($act, $dataobject->url, $dataobject->id, $dataobject->preferredtitle, $courseid);
rss_display_feeds($id);
rss_print_form($act, $dataobject->url, $dataobject->id, $dataobject->preferredtitle, $id);
*/
} 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, $courseid);
rss_display_feeds($id, '', $rssid);
rss_print_form($act, $url, $rssid, $preferredtitle, $id);
} else if ($act == 'delfeed') {
@ -185,7 +190,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 {
@ -233,8 +237,8 @@
print '</table>'."\n";
}
} else {
rss_display_feeds();
rss_get_form($act, $url, $rssid, $preferredtitle, $courseid);
rss_display_feeds($id);
rss_print_form($act, $url, $rssid, $preferredtitle, $id);
}
print_footer();

View file

@ -63,11 +63,11 @@
</tr>
<tr>
<td colspan="3" align="center"><a href=" <?php echo $CFG->wwwroot; ?>/blocks/rss_client/block_rss_client_action.php?courseid=<?php
if (!isset($courseid)) {
$courseid = '';
<td colspan="3" align="center"><a href=" <?php echo $CFG->wwwroot; ?>/blocks/rss_client/block_rss_client_action.php?id=<?php
if (!isset($id)) {
$id = '';
}
echo $courseid; ?>"><?php print_string('feedsaddedit', 'block_rss_client')?></a></center><br /><br />
echo $id; ?>"><?php print_string('feedsaddedit', 'block_rss_client')?></a></center><br /><br />
</td>
</tr>
</table>

View file

@ -1,7 +1,7 @@
<?php
require_once($CFG->libdir .'/rsslib.php');
$courseid = optional_param('courseid', SITEID, PARAM_INT);
$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);
@ -89,7 +89,7 @@ if ($currentaction == 'configblock') {
} else {
print_string('nofeeds', 'block_rss_client');
if ( isadmin() ) {
print '&nbsp;<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?courseid='. $courseid .'"> '. get_string('editnewsfeeds', 'block_rss_client') .'</a><br />';
print '&nbsp;<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $id .'"> '. get_string('editnewsfeeds', 'block_rss_client') .'</a><br />';
}
}
?>
@ -149,8 +149,8 @@ if ($currentaction == 'configblock') {
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, $courseid);
rss_print_form($act, $url, $rssid, $preferredtitle, $id);
print '</td></tr></table>';
} ?>

View file

@ -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 file

@ -344,10 +344,11 @@ define('SUBMITTERS_ADMIN_ONLY', 1);
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
@ -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));
@ -425,16 +427,20 @@ function rss_unhtmlentities($string) {
return strtr ($string, $trans_tbl);
}
/**
*/
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 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 bool $printnow True if the generated form should be printed out, false if the string should be returned from this function quietly
* @param int $courseid The course that is currently being viewed if applicable
* @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, $courseid=SITEID) {
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');
@ -442,53 +448,57 @@ function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $prin
$strupdatefeed = get_string('updatefeed', 'block_rss_client');
$straddfeed = get_string('addfeed', 'block_rss_client');
$returnstring = '<table align="center"><tbody><tr><td>'."\n";
$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;
}
$returnstring .= '" />'."\n";
$returnstring .= '" />'."\n";
$returnstring .= '<input type="hidden" name="act" value="';
if ($act == 'rss_edit') {
$returnstring .= 'updfeed';
} else {
$returnstring .= 'addfeed';
}
$returnstring .= '" />'."\n";
if ($act == 'rss_edit') {
$returnstring .= '<input type="hidden" name="rssid" value="'. $rssid .'" />'. "\n";
}
$returnstring .= '<input type="hidden" name="courseid" value="'. $courseid .'" />'."\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="';
$validatestring = "<a href=\"#\"
onClick=\"window.open('http://feedvalidator.org/check.cgi?url='+document.block_rss.elements['url'].value,'validate','width=640,height=480,scrollbars=yes,status=yes,resizable=yes');return true;\">". get_string('validatefeed', 'block_rss_client')."</a>";
if ($act == 'rss_edit') {
$returnstring .= $stredit;
} else {
$returnstring .= $stradd;
}
$returnstring .= '" />&nbsp;'. $validatestring .'</form>'."\n";
$returnstring .= '</td></tr></tbody></table>'."\n";
if ($printnow){
print $returnstring;
}
return $returnstring;
}
?>