/** * Generates the RSS Feed * * @param strClass $context the context the feed should be created under * @param array $args array of arguments to be used in the creation of the RSS Feed * @return NULL|string NULL if there is nothing to return, or the file path of the cached file if there is */ function dataform_rss_get_feed($context, $args) { global $CFG, $DB; // Check CFG->data_enablerssfeeds. if (empty($CFG->dataform_enablerssfeeds)) { debugging("DISABLED (module configuration)"); return null; } // Validate context. $dataformid = clean_param($args[3], PARAM_INT); $cm = get_coursemodule_from_instance('dataform', $dataformid, 0, false, MUST_EXIST); if ($cm) { $modcontext = context_module::instance($cm->id); // Context id from db should match the submitted one. if ($context->id != $modcontext->id) { return null; } } // Check RSS enbabled for instance. $dataform = $DB->get_record('dataform', array('id' => $dataformid), '*', MUST_EXIST); if (!rss_enabled_for_mod('dataform', $dataform, false, false)) { return null; } // Get the target view. $viewid = clean_param($args[4], PARAM_INT); $viewdata = $DB->get_record('dataform_views', array('id' => $viewid), '*', MUST_EXIST); $viewman = mod_dataform_view_manager::instance($dataformid); $view = $viewman->get_view_by_id($viewid); // If (!($view instanceof 'mod_dataform\interfaces\rss')) { // return null; // }. // Get the cache file info // The cached file name is formatted dfid_viewid_contentstamp, // where contentstamp is provided by the view. $componentid = $dataformid . "_{$viewid}"; $cachedfilepath = dataform_rss_get_cached_file_path($componentid); $contentstamp = $cachedfilepath ? dataform_rss_get_cached_content_stamp($cachedfilepath) : null; $newcontentstamp = $view->get_content_stamp(); $hasnewcontent = $newcontentstamp !== $contentstamp; // Neither existing nor new. if (!$cachedfilepath and !$hasnewcontent) { return null; } if ($cachedfilepath) { // Use cache under 60 seconds. $cachetime = filemtime($cachedfilepath); if (time() - $cachetime < 60) { return $cachedfilepath; } // Use cache if there is nothing new. if (!$hasnewcontent) { return $cachedfilepath; } // Cached file is outdated so delete it. $instance = (object) array('id' => $componentid); rss_delete_file('mod_dataform', $instance); } // Still here, fetch new content. // Each article is an stdclass {title, descrition, pubdate, entrylink}. if (!($items = $view->get_rss_items())) { return null; } // First all rss feeds common headers. $headertitle = $view->get_rss_header_title(); $headerlink = $view->get_rss_header_link(); $headerdescription = $view->get_rss_header_description(); $header = rss_standard_header($headertitle, $headerlink, $headerdescription); if (empty($header)) { return null; } // Now all rss feeds common footers. $footer = rss_standard_footer(); if (empty($footer)) { return null; } // All's good, save the content to file. $articles = rss_add_items($items); $rss = $header . $articles . $footer; $filename = $componentid . "_{$newcontentstamp}"; $status = rss_save_file('mod_dataform', $filename, $rss); $dirpath = dataform_rss_get_cache_dir_path(); return "{$dirpath}/{$filename}.xml"; }
/** * Given a forum object, deletes all cached RSS files associated with it. * * @param stdClass $forum */ function forum_rss_delete_file($forum) { rss_delete_file('mod_forum', $forum); }
/** * Given a anonforum object, deletes all cached RSS files associated with it. * * @param stdClass $anonforum */ function anonforum_rss_delete_file($anonforum) { rss_delete_file('mod_anonforum', $anonforum); }
/** * Given a twf object, deletes all cached RSS files associated with it. * * @param stdClass $twf */ function twf_rss_delete_file($twf) { rss_delete_file('mod_twf', $twf); }
/** * Given a quora object, deletes all cached RSS files associated with it. * * @param stdClass $quora */ function quora_rss_delete_file($quora) { rss_delete_file('mod_quora', $quora); }
/** * Given a glossary object, deletes all cached RSS files associated with it. * * @param stdClass $glossary */ function glossary_rss_delete_file($glossary) { global $CFG; require_once "{$CFG->libdir}/rsslib.php"; rss_delete_file('mod_glossary', $glossary); }
/** * Given a database object, deletes all cached RSS files associated with it. * * @param stdClass $data */ function data_rss_delete_file($data) { global $CFG; require_once "{$CFG->libdir}/rsslib.php"; rss_delete_file('mod_data', $data); }