Removed Martin's mistaken addition from a few days ago
[moodle.git] / mod / glossary / rsslib.php
CommitLineData
2dda0bbb 1<?PHP // $Id$
2 //This file adds support to rss feeds generation
3
4 //This function is the main entry point to glossary
5 //rss feeds generation. Foreach site glossary with rss enabled
6 //build one XML rss structure.
7 function glossary_rss_feeds() {
8
9 global $CFG;
10
11 $status = true;
12
13 //Check CFG->enablerssfeeds
14 if (empty($CFG->enablerssfeeds)) {
15 //Some debug...
16 if ($CFG->debug > 7) {
17 echo "DISABLED (admin variables)";
18 }
19 //Check CFG->glossary_enablerssfeeds
20 } else if (empty($CFG->glossary_enablerssfeeds)) {
21 //Some debug...
22 if ($CFG->debug > 7) {
23 echo "DISABLED (module configuration)";
24 }
25 //It's working so we start...
26 } else {
27 //Iterate over all glossaries
28 if ($glossaries = get_records("glossary")) {
29 foreach ($glossaries as $glossary) {
30 if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) {
31 //Some debug...
32 if ($CFG->debug > 7) {
33 echo "ID: $glossary->id->";
34 }
35 //Get the XML contents
36 $result = glossary_rss_feed($glossary);
37 //Save the XML contents to file
38 if (!empty($result)) {
39 $status = rss_save_file("glossary",$glossary,$result);
40 }
41 //Some debug...
42 if ($CFG->debug > 7) {
43 if (empty($result)) {
44 echo "(empty) ";
45 } else {
46 if (!empty($status)) {
47 echo "OK ";
48 } else {
49 echo "FAIL ";
50 }
51 }
52 }
53 }
54 }
55 }
56 }
57 return $status;
58 }
59
60 //This function return the XML rss contents about the glossary record passed as parameter
61 //It returns false if something is wrong
62 function glossary_rss_feed($glossary) {
63
64 global $CFG;
65
66 $status = true;
67
68 //Check CFG->enablerssfeeds
69 if (empty($CFG->enablerssfeeds)) {
70 //Some debug...
71 if ($CFG->debug > 7) {
72 echo "DISABLED (admin variables)";
73 }
74 //Check CFG->glossary_enablerssfeeds
75 } else if (empty($CFG->glossary_enablerssfeeds)) {
76 //Some debug...
77 if ($CFG->debug > 7) {
78 echo "DISABLED (module configuration)";
79 }
80 //It's working so we start...
81 } else {
82 //Check the glossary has rss activated
83 if (!empty($glossary->rsstype) && !empty($glossary->rssarticles)) {
84 //Depending of the glossary->rsstype, we are going to execute, different sqls
85 if ($glossary->rsstype == 1) { //With author RSS
86 $items = glossary_rss_feed_withauthor($glossary);
87 } else { //Without author RSS
88 $items = glossary_rss_feed_withoutauthor($glossary);
89
90 }
91 //Now, if items, we begin building the structure
92 if (!empty($items)) {
93 //First all rss feeds common headers
94 $header = rss_standard_header($glossary->name,
95 $CFG->wwwroot."/mod/glossary/view.php?f=".$glossary->id,
96 $glossary->intro);
97 //Now all the rss items
98 if (!empty($header)) {
99 $articles = rss_add_items($items);
100 }
101 //Now all rss feeds common footers
102 if (!empty($header) && !empty($articles)) {
103 $footer = rss_standard_footer();
104 }
105 //Now, if everything is ok, concatenate it
106 if (!empty($header) && !empty($articles) && !empty($footer)) {
107 $status = $header.$articles.$footer;
108 } else {
109 $status = false;
110 }
111 } else {
112 $status = false;
113 }
114 }
115 }
116 return $status;
117 }
118
119 //This function returns "items" record array to be used to build the rss feed
120 //for a Type=with author glossary
121 function glossary_rss_feed_withauthor($glossary) {
122
123 global $CFG;
124
125 $items = array();
126
127 if ($recs = get_records_sql ("SELECT e.id entryid,
128 e.concept entryconcept,
129 e.definition entrydefinition,
130 e.format entryformat,
131 e.timecreated entrytimecreated,
132 u.id userid,
133 u.firstname userfirstname,
134 u.lastname userlastname
135 FROM {$CFG->prefix}glossary_entries e,
136 {$CFG->prefix}user u
137 WHERE e.glossaryid = '$glossary->id' AND
d980b5da 138 u.id = e.userid AND
139 e.approved = 1
2dda0bbb 140 ORDER BY e.timecreated desc")) {
141 //Iterate over each entry to get glossary->rssarticles records
142 $articlesleft = $glossary->rssarticles;
143 $item = NULL;
144 $user = NULL;
145 foreach ($recs as $rec) {
146 unset($item);
147 unset($user);
148 $item->title = $rec->entryconcept;
149 $user->firstname = $rec->userfirstname;
150 $user->lastname = $rec->userlastname;
151 $item->author = fullname($user);
152 $item->pubdate = $rec->entrytimecreated;
153 $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid;
154 $item->description = format_text($rec->entrydefinition,$rec->entryformat,NULL,$glossary->course);
155 $items[] = $item;
156 $articlesleft--;
157 if ($articlesleft < 1) {
158 break;
159 }
160 }
161 }
162 return $items;
163 }
164
165 //This function returns "items" record array to be used to build the rss feed
166 //for a Type=without author glossary
167 function glossary_rss_feed_withoutauthor($glossary) {
168
169 global $CFG;
170
171 $items = array();
172
173 if ($recs = get_records_sql ("SELECT e.id entryid,
174 e.concept entryconcept,
175 e.definition entrydefinition,
176 e.format entryformat,
177 e.timecreated entrytimecreated,
178 u.id userid,
179 u.firstname userfirstname,
180 u.lastname userlastname
181 FROM {$CFG->prefix}glossary_entries e,
182 {$CFG->prefix}user u
183 WHERE e.glossaryid = '$glossary->id' AND
d980b5da 184 u.id = e.userid AND
185 e.approved = 1
2dda0bbb 186 ORDER BY e.timecreated desc")) {
187 //Iterate over each entry to get glossary->rssarticles records
188 $articlesleft = $glossary->rssarticles;
189 $item = NULL;
190 $user = NULL;
191 foreach ($recs as $rec) {
192 unset($item);
193 unset($user);
194 $item->title = $rec->entryconcept;
195 $user->firstname = $rec->userfirstname;
196 $user->lastname = $rec->userlastname;
197 //$item->author = fullname($user);
198 $item->pubdate = $rec->entrytimecreated;
199 $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid;
200 $item->description = format_text($rec->entrydefinition,$rec->entryformat,NULL,$glossary->course);
201 $items[] = $item;
202 $articlesleft--;
203 if ($articlesleft < 1) {
204 break;
205 }
206 }
207 }
208 return $items;
209 }
210
211?>