RSS and Atom now handled by latest version of magpierss (magpierss.sourceforge.com...
[moodle.git] / rss / rsslib.php
CommitLineData
b2ddd9d7 1<?php // $Id$
8adcb49f 2 // This file contains all the common stuff to be used in RSS System
3
65f1df62 4//This function returns the icon (from theme) with the link to rss/file.php
bab450a0 5function rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext='') {
8adcb49f 6
7 global $CFG, $THEME, $USER;
8
9 static $pixpath = '';
10 static $rsspath = '';
11
b2ddd9d7 12 //In site course, if no logged (userid), use admin->id. Bug 2048.
13 if ($courseid == SITEID and empty($userid)) {
14 $admin = get_admin();
15 $userid = $admin->id;
16 }
17
8adcb49f 18 if ($CFG->slasharguments) {
19 $rsspath = "$CFG->wwwroot/rss/file.php/$courseid/$userid/$modulename/$id/rss.xml";
20 } else {
21 $rsspath = "$CFG->wwwroot/rss/file.php?file=/$courseid/$userid/$modulename/$id/rss.xml";
22 }
23
24 if (empty($pixpath)) {
25 if (empty($THEME->custompix)) {
bab450a0 26 $pixpath = $CFG->wwwroot .'/pix';
8adcb49f 27 } else {
bab450a0 28 $pixpath = $CFG->wwwroot .'/theme/'. $CFG->theme .'/pix';
8adcb49f 29 }
30 }
31
bab450a0 32 $rsspix = $pixpath .'/i/rss.gif';
8adcb49f 33
bab450a0 34 return '<a href="'. $rsspath .'"><img src="'. $rsspix .'" title="'. $tooltiptext .'" alt="" /></a>';
8adcb49f 35
36}
37
65f1df62 38//This function prints the icon (from theme) with the link to rss/file.php
bab450a0 39function rss_print_link($courseid, $userid, $modulename, $id, $tooltiptext='') {
65f1df62 40
41 echo rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext);
42
43}
8adcb49f 44//This function iterates over each module in the server to see if
45//it supports generating rss feeds, searching for a MODULENAME_rss_feeds()
46//function and invoking it foreach activity as necessary
47function cron_rss_feeds () {
48
49 global $CFG;
50
51 $status = true;
52
bab450a0 53 mtrace(' Generating rssfeeds...');
8adcb49f 54
2f29ee13 55 //Check for required functions...
56 if(!function_exists('utf8_encode')) {
bab450a0 57 mtrace(' ERROR: You need to add XML support to your PHP installation!');
2f29ee13 58 return true;
59 }
60
bab450a0 61 if ($allmods = get_records('modules') ) {
8adcb49f 62 foreach ($allmods as $mod) {
b65a50e5 63 mtrace(' '.$mod->name.': ', '');
8adcb49f 64 $modname = $mod->name;
65 $modfile = "$CFG->dirroot/mod/$modname/rsslib.php";
66 //If file exists and we have selected to restore that type of module
67 if (file_exists($modfile)) {
68 include_once($modfile);
69 $generaterssfeeds = $modname.'_rss_feeds';
70 if (function_exists($generaterssfeeds)) {
71 if ($status) {
b65a50e5 72 mtrace('generating ', '');;
8adcb49f 73 $status = $generaterssfeeds();
74 if (!empty($status)) {
bab450a0 75 mtrace('...OK');
8adcb49f 76 } else {
bab450a0 77 mtrace('...FAILED');
8adcb49f 78 }
79 } else {
bab450a0 80 mtrace('...SKIPPED (failed above)');
8adcb49f 81 }
82 } else {
bab450a0 83 mtrace('...NOT SUPPORTED (function)');
8adcb49f 84 }
85 } else {
bab450a0 86 mtrace('...NOT SUPPORTED (file)');
8adcb49f 87 }
88 }
89 }
bab450a0 90 mtrace(' Ending rssfeeds...', '');
8adcb49f 91 if (!empty($status)) {
bab450a0 92 mtrace('...OK');
8adcb49f 93 } else {
bab450a0 94 mtrace('...FAILED');
8adcb49f 95 }
96
97 return $status;
98}
99
100//This function saves to file the rss feed specified in the parameters
bab450a0 101function rss_save_file ($modname, $mod, $result) {
8adcb49f 102
103 global $CFG;
104
105 $status = true;
106
bab450a0 107 if (! $basedir = make_upload_directory ('rss/'. $modname)) {
bc706aeb 108 //Cannot be created, so error
109 $status = false;
110 }
8adcb49f 111
112 if ($status) {
6069e206 113 $file = rss_file_name($modname, $mod);
bab450a0 114 $rss_file = fopen($file, "w");
8adcb49f 115 if ($rss_file) {
bab450a0 116 $status = fwrite ($rss_file, $result);
8adcb49f 117 fclose($rss_file);
bc706aeb 118 } else {
119 $status = false;
8adcb49f 120 }
121 }
122 return $status;
123}
124
6069e206 125
126function rss_file_name($modname, $mod) {
127 global $CFG;
128
129 return "$CFG->dataroot/rss/$modname/$mod->id.xml";
130}
131
8adcb49f 132//This function return all the common headers for every rss feed in the site
133function rss_standard_header($title = NULL, $link = NULL, $description = NULL) {
134
1adf511c 135 global $CFG, $THEME, $USER;
8adcb49f 136
137 static $pixpath = '';
138
139 $status = true;
140 $result = "";
141
142 if (!$site = get_site()) {
143 $status = false;
144 }
145
146 if ($status) {
147
148 //Calculate title, link and description
149 if (empty($title)) {
150 $title = $site->fullname;
151 }
152 if (empty($link)) {
153 $link = $CFG->wwwroot;
154 }
155 if (empty($description)) {
156 $description = $site->summary;
157 }
158
159 //xml headers
160 $result .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
161 $result .= "<rss version=\"2.0\">\n";
162
163 //open the channel
164 $result .= rss_start_tag("channel",1,true);
165
166 //write channel info
167 $result .= rss_full_tag("title",2,false,$title);
168 $result .= rss_full_tag("link",2,false,$link);
169 $result .= rss_full_tag("description",2,false,$description);
ec6dc3f6 170 if (!empty($USER->lang)) {
171 $result .= rss_full_tag("language",2,false,substr($USER->lang,0,2));
172 }
8adcb49f 173 $today = getdate();
174 $result .= rss_full_tag("copyright",2,false,"&copy; ".$today['year']." ".$site->fullname);
ec6dc3f6 175 if (!empty($USER->email)) {
176 $result .= rss_full_tag("managingEditor",2,false,$USER->email);
177 $result .= rss_full_tag("webMaster",2,false,$USER->email);
178 }
8adcb49f 179
180 //write image info
181 //Calculate the origin
182 if (empty($pixpath)) {
183 if (empty($THEME->custompix)) {
184 $pixpath = "$CFG->wwwroot/pix";
185 } else {
186 $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
187 }
188 }
189 $rsspix = $pixpath."/i/rsssitelogo.gif";
190
191 //write the info
192 $result .= rss_start_tag("image",2,true);
193 $result .= rss_full_tag("url",3,false,$rsspix);
194 $result .= rss_full_tag("title",3,false,"moodle");
195 $result .= rss_full_tag("link",3,false,$CFG->wwwroot);
196 $result .= rss_full_tag("width",3,false,"140");
197 $result .= rss_full_tag("height",3,false,"35");
198 $result .= rss_end_tag("image",2,true);
199 }
200
201 if (!$status) {
202 return false;
203 } else {
204 return $result;
205 }
206}
207
208//This function returns the rss XML code for every item passed in the array
209//item->title: The title of the item
ca87cbe1 210//item->author: The author of the item. Optional !!
8adcb49f 211//item->pubdate: The pubdate of the item
212//item->link: The link url of the item
213//item->description: The content of the item
214function rss_add_items($items) {
215
216 global $CFG;
217
218 $result = "";
219
220 if (!empty($items)) {
221 foreach ($items as $item) {
222 $result .= rss_start_tag("item",2,true);
223 $result .= rss_full_tag("title",3,false,$item->title);
224 $result .= rss_full_tag("link",3,false,$item->link);
225 $result .= rss_full_tag("pubDate",3,false,date("r",$item->pubdate));
ca87cbe1 226 //Include the author if exists
227 if (isset($item->author)) {
228 $item->description = get_string("byname","",$item->author)."<p>".$item->description;
229 }
8adcb49f 230 $result .= rss_full_tag("description",3,false,$item->description);
231 $result .= rss_end_tag("item",2,true);
232
233 }
234 } else {
235 $result = false;
236 }
237 return $result;
238}
239
240//This function return all the common footers for every rss feed in the site
241function rss_standard_footer($title = NULL, $link = NULL, $description = NULL) {
242
243 global $CFG, $USER;
244
245 $status = true;
246 $result = "";
247
248 //Close the chanel
249 $result .= rss_end_tag("channel",1,true);
250 ////Close the rss tag
251 $result .= "</rss>";
252
253 return $result;
254}
255
ec6dc3f6 256//This function return an error xml file (string)
257//to be sent when a rss is required (file.php)
258//and something goes wrong
259function rss_geterrorxmlfile() {
260
261 global $CFG;
262
263 $return = '';
264
265 //XML Header
266 $return = rss_standard_header();
267
268 //XML item
269 if ($return) {
270 $item->title = "RSS Error";
271 $item->link = $CFG->wwwroot;
272 $item->pubdate = time();
273 $item->description = get_string("rsserror");
274 $return .= rss_add_items(array($item));
275 }
276
277 //XML Footer
278 if ($return) {
279 $return .= rss_standard_footer();
280 }
281
282 return $return;
283}
284
8adcb49f 285// ===== This function are used to write XML tags =========
286// [stronk7]: They are similar to the glossary export and backup generation
287// but I've replicated them here because they have some minor
288// diferences. Someday all they should go to a common place.
289
290//Return the xml start tag
291function rss_start_tag($tag,$level=0,$endline=false) {
292 if ($endline) {
293 $endchar = "\n";
294 } else {
295 $endchar = "";
296 }
297 return str_repeat(" ",$level*2)."<".$tag.">".$endchar;
298}
299
300//Return the xml end tag
301function rss_end_tag($tag,$level=0,$endline=true) {
302 if ($endline) {
303 $endchar = "\n";
304 } else {
305 $endchar = "";
306 }
307 return str_repeat(" ",$level*2)."</".$tag.">".$endchar;
308}
309
310//Return the start tag, the contents and the end tag
311function rss_full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) {
312 //Here we encode absolute links
313 $st = rss_start_tag($tag,$level,$endline);
314 $co="";
315 if ($to_utf) {
316 $co = preg_replace("/\r\n|\r/", "\n", utf8_encode(htmlspecialchars($content)));
317 } else {
318 $co = preg_replace("/\r\n|\r/", "\n", htmlspecialchars($content));
319 }
320 $et = rss_end_tag($tag,0,true);
321 return $st.$co.$et;
322}
323
e8181a56 324//////////////////// LIBRARY FUNCTIONS FOR RSS_CLIENT BLOCK ////////////////
325
326//initialize config vars for rss_client block if missing
327if (empty($CFG->block_rss_client_submitters) ) {
328 $CFG->block_rss_client_submitters = 1; //default to admin only
329}
330if (empty($CFG->block_rss_client_num_entries) ) {
331 $CFG->block_rss_client_num_entries = 5; //default to 5 entries per block
332}
333if (empty($CFG->block_rss_timeout) ) {
334 $CFG->block_rss_timeout = 30;
335}
336
337/**
79dd93a9 338 * Determine by rss id if the raw xml is cached on the file system
339 * @param int $rssid The id of this feed in the rss table
340 * @return bool False if cache file is missing or expired
e8181a56 341 */
79dd93a9 342function rss_cache_valid_by_id($rssid) {
e8181a56 343 global $CFG;
e8181a56 344 $secs = $CFG->block_rss_timeout * 60;
79dd93a9 345
e8181a56 346 // If moodle dataroot cache folder is missing create it
347 if (!file_exists($CFG->dataroot .'/cache/')) {
348 mkdir($CFG->dataroot .'/cache');
349 }
350 // If moodle dataroot cache/rsscache folder is missing create it
351 if (!file_exists($CFG->dataroot .'/cache/rsscache/')) {
352 mkdir($CFG->dataroot .'/cache/rsscache');
353 }
354
355 $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml';
356// echo "file = ". $file; //debug
79dd93a9 357
e8181a56 358 if (file_exists($file)) {
79dd93a9 359 //check age of cached xml file
e8181a56 360 // echo "file exists $file"; //debug
79dd93a9 361
362 //get file information ignoring error information
363 $data = @stat($file);
c7ac239b 364
e8181a56 365 $now = time();
c7ac239b 366 //Note: there would be a problem here reading data[10] if the above stat() call failed
79dd93a9 367 if (empty($data)) {
368 // error getting stat on file, return
369 return false;
370 }
371 if ( ($now - $data[10]) > $secs) {
372 // The cached file has expired.
373 return false;
374 }
375 // no error, cache file is valid
376 return true;
377 }
378}
379
380/**
381 * Determines whether or not to get a news feed remotely or from cache and reads it into a string
382 * @param int rssid - id of feed in blog_rss table
383 * @param string url - url of remote feed
384 * @param string type - either 'A' or 'R' where A is an atom feed and R is either rss or rdf
385 * @return Atom|MagpieRSS|null This function returns an Atom object in the case of an Atom feed, a MagpieRSS object in the case of an RDF/RSS feed or null if there was an error loading the remote feed.
386 * NOTE that this function requires allow_url_fopen be On in your php.ini file
387 * (it may be off for security by your web host)
388 */
389function rss_get_feed($rssid, $url, $type) {
390 global $CFG;
391 $errorstring = '';
392 $urlfailurestring = '<p>Failed to open remote news feed at: ' . $url .'</p><ul>Troubleshooting suggestions:<li> Ensure that the setting <strong>allow_url_fopen</strong> is <strong>On</strong> in the php.ini. For more details on why this setting is needed for this file wrapper call to work please refer to <a href="http://us2.php.net/filesystem">http://us2.php.net/filesystem</a></li><li>Ensure that you do not have a proxy enabled between your server and the remote site. If it is possible for you to launch a web browser on your server then you can test this by load the remote URL on the server itself.</li></ul>';
393 $filefailurestring = 'Could not open the file located at: ';
394 $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml';
395
396 // some flags to be used in managing where the rss data is read from
397 $writetofile = false;
398 $readfromfile = false;
399 $readfromurl = false;
400 $cachefilevalid = false;
401
402 if (rss_cache_valid_by_id($rssid)) {
403 //valid xml feed info in cache, read from file
404 $readfromfile = true;
405 $cachefilevalid = true;
406 } else {
407 // xml feed missing or expired, read from source url
408 $readfromurl = true;
409 }
410
411 if ($readfromfile) {
412 // Cached file has not expired. Attempt to read from cached file.
413 $xml = load_feed_from_file($file);
414 if (!empty($xml) && empty($xml->xml) && !empty($xml->ERROR)) {
415 // Failed to load from cache, attempt to read from source
416 if ($CFG->debug) {
417 if (!empty($xml) && !empty($xml->ERROR)) {
418 $errorstring = $xml->ERROR . $errorstring .'<br />';
e8181a56 419 }
79dd93a9 420 $errorstring = $filefailurestring . $file .'<br /><br />'. $errorstring .'<br />';
e8181a56 421 }
79dd93a9 422 $readfromurl = true; // read from file failed, try to get from source next
e8181a56 423 }
79dd93a9 424 }
425
426 if ($readfromurl) {
e8181a56 427 $xml = load_feed_from_url($url);
c7ac239b 428 if (!empty($xml) && !empty($xml->xml) && empty($xml->ERROR)) {
e8181a56 429 //success
430 $writetofile = true;
431 } else {
79dd93a9 432 // Failed to load remote feed. Since the file exists attempt to read from cache
e8181a56 433 if ($CFG->debug) {
79dd93a9 434 if (isset($xml) && isset($xml->ERROR)) {
435 $errorstring = $xml->ERROR . $errorstring .'<br />';
c7ac239b 436 }
437 $errorstring = $urlfailurestring .'<br /><br />'. $errorstring .'<br />';
e8181a56 438 }
79dd93a9 439 $xml = load_feed_from_file($file);
440 if (!empty($xml) && empty($xml->xml) && !empty($xml->ERROR)) {
441 // Failed to load from cache as well!
442 if ($CFG->debug) {
443 if (!empty($xml) && !empty($xml->ERROR)) {
444 $errorstring = $xml->ERROR . $errorstring;
445 }
446 $errorstring = $filefailurestring . $file .'<br /><br />'. $errorstring .'<br />';
447 $err->ERROR = $errorstring .'<br />';
448 return $err;
449 }
450 }
e8181a56 451 }
452 }
79dd93a9 453
19c64818 454 // echo 'DEBUG: raw xml was loaded successfully:<br />';//debug
e8181a56 455 //print_object($xml); //debug
c7ac239b 456
457 //implode xml file. in some cases this operation may fail, capture failure info to errorstring.
458 ob_start();
459 $xmlstr = implode(' ', $xml->xml);
460 $errorstring .= ob_get_contents();
461 ob_end_clean();
462 //print_object($xmlstr);
e8181a56 463
464 if ( $writetofile && !empty($xmlstr) ) { //write file to cache
465 // jlb: adding file:/ to the start of the file name fixed
466 // some caching problems that I was experiencing.
467 //$file="file:/" + $file;
468 file_put_contents($file, $xmlstr);
469 }
470
c7ac239b 471 if (empty($xmlstr) && !empty($errorstring)) {
472 $err->ERROR = 'XML file failed to implode correctly:<br /><br />'. $errorstring .'<br />';
473 return $err;
474 }
475
e8181a56 476 if ($type == 'A') {
477 //note: Atom is being modified by a working group
478 //http://www.mnot.net/drafts/draft-nottingham-atom-format-02.html
479 include_once($CFG->dirroot .'/rss/class.Atom.php');
480 $atom = new Atom($xmlstr);
481 $atom->channel = $atom->feed;
482 $atom->items = $atom->entries;
483 $atom->channel['description'] = $atom->channel['tagline'];
484 for($i=0;$i<count($atom->items);$i++) {
485 $atom->items[$i]['description'] = $atom->items[$i]['content'];
486 }
487 return $atom;
488 } else {
489 include_once($CFG->dirroot .'/rss/class.RSS.php');
490 $rss = new MagpieRSS($xmlstr);
491 return $rss;
492 }
493}
494
495/**
496 * @param string $file The path to the cached feed to load
c7ac239b 497 * @return stdObject Object with ->xml string value and ->ERROR string value if applicable.
e8181a56 498 */
499function load_feed_from_file($file) {
500 global $CFG;
c7ac239b 501 $errorstring = '';
e8181a56 502// echo "read from cache"; //debug
503 //read in from cache
c7ac239b 504 ob_start();
505 $xml = file($file);
506 $errorstring .= ob_get_contents();
507 ob_end_clean();
508
509 $returnobj->xml = $xml;
510 if (!empty($errorstring)){
511 $returnobj->ERROR = 'XML file failed to load:<br /><br />'. $errorstring .'<br />';
e8181a56 512 }
c7ac239b 513 return $returnobj;
e8181a56 514}
515
516/**
517 * @param string $url The url of the remote news feed to load
c7ac239b 518 * @return stdObject Object with ->xml string value and ->ERROR string value if applicable.
e8181a56 519 */
520function load_feed_from_url($url) {
521 global $CFG;
c7ac239b 522// echo "read from source url"; //debug
523 //read from source url
524 $errorstring = '';
525// echo "read from cache"; //debug
526 //read in from cache
527 ob_start();
528 $xml = file($url);
529 $errorstring .= ob_get_contents();
530 ob_end_clean();
531
532 $returnobj->xml = $xml;
533 if (!empty($errorstring)){
534 $returnobj->ERROR = 'XML url failed to load:<br />'. $errorstring;
e8181a56 535 }
c7ac239b 536 return $returnobj;
537
e8181a56 538}
539
540/**
541 * @param int $rssid .
542 */
543function rss_display_feeds($rssid='none') {
544 global $db, $USER, $CFG, $THEME;
545 global $blogid; //hackish, but if there is a blogid it would be good to preserve it
546
bab450a0 547 static $pixpath = '';
548 if (empty($pixpath)) {
549 if (empty($THEME->custompix)) {
550 $pixpath = $CFG->wwwroot .'/pix';
551 } else {
552 $pixpath = $CFG->wwwroot .'/theme/'. $CFG->theme .'/pix';
553 }
554 }
555
556 $rsspix = $pixpath .'/i/rss.gif';
557
e8181a56 558 $closeTable = false;
559 //Daryl Hawes note: convert this sql statement to a moodle function call
560 if ($rssid != 'none'){
561 $sql = 'SELECT * FROM '. $CFG->prefix .'block_rss_client WHERE id='. $rssid;
562 } else {
563 $sql = 'SELECT * FROM '. $CFG->prefix .'block_rss_client';
564 }
565
566 $res = $db->Execute($sql);
567// print_object($res); //debug
568
569 if ($res->fields){
570 $closeTable = true;
571 ?>
572 <table width="100%">
573 <tr bgcolor="<?php echo $THEME->cellheading;?>" class="forumpostheadertopic">
574 <td><?php print_string('block_rss_feed', 'block_rss_client'); ?></td>
575 <td><?php print_string('edit'); ?></td>
576 <td><?php print_string('delete'); ?></td>
577 </tr>
578 <?php
579 }
580
581 if (isset($res) && $res->fields){
582 while(!$res->EOF) {
583 $editString = '&nbsp;';
584 $deleteString = '&nbsp;';
585 if ($res->fields['userid'] == $USER->id || isadmin()){
586 $editString = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=rss_edit&rssid='. $res->fields['id'] .'&blogid='. $blogid .'">';
587 $editString .= '<img src="'. $CFG->pixpath .'/t/edit.gif" alt="'. get_string('edit');
588$editString .= '" title="'. get_string('edit') .'" align="absmiddle" height=\"16\" width=\"16\" border=\"0\" /></a>';
589
590 $deleteString = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=delfeed&rssid='. $res->fields['id'];
591 $deleteString .= '&blogid='. $blogid .'" onClick="return confirm(\''. get_string('block_rss_delete_feed_confirm', 'block_rss_client') .'\');">';
592 $deleteString .= '<img src="'. $CFG->pixpath .'/t/delete.gif" alt="'. get_string('delete');
593$deleteString .= '" title="'. get_string('delete') .'" align="absmiddle" border=\"0\" /></a>';
594 }
595 print '<tr bgcolor="'. $THEME->cellcontent .'" class="forumpostmessage"><td><strong><a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=view&rssid=';
596 print $res->fields['id'] .'&blogid='. $blogid .'">'. $res->fields['title'] .'</a></strong><br />' ."\n";
597 print $res->fields['description'] .'&nbsp;<br />' ."\n";
bab450a0 598 print $res->fields['url'] .'&nbsp;&nbsp;<a href="'. $res->fields['url'] .'" target=_new><img src="'. $rsspix .'" border="0" /></a>' ."\n";
e8181a56 599 print '<a href="http://feeds.archive.org/validator/check?url='. $res->fields['url'] .'">(Validate)</a>';
600 print '</td><td align="center">'. $editString .'</td>' ."\n";
601 print '<td align=\"center\">'. $deleteString .'</td>' ."\n";
602 print '</tr>'."\n";
603 $res->MoveNext();
604 }
605 }
606 if ($closeTable){
607 print '</table>'."\n";
608 }
609}
610
611/**
612 * @param string $act .
613 * @param string $url .
614 * @param int $rssid .
615 * @param string $rsstype .
616 * @param bool $printnow .
617 */
618function rss_get_form($act, $url, $rssid, $rsstype, $printnow=true) {
619 global $USER, $CFG, $_SERVER, $blockid, $blockaction;
620 global $blogid; //hackish, but if there is a blogid it would be good to preserve it
621
622 $returnstring = '<table><tr><td valign=\"top\">';
623 if ($act == 'rss_edit') {
624 $returnstring .= get_string('edit');
625 } else {
626 $returnstring .= get_string('block_rss_add_new', 'block_rss_client');
627 }
628 $returnstring .= ' '. get_string('block_rss_feed', 'block_rss_client');
629
630 $returnstring .= '</td></tr><tr><td>';
631
632 $returnstring .= '<form action="'. $_SERVER['PHP_SELF'] .'" method=POST name="block_rss">';
633 $returnstring .= 'URL: <input type="text" size="32" maxlength="128" name="url" value="';
634 if ($act == 'rss_edit') {
635 $returnstring .= $url;
636 }
637
638 $returnstring .= '" /><br /><select name="rsstype"><option value="R">RSS/RDF</option>
639 <option value="A"';
640 if ($act == 'rss_edit' and $rsstype == 'A') {
641 $returnstring .= ' selected';
642 }
643
644 $returnstring .= '>Atom</option></select>';
645
646 $returnstring .= '<input type="hidden" name="act" value="';
647 if ($act == 'rss_edit') {
648 $returnstring .= 'updfeed';
649 } else {
650 $returnstring .= 'addfeed';
651 }
652 $returnstring .= '" />';
653 if ($act == 'rss_edit') {
654 $returnstring .= '<input type="hidden" name="rssid" value="'. $rssid .'" />'. "\n";
655 }
656 $returnstring .= '<input type="hidden" name="blogid" value="'. $blogid .'" />';
657 $returnstring .= '<input type="hidden" name="user" value="'. $USER->id .'" />';
658 $returnstring .= '<input type="submit" value="';
659 if ($act == 'rss_edit') {
660 $returnstring .= get_string('update');
661 } else {
662 $returnstring .= get_string('add');
663 }
664 $returnstring .= '" />&nbsp;</form>';
665
666 $returnstring .= '<ul>' . get_string('block_rss_find_more_feeds', 'block_rss_client');
667// removed as this is possibly out of place here
668// $returnstring .= '<li><a href="http://www.syndic8.com" target="_new">syndic8</a> <li><a href="http://www.newsisfree.com" target="_new">NewsIsFree</A>';
669 $returnstring .= '</ul>';
670 $returnstring .= '</td></tr></table>';
671
672 if ($printnow){
673 print $returnstring;
674 }
675 return $returnstring;
676}
677
678/**
679 * added by Daryl Hawes for rss/atom feeds
680 * found at http://us4.php.net/manual/en/function.fwrite.php
681 * added check for moodle debug option. if off then use '@' to suppress error/warning messages
682 * @param string $filename .
683 * @param string $content .
684 */
685if (! function_exists('file_put_contents')){
686 function file_put_contents($filename, $content) {
687 global $CFG;
688 $nr_of_bytes = 0;
689 if ($CFG->debug){
690 if (($file = fopen($filename, 'w+')) === false) return false;
691 } else {
692 if (($file = @fopen($filename, 'w+')) === false) return false;
693 }
694 if ($CFG->debug){
695 if ($nr_of_bytes = fwrite($file, $content, strlen($content)) === false) return false;
696 } else {
697 if ($nr_of_bytes = @fwrite($file, $content, strlen($content)) === false) return false;
698 }
699 fclose($file);
700 return $nr_of_bytes;
701 }
702}
bab450a0 703?>