OSDN Git Service

embrj
[embrj/master.git] / user.php
1 <?php 
2         include ('lib/twitese.php');
3         $title = "{$_GET['id']}";
4         include ('inc/header.php');
5         include ('lib/timeline_format.php');
6
7 ?>
8
9 <script src="js/user.js"></script>
10
11 <div id="statuses" class="column round-left">
12 <?php 
13         if (!loginStatus() || !isset($_GET['id'])) {
14                 header('location: error.php');exit();
15         }
16
17         $t = getTwitter();
18         $userid = $_GET['id'];
19         $since_id = isset($_GET['since_id']) ? $_GET['since_id'] : false;
20         $max_id = isset($_GET['max_id']) ? $_GET['max_id'] : false;
21         if (isset($_GET['fav'])) {
22                 $statuses = $t->getFavorites($userid, $since_id, $max_id);
23         } else {
24                 $statuses = $t->userTimeline($userid, $since_id, $max_id);
25         }
26         
27         if ($statuses === false) {
28                 header('location: error.php');exit;
29         }
30         if ($t->http_code == 429) {
31                 $apiout = true;
32         } else {
33                 $aptout = false;
34         }
35
36         $user = $t->showUser($userid);
37         if (strcasecmp($userid,$t->username) == 0) {header('location: profile.php');exit();}
38
39         $isProtected = ($statuses == 'protected') || ($statuses->error == 'Not authorized');
40         $r = getRelationship($user->screen_name);
41         $isFriend = $r == 2 || $r == 1;
42         $isFollower = $r == 3 || $r == 1;
43         $isBlocked = $r == 4;
44
45         if (!$isProtected) {
46
47                 $userinfo = array();
48                 $userinfo['name'] = $user->name;
49                 $userinfo['screen_name'] = $user->screen_name;
50                 $userinfo['friends_count'] = $user->friends_count;
51                 $userinfo['statuses_count'] = $user->statuses_count;
52                 $userinfo['followers_count'] = $user->followers_count;
53                 $userinfo['url'] = $user->entities->url->urls[0]->expanded_url ? $user->entities->url->urls[0]->expanded_url : $user->url;
54                 $userinfo['description'] = formatText($user->description);
55                 $userinfo['location'] = $user->location;
56                 $userinfo['date_joined'] = date('Y-m-d', format_time($user->created_at)); //from dabr
57                 $userinfo['protected'] = $user->url;
58                 $userinfo['id'] = $user->id;
59                 $userinfo['image_url'] = getAvatar($user->profile_image_url);
60
61 ?>
62         <div id="info_head" class="round">
63                 <a href="https://twitter.com/<?php echo $userid ?>"><img id="info_headimg" src="<?php echo $userinfo['image_url'] ?>" /></a>
64                 <div id="info_name" style="display:inline-block"><?php echo $userid ?></div>
65                 <?php if ($isFollower) {?>
66                 <span id="following_me" style="display:inline!important"><img style="" src="img/yes.gif" alt="" class="icon"/><span>Following me</span></span>
67 <?php 
68                 }
69 ?>
70                 <div id="info_relation">
71                 <?php if ($isFriend) {?>
72                         <a id="info_block_btn" class="btn btn-red" href="#">Unfollow</a>
73                 <?php } else { ?>
74                         <a id="info_follow_btn" class="btn btn-green" href="#">Follow</a>
75                 <?php } ?>
76                 <?php if ($isFollower) {?>
77                         <a class="btn" id="info_send_btn" href="message.php?id=<?php echo $userid ?>">DM</a>
78                 <?php } ?>
79 <?php if($isBlocked){ ?>
80                 <a class='btn' id='unblock_btn' href='#'>Unblock</a>
81 <?php }else{ ?>
82                 <a class='btn' id='block_btn' href='#'>Block</a>
83 <?php } ?>
84                         <a class="btn" id="info_reply_btn" href="#">Reply</a>
85                         <a class="btn" id="info_hide_btn" href="#">Hide @</a>
86                         <a class="btn " id="report_btn" href="#" style="color:#a22">Report Spam</a>
87                 </div>
88         </div>
89         <div class="clear"></div>
90 <?php 
91                 $empty = count($statuses) == 0? true: false;
92                 if ($empty) {
93                         echo "<div id=\"empty\">No tweet to display.</div>";
94                 } else if ($apiout) {
95                         echo "<div id=\"empty\">API quota is used out, please wait for a moment before next refresh.</div>";
96                 } else {
97                         $output = '<ol class="timeline" id="allTimeline">';
98                         $firstid = false;
99                         $lastid = false;
100                         foreach ($statuses as $status) {
101                                 if (isset($status->retweeted_status)) {
102                                         $output .= format_retweet($status);
103                                 } else { 
104                                         $output .= format_timeline($status,$t->username);
105                                 }
106                                 if(!$firstid)
107                                         $firstid = $status->id_str;
108                                 $lastid = $status->id_str;
109                         }
110                         $lastid = bcsub($lastid, "1");
111
112                         $output .= "</ol><div id=\"pagination\">";
113                         if ($_GET['fav'] == true) {
114                                 $output .= "<a id=\"less\" class=\"round more\" style=\"float: left;\" href=\"user.php?id=$userid&fav=true&since_id={$firstid}\">Back</a>";
115                                 $output .= "<a id=\"more\" class=\"round more\" style=\"float: right;\" href=\"user.php?id=$userid&fav=true&max_id={$lastid}\">Next</a>";
116                         } else {
117                                 $output .= "<a id=\"less\" class=\"round more\" style=\"float: left;\" href=\"user.php?id=$userid&since_id={$firstid}\">Back</a>";
118                                 $output .= "<a id=\"more\" class=\"round more\" style=\"float: right;\" href=\"user.php?id=$userid&max_id={$lastid}\">Next</a>";
119                         }
120                         $output .= "</div>";
121                         echo $output;
122                 }
123         }//end of if(!$isProtected)
124         else {
125 ?>
126                 <div id="info_head" class="round">
127                         <div id="info_name"><?php echo $userid ?></div>
128                         <div id="info_relation">
129                         <?php if ($isFriend) {?>
130                                 <a id="info_block_btn" class="btn_hover" href="#">Unfollow</a>
131                         <?php } else { ?>
132                                 <a id="info_follow_btn" class="btn" href="#">Follow</a>
133                         <?php } ?>
134                         <?php if ($isFollower) {?>
135                                 <a class="btn" id="info_send_btn" href="message.php?id=<?php echo $userid ?>">Send DM</a>
136                         <?php } ?>
137 <?php if($isBlocked){ ?>
138                 <a class='btn_hover' id='unblock_btn' href='#'>Unblock</a>
139 <?php }else{ ?>
140                 <a class='btn' id='block_btn' href='#'>Block</a>
141 <?php } ?>
142                                 <a class="btn" id="info_reply_btn" href="#">Reply</a>
143                                 <a class="btn" id="info_hide_btn" href="#">Hide @</a>
144                         </div>
145                 </div>
146                 <div class="clear"></div>
147                 <div id="empty">This user has been protected. You ought to follow before viewing this page.</div>
148 <?php 
149         }
150 ?>
151 </div>
152
153 <?php if (!$isProtected) {?>
154 <td class="column round-right" id="side_base">
155 <table>
156 <tr>
157 <td>
158 <div id="side" class="round-right">
159         <ul id="user_info">
160                 <li><span>Name</span> <?php echo $userinfo['name']?></li>
161                 <?php if ($userinfo['location']) echo '<li><span>Location</span> ' . $userinfo['location'] . '</li>'; ?>
162                 <?php if (($userinfo['url']) and (strlen($userinfo['url'])>20)) echo '<li><span>Web</span> <a href="' .$userinfo['url']. '" target="_blank">' .substr($userinfo['url'], 0, 20). '...</a></li>'; else if (($userinfo['url']) and (strlen($userinfo['url'])<=20)) echo '<li><span>Web</span> <a href="' .$userinfo['url']. '" target="_blank">' .$userinfo['url']. '</a></li>';?>
163                 <?php  if ($userinfo['description']) echo "<li><span>Bio</span> " . $userinfo['description'] . "</li>"; ?>
164                 <?php  echo "<li><span>Joined at</span> " . $userinfo['date_joined'] . "</li>"; ?>
165         </ul>
166         <ul id="user_stats" style="margin:0 0 10px;">
167                 <li>
168                         <a href="friends.php?id=<?php echo $userid ?>">
169                                 <span class="count"><?php echo $userinfo['friends_count'] ?></span>
170                                 <span class="label">Following</span>
171                         </a>
172                 </li>
173                 <li>
174                         <a href="followers.php?id=<?php echo $userid ?>">
175                                 <span class="count"><?php echo $userinfo['followers_count'] ?></span>
176                                 <span class="label">Followers</span>
177                         </a>
178                 </li>
179                 <li>
180                         <a href="user.php?id=<?php echo $userid ?>">
181                                 <span class="count"><?php echo $userinfo['statuses_count'] ?></span>
182                                 <span class="label">Tweets</span>
183                         </a>
184                 </li>
185         </ul>
186         <div class="clear"></div>
187         <ul id="primary_nav" class="sidebar-menu">
188         <li id="tweets_tab"><a class="in-page-link" href="user.php?id=<?php echo $userid ?>"><span>Tweets</span></a></li>
189         <li id="@_tab"><a class="in-page-link" href="search.php?q=@<?php echo $userid ?>"><span>@<?php echo $userid ?></span></a></li>
190         <li id="favs_tab"><a class="in-page-link" href="user.php?id=<?php echo $userid ?>&fav=true"><span>Favorites</span></a></li>
191         <li id="lists_tab"><a class="in-page-link" href="lists.php?id=<?php echo $userid ?>"><span>Lists</span></a></li>
192         </ul>
193         <div class="clear"></div>
194         <?php include ('inc/sidepost.php') ?>
195 </div>
196 </td>
197 </tr>
198 </table>
199 <?php } else { 
200                 include ('inc/sidebar.php');
201 }
202
203         include ('inc/footer.php');
204 ?>