function glossary_rss_feeds() { global $CFG; $status = true; //Check CFG->enablerssfeeds if (empty($CFG->enablerssfeeds)) { debugging("DISABLED (admin variables)"); //Check CFG->glossary_enablerssfeeds } else { if (empty($CFG->glossary_enablerssfeeds)) { debugging("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 " . format_string($glossary->name, true) . ", 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 (debugging()) { if (empty($result)) { echo "ID: {$glossary->id}-> (empty) "; } else { if (!empty($status)) { echo "ID: {$glossary->id}-> OK "; } else { echo "ID: {$glossary->id}-> FAIL "; } } } } } } } } return $status; }
function glossary_rss_get_feed($context, $args) { global $CFG, $DB; $status = true; if (empty($CFG->glossary_enablerssfeeds)) { debugging("DISABLED (module configuration)"); return null; } $glossaryid = clean_param($args[3], PARAM_INT); $cm = get_coursemodule_from_instance('glossary', $glossaryid, 0, false, MUST_EXIST); if ($cm) { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); //context id from db should match the submitted one //no specific capability required to view glossary entries so just check user is enrolled if ($context->id != $modcontext->id || !is_enrolled($context)) { return null; } } $glossary = $DB->get_record('glossary', array('id' => $glossaryid), '*', MUST_EXIST); if (!rss_enabled_for_mod('glossary', $glossary)) { return null; } $sql = glossary_rss_get_sql($glossary); //get the cache file info $filename = rss_get_file_name($glossary, $sql); $cachedfilepath = rss_get_file_full_name('mod_glossary', $filename); //Is the cache out of date? $cachedfilelastmodified = 0; if (file_exists($cachedfilepath)) { $cachedfilelastmodified = filemtime($cachedfilepath); } //if the cache is more than 60 seconds old and there's new stuff $dontrecheckcutoff = time() - 60; if ($dontrecheckcutoff > $cachedfilelastmodified && glossary_rss_newstuff($glossary, $cachedfilelastmodified)) { if (!($recs = $DB->get_records_sql($sql, array(), 0, $glossary->rssarticles))) { return null; } $items = array(); $formatoptions = new stdClass(); $formatoptions->trusttext = true; foreach ($recs as $rec) { $item = new stdClass(); $user = new stdClass(); $item->title = $rec->entryconcept; if ($glossary->rsstype == 1) { //With author $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, $formatoptions, $glossary->course); $items[] = $item; } //First all rss feeds common headers $header = rss_standard_header(format_string($glossary->name, true), $CFG->wwwroot . "/mod/glossary/view.php?g=" . $glossary->id, format_string($glossary->intro, true)); //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)) { $rss = $header . $articles . $footer; //Save the XML contents to file. $status = rss_save_file('mod_glossary', $filename, $rss); } } if (!$status) { $cachedfilepath = null; } return $cachedfilepath; }