Merge branch 'master' of /home/arun/nubati.net/git/e-DoKo
[e-DoKo.git] / rss.php
1 <?php
2   /* get some information from the database */
3 error_reporting(E_ALL);
4
5 /* start a session, if it is not already running.
6  * This way people don't have to log in all the times.
7  * The session variables can also be read out from different
8  * php scripts, so that the code can be easily split up across several files
9  */
10
11 include_once("config.php");                /* needs to be first in list, since other includes use this */
12 include_once("./include/output.php");      /* html output only */
13 include_once("./include/db.php");          /* database only */
14 include_once("./include/functions.php");   /* the rest */
15
16 /* make sure that user has set all variables in config.php */
17 config_check();
18
19 /* open the database */
20 if(DB_open()<0)
21   {
22     output_header();
23     echo "Database error, can't connect... Please wait a while and try again. ".
24       "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
25     output_footer();
26     exit();
27   }
28
29 $ok = 0;
30 $id = 0;
31
32 if(!myisset("uid","token"))
33   {
34     echo "error";
35   }
36 else
37   {
38     $id = $_REQUEST['uid'];
39     $token = get_user_token($id);
40
41     if($token == $_REQUEST['token'])
42       $ok = 1;
43   }
44
45 if(! $ok)
46   {
47     echo "No valid userid";
48     exit();
49   }
50
51 header("Content-Type: text/xml");
52 /* start the feed */
53 ?>
54 <feed xmlns="http://www.w3.org/2005/Atom">
55 <title>E-DoKo Feed</title>
56 <subtitle>Know when it is your turn</subtitle>
57 <?php
58
59   global $WIKI,$INDEX, $HOST;
60
61   /* output last creation date */
62 echo "<link href=\"$HOST/$INDEX\" />\n";
63 echo "<link rel=\"self\" href=\"".$HOST.htmlentities($_SERVER['REQUEST_URI'])."\" />\n";
64 $date = DB_query_array("Select create_date from User order by create_date ASC limit 1");
65 $date = $date[0];
66 $timestamp = strtotime($date);
67 echo "<id>tag:".$_SERVER['SERVER_NAME'].",".date("Y-m-d",$timestamp).":$INDEX</id>\n";
68 echo "<updated>".date(DATE_ATOM)."</updated>\n";
69 echo "<author>\n";
70 echo "<name>$ADMIN_NAME  $date $timestamp</name>\n";
71 echo "<email>$ADMIN_EMAIL</email>\n";
72 echo "</author>\n\n";
73
74
75  /* output the entries */
76
77
78   $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand".
79                      " LEFT JOIN Game On Hand.game_id=Game.id".
80                      " WHERE Hand.user_id='$id'".
81                      " AND ( Game.player='$id' OR ISNULL(Game.player) )".
82                      " AND ( Game.status='pre' OR Game.status='play' )".
83                      " ORDER BY Game.session" );
84
85   while( $r = DB_fetch_array($result))
86     {
87       echo "<entry>\n";
88       echo "<title>game ".DB_format_gameid($r[1])."</title>\n";
89       $url=$INDEX."?action=game&amp;me=".$r[0];
90       echo "<link href=\"".$HOST.$url."\" />\n";
91       $date = DB_get_game_timestamp($r[1]);
92       $timestamp = strtotime($date);
93       $date = date("Y-m-d",$timestamp);
94       echo "<id>tag:doko.nubati.net,$date:$url</id>\n";
95       echo "<updated>".date(DATE_ATOM,$timestamp)."</updated>\n";
96       echo "<summary>Please use the link to access the game.</summary>\n";
97       echo "</entry>\n\n";
98     }
99
100 ?>
101 </feed>