tagging as ATutor 1.5.4-release
[atutor.git] / get_rss.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
9 /* This program is free software. You can redistribute it and/or                */
10 /* modify it under the terms of the GNU General Public License                  */
11 /* as published by the Free Software Foundation.                                                */
12 /************************************************************************/
13 // $Id: get_acheck.php 2291 2004-11-16 19:35:41Z joel $
14
15 /* call it:
16  * ATUTOR_PATH/get_rss.php?COURSE_ID-VERSION
17
18         COURSE_ID: integer value of the course (non-zero)
19         VERSION: [1|2] version of RSS
20 */
21
22 /* assumption: if the rss files exist, then they're supposed to exist and are public.
23  * if the rss file does not exist: check if this course has it enabled, and create it if needed.
24  * that way rss is only ever created if it's ever called. if it's enabled and never viewed, then there's no need
25  * to generate the files.
26  */
27
28 $_user_location = 'public';
29
30 define('AT_INCLUDE_PATH', 'include/');
31 require(AT_INCLUDE_PATH . '/vitals.inc.php');
32
33 if (isset($_SERVER['QUERY_STRING'])) {
34         $parts   = explode('-', $_SERVER['QUERY_STRING'], 2);
35         $course  = intval($parts[0]);
36         $version = intval($parts[1]);
37 } else {
38         header('HTTP/1.1 404 Not Found');
39         exit;
40 }
41
42 if (file_exists(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS' . $version . '.0.xml')) {
43         header('Content-Type: text/xml');
44         header('Content-Length: ' . filesize(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS'.$version.'.0.xml'));
45         echo file_get_contents(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS'.$version.'.0.xml');
46         exit;
47 } // else: (rss does not exist)
48 if ($system_courses[$course]['rss'] && (($version == 1) || ($version == 2))) {
49         // only RSS1 and 2 for now.
50
51         require(AT_INCLUDE_PATH . 'classes/feedcreator.class.php');
52
53         if (!is_dir(AT_CONTENT_DIR.'feeds/')){
54                 @mkdir(AT_CONTENT_DIR. 'feeds/', 0700);
55         }
56         if (!is_dir(AT_CONTENT_DIR . 'feeds/' . $course)){
57                 @mkdir(AT_CONTENT_DIR . 'feeds/' . $course . '/', 0700);
58         }
59
60         $rss = new UniversalFeedCreator();
61         $rss->useCached();
62         $rss->title          = $system_courses[$course]['title'];
63         $rss->description    = $system_courses[$course]['description'];
64         $rss->link           = AT_BASE_HREF;
65         $rss->syndicationURL = AT_BASE_HREF;
66         
67         $image = new FeedImage();
68         $image->title = 'ATutor Logo';
69         $image->url   = AT_BASE_HREF . 'images/at-logo.v.3.gif';
70         $image->link  = AT_BASE_HREF;
71         $rss->image   = $image;
72
73         $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
75         $res = mysql_query($sql, $db);
76
77         while ($data = mysql_fetch_assoc($res)) {
78                 $item = new FeedItem();
79                 
80                 $item->title          = $data['title'];
81                 $item->link           = AT_BASE_HREF . 'index.php';
82                 $item->description    = $data['body'];
83                 $item->date           = strtotime($data['date']);
84                 $item->source         = AT_BASE_HREF;
85                 $item->author         = $data['login'];
86
87                 $rss->addItem($item);
88         }
89
90         header('Content-Type: text/xml');
91         $rss->saveFeed('RSS'.$version.'.0', AT_CONTENT_DIR . 'feeds/' . $course . '/RSS' . $version . '.0.xml', false);
92
93         echo file_get_contents(AT_CONTENT_DIR . 'feeds/' . $course . '/RSS'.$version.'.0.xml');
94
95         exit;
96 } // else: this course didn't enable rss
97
98 header('HTTP/1.1 404 Not Found');
99 exit;
100
101
102 ?>