Пример #1
0
/**
 * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary.
 * @param stdClass $context the context
 * @param array    $args    the arguments received in the url
 * @return string the full path to the cached RSS feed directory. Null if there is a problem.
 */
function forum_rss_get_feed($context, $args) {
    global $CFG, $DB, $USER;

    $status = true;

    //are RSS feeds enabled?
    if (empty($CFG->forum_enablerssfeeds)) {
        debugging('DISABLED (module configuration)');
        return null;
    }

    $forumid  = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('forum', $forumid, 0, false, MUST_EXIST);
    $modcontext = context_module::instance($cm->id);

    //context id from db should match the submitted one
    if ($context->id != $modcontext->id || !has_capability('mod/forum:viewdiscussion', $modcontext)) {
        return null;
    }

    $forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
    if (!rss_enabled_for_mod('forum', $forum)) {
        return null;
    }

    //the sql that will retreive the data for the feed and be hashed to get the cache filename
    list($sql, $params) = forum_rss_get_sql($forum, $cm);

    // Hash the sql to get the cache file name.
    $filename = rss_get_file_name($forum, $sql, $params);
    $cachedfilepath = rss_get_file_full_name('mod_forum', $filename);

    //Is the cache out of date?
    $cachedfilelastmodified = 0;
    if (file_exists($cachedfilepath)) {
        $cachedfilelastmodified = filemtime($cachedfilepath);
    }
    // Used to determine if we need to generate a new RSS feed.
    $dontrecheckcutoff = time() - 60; // Sixty seconds ago.

    // If it hasn't been generated we need to create it.
    // Otherwise, if it has been > 60 seconds since we last updated, check for new items.
    if (($cachedfilelastmodified == 0) || (($dontrecheckcutoff > $cachedfilelastmodified) &&
        forum_rss_newstuff($forum, $cm, $cachedfilelastmodified))) {
        // Need to regenerate the cached version.
        $result = forum_rss_feed_contents($forum, $sql, $params, $modcontext);
        $status = rss_save_file('mod_forum', $filename, $result);
    }

    //return the path to the cached version
    return $cachedfilepath;
}
Пример #2
0
/**
 * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary.
 * @param stdClass $context the context
 * @param array    $args    the arguments received in the url
 * @return string the full path to the cached RSS feed directory. Null if there is a problem.
 */
function forum_rss_get_feed($context, $args) {
    global $CFG, $DB;

    $status = true;

    //are RSS feeds enabled?
    if (empty($CFG->forum_enablerssfeeds)) {
        debugging('DISABLED (module configuration)');
        return null;
    }

    $forumid  = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('forum', $forumid, 0, false, MUST_EXIST);
    if ($cm) {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);

        //context id from db should match the submitted one
        if ($context->id != $modcontext->id || !has_capability('mod/forum:viewdiscussion', $modcontext)) {
            return null;
        }
    }

    $forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
    if (!rss_enabled_for_mod('forum', $forum)) {
        return null;
    }

    //the sql that will retreive the data for the feed and be hashed to get the cache filename
    $sql = forum_rss_get_sql($forum, $cm);

    //hash the sql to get the cache file name
    $filename = rss_get_file_name($forum, $sql);
    $cachedfilepath = rss_get_file_full_name('mod_forum', $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 && forum_rss_newstuff($forum, $cm, $cachedfilelastmodified)) {
        //need to regenerate the cached version
        $result = forum_rss_feed_contents($forum, $sql);
        if (!empty($result)) {
            $status = rss_save_file('mod_forum',$filename,$result);
        }
    }

    //return the path to the cached version
    return $cachedfilepath;
}
Пример #3
0
/**
 * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary.
 * @param stdClass $context the context
 * @param array    $args    the arguments received in the url
 * @return string the full path to the cached RSS feed directory. Null if there is a problem.
 */
function hsuforum_rss_get_feed($context, $args)
{
    global $DB;
    $config = get_config('hsuforum');
    //are RSS feeds enabled?
    if (empty($config->enablerssfeeds)) {
        debugging('DISABLED (module configuration)');
        return null;
    }
    $forumid = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('hsuforum', $forumid, 0, false, MUST_EXIST);
    $modcontext = context_module::instance($cm->id);
    //context id from db should match the submitted one
    if ($context->id != $modcontext->id || !has_capability('mod/hsuforum:viewdiscussion', $modcontext)) {
        return null;
    }
    $forum = $DB->get_record('hsuforum', array('id' => $forumid), '*', MUST_EXIST);
    if (!rss_enabled_for_mod('hsuforum', $forum)) {
        return null;
    }
    //the sql that will retreive the data for the feed and be hashed to get the cache filename
    list($sql, $params) = hsuforum_rss_get_sql($forum, $cm);
    // Hash the sql to get the cache file name.
    $filename = rss_get_file_name($forum, $sql, $params);
    $cachedfilepath = rss_get_file_full_name('mod_hsuforum', $filename);
    //Is the cache out of date?
    $cachedfilelastmodified = 0;
    if (file_exists($cachedfilepath)) {
        $cachedfilelastmodified = filemtime($cachedfilepath);
    }
    // Used to determine if we need to generate a new RSS feed.
    $dontrecheckcutoff = time() - 60;
    // If it hasn't been generated we will need to create it, otherwise only update
    // if there is new stuff to show and it is older than the cut off date set above.
    if ($cachedfilelastmodified == 0 || $dontrecheckcutoff > $cachedfilelastmodified && hsuforum_rss_newstuff($forum, $cm, $cachedfilelastmodified)) {
        // Need to regenerate the cached version.
        $result = hsuforum_rss_feed_contents($forum, $sql, $params, $modcontext);
        rss_save_file('mod_hsuforum', $filename, $result);
    }
    //return the path to the cached version
    return $cachedfilepath;
}
Пример #4
0
function data_rss_get_feed($context, $args)
{
    global $CFG, $DB;
    // Check CFG->data_enablerssfeeds.
    if (empty($CFG->data_enablerssfeeds)) {
        debugging("DISABLED (module configuration)");
        return null;
    }
    $dataid = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('data', $dataid, 0, false, MUST_EXIST);
    if ($cm) {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        //context id from db should match the submitted one
        if ($context->id != $modcontext->id || !has_capability('mod/data:viewentry', $modcontext)) {
            return null;
        }
    }
    $data = $DB->get_record('data', array('id' => $dataid), '*', MUST_EXIST);
    if (!rss_enabled_for_mod('data', $data, false, true)) {
        return null;
    }
    $sql = data_rss_get_sql($data);
    //get the cache file info
    $filename = rss_get_file_name($data, $sql);
    $cachedfilepath = rss_get_file_full_name('mod_data', $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 && data_rss_newstuff($data, $cachedfilelastmodified)) {
        require_once $CFG->dirroot . '/mod/data/lib.php';
        // Get the first field in the list  (a hack for now until we have a selector)
        if (!($firstfield = $DB->get_record_sql('SELECT id,name FROM {data_fields} WHERE dataid = ? ORDER by id', array($data->id), true))) {
            return null;
        }
        if (!($records = $DB->get_records_sql($sql, array(), 0, $data->rssarticles))) {
            return null;
        }
        $firstrecord = array_shift($records);
        // Get the first and put it back
        array_unshift($records, $firstrecord);
        // Now create all the articles
        $items = array();
        foreach ($records as $record) {
            $recordarray = array();
            array_push($recordarray, $record);
            $item = null;
            // guess title or not
            if (!empty($data->rsstitletemplate)) {
                $item->title = data_print_template('rsstitletemplate', $recordarray, $data, '', 0, true);
            } else {
                // else we guess
                $item->title = strip_tags($DB->get_field('data_content', 'content', array('fieldid' => $firstfield->id, 'recordid' => $record->id)));
            }
            $item->description = data_print_template('rsstemplate', $recordarray, $data, '', 0, true);
            $item->pubdate = $record->timecreated;
            $item->link = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id;
            array_push($items, $item);
        }
        $course = $DB->get_record('course', array('id' => $data->course));
        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
        $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
        // First all rss feeds common headers.
        $header = rss_standard_header($courseshortname . ': ' . format_string($data->name, true, array('context' => $context)), $CFG->wwwroot . "/mod/data/view.php?d=" . $data->id, format_text($data->intro, $data->introformat, array('context' => $context)));
        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_data', $filename, $rss);
        }
    }
    return $cachedfilepath;
}
Пример #5
0
/**
 * This function saves to file the rss feed specified in the parameters
 *
 * @param string $componentname  the module name ie forum. Used to create a cache directory.
 * @param string $filename       the name of the file to be created ie "rss.xml"
 * @param string $contents       the data to be written to the file
 * @param bool   $expandfilename whether or not the fullname of the RSS file should be used
 * @return bool whether the save was successful or not
 */
function rss_save_file($componentname, $filename, $contents, $expandfilename = true)
{
    global $CFG;
    $status = true;
    if (!($basedir = make_cache_directory('rss/' . $componentname))) {
        //Cannot be created, so error
        $status = false;
    }
    if ($status) {
        $fullfilename = $filename;
        if ($expandfilename) {
            $fullfilename = rss_get_file_full_name($componentname, $filename);
        }
        $rss_file = fopen($fullfilename, "w");
        if ($rss_file) {
            $status = fwrite($rss_file, $contents);
            fclose($rss_file);
        } else {
            $status = false;
        }
    }
    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;
}
/**
 * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary.
 * @global object $CFG
 * @global object $DB
 * @param object $context the context
 * @param array $args the arguments received in the url
 * @return string the full path to the cached RSS feed directory. Null if there is a problem.
 */
function lightboxgallery_rss_get_feed($context, $args)
{
    global $CFG, $DB;
    $config = get_config('lightboxgallery');
    $status = true;
    // Are RSS feeds enabled?
    if (empty($config->enablerssfeeds)) {
        debugging('DISABLED (module configuration)');
        return null;
    }
    $galleryid = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('lightboxgallery', $galleryid, 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;
        }
    }
    $gallery = $DB->get_record('lightboxgallery', array('id' => $galleryid), '*', MUST_EXIST);
    $captions = array();
    if ($cobjs = $DB->get_records('lightboxgallery_image_meta', array('metatype' => 'caption', 'gallery' => $gallery->id))) {
        foreach ($cobjs as $cobj) {
            $captions[$cobj->image] = $cobj->description;
        }
    }
    $fs = get_file_storage();
    $storedfiles = $fs->get_area_files($context->id, 'mod_lightboxgallery', 'gallery_images');
    $items = array();
    $counter = 1;
    $articles = '';
    foreach ($storedfiles as $file) {
        $filename = $file->get_filename();
        if ($filename == '.') {
            continue;
        }
        $description = isset($captions[$filename]) ? $captions[$filename] : $filename;
        $image = new lightboxgallery_image($file, $gallery, $cm);
        $item = new stdClass();
        $item->{"media:description"} = $description;
        $articles .= rss_start_tag('item', 2, true);
        $articles .= rss_full_tag('title', 3, false, $filename);
        $articles .= rss_full_tag('link', 3, false, $image->get_image_url());
        $articles .= rss_full_tag('guid', 3, false, 'img' . $counter);
        $articles .= rss_full_tag('media:description', 3, false, $description);
        $articles .= rss_full_tag('media:thumbnail', 3, false, '', array('url' => $image->get_thumbnail_url()));
        $articles .= rss_full_tag('media:content', 3, false, '', array('url' => $image->get_image_url(), 'type' => $file->get_mimetype()));
        $articles .= rss_end_tag('item', 2, true);
    }
    // Get the cache file info.
    $filename = rss_get_file_name($gallery, $sql);
    $cachedfilepath = rss_get_file_full_name('mod_lightboxgallery', $filename);
    // Is the cache out of date?
    $cachedfilelastmodified = 0;
    if (file_exists($cachedfilepath)) {
        $cachedfilelastmodified = filemtime($cachedfilepath);
    }
    // First all rss feeds common headers.
    $header = lightboxgallery_rss_header(format_string($gallery->name, true), $CFG->wwwroot . "/mod/lightboxgallery/view.php?id=" . $cm->id, format_string($gallery->intro, true));
    // 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_lightboxgallery', $filename, $rss);
    }
    if (!$status) {
        $cachedfilepath = null;
    }
    return $cachedfilepath;
}
Пример #8
0
/**
 * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary.
 * The RSS feed content is a course search result.
 * @param array $args the arguments received in the url
 * $args[0] => context id = 2 (Front page) - not used
 * $args[1] => token
 * $args[2] => module name (it was needed by the rss/file.php to call this function) - not used
 * $args[3] => downloadable - PARAM_INT
 * $args[4] => audience - PARAM_ALPHA
 * $args[5] => educationallevel - PARAM_ALPHA
 * $args[6] => subject - PARAM_ALPHA
 * $args[7] => licence - PARAM_ALPHA
 * $args[8] => language - PARAM_ALPHANUMEXT
 * $args[9] => search - PARAM_TEXT (url encoded)
 * $args[10] => orderby - PARAM_ALPHA
 * @return string the full path to the cached RSS feed directory. Null if there is a problem.
 */
function hub_rss_get_feed($context, $args)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/local/hub/lib.php';
    //are RSS feeds enabled?
    $enablerssfeeds = get_config('local_hub', 'enablerssfeeds');
    if (empty($enablerssfeeds)) {
        debugging('DISABLED (module configuration)');
        return null;
    }
    //check capabilities
    if (!has_capability('local/hub:view', $context)) {
        return null;
    }
    //TODO: cache
    $filename = 'rsssearch_' . $args[3] . '_' . $args[4] . '_' . $args[5] . '_' . $args[6] . '_' . $args[7] . '_' . $args[8] . '_' . $args[9] . '_' . $args[10];
    $cachedfilepath = rss_get_file_full_name('local_hub', $filename);
    //get the courses from the search
    if ($args[7] != 'all') {
        $options['licenceshortname'] = $args[7];
    }
    if ($args[6] != 'all') {
        $options['subject'] = $args[6];
    }
    if ($args[4] != 'all') {
        $options['audience'] = $args[4];
    }
    if ($args[5] != 'all') {
        $options['educationallevel'] = $args[5];
    }
    if ($args[8] != 'all') {
        $options['language'] = $args[8];
    }
    if ($args[3] != 'all') {
        $options['downloadable'] = $args[3];
        $options['enrollable'] = !$args[3];
    } else {
        $options['downloadable'] = true;
        $options['enrollable'] = true;
    }
    $options['search'] = empty($args[9]) ? '' : urldecode($args[9]);
    //if the RSS invisible secret is passed as parameter, display not visible course
    $rsssecret = get_config('local_hub', 'rsssecret');
    if (!empty($rsssecret) and $rsssecret == optional_param('rsssecret', false, PARAM_RAW)) {
        $options['visibility'] = COURSEVISIBILITY_NOTVISIBLE;
    } else {
        $options['visibility'] = COURSEVISIBILITY_VISIBLE;
    }
    //order by
    switch ($args[10]) {
        case 'newest':
            $options['orderby'] = 'timemodified DESC';
            break;
        case 'eldest':
            $options['orderby'] = 'timemodified ASC';
            break;
        case 'publisher':
            $options['orderby'] = 'publishername ASC';
            break;
        case 'fullname':
            $options['orderby'] = 'fullname ASC';
            break;
        case 'ratingaverage':
            $options['orderby'] = 'ratingaverage DESC';
            break;
        default:
            break;
    }
    $hub = new local_hub();
    $courses = $hub->get_courses($options, 0, 10);
    //generate the information for rss
    $rssfeedinfo = local_hub_rss_generate_feed_info($courses);
    //generate the rss content
    require_once $CFG->libdir . "/rsslib.php";
    //First the RSS header
    $searchurl = new moodle_url($CFG->wwwroot . '/', array('downloadable' => $args[3], 'audience' => $args[4], 'educationallevel' => $args[5], 'subject' => $args[6], 'licence' => $args[7], 'language' => $args[8], 'search' => $args[9], 'orderby' => $args[10], 'submitbutton' => 'Search+for+courses'));
    $rsscontent = rss_standard_header(get_config('local_hub', 'name'), $searchurl->out(), get_string('hubcoursessearch', 'local_hub'));
    $rsscontent .= rss_add_items($rssfeedinfo);
    //Now the RSS footer
    $rsscontent .= rss_standard_footer();
    if (!empty($rsscontent)) {
        rss_save_file('local_hub', $filename, $rsscontent);
    }
    //return the path to the cached version
    return $cachedfilepath;
}
Пример #9
0
/**
 * This function is the main entry point to pcast
 * rss feeds generation.
 *
 * @global object $CFG
 * @global object $DB
 * @param string? $context
 * @param array $args
 * @return string (path)
 */
function pcast_rss_get_feed($context, $args)
{
    global $CFG, $DB;
    if (empty($CFG->pcast_enablerssfeeds)) {
        debugging("DISABLED (module configuration)");
        return null;
    }
    $status = true;
    $token = clean_param($args[1], PARAM_ALPHANUM);
    $pcastid = clean_param($args[3], PARAM_INT);
    $groupid = clean_param($args[4], PARAM_INT);
    $uservalidated = false;
    //check capabilities
    $cm = get_coursemodule_from_instance('pcast', $pcastid, 0, false, MUST_EXIST);
    if ($cm) {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        //context id from db should match the submitted one
        if ($context->id == $modcontext->id && has_capability('mod/pcast:view', $modcontext)) {
            $uservalidated = true;
        }
    }
    //get userid from Token
    $userid = rss_get_userid_from_token($token);
    //Check group mode 0/1/2 (All participants)
    $groupmode = groups_get_activity_groupmode($cm);
    //Using Groups, check to see if user should see all participants
    if ($groupmode == SEPARATEGROUPS) {
        //User must have the capability to see all groups or be a member of that group
        $members = get_enrolled_users($context, 'mod/pcast:write', $groupid, 'u.id', 'u.id ASC');
        // Is a member of the current group
        if (!isset($members[$userid]->id) or $members[$userid]->id != $userid) {
            // Not a member of the group, can you see all groups (from CAPS)
            if (!has_capability('moodle/site:accessallgroups', $context, $userid)) {
                $uservalidated = false;
            }
        } else {
            // Are a member of the current group
            // Is the group #0 (Group 0 is all users)
            if ($groupid == 0 and !has_capability('moodle/site:accessallgroups', $context, $userid)) {
                $uservalidated = false;
            }
        }
    }
    if (!$uservalidated) {
        return null;
    }
    // OK the user can view the RSS feed
    $pcast = $DB->get_record('pcast', array('id' => $pcastid), '*', MUST_EXIST);
    // Check to se if RSS is enabled
    // NOTE: cannot use the rss_enabled_for_mod() function due to the functions internals and naming conflicts
    if ($pcast->rssepisodes == 0 || empty($pcast->rssepisodes)) {
        return null;
    }
    $sql = pcast_rss_get_sql($pcast);
    //get the cache file info
    $filename = rss_get_file_name($pcast, $sql);
    //Append the GroupID to the end of the filename
    $filename .= '_' . $groupid;
    $cachedfilepath = rss_get_file_full_name('mod_pcast', $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 && pcast_rss_newstuff($pcast, $cachedfilelastmodified)) {
        if (!($recs = $DB->get_records_sql($sql, array(), 0, $pcast->rssepisodes))) {
            return null;
        }
        $items = array();
        $formatoptions = new stdClass();
        $formatoptions->trusttext = true;
        foreach ($recs as $rec) {
            $item = new stdClass();
            $user = new stdClass();
            $item->title = $rec->episodename;
            $item->pcastid = $rec->pcastid;
            $item->id = $rec->episodeid;
            $item->userid = $rec->userid;
            $item->course = $rec->course;
            if ($pcast->displayauthor == 1) {
                //With author
                $user->firstname = $rec->userfirstname;
                $user->lastname = $rec->userlastname;
                $item->author = fullname($user);
            }
            $item->keywords = $rec->keywords;
            $item->subtitle = $rec->subtitle;
            $item->duration = $rec->duration;
            $item->pubdate = $rec->episodetimecreated;
            $item->link = new moodle_url('/mod/pcast/showepisode.php', array('eid' => $rec->episodeid));
            $item->description = format_text($rec->episodesummary, 'HTML', NULL, $pcast->course);
            // $item->description = strip_tags($rec->episodesummary);
            if ($pcast->userscancategorize) {
                //TODO: This is very inefficient (this generates 2 DB queries per entry)
                $category = pcast_rss_category_lookup($rec);
                $item->topcategory = $category->top->name;
                $item->nestedcategory = $category->nested->name;
            }
            $items[] = $item;
        }
        //First all rss feeds common headers
        $url = new moodle_url('/mod/pcast/view.php', array('id' => $pcast->id));
        $header = pcast_rss_header(format_string($pcast->name, true), $url, format_string($pcast->intro, true), $pcast);
        // Do we need iTunes tags?
        if (isset($pcast->enablerssitunes) && $pcast->enablerssitunes == 1) {
            $itunes = true;
        } else {
            $itunes = false;
        }
        //Now all the rss items
        if (!empty($header)) {
            $episodes = pcast_rss_add_items($context, $items, $itunes, $groupid);
        }
        //Now all rss feeds common footers
        if (!empty($header) && !empty($episodes)) {
            $footer = pcast_rss_footer();
        }
        //Now, if everything is ok, concatenate it
        if (!empty($header) && !empty($episodes) && !empty($footer)) {
            $rss = $header . $episodes . $footer;
            //Save the XML contents to file.
            $status = rss_save_file('mod_pcast', $filename, $rss);
        }
    }
    if (!$status) {
        $cachedfilepath = null;
    }
    return $cachedfilepath;
}