1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
<?PHP // $Id: rsslib.php,v 1.3.2.1 2004/09/29 07:52:34 moodler Exp $
//This file adds support to rss feeds generation
//This function is the main entry point to glossary
//rss feeds generation. Foreach site glossary with rss enabled
//build one XML rss structure.
function glossary_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->glossary_enablerssfeeds
} else if (empty($CFG->glossary_enablerssfeeds)) {
//Some debug...
if ($CFG->debug > 7) {
echo "DISABLED (module configuration)";
}
//It's working so we start...
} else {
//Iterate over all glossaries
if ($glossaries = get_records("glossary")) {
foreach ($glossaries as $glossary) {
if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) {
$filename = rss_file_name('glossary', $glossary); // RSS file
//First let's make sure there is work to do by checking existing files
if (file_exists($filename)) {
if ($lastmodified = filemtime($filename)) {
if (!glossary_rss_newstuff($glossary, $lastmodified)) {
continue;
}
}
}
//Ignore hidden forums
if (!instance_is_visible('glossary',$glossary)) {
if (file_exists($filename)) {
@unlink($filename);
}
continue;
}
mtrace("Updating RSS feed for $glossary->name, ID: $glossary->id");
//Some debug...
if ($CFG->debug > 7) {
echo "ID: $glossary->id->";
}
//Get the XML contents
$result = glossary_rss_feed($glossary);
//Save the XML contents to file
if (!empty($result)) {
$status = rss_save_file("glossary",$glossary,$result);
}
//Some debug...
if ($CFG->debug > 7) {
if (empty($result)) {
echo "(empty) ";
} else {
if (!empty($status)) {
echo "OK ";
} else {
echo "FAIL ";
}
}
}
}
}
}
}
return $status;
}
function glossary_rss_newstuff($glossary, $time) {
// If there is new stuff in the glossary since $time then this returns
// true. Otherwise it returns false.
if ($glossary->rsstype == 1) {
$items = glossary_rss_feed_withauthor($glossary, $time);
} else {
$items = glossary_rss_feed_withoutauthor($glossary, $time);
}
return (!empty($items));
}
//This function return the XML rss contents about the glossary record passed as parameter
//It returns false if something is wrong
function glossary_rss_feed($glossary) {
global $CFG;
$status = true;
//Check CFG->enablerssfeeds
if (empty($CFG->enablerssfeeds)) {
//Some debug...
if ($CFG->debug > 7) {
echo "DISABLED (admin variables)";
}
//Check CFG->glossary_enablerssfeeds
} else if (empty($CFG->glossary_enablerssfeeds)) {
//Some debug...
if ($CFG->debug > 7) {
echo "DISABLED (module configuration)";
}
//It's working so we start...
} else {
//Check the glossary has rss activated
if (!empty($glossary->rsstype) && !empty($glossary->rssarticles)) {
//Depending of the glossary->rsstype, we are going to execute, different sqls
if ($glossary->rsstype == 1) { //With author RSS
$items = glossary_rss_feed_withauthor($glossary);
} else { //Without author RSS
$items = glossary_rss_feed_withoutauthor($glossary);
}
//Now, if items, we begin building the structure
if (!empty($items)) {
//First all rss feeds common headers
$header = rss_standard_header($glossary->name,
$CFG->wwwroot."/mod/glossary/view.php?f=".$glossary->id,
$glossary->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=with author glossary
function glossary_rss_feed_withauthor($glossary, $newsince=0) {
global $CFG;
$items = array();
if ($newsince) {
$newsince = " AND e.timecreated > '$newsince'";
} else {
$newsince = "";
}
if ($recs = get_records_sql ("SELECT e.id AS entryid,
e.concept AS entryconcept,
e.definition AS entrydefinition,
e.format AS entryformat,
e.timecreated AS entrytimecreated,
u.id AS userid,
u.firstname AS userfirstname,
u.lastname AS userlastname
FROM {$CFG->prefix}glossary_entries e,
{$CFG->prefix}user u
WHERE e.glossaryid = '$glossary->id' AND
u.id = e.userid AND
e.approved = 1 $newsince
ORDER BY e.timecreated desc")) {
//Are we just looking for new ones? If so, then return now.
if ($newsince) {
return true;
}
//Iterate over each entry to get glossary->rssarticles records
$articlesleft = $glossary->rssarticles;
$item = NULL;
$user = NULL;
foreach ($recs as $rec) {
unset($item);
unset($user);
$item->title = $rec->entryconcept;
$user->firstname = $rec->userfirstname;
$user->lastname = $rec->userlastname;
$item->author = fullname($user);
$item->pubdate = $rec->entrytimecreated;
$item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid;
$item->description = format_text($rec->entrydefinition,$rec->entryformat,NULL,$glossary->course);
$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=without author glossary
function glossary_rss_feed_withoutauthor($glossary, $newsince=0) {
global $CFG;
$items = array();
if ($newsince) {
$newsince = " AND e.timecreated > '$newsince'";
} else {
$newsince = "";
}
if ($recs = get_records_sql ("SELECT e.id AS entryid,
e.concept AS entryconcept,
e.definition AS entrydefinition,
e.format AS entryformat,
e.timecreated AS entrytimecreated,
u.id AS userid,
u.firstname AS userfirstname,
u.lastname AS userlastname
FROM {$CFG->prefix}glossary_entries e,
{$CFG->prefix}user u
WHERE e.glossaryid = '$glossary->id' AND
u.id = e.userid AND
e.approved = 1 $newsince
ORDER BY e.timecreated desc")) {
//Are we just looking for new ones? If so, then return now.
if ($newsince) {
return true;
}
//Iterate over each entry to get glossary->rssarticles records
$articlesleft = $glossary->rssarticles;
$item = NULL;
$user = NULL;
foreach ($recs as $rec) {
unset($item);
unset($user);
$item->title = $rec->entryconcept;
$user->firstname = $rec->userfirstname;
$user->lastname = $rec->userlastname;
//$item->author = fullname($user);
$item->pubdate = $rec->entrytimecreated;
$item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid;
$item->description = format_text($rec->entrydefinition,$rec->entryformat,NULL,$glossary->course);
$items[] = $item;
$articlesleft--;
if ($articlesleft < 1) {
break;
}
}
}
return $items;
}
?>
|