]> git.mjollnir.org Git - moodle.git/commitdiff
First version of RSS System.
authorstronk7 <stronk7>
Sun, 2 May 2004 23:08:19 +0000 (23:08 +0000)
committerstronk7 <stronk7>
Sun, 2 May 2004 23:08:19 +0000 (23:08 +0000)
Discussion and post forum feeds supported.
Integrated in cron system.
Some strings missing.
Test, test, test...

18 files changed:
admin/config.html
admin/cron.php
lang/en/forum.php
mod/forum/config.html
mod/forum/db/mysql.php
mod/forum/db/mysql.sql
mod/forum/db/oci8po.sql
mod/forum/db/postgres7.php
mod/forum/db/postgres7.sql
mod/forum/mod.html
mod/forum/rsslib.php [new file with mode: 0644]
mod/forum/version.php
mod/forum/view.php
pix/i/rss.gif [new file with mode: 0644]
pix/i/rsssitelogo.gif [new file with mode: 0644]
rss/file.php [new file with mode: 0644]
rss/rsslib.php [new file with mode: 0644]
version.php

index 7594621260df9f52e840c1b0d5184b0d0fefd90f..52b3fff01fe4b9a0a65ad2153e604f9614e68053 100644 (file)
     </td>
 </tr>
 
+<tr valign=top>
+        <td align=right><p>enablerssfeeds:</td>
+        <td>
+    <?php
+       unset($options);
+       $options[0] = get_string("no");
+       $options[1] = get_string("yes");
+
+       choose_from_menu ($options, "enablerssfeeds", $config->enablerssfeeds, "", "", "");
+    ?>
+    </td>
+    <td>
+    <?php print_string("configenablerssfeeds") ?>
+    </td>
+</tr>
+
 <tr>
     <td colspan=3 align=center>
        <input type="submit" value="<?php print_string("savechanges") ?>"></td>
index 80fd628a54fade3442c13314f55a3a8d458a40b0..5a16fd5598af51238ae6ce8767df773e2c90cb98 100644 (file)
         }
     }
 
+    if (!empty($CFG->enablerssfeeds)) {  //Defined in admin/variables page
+        if (file_exists("$CFG->dirroot/rss/rsslib.php")) {
+            include_once("$CFG->dirroot/rss/rsslib.php");
+            echo "Running rssfeeds if required...\n";
+            flush();
+
+            if ( ! cron_rss_feeds()) {
+                echo "Something went wrong while generating rssfeeds!!!\n";
+            } else {
+                echo "Rssfeeds finished\n";
+            }
+        }
+    }
+
     echo "Cron script completed correctly\n";
 
     $difftime = microtime_diff($starttime, microtime());
index 607c60143dd62a4959274260f4e95a7f9a36ea3e..5a4155828fc49917bd2d9a33f5140af52cd0b8ab 100644 (file)
@@ -111,6 +111,8 @@ $string['repliesmany'] = '$a replies so far';
 $string['repliesone'] = '$a reply so far';
 $string['reply'] = 'Reply';
 $string['replyforum'] = 'Reply to forum';
+$string['rsssubscriberssdiscussions'] = 'This is a link to susbscribe to the \'$a\' forum RSS discussions channel';
+$string['rsssubscriberssposts'] = 'This is a link to subscribe to the \'$a\' forum RSS posts channel';
 $string['search'] = 'Search';
 $string['searchforums'] = 'Search forums';
 $string['searcholderposts'] = 'Search older posts...';
index a374d2eeb616a6ce226cdbf0b329ff6ecec6321f..7b44f470d1aefb41f511760b95f3d96fcc73f844 100644 (file)
     <?php print_string("configmaxbytes", "forum") ?>
     </td>
 </tr>
+<tr valign=top>
+        <td align=right><p>forum_enablerssfeeds:</td>
+        <td>
+    <?php
+        if ($CFG->enablerssfeeds == 0) {
+            print_string("no");
+        } else {
+            unset($options);
+            $options[0] = get_string("no");
+            $options[1] = get_string("yes");
+            choose_from_menu ($options, "forum_enablerssfeeds", $CFG->forum_enablerssfeeds, "", "", "");
+        }
+    ?>
+    </td>
+    <td>
+    <?php 
+        print_string("configenablerssfeeds","forum");
+        if ($CFG->enablerssfeeds == 0) {
+            print_string("configenablerssfeedsdisabled","forum");
+        }
+    ?>
+    </td>
+</tr>
 
 <tr>
     <td colspan=3 align=center>
index c910bfb98d6a31bf22bea8fed5a91232a559bfe0..e7f4ea88806c0df9aca101e540708cabaf3efe0d 100644 (file)
@@ -108,6 +108,12 @@ function forum_upgrade($oldversion) {
   if ($oldversion < 2004020600) {
       table_column("forum_discussions", "", "usermodified", "integer", "10", "unsigned", "0", "", "timemodified");
   }
+
+  if ($oldversion < 2004050300) {
+      table_column("forum","","rsstype","tinyint","2", "unsigned", "0", "", "forcesubscribe");
+      table_column("forum","","rssarticles","tinyint","2", "unsigned", "0", "", "rsstype");
+      set_config("forum_enablerssfeeds",0);
+  }
   
   return true;
 
index c5c189ab11e0c0c04f0cb0a2e351b9acde8d99d1..b3a25585fd4479ce6efa448ae6e7770c4f867fd2 100644 (file)
@@ -16,6 +16,8 @@ CREATE TABLE prefix_forum (
   scale int(10) NOT NULL default '0',
   maxbytes int(10) unsigned NOT NULL default '0',
   forcesubscribe tinyint(1) unsigned NOT NULL default '0',
+  rsstype tinyint(2) unsigned NOT NULL default '0',
+  rssarticles tinyint(2) unsigned NOT NULL default '0',
   timemodified int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (id),
   UNIQUE KEY id (id)
index 5bb50926c58e721e3ab406eef8596f5aa020db7b..749a61b747f5d5b2e00c5d70605a57d2ed0ea324 100755 (executable)
@@ -16,6 +16,8 @@ CREATE TABLE prefix_forum (
   scale number(10)  default '0' NOT NULL,
   maxbytes number(10)  default '0' NOT NULL,
   forcesubscribe number(1)  default '0' NOT NULL,
+  rsstype number(2) default '0' NOT NULL,
+  rssarticles number(2) default '0' NOT NULL,
   timemodified number(10)  default '0' NOT NULL
 );
 
index 5d9b69b5e6226b09902ff46f633e6d0e825301ac..1c5babc1d7798c33ba7771a725fa77658234f8c0 100644 (file)
@@ -47,6 +47,12 @@ function forum_upgrade($oldversion) {
       table_column("forum_discussions", "", "usermodified", "integer", "10", "unsigned", "0", "", "timemodified");
   }
 
+  if ($oldversion < 2004050300) {
+      table_column("forum","","rsstype","integer","2", "unsigned", "0", "", "forcesubscribe");
+      table_column("forum","","rssarticles","integer","2", "unsigned", "0", "", "rsstype");
+      set_config("forum_enablerssfeeds",0);
+  }
+
   return true;
 
 }
index 5cc0276feefa2443d813cb7ce197fcd69dc5612a..d7c716f5c056846aa73dfdba89037382e6bfb143 100644 (file)
@@ -16,6 +16,8 @@ CREATE TABLE prefix_forum (
   scale integer NOT NULL default '0',
   maxbytes integer NOT NULL default '0',
   forcesubscribe integer NOT NULL default '0',
+  rsstype integer NOT NULL default '0',
+  rssarticles integer NOT NULL default '0',
   timemodified integer NOT NULL default '0'
 );
 # --------------------------------------------------------
index 191f84da092e15c4dbd712f2cea176e6a590556d..18d4df98b791e4442ce2de9ddbccf745f2666534 100644 (file)
     if (!isset($form->maxbytes)) {
         $form->maxbytes = $CFG->forum_maxbytes;
     }
+    if (!isset($form->rsstype)) {
+        $form->rsstype = 0;
+    }
+    if (!isset($form->rssarticles)) {
+        $form->rssarticles = 0;
+    }
 ?>
 <form name="form" method="post" <?php echo $onsubmit ?> action="mod.php">
 <table cellpadding=5>
         ?>
        </td>
 </tr>
+<?php  
+    //Only show rss parameters if rss is activated at site and forum levels  
+    if ($CFG->enablerssfeeds && $CFG->forum_enablerssfeeds) {
+        echo "<tr valign=top>";
+        echo "<td align=right><p><b>".get_string("rsstype", "forum")."</b></p></td>";
+        echo "<td>";
+        unset($choices);
+        $choices[0] = get_string("none");
+        $choices[1] = get_string("discussions", "forum");
+        $choices[2] = get_string("posts", "forum");
+        choose_from_menu ($choices, "rsstype", $form->rsstype, "");
+        helpbutton("rsstype", get_string("rsstype", "forum"), "forum");
+        echo "</td>";
+        echo "</tr>";
 
+        echo "<tr valign=top>";
+        echo "<td align=right><p><b>".get_string("rssarticles", "forum")."</b></p></td>";
+        echo "<td>";
+        unset($choices);
+        $choices[0] = "0";
+        $choices[1] = "1";
+        $choices[2] = "2";
+        $choices[3] = "3";
+        $choices[4] = "4";
+        $choices[5] = "5";
+        $choices[10] = "10";
+        $choices[15] = "15";
+        $choices[20] = "20";
+        $choices[25] = "25";
+        $choices[30] = "30";
+        $choices[40] = "40";
+        $choices[50] = "50";
+        choose_from_menu ($choices, "rssarticles", $form->rssarticles, "");
+        helpbutton("rssarticles", get_string("rssarticles", "forum"), "forum");
+        echo "</td>";
+        echo "</tr>";
+    }
+?>
 <tr>
     <td align=right valign=top><p><b><?php print_string("allowratings", "forum") ?>:</b></p></td>
     <td>
diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php
new file mode 100644 (file)
index 0000000..3553aac
--- /dev/null
@@ -0,0 +1,212 @@
+<?PHP  // $Id$
+    //This file adds support to rss feeds generation
+
+    //This function is the main entry point to forum
+    //rss feeds generation. Foreach site forum with rss enabled
+    //build one XML rss structure.
+    function forum_rss_feeds() {
+
+        global $CFG;
+
+        $status = true;
+
+        //Check CFG->enablerssfeeds
+        if (empty($CFG->enablerssfeeds)) {
+            //Some debug...
+            if ($CFG->debug > 7) {
+                echo "DISABLED (admin variables)";
+            }
+        //Check CFG->forum_enablerssfeeds
+        } else if (empty($CFG->forum_enablerssfeeds)) {
+            //Some debug...
+            if ($CFG->debug > 7) {
+                echo "DISABLED (module configuration)";
+            }
+        //It's working so we start...
+        } else {
+            //Iterate over all forums
+            if ($forums = get_records("forum")) {
+                foreach ($forums as $forum) {
+                    if (!empty($forum->rsstype) && !empty($forum->rssarticles) && $status) {
+                        //Some debug...
+                        if ($CFG->debug > 7) {
+                            echo "ID: $forum->id->";
+                        }
+                        //Get the XML contents
+                        $result = forum_rss_feed($forum);
+                        //Save the XML contents to file
+                        if (!empty($result)) {
+                            $status = rss_save_file("forum",$forum,$result);
+                        }
+                        //Some debug...
+                        if ($CFG->debug > 7) {
+                            if (empty($result)) {
+                                echo "(empty) ";
+                            } else {
+                                if (!empty($status)) {
+                                    echo "OK ";
+                                } else {
+                                    echo "FAIL ";
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return $status;
+    }
+
+    //This function return the XML rss contents about the forum record passed as parameter
+    //It returns false if something is wrong
+    function forum_rss_feed($forum) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Check CFG->enablerssfeeds
+        if (empty($CFG->enablerssfeeds)) {
+            //Some debug...
+            if ($CFG->debug > 7) {
+                echo "DISABLED (admin variables)"; 
+            }           
+        //Check CFG->forum_enablerssfeeds
+        } else if (empty($CFG->forum_enablerssfeeds)) {
+            //Some debug... 
+            if ($CFG->debug > 7) {
+                echo "DISABLED (module configuration)";
+            }           
+        //It's working so we start...
+        } else {
+            //Check the forum has rss activated
+            if (!empty($forum->rsstype) && !empty($forum->rssarticles)) {
+                //Depending of the forum->rsstype, we are going to execute, different sqls
+                if ($forum->rsstype == 1) {    //Discussion RSS
+                    $items = forum_rss_feed_discussions($forum);
+                } else {                //Post RSS
+                    $items = forum_rss_feed_posts($forum);
+     
+                }
+                //Now, if items, we begin building the structure
+                if (!empty($items)) {
+                    //First all rss feeds common headers
+                    $header = rss_standard_header($forum->name,
+                                                  $CFG->wwwroot."/mod/forum/view.php?f=".$forum->id,
+                                                  $forum->intro);
+                    //Now all the rss items
+                    if (!empty($header)) {
+                        $articles = rss_add_items($items);
+                    }
+                    //Now all rss feeds common footers
+                    if (!empty($header) && !empty($articles)) {
+                        $footer = rss_standard_footer();
+                    }
+                    //Now, if everything is ok, concatenate it
+                    if (!empty($header) && !empty($articles) && !empty($footer)) {
+                        $status = $header.$articles.$footer;
+                    } else {
+                        $status = false;
+                    } 
+                } else {
+                    $status = false;
+                }
+            }
+        }
+        return $status;
+    }
+
+    //This function returns "items" record array to be used to build the rss feed
+    //for a Type=discussions forum
+    function forum_rss_feed_discussions($forum) {
+
+        global $CFG;
+
+        $items = array();
+
+        if ($recs = get_records_sql ("SELECT d.id discussionid, 
+                                             d.name discussionname, 
+                                             u.id userid, 
+                                             u.firstname userfirstname,
+                                             u.lastname userlastname,
+                                             p.message postmessage,
+                                             p.created postcreated
+                                      FROM {$CFG->prefix}forum_discussions d,
+                                           {$CFG->prefix}forum_posts p,
+                                           {$CFG->prefix}user u
+                                      WHERE d.forum = '$forum->id' AND
+                                            p.discussion = d.id AND
+                                            p.parent = 0 AND
+                                            u.id = p.userid
+                                      ORDER BY p.created desc")) {
+            //Iterate over each discussion to get forum->rssarticles records
+            $articlesleft = $forum->rssarticles;
+            $item = NULL;
+            $user = NULL;
+            foreach ($recs as $rec) {
+                unset($item);
+                unset($user);
+                $item->title = $rec->discussionname;
+                $user->firstname = $rec->userfirstname;
+                $user->lastname = $rec->userlastname;
+                $item->author = fullname($user);
+                $item->pubdate = $rec->postcreated;
+                $item->link = $CFG->wwwroot."/mod/forum/discuss.php?d=".$rec->discussionid;
+                $item->description = $rec->postmessage;
+                $items[] = $item;
+                $articlesleft--;
+                if ($articlesleft < 1) {
+                    break;
+                }
+            }
+        }
+        return $items;
+    }
+    
+    //This function returns "items" record array to be used to build the rss feed
+    //for a Type=posts forum
+    function forum_rss_feed_posts($forum) {
+
+        global $CFG;
+
+        $items = array();
+
+        if ($recs = get_records_sql ("SELECT p.id postid,
+                                             d.id discussionid,
+                                             d.name discussionname,
+                                             u.id userid,
+                                             u.firstname userfirstname,
+                                             u.lastname userlastname,
+                                             p.message postmessage,
+                                             p.created postcreated
+                                      FROM {$CFG->prefix}forum_discussions d,
+                                           {$CFG->prefix}forum_posts p,
+                                           {$CFG->prefix}user u
+                                      WHERE d.forum = '$forum->id' AND
+                                            p.discussion = d.id AND
+                                            u.id = p.userid
+                                      ORDER BY p.created desc")) {
+            //Iterate over each discussion to get forum->rssarticles records
+            $articlesleft = $forum->rssarticles;
+            $item = NULL;
+            $user = NULL;
+            foreach ($recs as $rec) {
+                unset($item);
+                unset($user);
+                $item->title = $rec->discussionname;
+                $user->firstname = $rec->userfirstname;
+                $user->lastname = $rec->userlastname;
+                $item->author = fullname($user);
+                $item->pubdate = $rec->postcreated;
+                $item->link = $CFG->wwwroot."/mod/forum/discuss.php?d=".$rec->discussionid."&parent=".$rec->postid;
+                $item->description = $rec->postmessage;
+                $items[] = $item;
+                $articlesleft--;
+                if ($articlesleft < 1) {
+                    break;
+                }
+            }
+        }
+        return $items;
+    }
+?>
index f954f14385f9e40eef08fa704459f200a85cd1b4..bf44447c068075bb299f68032b98371c03757975 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004031000;
+$module->version  = 2004050300;
 $module->requires = 2004031000;  // Requires this Moodle version
 $module->cron     = 60;
 
index 6bd42708852a32c6d8b61281acb10e18e50b0ed1..4aa876cfae22206609d3343e254464d73093170d 100644 (file)
@@ -2,6 +2,7 @@
 
     require_once("../../config.php");
     require_once("lib.php");
+    require_once("$CFG->dirroot/rss/rsslib.php");
 
     optional_variable($id);            // Course Module ID
     optional_variable($f);             // Forum ID
             echo "<br />";
             echo "<font size=1><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>";
         }
+
+        //If rss are activated at site and forum level and this forum has rss defined, show link
+        if ($CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
+            echo "<br />";
+            if ($forum->rsstype == 1) {
+                $tooltiptext = get_string("rsssubscriberssdiscussions","forum",$forum->name);
+            } else {
+                $tooltiptext = get_string("rsssubscriberssposts","forum",$forum->name);
+            }
+            rss_print_link($course->id, $USER->id, "forum", $forum->id, $tooltiptext);
+        }
+
         echo '</td>';
     }
 
diff --git a/pix/i/rss.gif b/pix/i/rss.gif
new file mode 100644 (file)
index 0000000..22e8848
Binary files /dev/null and b/pix/i/rss.gif differ
diff --git a/pix/i/rsssitelogo.gif b/pix/i/rsssitelogo.gif
new file mode 100644 (file)
index 0000000..ffb0aef
Binary files /dev/null and b/pix/i/rsssitelogo.gif differ
diff --git a/rss/file.php b/rss/file.php
new file mode 100644 (file)
index 0000000..e295dfc
--- /dev/null
@@ -0,0 +1,76 @@
+<?PHP //$Id
+    //This file returns the required rss feeds
+    //The URL format MUST include:
+    //    course: the course id
+    //    user: the user id
+    //    name: the name of the module (forum...)
+    //    id: the id of the module (forumid...)
+    //If the course has a password or it doesn't
+    //allow guest access then the user field is 
+    //required to see that the user is enrolled
+    //in the course, else no check is performed.
+    //This allows to limit a bit the rss access
+    //to correct users. It isn't unbreakable,
+    //obviously, but its the best I've thought!!
+
+    require_once("../config.php");
+    require_once("$CFG->dirroot/files/mimetypes.php");
+
+    $allowed = true;
+    $error = false;
+
+    if (empty($CFG->filelifetime)) {
+        $CFG->filelifetime = 86400;     /// Seconds for files to remain in caches
+    }
+
+    if (isset($file)) {     // workaround for situations where / syntax doesn't work
+        $pathinfo = $file;
+    } else {
+        $pathinfo = get_slash_arguments("file.php");
+    }
+
+    if (!$pathinfo) {
+        $error = true;
+    }
+
+    $pathinfo = urldecode($pathinfo);
+
+    if (! $args = parse_slash_arguments($pathinfo)) {
+        $error = true;
+    }
+
+    $numargs = count($args);
+    if ($numargs < 5 or empty($args[1])) {
+        $error = true;
+    }
+
+    $courseid = (integer)$args[0];
+    if (! $course = get_record("course", "id", $courseid)) {
+        $error = true;
+    }
+
+    //Check for "security" if !course->guest or course->password
+    if (!$course->guest || $course->password) {
+        $allowed = (isstudent($course->id,$args[1]) || isteacher($course->id,$args[1])); 
+    }
+
+    $pathname = $CFG->dataroot."/rss/".$args[2]."/".$args[3].".xml";
+    $filename = $args[$numargs-1];
+
+    //If the file exists and its allowed for me, download it!
+    if (file_exists($pathname) && $allowed && !$error) {
+        $lastmodified = filemtime($pathname);
+        $mimetype = mimeinfo("type", $filename);
+    
+        header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
+        header("Expires: " . gmdate("D, d M Y H:i:s", time() + $CFG->filelifetime) . " GMT");
+        header("Cache-control: max_age = $CFG->filelifetime");
+        header("Pragma: ");
+        header("Content-disposition: inline; filename=$filename");
+    
+        header("Content-length: ".filesize($pathname));
+        header("Content-type: $mimetype");
+        readfile($pathname);
+    }
+
+?>
diff --git a/rss/rsslib.php b/rss/rsslib.php
new file mode 100644 (file)
index 0000000..03d06c3
--- /dev/null
@@ -0,0 +1,265 @@
+<?PHP  // $Id$
+       // This file contains all the common stuff to be used in RSS System
+
+//This function prints the icon (from theme) with the link to rss/file.php
+function rss_print_link($courseid, $userid, $modulename, $id, $tooltiptext="") {
+
+ global $CFG, $THEME, $USER;
+
+    static $pixpath = '';
+    static $rsspath = '';
+
+    if ($CFG->slasharguments) {
+        $rsspath = "$CFG->wwwroot/rss/file.php/$courseid/$userid/$modulename/$id/rss.xml";
+    } else {
+        $rsspath = "$CFG->wwwroot/rss/file.php?file=/$courseid/$userid/$modulename/$id/rss.xml";
+    }
+
+    if (empty($pixpath)) {
+        if (empty($THEME->custompix)) {
+            $pixpath = "$CFG->wwwroot/pix";
+        } else {
+            $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
+        }
+    }
+
+    $rsspix = $pixpath."/i/rss.gif";
+
+     echo "<a href=\"".$rsspath."\"><img src=\"$rsspix\" title=\"$tooltiptext\"></a>";
+
+}
+
+//This function iterates over each module in the server to see if
+//it supports generating rss feeds, searching for a MODULENAME_rss_feeds()
+//function and invoking it foreach activity as necessary
+function cron_rss_feeds () {
+
+    global $CFG;
+
+    $status = true;
+   
+    echo "    Generating rssfeeds...\n";
+
+    if ($allmods = get_records("modules") ) {
+        foreach ($allmods as $mod) {
+            echo '        '.$mod->name.': ';
+            $modname = $mod->name;
+            $modfile = "$CFG->dirroot/mod/$modname/rsslib.php";
+            //If file exists and we have selected to restore that type of module
+            if (file_exists($modfile)) {
+                include_once($modfile);
+                $generaterssfeeds = $modname.'_rss_feeds';
+                if (function_exists($generaterssfeeds)) {
+                    if ($status) {
+                        echo 'generating ';
+                        $status = $generaterssfeeds();
+                        if (!empty($status)) {
+                            echo "...OK\n";
+                        } else {
+                            echo "...FAILED\n";
+                        }
+                    } else {
+                        echo "...SKIPPED (failed above)\n";
+                    }
+                } else {
+                    echo "...NOT SUPPORTED (function)\n";
+                }
+            } else {
+                echo "...NOT SUPPORTED (file)\n";
+            }
+        }
+    }
+    echo "    Ending  rssfeeds...";
+    if (!empty($status)) {
+        echo "...OK\n";
+    } else {
+        echo "...FAILED\n";
+    }
+
+    return $status;
+}
+
+//This function saves to file the rss feed specified in the parameters
+function rss_save_file ($modname,$mod,$result) {
+    global $CFG;
+    
+    $status = true;
+
+    $basedir = $CFG->dataroot."/rss";
+
+    //Check dataroot/rss exists
+    $status = check_dir_exists($basedir,true);
+
+    $basedir .= "/".$modname;
+
+    //Check dataroot/rrs/$modname exists
+    $status = check_dir_exists($basedir,true);
+
+    if ($status) {
+        $file = $basedir .= "/".$mod->id.".xml";
+        $rss_file = fopen($file,"w");
+        if ($rss_file) {
+            $status = fwrite ($rss_file,$result);
+            fclose($rss_file);
+        }
+    }
+    return $status;
+}
+
+//This function return all the common headers for every rss feed in the site
+function rss_standard_header($title = NULL, $link = NULL, $description = NULL) {
+
+    global $CFG, $USER;
+
+    static $pixpath = '';
+
+    $status = true;
+    $result = "";
+
+    if (!$site = get_site()) {
+        $status = false;
+    }
+
+    if ($status) {
+
+        //Calculate title, link and description
+        if (empty($title)) {
+            $title = $site->fullname;
+        }
+        if (empty($link)) {
+            $link = $CFG->wwwroot;
+        }
+        if (empty($description)) {
+            $description = $site->summary;
+        }
+
+        //xml headers
+        $result .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+        $result .= "<rss version=\"2.0\">\n";
+
+        //open the channel
+        $result .= rss_start_tag("channel",1,true);
+
+        //write channel info
+        $result .= rss_full_tag("title",2,false,$title);
+        $result .= rss_full_tag("link",2,false,$link);
+        $result .= rss_full_tag("description",2,false,$description);
+        $result .= rss_full_tag("language",2,false,substr($USER->lang,0,2));
+        $today = getdate();
+        $result .= rss_full_tag("copyright",2,false,"&copy; ".$today['year']." ".$site->fullname);
+        $result .= rss_full_tag("managingEditor",2,false,$USER->email);
+        $result .= rss_full_tag("webMaster",2,false,$USER->email);
+
+        //write image info
+        //Calculate the origin
+        if (empty($pixpath)) {
+            if (empty($THEME->custompix)) {
+                $pixpath = "$CFG->wwwroot/pix";
+            } else {
+                $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
+            }
+        }
+        $rsspix = $pixpath."/i/rsssitelogo.gif";
+
+        //write the info 
+        $result .= rss_start_tag("image",2,true);
+        $result .= rss_full_tag("url",3,false,$rsspix);
+        $result .= rss_full_tag("title",3,false,"moodle");
+        $result .= rss_full_tag("link",3,false,$CFG->wwwroot);
+        $result .= rss_full_tag("width",3,false,"140");
+        $result .= rss_full_tag("height",3,false,"35");
+        $result .= rss_end_tag("image",2,true);
+    }
+
+    if (!$status) {
+        return false;
+    } else {
+        return $result;
+    }
+}
+
+//This function returns the rss XML code for every item passed in the array
+//item->title: The title of the item
+//item->author: The author of the item
+//item->pubdate: The pubdate of the item
+//item->link: The link url of the item
+//item->description: The content of the item
+function rss_add_items($items) {
+
+    global $CFG;
+        
+    $result = "";
+
+    if (!empty($items)) {
+        foreach ($items as $item) {
+            $result .= rss_start_tag("item",2,true);
+            $result .= rss_full_tag("title",3,false,$item->title);
+            $result .= rss_full_tag("link",3,false,$item->link);
+            $result .= rss_full_tag("pubDate",3,false,date("r",$item->pubdate));
+            $result .= rss_full_tag("description",3,false,$item->description);
+            $result .= rss_end_tag("item",2,true);
+
+        }
+    } else {
+        $result = false;
+    }
+    return $result;
+}
+
+//This function return all the common footers for every rss feed in the site
+function rss_standard_footer($title = NULL, $link = NULL, $description = NULL) {
+
+    global $CFG, $USER;
+
+    $status = true;
+    $result = "";
+
+    //Close the chanel
+    $result .= rss_end_tag("channel",1,true);
+    ////Close the rss tag
+    $result .= "</rss>";
+
+    return $result;
+}
+
+// ===== This function are used to write XML tags =========
+// [stronk7]: They are similar to the glossary export and backup generation
+// but I've replicated them here because they have some minor
+// diferences. Someday all they should go to a common place.
+
+//Return the xml start tag
+function rss_start_tag($tag,$level=0,$endline=false) {
+    if ($endline) {
+       $endchar = "\n";
+    } else {
+       $endchar = "";
+    }
+    return str_repeat(" ",$level*2)."<".$tag.">".$endchar;
+}
+
+//Return the xml end tag
+function rss_end_tag($tag,$level=0,$endline=true) {
+    if ($endline) {
+       $endchar = "\n";
+    } else {
+       $endchar = "";
+    }
+    return str_repeat(" ",$level*2)."</".$tag.">".$endchar;
+}
+
+//Return the start tag, the contents and the end tag
+function rss_full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) {
+    //Here we encode absolute links
+    $st = rss_start_tag($tag,$level,$endline);
+    $co="";
+    if ($to_utf) {
+        $co = preg_replace("/\r\n|\r/", "\n", utf8_encode(htmlspecialchars($content)));
+    } else {
+        $co = preg_replace("/\r\n|\r/", "\n", htmlspecialchars($content));
+    }
+    $et = rss_end_tag($tag,0,true);
+    return $st.$co.$et;
+}
+
+?>
index 82f0f2404ae2ef8b4e9d8afbf94e4ae72317c92e..0820e579219fec1a8dab6c2dc370b008a9505290 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2004050200;   // The current version is a date (YYYYMMDDXX)
+$version = 2004050300;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.3 development";   // User-friendly version number