示例#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;

    $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;
}
示例#2
0
文件: rsslib.php 项目: verbazend/AWFA
/**
 * 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;
}
/**
 * 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;
}
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;
}
示例#7
0
            $uservalidated = false;
        }
    }
}
if (!$uservalidated) {
    pcast_rss_error('rsserrorauth');
}
// OK, the use should be able to see the feed, generate the .pcast file
$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)) {
    pcast_rss_error();
}
$sql = pcast_rss_get_sql($pcast);
$filename = rss_get_file_name($pcast, $sql);
//Append the GroupID to the end of the filename
$filename .= '_' . $groupid;
$cachedfilepath = pcast_rss_get_file_full_name('mod_pcast', $filename);
// Figure out the URL for the podcast based on the user info
$args = $pcast->id . '/' . $userid . '/' . $groupid;
$url = new moodle_url(rss_get_url($context->id, $userid, 'pcast', $args));
// Build the .pcast file
$rss = pcast_build_pcast_file($pcast, $url);
//Save the XML contents to file.
$status = pcast_rss_save_file('mod_pcast', $filename, $rss);
if (!$status) {
    $cachedfilepath = null;
}
// Check that file exists
if (empty($cachedfilepath) || !file_exists($cachedfilepath)) {
示例#8
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;
}