NEW FEATURE: provide an RSS feed for each user showing in which games it's his turn
authorArun Persaud <arun@nubati.net>
Wed, 3 Feb 2010 06:37:27 +0000 (22:37 -0800)
committerArun Persaud <arun@nubati.net>
Fri, 5 Feb 2010 06:17:09 +0000 (22:17 -0800)
the feed shows the same as the "It's your turn in these games" box.

INSTALL
config.php_template
include/db.php
include/functions.php
include/output.php
rss.php [new file with mode: 0644]

diff --git a/INSTALL b/INSTALL
index 86b65d418a240284661d535e858aa25db6868624..0fada71b774e4d81101c8b8e24a2163d05b1758f 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -26,6 +26,7 @@ Installation
   $HOST:  for example "http://localhost"
   $INDEX: the absolute web path to your index.php file e.g. "/mypath/index.php"
   $STATS: the absolute web path to your stats.php file e.g. "/mypath/stast.php"
+  $RSSS:  the absolute web path to your rss.php file e.g. "/mypath/rss.php"
 
   database info:
 
index 93e951cf68f9dc491a55c5808f4420d5127590d9..a3e9e54c17d911f5aa72222197554b9cc167c150 100644 (file)
@@ -33,6 +33,8 @@
      */
     $INDEX = "/index.php";
     $HOST  = "http://www.example.com";
+    $STATS = "/stats.php";
+    $RSS   = "/rss.php";
 
     /* point this to a Wiki that explains the rules, etc (or use this one)*/
     $WIKI  = "http://wiki.nubati.net/index.php?title=EmailDoko";
index 882a1adb35448224451f230aff4f6278fa373a80..55d97c97e4673134418ad5a1aa49f934a65e799a 100644 (file)
@@ -498,6 +498,15 @@ function DB_update_game_timestamp($gameid)
   return;
 }
 
+function DB_get_game_timestamp($gameid)
+{
+  $r = DB_query_array("SELECT mod_date FROM Game WHERE id=".DB_quote_smart($gameid));
+
+  if($r)
+    return $r[0];
+  else
+    return NULL;
+}
 
 function DB_update_user_timestamp($userid)
 {
@@ -514,6 +523,17 @@ function DB_get_user_timestamp($userid)
   else
     return NULL;
 }
+
+function DB_get_user_creation_date($userid)
+{
+  $r = DB_query_array("SELECT create_date FROM User WHERE id=".DB_quote_smart($userid));
+
+  if($r)
+    return $r[0];
+  else
+    return NULL;
+}
+
 function DB_get_user_timezone($userid)
 {
   $r = DB_query_array("SELECT timezone FROM User WHERE id=".DB_quote_smart($userid));
index eca0155f3e2de43cc22cdb11b91c9d8e4907dd02..33da9ef04ebbd8de8b11bb36a93538581d49cb27 100644 (file)
@@ -1384,4 +1384,18 @@ function cancel_game($why,$gameid)
   return;
 }
 
+function get_user_token($userid)
+{
+
+  $token = NULL;
+
+  $date = DB_get_user_creation_date($userid);
+  $name = DB_get_name('userid',$userid);
+
+  if($date && $name)
+    $token = md5("token".$name.$date);
+
+  return $token;
+}
+
 ?>
index 57b3152c035ea29efc511af39670308606951e23..61fef6004fbe5d60d8c1087ec5db8ad54edc1570 100644 (file)
@@ -380,39 +380,44 @@ function output_footer()
 
 function output_status()
 {
-  global $defaulttimezone,$INDEX,$WIKI;
-   if(isset($_SESSION["name"]))
-     {
-       $name = $_SESSION["name"];
-
-       /* logout info */
-       echo "\n<div class=\"status\">\n";
-       echo $name,"\n";
-       echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
-       echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
-       echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
-       echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
-       echo " | <a href=\"".$WIKI."\">wiki</a>\n";
-       echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
-       echo "</div>\n";
-
-       /* last logon time */
-       $myid  = DB_get_userid("name",$name);
-       $zone  = DB_get_user_timezone($myid);
-
-       $time     = DB_get_user_timestamp($myid);
-       date_default_timezone_set($defaulttimezone);
-       $unixtime = strtotime($time);
-       date_default_timezone_set($zone);
-
-       echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
-     }
-   else
-     {
-       echo "\n<div class=\"status\">\n";
-       echo "<a href=\"".$INDEX."\">login</a>\n";
-       echo "</div>\n";
-     }
+  global $defaulttimezone, $INDEX, $WIKI, $RSS;
+
+  if(isset($_SESSION["name"]))
+    {
+      $name = $_SESSION["name"];
+
+      /* last logon time */
+      $myid  = DB_get_userid("name",$name);
+      $zone  = DB_get_user_timezone($myid);
+
+      $time     = DB_get_user_timestamp($myid);
+      date_default_timezone_set($defaulttimezone);
+      $unixtime = strtotime($time);
+      date_default_timezone_set($zone);
+
+      /* rss token */
+      $token = get_user_token($myid);
+
+      /* logout info */
+      echo "\n<div class=\"status\">\n";
+      echo $name,"\n";
+      echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
+      echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
+      echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
+      echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
+      echo " | <a href=\"".$WIKI."\">wiki</a>\n";
+      echo " | <a href=\"".$RSS."?uid=".$myid."&amp;token=".$token."\">rss</a>\n";
+      echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
+      echo "</div>\n";
+
+      echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
+    }
+  else
+    {
+      echo "\n<div class=\"status\">\n";
+      echo "<a href=\"".$INDEX."\">login</a>\n";
+      echo "</div>\n";
+    }
   return;
 }
 
diff --git a/rss.php b/rss.php
new file mode 100644 (file)
index 0000000..6dbb6e6
--- /dev/null
+++ b/rss.php
@@ -0,0 +1,101 @@
+<?php
+  /* get some information from the database */
+error_reporting(E_ALL);
+
+/* start a session, if it is not already running.
+ * This way people don't have to log in all the times.
+ * The session variables can also be read out from different
+ * php scripts, so that the code can be easily split up across several files
+ */
+
+include_once("config.php");                /* needs to be first in list, since other includes use this */
+include_once("./include/output.php");      /* html output only */
+include_once("./include/db.php");          /* database only */
+include_once("./include/functions.php");   /* the rest */
+
+/* make sure that user has set all variables in config.php */
+config_check();
+
+/* open the database */
+if(DB_open()<0)
+  {
+    output_header();
+    echo "Database error, can't connect... Please wait a while and try again. ".
+      "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
+    output_footer();
+    exit();
+  }
+
+$ok = 0;
+$id = 0;
+
+if(!myisset("uid","token"))
+  {
+    echo "error";
+  }
+else
+  {
+    $id = $_REQUEST['uid'];
+    $token = get_user_token($id);
+
+    if($token == $_REQUEST['token'])
+      $ok = 1;
+  }
+
+if(! $ok)
+  {
+    echo "No valid userid";
+    exit();
+  }
+
+header("Content-Type: text/xml");
+/* start the feed */
+?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+<title>E-DoKo Feed</title>
+<subtitle>Know when it is your turn</subtitle>
+<?php
+
+  global $WIKI,$INDEX, $HOST;
+
+  /* output last creation date */
+echo "<link href=\"$HOST/$INDEX\" />\n";
+echo "<link rel=\"self\" href=\"".$HOST.htmlentities($_SERVER['REQUEST_URI'])."\" />\n";
+$date = DB_query_array("Select create_date from User order by create_date ASC limit 1");
+$date = $date[0];
+$timestamp = strtotime($date);
+echo "<id>tag:".$_SERVER['SERVER_NAME'].",".date("Y-m-d",$timestamp).":$INDEX</id>\n";
+echo "<updated>".date(DATE_ATOM)."</updated>\n";
+echo "<author>\n";
+echo "<name>$ADMIN_NAME  $date $timestamp</name>\n";
+echo "<email>$ADMIN_EMAIL</email>\n";
+echo "</author>\n\n";
+
+
+ /* output the entries */
+
+
+  $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand".
+                    " LEFT JOIN Game On Hand.game_id=Game.id".
+                    " WHERE Hand.user_id='$id'".
+                    " AND ( Game.player='$id' OR ISNULL(Game.player) )".
+                    " AND ( Game.status='pre' OR Game.status='play' )".
+                    " ORDER BY Game.session" );
+
+  while( $r = DB_fetch_array($result))
+    {
+      echo "<entry>\n";
+      echo "<title>game ".DB_format_gameid($r[1])."</title>\n";
+      $url=$INDEX."?action=game&amp;me=".$r[0];
+      echo "<link href=\"".$HOST.$url."\" />\n";
+      $date = DB_get_game_timestamp($r[1]);
+      $timestamp = strtotime($date);
+      $date = date("Y-m-d",$timestamp);
+      echo "<id>tag:doko.nubati.net,$date:$url</id>\n";
+      echo "<updated>".date(DATE_ATOM,$timestamp)."</updated>\n";
+      echo "<summary>Please use the link to access the game.</summary>\n";
+      echo "</entry>\n\n";
+    }
+
+?>
+</feed>
\ No newline at end of file