diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index 218564d0879..665c86699be 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -1,25 +1,25 @@ title = get_string('feedstitle', 'block_rss_client'); diff --git a/blocks/rss_client/block_rss_client_action.php b/blocks/rss_client/block_rss_client_action.php index 0d68ceee269..e90ec05a527 100644 --- a/blocks/rss_client/block_rss_client_action.php +++ b/blocks/rss_client/block_rss_client_action.php @@ -1,7 +1,8 @@ libdir .'/rsslib.php'); - require_once(MAGPIE_DIR .'rss_fetch.inc'); +require_once('../../config.php'); +require_once($CFG->libdir .'/rsslib.php'); +require_once(MAGPIE_DIR .'rss_fetch.inc'); - require_login(); - global $USER; +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']; - } else { - $referrer = $CFG->wwwroot; - } - if (isguest()) { - error(get_string('noguestpost', 'forum'), $referrer); - } +//ensure that the logged in user is not using the guest account +if (isset($_SERVER['HTTP_REFERER'])) { + $referrer = $_SERVER['HTTP_REFERER']; +} else { + $referrer = $CFG->wwwroot; +} +if (isguest()) { + error(get_string('noguestpost', 'forum'), $referrer); +} - $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'); +$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 (!defined('MAGPIE_OUTPUT_ENCODING')) { + define('MAGPIE_OUTPUT_ENCODING', get_string('thischarset')); // see bug 3107 +} - 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); - } +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'); - if ( isadmin() ) { - $stradmin = get_string('administration'); - $strconfiguration = get_string('configuration'); - $navigation = "wwwroot/$CFG->admin/index.php\">$stradmin -> ". - "wwwroot/$CFG->admin/configure.php\">$strconfiguration -> $straddedit"; - } else if (!empty($course)) { - $navigation = "wwwroot/course/view.php?id=$id\">$course->shortname -> $straddedit"; - } else { - $navigation = $straddedit; - } +$straddedit = get_string('feedsaddedit', 'block_rss_client'); +if ( isadmin() ) { + $stradmin = get_string('administration'); + $strconfiguration = get_string('configuration'); + $navigation = "wwwroot/$CFG->admin/index.php\">$stradmin -> ". + "wwwroot/$CFG->admin/configure.php\">$strconfiguration -> $straddedit"; +} else if (!empty($course)) { + $navigation = "wwwroot/course/view.php?id=$id\">$course->shortname -> $straddedit"; +} else { + $navigation = $straddedit; +} - print_header(get_string('feedsaddedit', 'block_rss_client'), - get_string('feedsaddedit', 'block_rss_client'), - $navigation ); +print_header(get_string('feedsaddedit', 'block_rss_client'), + get_string('feedsaddedit', 'block_rss_client'), + $navigation ); - //check to make sure that the user is allowed to post new feeds - $submitters = $CFG->block_rss_client_submitters; - $isteacher = false; - if (!empty($course)) { - $isteacher = isteacher($id); - } +//check to make sure that the user is allowed to post new feeds +$submitters = $CFG->block_rss_client_submitters; +$isteacher = false; +if (!empty($course)) { + $isteacher = isteacher($id); +} - $rss_record = get_record('block_rss_client', 'id', $rssid); +$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) || - ( ($act == 'rss_edit' || $act == 'delfeed') && $USER->id == $rss_record->userid) ) ) { +//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) || + ( ($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($id); + rss_print_form($act, $url, $rssid, $preferredtitle, $id); + +} else if ($act == 'updfeed') { + if (empty($url)) { + error( 'url not defined for rss feed' ); } - if ($act == 'none') { - rss_display_feeds($id); - rss_print_form($act, $url, $rssid, $preferredtitle, $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. + $message = ''; + ob_start(); + $rss = fetch_rss($url); + if ($CFG->debug) { + $message .= ob_get_contents(); + } + ob_end_clean(); - } else if ($act == 'updfeed') { - if (empty($url)) { - error( 'url not defined for rss feed' ); - } + $dataobject->id = $rssid; + if ($rss === false) { + $dataobject->description = ''; + $dataobject->title = ''; + $dataobject->preferredtitle = ''; + } else { + $dataobject->description = addslashes(rss_unhtmlentities($rss->channel['description'])); + $dataobject->title = addslashes(rss_unhtmlentities($rss->channel['title'])); + $dataobject->preferredtitle = addslashes($preferredtitle); + } + $dataobject->url = addslashes($url); - // 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); - if ($CFG->debug) { - $message .= ob_get_contents(); - } - ob_end_clean(); + if (!update_record('block_rss_client', $dataobject)) { + error('There was an error trying to update rss feed with id:'. $rssid); + } + + $message .= '
'. get_string('feedupdated', 'block_rss_client'); + redirect($referrer, $message); + +} else if ($act == 'addfeed' ) { + + if (empty($url)) { + error('url not defined for rss feed'); + } + $dataobject->userid = $USER->id; + $dataobject->description = ''; + $dataobject->title = ''; + $dataobject->url = addslashes($url); + $dataobject->preferredtitle = addslashes($preferredtitle); + + $rssid = insert_record('block_rss_client', $dataobject); + if (!$rssid) { + error('There was an error trying to add a new rss feed:'. $url); + } + + // 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); + 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 + } else { $dataobject->id = $rssid; - if ($rss === false) { - $dataobject->description = ''; - $dataobject->title = ''; - $dataobject->preferredtitle = ''; - } else { + if (!empty($rss->channel['description'])) { $dataobject->description = addslashes(rss_unhtmlentities($rss->channel['description'])); - $dataobject->title = addslashes(rss_unhtmlentities($rss->channel['title'])); - $dataobject->preferredtitle = addslashes($preferredtitle); } - $dataobject->url = addslashes($url); - + if (!empty($rss->channel['title'])) { + $dataobject->title = addslashes(rss_unhtmlentities($rss->channel['title'])); + } if (!update_record('block_rss_client', $dataobject)) { error('There was an error trying to update rss feed with id:'. $rssid); } - - $message .= '
'. get_string('feedupdated', 'block_rss_client'); - redirect($referrer, $message); - - } else if ($act == 'addfeed' ) { - - if (empty($url)) { - error('url not defined for rss feed'); - } - $dataobject->userid = $USER->id; - $dataobject->description = ''; - $dataobject->title = ''; - $dataobject->url = addslashes($url); - $dataobject->preferredtitle = addslashes($preferredtitle); - - $rssid = insert_record('block_rss_client', $dataobject); - if (!$rssid) { - error('There was an error trying to add a new rss feed:'. $url); - } - - // 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); - 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 - } else { - - $dataobject->id = $rssid; - if (!empty($rss->channel['description'])) { - $dataobject->description = addslashes(rss_unhtmlentities($rss->channel['description'])); - } - if (!empty($rss->channel['title'])) { - $dataobject->title = addslashes(rss_unhtmlentities($rss->channel['title'])); - } - 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'); - } - redirect($referrer, $message); + $message .= '
'. get_string('feedadded', 'block_rss_client'); + } + redirect($referrer, $message); /* rss_display_feeds($id); rss_print_form($act, $dataobject->url, $dataobject->id, $dataobject->preferredtitle, $id); */ - } else if ( $act == 'rss_edit') { +} else if ( $act == 'rss_edit') { - $preferredtitle = stripslashes_safe($rss_record->preferredtitle); - if (empty($preferredtitle)) { - $preferredtitle = stripslashes_safe($rss_record->title); - } - $url = stripslashes_safe($rss_record->url); - rss_display_feeds($id, '', $rssid); - rss_print_form($act, $url, $rssid, $preferredtitle, $id); + $preferredtitle = stripslashes_safe($rss_record->preferredtitle); + if (empty($preferredtitle)) { + $preferredtitle = stripslashes_safe($rss_record->title); + } + $url = stripslashes_safe($rss_record->url); + rss_display_feeds($id, '', $rssid); + rss_print_form($act, $url, $rssid, $preferredtitle, $id); - } else if ($act == 'delfeed') { +} else if ($act == 'delfeed') { - $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml'; - if (file_exists($file)) { - unlink($file); - } - - // echo "DEBUG: act = delfeed"; //debug - //Daryl Hawes note: convert this sql statement to a moodle function call - $sql = 'DELETE FROM '. $CFG->prefix .'block_rss_client WHERE id='. $rssid; - $res= $db->Execute($sql); - - redirect($referrer, get_string('feeddeleted', 'block_rss_client') ); - - } else if ($act == 'view') { - // echo $sql; //debug - // print_object($res); //debug - if (!$rss_record->id) { - print ''. get_string('couldnotfindfeed', 'block_rss_client') .': '. $rssid .''; - } else { - // 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(); - $rss = fetch_rss($rss_record->url); - ob_end_clean(); - - if (empty($rss_record->preferredtitle)) { - $feedtitle = stripslashes_safe($rss_record->preferredtitle); - } else { - $feedtitle = stripslashes_safe(rss_unhtmlentities($rss->channel['title'])); - } - print ''."\n"; - print ''."\n"; - for($y=0; $y < count($rss->items); $y++) { - $rss->items[$y]['title'] = stripslashes_safe(rss_unhtmlentities($rss->items[$y]['title'])); - $rss->items[$y]['description'] = stripslashes_safe(rss_unhtmlentities($rss->items[$y]['description'])); - if ($rss->items[$y]['link'] == '') { - $rss->items[$y]['link'] = $rss->items[$y]['guid']; - } - - if ($rss->items[$y]['title'] == '') { - $rss->items[$y]['title'] = '>>'; - } - - print ''."\n"; - if (file_exists($CFG->dirroot .'/blog/lib.php')) { - //Blog module is installed - provide "blog this" link - print ''."\n"; - print ''."\n"; - } - print '
'. $feedtitle .'
'."\n"; - print ''. $rss->items[$y]['title']; - print ''."\n"; - print ''."\n"; - print ''. get_string('blogthis', 'blog').''."\n"; - print ''. get_string('blogthis', 'blog') .''."\n"; - } else { - print ' '; - } - print '
'; - print $rss->items[$y]['description'] .'
'."\n"; - } - } else { - rss_display_feeds($id); - rss_print_form($act, $url, $rssid, $preferredtitle, $id); + $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml'; + if (file_exists($file)) { + unlink($file); } - print_footer(); + // echo "DEBUG: act = delfeed"; //debug + //Daryl Hawes note: convert this sql statement to a moodle function call + $sql = 'DELETE FROM '. $CFG->prefix .'block_rss_client WHERE id='. $rssid; + $res= $db->Execute($sql); + + redirect($referrer, get_string('feeddeleted', 'block_rss_client') ); + +} else if ($act == 'view') { + // echo $sql; //debug + // print_object($res); //debug + if (!$rss_record->id) { + print ''. get_string('couldnotfindfeed', 'block_rss_client') .': '. $rssid .''; + } else { + // 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(); + $rss = fetch_rss($rss_record->url); + ob_end_clean(); + + if (empty($rss_record->preferredtitle)) { + $feedtitle = stripslashes_safe($rss_record->preferredtitle); + } else { + $feedtitle = stripslashes_safe(rss_unhtmlentities($rss->channel['title'])); + } + print ''."\n"; + print ''."\n"; + for($y=0; $y < count($rss->items); $y++) { + $rss->items[$y]['title'] = stripslashes_safe(rss_unhtmlentities($rss->items[$y]['title'])); + $rss->items[$y]['description'] = stripslashes_safe(rss_unhtmlentities($rss->items[$y]['description'])); + if ($rss->items[$y]['link'] == '') { + $rss->items[$y]['link'] = $rss->items[$y]['guid']; + } + + if ($rss->items[$y]['title'] == '') { + $rss->items[$y]['title'] = '>>'; + } + + print ''."\n"; + if (file_exists($CFG->dirroot .'/blog/lib.php')) { + //Blog module is installed - provide "blog this" link + print ''."\n"; + print ''."\n"; + } + print '
'. $feedtitle .'
'."\n"; + print ''. $rss->items[$y]['title']; + print ''."\n"; + print ''."\n"; + print ''. get_string('blogthis', 'blog').''."\n"; + print ''. get_string('blogthis', 'blog') .''."\n"; + } else { + print ' '; + } + print '
'; + print $rss->items[$y]['description'] .'
'."\n"; + } +} else { + rss_display_feeds($id); + rss_print_form($act, $url, $rssid, $preferredtitle, $id); +} + +print_footer(); ?> \ No newline at end of file