OSDN Git Service

embrj
[embrj/master.git] / index.php
1 <?php
2         include ('lib/twitese.php');
3         $title = 'Home';
4         include ('inc/header.php');
5
6         if (!loginStatus()) header('location: login.php'); 
7         $t = getTwitter();
8         if (isset($_POST['status']) && isset($_POST['in_reply_to'])) {
9                 if (trim($_POST['status']) !== '')
10                 {
11                         $result = $t->update($_POST['status'], $_POST['in_reply_to']);
12                         if ($result)
13                         {
14                                 $user = $result->user;
15                                 $time = $_SERVER['REQUEST_TIME']+3600*24*365;
16                                 if ($user)
17                                 {
18                                         setcookie('friends_count', $user->friends_count, $time, '/');
19                                         setcookie('statuses_count', $user->statuses_count, $time, '/');
20                                         setcookie('followers_count', $user->followers_count, $time, '/');
21                                         setcookie('imgurl', getAvatar($user->profile_image_url), $time, '/');
22                                         setcookie('name', $user->name, $time, '/');
23                                 }
24                         }
25                 }
26                 header('location: index.php');
27         }
28 ?>
29 <script src="js/home.js"></script>
30 <div id="statuses" class="column round-left">
31 <?php
32   include('inc/sentForm.php'); 
33   
34         $since_id = isset($_GET['since_id']) ? $_GET['since_id'] : false;
35         $max_id = isset($_GET['max_id']) ? $_GET['max_id'] : false;
36
37         $statuses = $t->homeTimeline($since_id, $max_id);
38         if ($statuses == false)
39         {
40                 header('location: error.php');exit();
41         }
42         $count = count($statuses);
43         $empty = $count == 0 ? true : false;
44         if ($empty)
45         {
46                 echo "<div id=\"empty\">No tweet to display.</div>";
47         } else if ($t->http_code == 429) {
48                 echo "<div id=\"empty\">API quota is used out, please wait for a moment before next refresh.</div>";
49         } else {
50                 $output = '<ol class="timeline" id="allTimeline">';
51
52                 include('lib/timeline_format.php');
53                 $maxid = isset($_COOKIE['maxid']) ? $_COOKIE['maxid'] : '';
54                 $firstid = false;
55                 $lastid = false;
56                 foreach ($statuses as $status) {
57                         if (!$firstid) $firstid = $status->id_str;
58                         $lastid = $status->id_str;
59                         if($maxid == '' || $p == 1 || strcmp($status->id_str,$maxid) < 0) {
60                                 if (isset($status->retweeted_status)) {
61                                         $output .= format_retweet($status);
62                                 } else { 
63                                         $output .= format_timeline($status,$t->username);
64                                 }
65                         }
66                 }
67                 $lastid = bcsub($lastid, "1");
68
69                 $output .= "</ol><div id=\"pagination\">";
70                 $time = $_SERVER['REQUEST_TIME']+3600;
71                 setcookie('maxid',$statuses[$count-1]->id_str,$time,'/');
72
73                 $output .= "<a id=\"less\" class=\"round more\" style=\"float: left;\" href=\"index.php?since_id=" . $firstid . "\">Back</a>";
74                 $output .= "<a id=\"more\" class=\"round more\" style=\"float: right;\" href=\"index.php?max_id=" . $lastid . "\">Next</a>";
75                 $output .= "</div>";
76                 echo $output;
77         }
78 ?>
79 </div>
80 <?php 
81         include ('inc/sidebar.php');
82         include ('inc/footer.php');
83 ?>