| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php //$Id: block_rss_client_action.php,v 1.54.2.6 2008/06/08 18:29:51 dongsheng Exp $ 2 3 /******************************************************************* 4 * This file contains no classes. It will display a list of existing feeds 5 * defined for the site and allow add/edit/delete of site feeds. 6 * 7 * @author Daryl Hawes 8 * @version $Id: block_rss_client_action.php,v 1.54.2.6 2008/06/08 18:29:51 dongsheng Exp $ 9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 10 * @package base 11 ******************************************************************/ 12 13 require_once('../../config.php'); 14 require_once($CFG->libdir .'/rsslib.php'); 15 require_once(MAGPIE_DIR .'rss_fetch.inc'); 16 17 require_login(); 18 global $USER; 19 20 21 if (isset($_SERVER['HTTP_REFERER'])) { 22 $referrer = $_SERVER['HTTP_REFERER']; 23 } else { 24 $referrer = $CFG->wwwroot.'/'; 25 } 26 27 28 // Ensure that the logged in user is not using the guest account 29 if (isguest()) { 30 print_error('noguestpost', 'forum', $referrer); 31 } 32 33 34 $url = optional_param('url','',PARAM_URL); 35 36 if (!empty($url)) { 37 // attempting to replace feed and rss url types with http 38 // it appears that the rss feed validator will validate these url types but magpie will not load them $url = str_replace ("feed://", "http://", "$url"); 39 // Shifting this forward since PARAM_URL rejects these feed types as invalid entries! 40 $url = str_replace ("feed://", "http://", "$url"); 41 $url = str_replace ("FEED://", "http://", "$url"); 42 $url = str_replace ("rss://", "http://", "$url"); 43 $url = str_replace ("RSS://", "http://", "$url"); 44 } 45 46 $act = optional_param('act', NULL, PARAM_ALPHA); 47 $rssid = optional_param('rssid', NULL, PARAM_INT); 48 $id = optional_param('id', SITEID, PARAM_INT); 49 //$url = clean_param($url, PARAM_URL); 50 $preferredtitle = optional_param('preferredtitle', '', PARAM_TEXT); 51 $shared = optional_param('shared', 0, PARAM_INT); 52 53 54 if (!defined('MAGPIE_OUTPUT_ENCODING')) { 55 define('MAGPIE_OUTPUT_ENCODING', 'utf-8'); // see bug 3107 56 } 57 58 59 if (!empty($id)) { 60 // we get the complete $course object here because print_header assumes this is 61 // a complete object (needed for proper course theme settings) 62 if ($course = get_record('course', 'id', $id)) { 63 $context = get_context_instance(CONTEXT_COURSE, $id); 64 } 65 } else { 66 $context = get_context_instance(CONTEXT_SYSTEM); 67 } 68 69 70 $straddedit = get_string('feedsaddedit', 'block_rss_client'); 71 $link = $CFG->wwwroot.'/course/view.php?id='.$id; 72 if (empty($course)) { 73 $link = ''; 74 } 75 $navlinks = array(); 76 $navlinks = array(array('name' => get_string('administration'), 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc')); 77 $navlinks[] = array('name' => get_string('managemodules'), 'link' => null, 'type' => 'misc'); 78 $navlinks[] = array('name' => get_string('blocks'), 'link' => null, 'type' => 'misc'); 79 $navlinks[] = array('name' => get_string('feedstitle', 'block_rss_client'), 'link' => "$CFG->wwwroot/$CFG->admin/settings.php?section=blocksettingrss_client", 'type' => 'misc'); 80 $navlinks[] = array('name' => get_string('addnew', 'block_rss_client'), 'link' => null, 'type' => 'misc'); 81 $navigation = build_navigation($navlinks); 82 print_header($straddedit, $straddedit, $navigation); 83 84 85 if ( !isset($act) ) { 86 rss_display_feeds($id, $USER->id, '', $context); 87 rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context); 88 print_footer(); 89 die(); 90 } 91 92 if ( isset($rssid) ) { 93 $rss_record = get_record('block_rss_client', 'id', $rssid); 94 } 95 96 97 if (isset($rss_record)) { 98 $managefeeds = ($rss_record->userid == $USER->id && has_capability('block/rss_client:manageownfeeds', $context)) 99 || ($rss_record->userid != $USER->id && has_capability('block/rss_client:manageanyfeeds', $context)); 100 } 101 102 103 if ($act == 'updfeed') { 104 105 if (!$managefeeds) { 106 error(get_string('noguestpost', 'forum'). 107 ' You are not allowed to make modifications to this RSS feed at this time.', 108 $referrer); 109 //print_error('noguestpost', 'forum', $referrer, 'You are not allowed to make modifications to this RSS feed at this time.'); 110 } 111 112 113 if (empty($url)) { 114 error( 'URL not defined for rss feed' ); 115 } 116 117 // By capturing the output from fetch_rss this way 118 // error messages do not display and clutter up the moodle interface 119 // however, we do lose out on seeing helpful messages like "cache hit", etc. 120 $message = ''; 121 ob_start(); 122 $rss = fetch_rss($url); 123 if (debugging()) { 124 $message .= ob_get_contents(); 125 } 126 ob_end_clean(); 127 128 $canaddsharedfeeds = has_capability('block/rss_client:createsharedfeeds', $context); 129 130 $dataobject->id = $rssid; 131 if ($rss === false) { 132 $dataobject->description = ''; 133 $dataobject->title = ''; 134 $dataobject->preferredtitle = ''; 135 $dataobject->shared = 0; 136 } else { 137 $dataobject->description = addslashes($rss->channel['description']); 138 $dataobject->title = addslashes($rss->channel['title']); 139 $dataobject->preferredtitle = addslashes($preferredtitle); 140 if ($shared == 1 && $canaddsharedfeeds) { 141 $dataobject->shared = 1; 142 } else { 143 $dataobject->shared = 0; 144 } 145 } 146 $dataobject->url = addslashes($url); 147 148 if (!update_record('block_rss_client', $dataobject)) { 149 error('There was an error trying to update rss feed with id:'. $rssid); 150 } 151 152 $message .= '<br />'. get_string('feedupdated', 'block_rss_client'); 153 redirect($referrer, $message); 154 155 } else if ($act == 'addfeed' ) { 156 157 $canaddprivfeeds = has_capability('block/rss_client:createprivatefeeds', $context); 158 $canaddsharedfeeds = has_capability('block/rss_client:createsharedfeeds', $context); 159 160 if (!$canaddprivfeeds && !$canaddsharedfeeds) { 161 error('You do not have the permission to add RSS feeds'); 162 } 163 164 if (empty($url)) { 165 error('URL not defined for rss feed'); 166 } 167 $dataobject->userid = $USER->id; 168 $dataobject->description = ''; 169 $dataobject->title = ''; 170 $dataobject->url = addslashes($url); 171 $dataobject->preferredtitle = addslashes($preferredtitle); 172 173 if ($shared == 1 && $canaddsharedfeeds) { 174 $dataobject->shared = 1; 175 } else { 176 $dataobject->shared = 0; 177 } 178 179 $rssid = insert_record('block_rss_client', $dataobject); 180 if (!$rssid) { 181 error('There was an error trying to add a new rss feed:'. $url); 182 } 183 184 // By capturing the output from fetch_rss this way 185 // error messages do not display and clutter up the moodle interface 186 // however, we do lose out on seeing helpful messages like "cache hit", etc. 187 $message = ''; 188 ob_start(); 189 $rss = fetch_rss($url); 190 if (debugging()) { 191 $message .= ob_get_contents(); 192 } 193 ob_end_clean(); 194 195 if ($rss === false) { 196 $message .= '<br /><br />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 197 } else { 198 199 $dataobject->id = $rssid; 200 if (!empty($rss->channel['description'])) { 201 $dataobject->description = addslashes($rss->channel['description']); 202 } 203 if (!empty($rss->channel['title'])) { 204 $dataobject->title = addslashes($rss->channel['title']); 205 } 206 if (!update_record('block_rss_client', $dataobject)) { 207 error('There was an error trying to update rss feed with id:'. $rssid); 208 } 209 $message .= '<br />'. get_string('feedadded', 'block_rss_client'); 210 } 211 redirect($referrer, $message); 212 /* 213 rss_display_feeds($id, $USER->id, '', $context); 214 rss_print_form($act, $dataobject->url, $dataobject->id, $dataobject->preferredtitle, $shared, $id, $context); 215 */ 216 } else if ( isset($rss_record) && $act == 'rssedit' ) { 217 218 $preferredtitle = stripslashes_safe($rss_record->preferredtitle); 219 if (empty($preferredtitle)) { 220 $preferredtitle = stripslashes_safe($rss_record->title); 221 } 222 $url = stripslashes_safe($rss_record->url); 223 $shared = stripslashes_safe($rss_record->shared); 224 rss_display_feeds($id, $USER->id, $rssid, $context); 225 rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context); 226 227 } else if ($act == 'delfeed') { 228 229 if (!$managefeeds) { 230 error(get_string('noguestpost', 'forum'). 231 ' You are not allowed to make modifications to this RSS feed at this time.', 232 $referrer); 233 //print_error('noguestpost', 'forum', $referrer, 'You are not allowed to make modifications to this RSS feed at this time.'); 234 } 235 236 $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml'; 237 if (file_exists($file)) { 238 unlink($file); 239 } 240 241 // echo "DEBUG: act = delfeed"; //debug 242 delete_records('block_rss_client', 'id', $rssid); 243 244 redirect($referrer, get_string('feeddeleted', 'block_rss_client') ); 245 246 } else if ( isset($rss_record) && $act == 'view' ) { 247 // echo $sql; //debug 248 // print_object($res); //debug 249 if (!$rss_record->id) { 250 print '<strong>'. get_string('couldnotfindfeed', 'block_rss_client') .': '. $rssid .'</strong>'; 251 } else { 252 // By capturing the output from fetch_rss this way 253 // error messages do not display and clutter up the moodle interface 254 // however, we do lose out on seeing helpful messages like "cache hit", etc. 255 ob_start(); 256 $rss = fetch_rss($rss_record->url); 257 ob_end_clean(); 258 259 if (empty($rss_record->preferredtitle)) { 260 $feedtitle = $rss_record->preferredtitle; 261 } else { 262 $feedtitle = $rss->channel['title']; 263 } 264 print '<table align="center" width="50%" cellspacing="1">'."\n"; 265 print '<tr><td colspan="2"><strong>'. $feedtitle .'</strong></td></tr>'."\n"; 266 for($y=0; $y < count($rss->items); $y++) { 267 if ($rss->items[$y]['link'] == '') { 268 $rss->items[$y]['link'] = $rss->items[$y]['guid']; 269 } 270 271 if ($rss->items[$y]['title'] == '') { 272 $rss->items[$y]['title'] = '>>'; 273 } 274 275 print '<tr><td valign="middle">'."\n"; 276 print '<a href="'. $rss->items[$y]['link'] .'" target="_blank"><strong>'. $rss->items[$y]['title']; 277 print '</strong></a>'."\n"; 278 print '</td>'."\n"; 279 if (file_exists($CFG->dirroot .'/blog/lib.php')) { 280 //Blog module is installed - provide "blog this" link 281 print '<td align="right">'."\n"; 282 283 /// MDL-9291, blog this feature needs further discussion/implementation 284 /// temporarily disabling for now. 285 286 // print '<img src="'. $CFG->pixpath .'/blog/blog.gif" alt="'. get_string('blogthis', 'blog').'" title="'. get_string('blogthis', 'blog') .'" border="0" align="middle" />'."\n"; 287 //print '<a href="'. $CFG->wwwroot .'/blog/blogthis.php?userid='. $USER->id .'&act=use&item='. $y .'&rssid='. $rssid .'"><small><strong>'. get_string('blogthis', 'blog') .'</strong></small></a>'."\n"; 288 } else { 289 print '<td> '; 290 } 291 print '</td></tr>'."\n"; 292 print '<tr><td colspan=2><small>'; 293 print $rss->items[$y]['description'] .'</small></td></tr>'."\n"; 294 } 295 print '</table>'."\n"; 296 } 297 } else { 298 rss_display_feeds($id, $USER->id, '', $context); 299 rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context); 300 } 301 print_footer(); 302 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |