Example #1
0
}
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)) {
    die($cachedfilepath);
    pcast_rss_error();
}
Example #2
0
/**
 * This function saves to file the rss feed specified in the parameters
 *
 * @global object
 * @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 "1234"
 * @param string $contents the data to be written to the file
 */
function pcast_rss_save_file($componentname, $filename, $contents, $expandfilename = true)
{
    global $CFG;
    $status = true;
    if (!($basedir = make_upload_directory('cache/rss/' . $componentname))) {
        //Cannot be created, so error
        $status = false;
    }
    if ($status) {
        $fullfilename = $filename;
        if ($expandfilename) {
            $fullfilename = pcast_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;
}