2 //This file adds support to rss feeds generation
4 //This function is the main entry point to glossary
5 //rss feeds generation.
6 function glossary_rss_get_feed($context, $cm, $instance, $args) {
9 if (empty($CFG->glossary_enablerssfeeds)) {
10 debugging("DISABLED (module configuration)");
15 //glossary module doesn't require any capabilities to view glossary entries (aside from being logged in)
17 $glossary = $DB->get_record('glossary', array('id' => $instance), '*', MUST_EXIST);
19 if (!rss_enabled('glossary', $glossary)) {
23 $sql = glossary_rss_get_sql($glossary, $cm);
25 //get the cache file info
26 $filename = rss_get_file_name($glossary, $sql);
27 $cachedfilepath = rss_get_file_full_name('glossary', $filename);
29 //Is the cache out of date?
30 $cachedfilelastmodified = 0;
31 if (file_exists($cachedfilepath)) {
32 $cachedfilelastmodified = filemtime($cachedfilepath);
35 if (glossary_rss_newstuff($glossary, $cm, $cachedfilelastmodified)) {
36 if (!$recs = $DB->get_records_sql($sql, array(), 0, $glossary->rssarticles)) {
42 $formatoptions = new object;
43 $formatoptions->trusttext = true;
45 foreach ($recs as $rec) {
48 $item->title = $rec->entryconcept;
50 if ($glossary->rsstype == 1) {//With author
51 $user->firstname = $rec->userfirstname;
52 $user->lastname = $rec->userlastname;
54 $item->author = fullname($user);
57 $item->pubdate = $rec->entrytimecreated;
58 $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid;
59 $item->description = format_text($rec->entrydefinition,$rec->entryformat,$formatoptions,$glossary->course);
63 //First all rss feeds common headers
64 $header = rss_standard_header(format_string($glossary->name,true),
65 $CFG->wwwroot."/mod/glossary/view.php?g=".$glossary->id,
66 format_string($glossary->intro,true));
67 //Now all the rss items
68 if (!empty($header)) {
69 $articles = rss_add_items($items);
71 //Now all rss feeds common footers
72 if (!empty($header) && !empty($articles)) {
73 $footer = rss_standard_footer();
75 //Now, if everything is ok, concatenate it
76 if (!empty($header) && !empty($articles) && !empty($footer)) {
77 $rss = $header.$articles.$footer;
79 //Save the XML contents to file.
80 $status = rss_save_file('glossary', $filename, $rss);
84 return $cachedfilepath;
87 function glossary_rss_get_sql($glossary, $cm, $time=0) {
88 //do we only want new items?
90 $time = "AND e.timecreated > $time";
95 if ($glossary->rsstype == 1) {//With author
96 $sql = "SELECT e.id AS entryid,
97 e.concept AS entryconcept,
98 e.definition AS entrydefinition,
99 e.definitionformat AS entryformat,
100 e.definitiontrust AS entrytrust,
101 e.timecreated AS entrytimecreated,
103 u.firstname AS userfirstname,
104 u.lastname AS userlastname
105 FROM {glossary_entries} e,
107 WHERE e.glossaryid = {$glossary->id} AND
110 ORDER BY e.timecreated desc";
111 } else {//Without author
112 $sql = "SELECT e.id AS entryid,
113 e.concept AS entryconcept,
114 e.definition AS entrydefinition,
115 e.definitionformat AS entryformat,
116 e.definitiontrust AS entrytrust,
117 e.timecreated AS entrytimecreated,
119 FROM {glossary_entries} e,
121 WHERE e.glossaryid = {$glossary->id} AND
124 ORDER BY e.timecreated desc";
131 * If there is new stuff in since $time this returns true
132 * Otherwise it returns false.
134 * @param object $glossary the glossary activity object
136 * @param int $time timestamp
139 function glossary_rss_newstuff($glossary, $cm, $time) {
142 $sql = glossary_rss_get_sql($glossary, $cm, $time);
144 $recs = $DB->get_records_sql($sql, null, 0, 1);//limit of 1. If we get even 1 back we have new stuff
145 return ($recs && !empty($recs));