From a508f208ceefe3e503b00688db262d8ba6f8dd89 Mon Sep 17 00:00:00 2001 From: vyshane Date: Thu, 16 Feb 2006 03:35:10 +0000 Subject: [PATCH] RSS support --- mod/data/rsslib.php | 92 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 mod/data/rsslib.php diff --git a/mod/data/rsslib.php b/mod/data/rsslib.php new file mode 100644 index 00000000000..bbfb2897a74 --- /dev/null +++ b/mod/data/rsslib.php @@ -0,0 +1,92 @@ +enablerssfeeds. + if (empty($CFG->enablerssfeeds)) { + //Some debug... + if ($CFG->debug > 7) { + echo "DISABLED (admin variables)"; + } + } + // Check CFG->data_enablerssfeeds. + else if (empty($CFG->data_enablerssfeeds)) { + //Some debug... + if ($CFG->debug > 7) { + echo "DISABLED (module configuration)"; + } + } + // It's working so we start... + else { + // Iterate over all data. + if ($dataActivities = get_records('data')) { + foreach ($dataActivities as $dataActivity) { + + if ($dataActivity->rssarticles > 0) { + $filename = rss_file_name('data', $dataActivity); // RSS file + + // Get the data_records out. + $sql = 'SELECT dr.* ' . + 'FROM data_records AS dr ' . + "WHERE dr.dataid = {$dataActivity->id} " . + 'ORDER BY dr.timecreated DESC ' . + "LIMIT {$dataActivity->rssarticles}"; + + $dataRecords = recordset_to_array(get_recordset_sql($sql)); + + // Now all the rss items. + $items = array(); + + foreach ($dataRecords as $dataRecord) { + $item = null; + $temp = array(); + array_push($temp, $dataRecord); + + /*$user->firstname = 'test'; + $user->lastname = 'test'; + $item->author = fullname($user);*/ + $item->title = $dataActivity->name; + $item->pubdate = $dataRecord->timecreated; + $item->link = $CFG->wwwroot.'/mod/data/view.php?d='.$dataActivity->id.'&rid='.$dataRecord->id; + $item->description = data_print_template($temp, $dataActivity, '', 'rsstemplate', false, 0, 0, 'timecreated DESC', '', true); + + array_push($items, $item); + } + + // First all rss feeds common headers. + $header = rss_standard_header(format_string($dataActivity->name,true), + $CFG->wwwroot."/mod/data/view.php?d=".$dataActivity->id, + format_string($dataActivity->intro,true)); + + 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", $dataActivity, $rss); + } + else { + $status = false; + } + } + } + } + } + return $status; + } + +?> \ No newline at end of file