From b76cddb9313d8a67e5d7e1830503b5775666238f Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Tue, 2 Feb 2010 22:37:27 -0800 Subject: [PATCH 1/1] NEW FEATURE: provide an RSS feed for each user showing in which games it's his turn the feed shows the same as the "It's your turn in these games" box. --- INSTALL | 1 + config.php_template | 2 + include/db.php | 20 +++++++++ include/functions.php | 14 ++++++ include/output.php | 71 +++++++++++++++-------------- rss.php | 101 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 33 deletions(-) create mode 100644 rss.php diff --git a/INSTALL b/INSTALL index 86b65d4..0fada71 100644 --- 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: diff --git a/config.php_template b/config.php_template index 93e951c..a3e9e54 100644 --- a/config.php_template +++ b/config.php_template @@ -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"; diff --git a/include/db.php b/include/db.php index 882a1ad..55d97c9 100644 --- a/include/db.php +++ b/include/db.php @@ -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)); diff --git a/include/functions.php b/include/functions.php index eca0155..33da9ef 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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; +} + ?> diff --git a/include/output.php b/include/output.php index 57b3152..61fef60 100644 --- a/include/output.php +++ b/include/output.php @@ -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
\n"; - echo $name,"\n"; - echo " | mypage \n"; - echo " | settings\n"; - echo " | new game\n"; - echo " | statistics\n"; - echo " | wiki\n"; - echo " |    logout\n"; - echo "
\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 "
last login: ".date("r",$unixtime)."
\n"; - } - else - { - echo "\n
\n"; - echo "login\n"; - echo "
\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
\n"; + echo $name,"\n"; + echo " | mypage \n"; + echo " | settings\n"; + echo " | new game\n"; + echo " | statistics\n"; + echo " | wiki\n"; + echo " | rss\n"; + echo " |    logout\n"; + echo "
\n"; + + echo "
last login: ".date("r",$unixtime)."
\n"; + } + else + { + echo "\n
\n"; + echo "login\n"; + echo "
\n"; + } return; } diff --git a/rss.php b/rss.php new file mode 100644 index 0000000..6dbb6e6 --- /dev/null +++ b/rss.php @@ -0,0 +1,101 @@ + + +E-DoKo Feed +Know when it is your turn +\n"; +echo "\n"; +$date = DB_query_array("Select create_date from User order by create_date ASC limit 1"); +$date = $date[0]; +$timestamp = strtotime($date); +echo "tag:".$_SERVER['SERVER_NAME'].",".date("Y-m-d",$timestamp).":$INDEX\n"; +echo "".date(DATE_ATOM)."\n"; +echo "\n"; +echo "$ADMIN_NAME $date $timestamp\n"; +echo "$ADMIN_EMAIL\n"; +echo "\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 "\n"; + echo "game ".DB_format_gameid($r[1])."\n"; + $url=$INDEX."?action=game&me=".$r[0]; + echo "\n"; + $date = DB_get_game_timestamp($r[1]); + $timestamp = strtotime($date); + $date = date("Y-m-d",$timestamp); + echo "tag:doko.nubati.net,$date:$url\n"; + echo "".date(DATE_ATOM,$timestamp)."\n"; + echo "Please use the link to access the game.\n"; + echo "\n\n"; + } + +?> + \ No newline at end of file -- 2.17.1