Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
function forum_rss_delete_file($forum)
{
    global $CFG;
    $rssfile = rss_file_name('forum', $forum);
    if (file_exists($rssfile)) {
        return unlink($rssfile);
    } else {
        return true;
    }
}
function lightboxgallery_rss_feeds()
{
    global $CFG;
    $status = true;
    if (!$CFG->enablerssfeeds) {
        debugging('DISABLED (admin variables)');
    } else {
        if (!get_config('lightboxgallery', 'enablerssfeeds')) {
            debugging('DISABLED (module configuration)');
        } else {
            if ($galleries = get_records('lightboxgallery')) {
                foreach ($galleries as $gallery) {
                    if ($gallery->rss && $status) {
                        $filename = rss_file_name('lightboxgallery', $gallery);
                        if (file_exists($filename)) {
                            if ($lastmodified = filemtime($filename)) {
                                if ($lastmodified > time() - HOURSECS) {
                                    continue;
                                }
                            }
                        }
                        if (!instance_is_visible('lightboxgallery', $gallery)) {
                            if (file_exists($filename)) {
                                @unlink($filename);
                            }
                            continue;
                        }
                        mtrace('Updating RSS feed for ' . format_string($gallery->name, true) . ', ID: ' . $gallery->id);
                        $result = lightboxgallery_rss_feed($gallery);
                        if (!empty($result)) {
                            $status = rss_save_file('lightboxgallery', $gallery, $result);
                        }
                        if (debugging()) {
                            if (empty($result)) {
                                echo 'ID: ' . $gallery->id . '-> (empty) ';
                            } else {
                                if (!empty($status)) {
                                    echo 'ID: ' . $gallery->id . '-> OK ';
                                } else {
                                    echo 'ID: ' . $gallery->id . '-> FAIL ';
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $status;
}
Exemplo n.º 4
0
function data_rss_feeds()
{
    global $CFG, $DB;
    $status = true;
    // Check CFG->enablerssfeeds.
    if (empty($CFG->enablerssfeeds)) {
        debugging("DISABLED (admin variables)");
    } else {
        if (empty($CFG->data_enablerssfeeds)) {
            debugging("DISABLED (module configuration)");
        } else {
            // Iterate over all data.
            if ($datas = $DB->get_records('data')) {
                foreach ($datas as $data) {
                    if ($data->rssarticles > 0) {
                        // 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))) {
                            continue;
                        }
                        // Get the data_records out.
                        $approved = $data->approval ? ' AND dr.approved = 1 ' : ' ';
                        $sql = "SELECT dr.*, u.firstname, u.lastname\n                                  FROM {data_records} dr, {user} u\n                                 WHERE dr.dataid = ? {$approved}\n                                       AND dr.userid = u.id\n                              ORDER BY dr.timecreated DESC";
                        if (!($records = $DB->get_records_sql($sql, array($data->id), 0, $data->rssarticles))) {
                            continue;
                        }
                        $firstrecord = array_shift($records);
                        // Get the first and put it back
                        array_unshift($records, $firstrecord);
                        $filename = rss_file_name('data', $data);
                        if (file_exists($filename)) {
                            if (filemtime($filename) >= $firstrecord->timemodified) {
                                continue;
                            }
                        }
                        // Now create all the articles
                        mtrace('Creating feed for ' . $data->name);
                        $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));
                        // First all rss feeds common headers.
                        $header = rss_standard_header($course->shortname . ': ' . format_string($data->name, true), $CFG->wwwroot . "/mod/data/view.php?d=" . $data->id, format_string($data->intro, true));
                        //TODO: fix format
                        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('data', $data, $rss);
                        } else {
                            $status = false;
                        }
                    }
                }
            }
        }
    }
    return $status;
}
Exemplo n.º 5
0
function rss_save_file($modname, $mod, $result)
{
    global $CFG;
    $status = true;
    if (!($basedir = make_upload_directory('rss/' . $modname))) {
        //Cannot be created, so error
        $status = false;
    }
    if ($status) {
        $file = rss_file_name($modname, $mod);
        $rss_file = fopen($file, "w");
        if ($rss_file) {
            $status = fwrite($rss_file, $result);
            fclose($rss_file);
        } else {
            $status = false;
        }
    }
    return $status;
}