if there are multiple feeds within a single block the title of each feed is shown...
[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
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)) {
26 $pixpath = "$CFG->wwwroot/pix";
27 } else {
28 $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
29 }
30 }
31
32 $rsspix = $pixpath."/i/rss.gif";
33
839f2456 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
39function rss_print_link($courseid, $userid, $modulename, $id, $tooltiptext="") {
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
b65a50e5 53 mtrace(" Generating rssfeeds...");
8adcb49f 54
2f29ee13 55 //Check for required functions...
56 if(!function_exists('utf8_encode')) {
b65a50e5 57 mtrace(" ERROR: You need to add XML support to your PHP installation!");
2f29ee13 58 return true;
59 }
60
8adcb49f 61 if ($allmods = get_records("modules") ) {
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)) {
b65a50e5 75 mtrace("...OK");
8adcb49f 76 } else {
b65a50e5 77 mtrace("...FAILED");
8adcb49f 78 }
79 } else {
b65a50e5 80 mtrace("...SKIPPED (failed above)");
8adcb49f 81 }
82 } else {
b65a50e5 83 mtrace("...NOT SUPPORTED (function)");
8adcb49f 84 }
85 } else {
b65a50e5 86 mtrace("...NOT SUPPORTED (file)");
8adcb49f 87 }
88 }
89 }
b65a50e5 90 mtrace(" Ending rssfeeds...", '');
8adcb49f 91 if (!empty($status)) {
b65a50e5 92 mtrace("...OK");
8adcb49f 93 } else {
b65a50e5 94 mtrace("...FAILED");
8adcb49f 95 }
96
97 return $status;
98}
99
100//This function saves to file the rss feed specified in the parameters
101function rss_save_file ($modname,$mod,$result) {
102
103 global $CFG;
104
105 $status = true;
106
bc706aeb 107 if (! $basedir = make_upload_directory ("rss/".$modname)) {
108 //Cannot be created, so error
109 $status = false;
110 }
8adcb49f 111
112 if ($status) {
6069e206 113 $file = rss_file_name($modname, $mod);
8adcb49f 114 $rss_file = fopen($file,"w");
115 if ($rss_file) {
116 $status = fwrite ($rss_file,$result);
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/**
338 * Determines whether or not to get a news feed remotely or from cache and reads it into a string
339 * @param int rssid - id of feed in blog_rss table
340 * @param string url - url of remote feed
341 * @param string type - either 'A' or 'R' where A is an atom feed and R is either rss or rdf
342 * @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.
343 * NOTE that this function requires allow_url_fopen be On in your php.ini file
344 * (it may be off for security by your web host)
345 */
346function rss_get_feed($rssid, $url, $type) {
347
348 global $CFG;
349 $writetofile = false;
c7ac239b 350 $errorstring = '';
351
53195528 352 $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>';
e8181a56 353 $filefailurestring = 'Could not open the file located at: ';
354 $secs = $CFG->block_rss_timeout * 60;
355
356 // If moodle dataroot cache folder is missing create it
357 if (!file_exists($CFG->dataroot .'/cache/')) {
358 mkdir($CFG->dataroot .'/cache');
359 }
360 // If moodle dataroot cache/rsscache folder is missing create it
361 if (!file_exists($CFG->dataroot .'/cache/rsscache/')) {
362 mkdir($CFG->dataroot .'/cache/rsscache');
363 }
364
365 $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml';
366// echo "file = ". $file; //debug
367
368 //if feed in cache
369 if (file_exists($file)) {
370 //check age of cache file
371 // echo "file exists $file"; //debug
c7ac239b 372
373 //get file information capturing any error information
374 ob_start();
375 $data = stat($file);
376 $errorstring .= ob_get_contents();
377 ob_end_clean();
378
e8181a56 379 $now = time();
c7ac239b 380 //Note: there would be a problem here reading data[10] if the above stat() call failed
e8181a56 381 if (($now - $data[10]) > $secs) {
382 // The cached file has expired. Attempt to read fresh from source
383 $xml = load_feed_from_url($url);
c7ac239b 384 if (!empty($xml) && !empty($xml->xml) && empty($xml->ERROR)) {
e8181a56 385 //success
386 $writetofile = true;
387 } else {
388 // Failed to load remote feed. Since the file exists attempt to read from cache
389 if ($CFG->debug) {
c7ac239b 390 if (isset($xml) && isset($xml->ERROR)) {
391 $errorstring = $xml->ERROR . $errorstring .'<br />';
392 }
393 $errorstring = $urlfailurestring .'<br /><br />'. $errorstring .'<br />';
e8181a56 394 }
395 $xml = load_feed_from_file($file);
19c64818 396 if (!empty($xml) && empty($xml->xml) && !empty($xml->ERROR)) {
e8181a56 397 // Failed to load from cache as well!
398 if ($CFG->debug) {
19c64818 399 if (!empty($xml) && !empty($xml->ERROR)) {
c7ac239b 400 $errorstring = $xml->ERROR . $errorstring;
401 }
402 $errorstring = $filefailurestring . $file .'<br /><br />'. $errorstring .'<br />';
403 $err->ERROR = $errorstring .'<br />';
404 return $err;
e8181a56 405 }
406 }
407 }
408 } else {
409 // Cached file has not expired. Attempt to read from cached file.
410 $xml = load_feed_from_file($file);
19c64818 411 if (!empty($xml) && empty($xml->xml) && !empty($xml->ERROR)) {
e8181a56 412 // Failed to load from cache, attempt to read from source
413 if ($CFG->debug) {
19c64818 414 if (!empty($xml) && !empty($xml->ERROR)) {
c7ac239b 415 $errorstring = $xml->ERROR . $errorstring .'<br />';
416 }
417 $errorstring = $filefailurestring . $file .'<br /><br />'. $errorstring .'<br />';
e8181a56 418 }
419 $xml = load_feed_from_url($url);
c7ac239b 420 if (!empty($xml) && !empty($xml->xml) && empty($xml->ERROR)) {
e8181a56 421 // success
422 $writetofile = true;
423 } else {
424 // Failed to read from source as well!
425 if ($CFG->debug) {
c7ac239b 426 if (!empty($xml) && !empty($xml->ERROR)) {
427 $errorstring = $xml->ERROR . $errorstring;
428 }
429 $errorstring = $urlfailurestring .'<br /><br />'. $errorstring .'<br />';
430 $err->ERROR = $errorstring .'<br />';
431 return $err;
e8181a56 432 }
433 return;
434 }
435 }
436 }
437 } else {
c7ac239b 438 // No cached file at all, read from source
e8181a56 439 $xml = load_feed_from_url($url);
c7ac239b 440 if (!empty($xml) && !empty($xml->xml) && empty($xml->ERROR)) {
e8181a56 441 //success
442 $writetofile = true;
443 } else {
444 // Failed to read from source url!
445 if ($CFG->debug) {
c7ac239b 446 if (!empty($xml) && !empty($xml->ERROR)) {
447 $errorstring = $xml->ERROR . $errorstring .'<br />';
448 }
449 $errorstring = $urlfailurestring .'<br /><br />'. $errorstring .'<br />';
450 $err->ERROR = $errorstring .'<br />';
451 return $err;
e8181a56 452 }
453 return;
454 }
455 }
456
19c64818 457 // echo 'DEBUG: raw xml was loaded successfully:<br />';//debug
e8181a56 458 //print_object($xml); //debug
c7ac239b 459
460 //implode xml file. in some cases this operation may fail, capture failure info to errorstring.
461 ob_start();
462 $xmlstr = implode(' ', $xml->xml);
463 $errorstring .= ob_get_contents();
464 ob_end_clean();
465 //print_object($xmlstr);
e8181a56 466
467 if ( $writetofile && !empty($xmlstr) ) { //write file to cache
468 // jlb: adding file:/ to the start of the file name fixed
469 // some caching problems that I was experiencing.
470 //$file="file:/" + $file;
471 file_put_contents($file, $xmlstr);
472 }
473
c7ac239b 474 if (empty($xmlstr) && !empty($errorstring)) {
475 $err->ERROR = 'XML file failed to implode correctly:<br /><br />'. $errorstring .'<br />';
476 return $err;
477 }
478
e8181a56 479 if ($type == 'A') {
480 //note: Atom is being modified by a working group
481 //http://www.mnot.net/drafts/draft-nottingham-atom-format-02.html
482 include_once($CFG->dirroot .'/rss/class.Atom.php');
483 $atom = new Atom($xmlstr);
484 $atom->channel = $atom->feed;
485 $atom->items = $atom->entries;
486 $atom->channel['description'] = $atom->channel['tagline'];
487 for($i=0;$i<count($atom->items);$i++) {
488 $atom->items[$i]['description'] = $atom->items[$i]['content'];
489 }
490 return $atom;
491 } else {
492 include_once($CFG->dirroot .'/rss/class.RSS.php');
493 $rss = new MagpieRSS($xmlstr);
494 return $rss;
495 }
496}
497
498/**
499 * @param string $file The path to the cached feed to load
c7ac239b 500 * @return stdObject Object with ->xml string value and ->ERROR string value if applicable.
e8181a56 501 */
502function load_feed_from_file($file) {
503 global $CFG;
c7ac239b 504 $errorstring = '';
e8181a56 505// echo "read from cache"; //debug
506 //read in from cache
c7ac239b 507 ob_start();
508 $xml = file($file);
509 $errorstring .= ob_get_contents();
510 ob_end_clean();
511
512 $returnobj->xml = $xml;
513 if (!empty($errorstring)){
514 $returnobj->ERROR = 'XML file failed to load:<br /><br />'. $errorstring .'<br />';
e8181a56 515 }
c7ac239b 516 return $returnobj;
e8181a56 517}
518
519/**
520 * @param string $url The url of the remote news feed to load
c7ac239b 521 * @return stdObject Object with ->xml string value and ->ERROR string value if applicable.
e8181a56 522 */
523function load_feed_from_url($url) {
524 global $CFG;
c7ac239b 525// echo "read from source url"; //debug
526 //read from source url
527 $errorstring = '';
528// echo "read from cache"; //debug
529 //read in from cache
530 ob_start();
531 $xml = file($url);
532 $errorstring .= ob_get_contents();
533 ob_end_clean();
534
535 $returnobj->xml = $xml;
536 if (!empty($errorstring)){
537 $returnobj->ERROR = 'XML url failed to load:<br />'. $errorstring;
e8181a56 538 }
c7ac239b 539 return $returnobj;
540
e8181a56 541}
542
543/**
544 * @param int $rssid .
545 */
546function rss_display_feeds($rssid='none') {
547 global $db, $USER, $CFG, $THEME;
548 global $blogid; //hackish, but if there is a blogid it would be good to preserve it
549
550 $closeTable = false;
551 //Daryl Hawes note: convert this sql statement to a moodle function call
552 if ($rssid != 'none'){
553 $sql = 'SELECT * FROM '. $CFG->prefix .'block_rss_client WHERE id='. $rssid;
554 } else {
555 $sql = 'SELECT * FROM '. $CFG->prefix .'block_rss_client';
556 }
557
558 $res = $db->Execute($sql);
559// print_object($res); //debug
560
561 if ($res->fields){
562 $closeTable = true;
563 ?>
564 <table width="100%">
565 <tr bgcolor="<?php echo $THEME->cellheading;?>" class="forumpostheadertopic">
566 <td><?php print_string('block_rss_feed', 'block_rss_client'); ?></td>
567 <td><?php print_string('edit'); ?></td>
568 <td><?php print_string('delete'); ?></td>
569 </tr>
570 <?php
571 }
572
573 if (isset($res) && $res->fields){
574 while(!$res->EOF) {
575 $editString = '&nbsp;';
576 $deleteString = '&nbsp;';
577 if ($res->fields['userid'] == $USER->id || isadmin()){
578 $editString = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=rss_edit&rssid='. $res->fields['id'] .'&blogid='. $blogid .'">';
579 $editString .= '<img src="'. $CFG->pixpath .'/t/edit.gif" alt="'. get_string('edit');
580$editString .= '" title="'. get_string('edit') .'" align="absmiddle" height=\"16\" width=\"16\" border=\"0\" /></a>';
581
582 $deleteString = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=delfeed&rssid='. $res->fields['id'];
583 $deleteString .= '&blogid='. $blogid .'" onClick="return confirm(\''. get_string('block_rss_delete_feed_confirm', 'block_rss_client') .'\');">';
584 $deleteString .= '<img src="'. $CFG->pixpath .'/t/delete.gif" alt="'. get_string('delete');
585$deleteString .= '" title="'. get_string('delete') .'" align="absmiddle" border=\"0\" /></a>';
586 }
587 print '<tr bgcolor="'. $THEME->cellcontent .'" class="forumpostmessage"><td><strong><a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?act=view&rssid=';
588 print $res->fields['id'] .'&blogid='. $blogid .'">'. $res->fields['title'] .'</a></strong><br />' ."\n";
589 print $res->fields['description'] .'&nbsp;<br />' ."\n";
590 print $res->fields['url'] .'&nbsp;&nbsp;<a href="'. $res->fields['url'] .'" target=_new><img src="'. $CFG->pixpath .'/blog/xml.gif" border="0" /></a>' ."\n";
591 print '<a href="http://feeds.archive.org/validator/check?url='. $res->fields['url'] .'">(Validate)</a>';
592 print '</td><td align="center">'. $editString .'</td>' ."\n";
593 print '<td align=\"center\">'. $deleteString .'</td>' ."\n";
594 print '</tr>'."\n";
595 $res->MoveNext();
596 }
597 }
598 if ($closeTable){
599 print '</table>'."\n";
600 }
601}
602
603/**
604 * @param string $act .
605 * @param string $url .
606 * @param int $rssid .
607 * @param string $rsstype .
608 * @param bool $printnow .
609 */
610function rss_get_form($act, $url, $rssid, $rsstype, $printnow=true) {
611 global $USER, $CFG, $_SERVER, $blockid, $blockaction;
612 global $blogid; //hackish, but if there is a blogid it would be good to preserve it
613
614 $returnstring = '<table><tr><td valign=\"top\">';
615 if ($act == 'rss_edit') {
616 $returnstring .= get_string('edit');
617 } else {
618 $returnstring .= get_string('block_rss_add_new', 'block_rss_client');
619 }
620 $returnstring .= ' '. get_string('block_rss_feed', 'block_rss_client');
621
622 $returnstring .= '</td></tr><tr><td>';
623
624 $returnstring .= '<form action="'. $_SERVER['PHP_SELF'] .'" method=POST name="block_rss">';
625 $returnstring .= 'URL: <input type="text" size="32" maxlength="128" name="url" value="';
626 if ($act == 'rss_edit') {
627 $returnstring .= $url;
628 }
629
630 $returnstring .= '" /><br /><select name="rsstype"><option value="R">RSS/RDF</option>
631 <option value="A"';
632 if ($act == 'rss_edit' and $rsstype == 'A') {
633 $returnstring .= ' selected';
634 }
635
636 $returnstring .= '>Atom</option></select>';
637
638 $returnstring .= '<input type="hidden" name="act" value="';
639 if ($act == 'rss_edit') {
640 $returnstring .= 'updfeed';
641 } else {
642 $returnstring .= 'addfeed';
643 }
644 $returnstring .= '" />';
645 if ($act == 'rss_edit') {
646 $returnstring .= '<input type="hidden" name="rssid" value="'. $rssid .'" />'. "\n";
647 }
648 $returnstring .= '<input type="hidden" name="blogid" value="'. $blogid .'" />';
649 $returnstring .= '<input type="hidden" name="user" value="'. $USER->id .'" />';
650 $returnstring .= '<input type="submit" value="';
651 if ($act == 'rss_edit') {
652 $returnstring .= get_string('update');
653 } else {
654 $returnstring .= get_string('add');
655 }
656 $returnstring .= '" />&nbsp;</form>';
657
658 $returnstring .= '<ul>' . get_string('block_rss_find_more_feeds', 'block_rss_client');
659// removed as this is possibly out of place here
660// $returnstring .= '<li><a href="http://www.syndic8.com" target="_new">syndic8</a> <li><a href="http://www.newsisfree.com" target="_new">NewsIsFree</A>';
661 $returnstring .= '</ul>';
662 $returnstring .= '</td></tr></table>';
663
664 if ($printnow){
665 print $returnstring;
666 }
667 return $returnstring;
668}
669
670/**
671 * added by Daryl Hawes for rss/atom feeds
672 * found at http://us4.php.net/manual/en/function.fwrite.php
673 * added check for moodle debug option. if off then use '@' to suppress error/warning messages
674 * @param string $filename .
675 * @param string $content .
676 */
677if (! function_exists('file_put_contents')){
678 function file_put_contents($filename, $content) {
679 global $CFG;
680 $nr_of_bytes = 0;
681 if ($CFG->debug){
682 if (($file = fopen($filename, 'w+')) === false) return false;
683 } else {
684 if (($file = @fopen($filename, 'w+')) === false) return false;
685 }
686 if ($CFG->debug){
687 if ($nr_of_bytes = fwrite($file, $content, strlen($content)) === false) return false;
688 } else {
689 if ($nr_of_bytes = @fwrite($file, $content, strlen($content)) === false) return false;
690 }
691 fclose($file);
692 return $nr_of_bytes;
693 }
694}
8adcb49f 695?>