diff --git a/README.md b/README.md index e9f75cd..4d71ce2 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,21 @@ Posts also have sequencial IDs, generated by incrementing the following key: INCR next_post_id => 134 Every post is stored into an hash named `post:134` with the following +fields: + + user_id + time + body + pre + +Comments +--- + +Comments also have sequencial IDs, generated by incrementing the following key: + + INCR next_comment_id => 123 + +Every comment is stored into an hash named `comment:123` with the following fields: user_id diff --git a/comment.php b/comment.php new file mode 100644 index 0000000..bb7587f --- /dev/null +++ b/comment.php @@ -0,0 +1,28 @@ + $value){ + if (empty($value)) { + $refferer = $_SERVER['HTTP_REFERER']; + header("Location:".$refferer); + exit; + } + $cid = $key; + $comment = $value; +} + +$r = redisLink(); +$commentid = $r->incr("next_comment_id"); +$comment = str_replace("\n"," ",$comment); +$r->hmset("comment:$commentid","user_id",$User['id'],"time",time(),"body",$comment); +$r->lpush("comments:$cid", $commentid); + +$refferer = $_SERVER['HTTP_REFERER']; +header("Location:".$refferer); +?> + diff --git a/followers.php b/followers.php new file mode 100644 index 0000000..8e22413 --- /dev/null +++ b/followers.php @@ -0,0 +1,27 @@ +My Followers"); +echo("They are:
"); +$r = redisLink(); +$userid = $User['id']; +$followers = $r->zrange("followers:$userid",0,-1); +echo(""); +echo(""); +$i = 0; +foreach($followers as $followerID) { + if ($i % 8 == 0) { + echo(""); + echo(""); + } + $followerName = $r->hget("user:$followerID","username"); + echo(""); + $i ++; +} +echo("
".utf8entities($followerName)."
"); +include("footer.php") +?> diff --git a/following.php b/following.php new file mode 100644 index 0000000..6da12b0 --- /dev/null +++ b/following.php @@ -0,0 +1,27 @@ +My Following"); +echo("They are
"); +$r = redisLink(); +$userid = $User['id']; +$following = $r->zrange("following:$userid",0,-1); +echo(""); +echo(""); +$i = 0; +foreach($following as $followingID) { + if ($i % 8 == 0) { + echo(""); + echo(""); + } + $followingName = $r->hget("user:$followingID","username"); + echo(""); + $i ++; +} +echo("
".utf8entities($followingName)."
"); +include("footer.php") +?> diff --git a/home.php b/home.php index 261a7a1..063b793 100644 --- a/home.php +++ b/home.php @@ -17,8 +17,8 @@
-zcard("followers:".$User['id'])?> followers
-zcard("following:".$User['id'])?> following
+zcard("followers:".$User['id'])?> followers
+zcard("following:".$User['id'])?> following
incr("next_post_id"); $status = str_replace("\n"," ",gt("status")); -$r->hmset("post:$postid","user_id",$User['id'],"time",time(),"body",$status); +$r->hmset("post:$postid","user_id",$User['id'],"time",time(),"body",$status,"ref",-1); $followers = $r->zrange("followers:".$User['id'],0,-1); -$followers[] = $User['id']; /* Add the post to our own posts too */ +$userID = $User['id']; +$followers[] = $userID; /* Add the post to our own posts too */ +$r->lpush("selfPosts:$userID",$postid); foreach($followers as $fid) { $r->lpush("posts:$fid",$postid); } diff --git a/profile.php b/profile.php index db9e1a8..8165d33 100644 --- a/profile.php +++ b/profile.php @@ -19,6 +19,6 @@ ?> diff --git a/repost.php b/repost.php new file mode 100644 index 0000000..3af58f7 --- /dev/null +++ b/repost.php @@ -0,0 +1,35 @@ + $value){ + if (empty($value)) { + $value = "REPOST"; + } + $cid = $key; + $status = $value; +} +$r = redisLink(); +$postid = $r->incr("next_post_id"); +$r->hmset("post:$postid","user_id",$User['id'],"time",time(),"body",$status,"ref",$cid); +$followers = $r->zrange("followers:".$User['id'],0,-1); +$userID = $User['id']; +$followers[] = $userID; /* Add the post to our own posts too */ + +$r->lpush("selfPosts:$userID",$postid); +foreach($followers as $fid) { + $r->lpush("posts:$fid",$postid); +} +# Push the post on the timeline, and trim the timeline to the +# newest 1000 elements. +$r->lpush("timeline",$postid); +$r->ltrim("timeline",0,1000); + +$refferer = $_SERVER['HTTP_REFERER']; +header("Location:".$refferer); +?> + diff --git a/retwis.php b/retwis.php index 86e3687..ce4ad57 100644 --- a/retwis.php +++ b/retwis.php @@ -86,6 +86,21 @@ function strElapsed($t) { return "$d day".($d > 1 ? "s" : ""); } +function showComment($id) { + $r = redisLink(); + $comments = $r->lrange("comments:".$id, 0, -1); + foreach($comments as $cid) { + $content = $r->hgetall("comment:".$cid); + $userid = $content['user_id']; + $username = $r->hget("user:$userid","username"); + $elapsed = strElapsed($content['time']); + $userlink = "".utf8entities($username).""; + $comment = utf8entities($content['body']); + echo("   ".$userlink.' '.utf8entities($content['body'])."
"); + echo('   commented '.$elapsed.' ago via web
'); + } +} + function showPost($id) { $r = redisLink(); $post = $r->hgetall("post:$id"); @@ -95,25 +110,53 @@ function showPost($id) { $username = $r->hget("user:$userid","username"); $elapsed = strElapsed($post['time']); $userlink = "".utf8entities($username).""; - - echo('
'.$userlink.' '.utf8entities($post['body'])."
"); - echo('posted '.$elapsed.' ago via web
'); + $status = utf8entities($post['body']); + $ref = $post['ref']; + + echo('
'.$userlink.' '.$status); + while($ref != -1) { + $refpost = $r->hgetall("post:$ref"); + if (empty($refpost)) break; + $refuserid = $refpost['user_id']; + $refusername = $r->hget("user:$refuserid","username"); + $refelapsed = strElapsed($refpost['time']); + $refuserlink = "".utf8entities($refusername).""; + $refstatus = utf8entities($refpost['body']); + echo(' || '.$refuserlink.' '.$refstatus); + $ref = $refpost['ref']; + } + echo('
'); + echo('posted '.$elapsed.' ago via web'); +?> +
+
+ + + +
+
+
+
+"); return true; } -function showUserPosts($userid,$start,$count) { +function showUserPosts($userid,$start,$count,$means="ALL") { $r = redisLink(); - $key = ($userid == -1) ? "timeline" : "posts:$userid"; - $posts = $r->lrange($key,$start,$start+$count); - $c = 0; + if($means != "ALL") + $key = "selfPosts:$userid"; + else + $key = ($userid == -1) ? "timeline" : "posts:$userid"; + $posts = $r->lrange($key,$start,$start+$count-1); foreach($posts as $p) { - if (showPost($p)) $c++; - if ($c == $count) break; + showPost($p); } - return count($posts) == $count+1; + return count($posts) == $count; } -function showUserPostsWithPagination($username,$userid,$start,$count) { +function showUserPostsWithPagination($username,$userid,$start,$count,$means="ALL") { global $_SERVER; $thispage = $_SERVER['PHP_SELF']; @@ -124,7 +167,7 @@ function showUserPostsWithPagination($username,$userid,$start,$count) { if ($prev < 0) $prev = 0; $u = $username ? "&u=".urlencode($username) : ""; - if (showUserPosts($userid,$start,$count)) + if (showUserPosts($userid,$start,$count,$means)) $nextlink = "Older posts »"; if ($start > 0) { $prevlink = "« Newer posts".($nextlink ? " | " : "");