OSDN Git Service

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