2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
12 // $Id: get_acheck.php 2291 2004-11-16 19:35:41Z joel $
15 * ATUTOR_PATH/get_rss.php?COURSE_ID-VERSION
17 COURSE_ID: integer value of the course (non-zero)
18 VERSION: [1|2] version of RSS
21 /* assumption: if the rss files exist, then they're supposed to exist and are public.
22 * if the rss file does not exist: check if this course has it enabled, and create it if needed.
23 * that way rss is only ever created if it's ever called. if it's enabled and never viewed, then there's no need
24 * to generate the files.
27 $_user_location = 'public';
29 define('AT_INCLUDE_PATH', 'include/');
30 require(AT_INCLUDE_PATH . '/vitals.inc.php');
32 if (isset($_SERVER['QUERY_STRING'])) {
33 $parts = explode('-', $_SERVER['QUERY_STRING'], 2);
34 $course = intval($parts[0]);
35 $version = intval($parts[1]);
37 header('HTTP/1.1 404 Not Found');
41 if (file_exists(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS' . $version . '.0.xml')) {
42 header('Content-Type: text/xml');
43 header('Content-Length: ' . filesize(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS'.$version.'.0.xml'));
44 echo file_get_contents(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS'.$version.'.0.xml');
46 } // else: (rss does not exist)
47 if ($system_courses[$course]['rss'] && (($version == 1) || ($version == 2))) {
48 // only RSS1 and 2 for now.
50 require(AT_INCLUDE_PATH . 'classes/feedcreator.class.php');
52 if (!is_dir(AT_CONTENT_DIR.'feeds/')){
53 @mkdir(AT_CONTENT_DIR. 'feeds/', 0700);
55 if (!is_dir(AT_CONTENT_DIR . 'feeds/' . $course)){
56 @mkdir(AT_CONTENT_DIR . 'feeds/' . $course . '/', 0700);
59 $rss = new UniversalFeedCreator();
61 $rss->title = $system_courses[$course]['title'];
62 $rss->description = $system_courses[$course]['description'];
63 $rss->link = AT_BASE_HREF;
64 $rss->syndicationURL = AT_BASE_HREF;
66 $image = new FeedImage();
67 $image->title = 'ATutor Logo';
68 $image->url = AT_BASE_HREF . 'images/at-logo.v.3.gif';
69 $image->link = AT_BASE_HREF;
72 $sql = "SELECT A.*, M.login from ".TABLE_PREFIX."news A, ".TABLE_PREFIX."members M WHERE A.course_id = ".$course." AND A.member_id=M.member_id ORDER BY A.date DESC LIMIT 5";
74 $res = mysql_query($sql, $db);
76 while ($data = mysql_fetch_assoc($res)) {
77 $item = new FeedItem();
79 $item->title = $data['title'];
80 $item->link = AT_BASE_HREF . 'index.php';
81 $item->description = $data['body'];
82 $item->date = strtotime($data['date']);
83 $item->source = AT_BASE_HREF;
84 $item->author = $data['login'];
89 header('Content-Type: text/xml');
90 $rss->saveFeed('RSS'.$version.'.0', AT_CONTENT_DIR . 'feeds/' . $course . '/RSS' . $version . '.0.xml', false);
92 echo file_get_contents(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS'.$version.'.0.xml');
95 } // else: this course didn't enable rss
97 header('HTTP/1.1 404 Not Found');