OSDN Git Service

rabr
[embrj/master.git] / lists.php
1 <?php \r
2         include ('lib/twitese.php');\r
3         $title = "Lists";\r
4         include ('inc/header.php');\r
5         \r
6         if (!loginStatus()) header('location: login.php');\r
7 ?>\r
8 \r
9 <script type="text/javascript" src="js/lists.js"></script>\r
10 \r
11 <div id="statuses">\r
12         <?php \r
13                 $t = getTwitter();\r
14                 $t->type = 'xml';\r
15                 if ( isset($_POST['list_name']) ) {\r
16                         if ($_POST['is_edit'] == 0) {\r
17                                 if (trim($_POST['list_name']) == '') {\r
18                                                 echo "<div id=\"otherTip\">创建推群失败,推群名不能为空</div>";\r
19                                 } else {\r
20                                         $isProtect = isset($_POST['list_protect']) ? true : false;\r
21                                         $result = $t->createList($_POST['list_name'], $_POST['list_description'], $isProtect);\r
22                                         if ($result) {\r
23                                                 echo "<div id=\"otherTip\">创建推群成功</div>";\r
24                                         } else {\r
25                                                 echo "<div id=\"otherTip\">创建推群失败,请重试</div>";\r
26                                         }\r
27                                 }\r
28                         } else {\r
29                                 if (trim($_POST['list_name']) == '') {\r
30                                                 echo "<div id=\"otherTip\">修改推群失败,推群名不能为空</div>";\r
31                                 } else {\r
32                                         $isProtect = isset($_POST['list_protect']) ? true : false;\r
33                                         $result = $t->editList($_POST['pre_list_name'], $_POST['list_name'], $_POST['list_description'], $isProtect);\r
34                                         if ($result) {\r
35                                                 echo "<div id=\"otherTip\">修改推群成功</div>";\r
36                                         } else {\r
37                                                 echo "<div id=\"otherTip\">修改推群失败,请重试</div>";\r
38                                         }\r
39                                 }\r
40                         }\r
41                 }\r
42                 \r
43                 if ( isset($_POST['list_members']) ) {\r
44                         if (trim($_POST['list_members']) == '') {\r
45                                         echo "<div id=\"otherTip\">添加成员失败,成员列表不能为空</div>";\r
46                         } else {\r
47                                 $listId = $_POST['member_list_name'];\r
48                                 $memberList = explode(",", $_POST['list_members']);\r
49                                 $count = 0;\r
50                                 $failList = '';\r
51                                 \r
52                                 foreach ($memberList as $member) {\r
53                                         $result = $t->addListMember($listId, $member);\r
54                                         if (!isset($result->error) && isset($result->user)) $count ++;\r
55                                         else $failList .= $member . " ";\r
56                                 }\r
57                                 \r
58                                 if ($count > 0) {\r
59                                         if ($count == count($memberList))\r
60                                                 echo "<div id=\"otherTip\">成功添加 $count 个成员</div>";\r
61                                         else \r
62                                                 echo "<div id=\"otherTip\">成功添加 $count 个成员,失败名单:$failList </div>";\r
63                                 } else {\r
64                                         echo "<div id=\"otherTip\">添加成员失败,请重试</div>";\r
65                                 }\r
66                         }\r
67                 }\r
68         ?>\r
69         <?php \r
70                 $isSelf = true;\r
71                 if (isset($_GET['id'])) {\r
72                         $id = $_GET['id'];\r
73                         $isSelf = false;\r
74                 } else {\r
75                         $id = $t->username;\r
76                 }\r
77                 $type = isset($_GET['t'])? $_GET['t'] : 1;\r
78                 $c = isset($_GET['c'])? $_GET['c'] : -1;\r
79                 switch ($type) {\r
80                         case 0:\r
81                                 $lists = $t->followedLists($id, $c);\r
82                                 $nextlist = $lists->next_cursor;\r
83                                 $prelist = $lists->previous_cursor;\r
84                                 $lists = $lists->lists; \r
85                                 break;\r
86                         case 1:\r
87                                 $lists = $t->createdLists($id);\r
88                                 $lists = $lists->lists; \r
89                                 break;\r
90                         case 2:\r
91                                 $lists = $t->beAddedLists($id, $c);\r
92                                 $nextlist = $lists->next_cursor;\r
93                                 $prelist = $lists->previous_cursor;\r
94                                 $lists = $lists->lists; \r
95                                 break;\r
96                         default:\r
97                                 $lists = false;\r
98                 }\r
99                 \r
100                 if ($lists === false) {\r
101                         header('location: error.php');\r
102                 } \r
103                 \r
104                 \r
105         ?>\r
106         <div id="subnav">\r
107         <?php if ($isSelf) { ?>\r
108                 <?php if ($type == 0) {?>\r
109                 <span class="subnavNormal">Lists you follow</span><span class="subnavLink"><a href="lists.php?t=1">Lists you created</a></span><span class="subnavLink"><a href="lists.php?t=2">Lists following you</a></span>\r
110                 <?php } else if ($type == 1) {?>\r
111                 <span class="subnavLink"><a href="lists.php?t=0">Lists you follow</a></span><span class="subnavNormal">Lists you created</span><span class="subnavLink"><a href="lists.php?t=2">Lists following you</a></span>\r
112                 <?php } else {?>\r
113                         <span class="subnavLink"><a href="lists.php?t=0">Lists you follow</a></span><span class="subnavLink"><a href="lists.php?t=1">Lists you created</a></span><span class="subnavNormal">Lists following you</span>\r
114                 <?php } ?>\r
115         <?php } else {?>\r
116                 <?php if ($type == 0) {?>\r
117                 <span class="subnavNormal">Following Lists</span><span class="subnavLink"><a href="lists.php?id=<?php echo $id?>&t=1">Created Lists</a></span><span class="subnavLink"><a href="lists.php?id=<?php echo $id?>&t=2">Lists Following</a></span>\r
118                 <?php } else if ($type == 1) {?>\r
119                 <span class="subnavLink"><a href="lists.php?t=0&id=<?php echo $id?>">Following Lists</a></span><span class="subnavNormal">Created Lists</span><span class="subnavLink"><a href="lists.php?id=<?php echo $id?>&t=2">Lists Following</a></span>\r
120                 <?php } else {?>\r
121                         <span class="subnavLink"><a href="lists.php?t=0&id=<?php echo $id?>">Following Lists</a></span><span class="subnavLink"><a href="lists.php?id=<?php echo $id?>&t=1">Created Lists</a></span><span class="subnavNormal">Lists Following</span>\r
122                 <?php } ?>\r
123         <?php } ?>\r
124     </div>\r
125     \r
126         <?php \r
127                 \r
128                 $empty = count($lists->list) == 0? true: false;\r
129                 if ($empty) {\r
130                         echo "<div id=\"empty\">No Tweet To Display</div>";\r
131                 } else {\r
132                         $output = '<ol class="rank_list">';                     \r
133                         foreach ($lists->list as $list) {\r
134                 \r
135                                 $listurl = substr($list->uri,1);\r
136                                 $user = $list->user;\r
137                                 $listname = explode('/',$list->full_name);\r
138                                 $mode = $list->mode == 'private' ? "Private" : "";\r
139                                 \r
140                                 $output .= "\r
141                                 <li>\r
142                                         <span class=\"rank_img\"><a href=\"https://twitter.com/$user->screen_name\"><img src=\"".getAvatar($user->profile_image_url)."\" /></a></span>\r
143                                         <div class=\"rank_content\">\r
144                                                 <span class=\"rank_num\"><span class=\"rank_name\"><a href=\"list.php?id=$listurl\"><em>$listname[0]/</em>$listname[1]</a></span></span>\r
145                                                 <span class=\"rank_count\">Followers:$list->subscriber_count  Members:$list->member_count  $mode</span> \r
146                                 ";\r
147                                 if ($list->description != '') $output .= "<span class=\"rank_description\">简介:$list->description</span>";\r
148                                 if ($type == 0) $output .= "<span id=\"list_action\"><a id=\"btn\" href=\"javascript:void()\" class=\"unfollow_list\">Unfollow</a></span>";\r
149                                 if ($type == 1 && $isSelf) $output .= "<span id=\"list_action\"><a id=\"btn\" href=\"javascript:void()\" class=\"edit_list\">Edit</a> <a id=\"btn\" href=\"javascript:void()\" class=\"delete_list\">Delete</a> <a id=\"btn\" href=\"javascript:void()\" class=\"add_member\">Add Members</a></span>";\r
150                                 $output .= "\r
151                                         </div>\r
152                                 </li>\r
153                                 ";\r
154                         }\r
155                         \r
156                         $output .= "</ol>";\r
157                         \r
158                         echo $output;\r
159                 }\r
160                 \r
161         ?>\r
162         \r
163         <?php if ($isSelf && $type == 1) {?>\r
164             <a href="javascript:void()" class="more round" id="list_create_btn" style="margin: 20px auto;">Create a new list</a>\r
165             <form method="POST" action="./lists.php?t=1" id="list_form">\r
166                 <input type="hidden" name="pre_list_name" value="" id="pre_list_name" />\r
167                 <input type="hidden" name="is_edit" value="0" id="is_edit" />\r
168                 <span><label for="list_name">List name</label><input type="text" name="list_name" id="list_name" /></span>\r
169                 <span><label for="list_description">Description</label><textarea type="text" name="list_description" id="list_description"></textarea></span>\r
170                 <span><label for="list_protect">Private</label><input type="checkbox" name="list_protect" id="list_protect"  />\r
171                         <a style="background: transparent url(img/sprite-icons.png) no-repeat scroll -272px -16px; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-decoration: none; height: 10px; float: right; position: relative; width: 9px; left: 3px; top: -160px;" title="Close" onclick="$('#list_form').slideToggle(300)" href="#"></a>\r
172                         <input type="submit" class="btn" id="list_submit" value="Creat" />\r
173                         \r
174                         </span>\r
175                 <span></span>\r
176             </form>\r
177             \r
178             \r
179         <?php }?>\r
180         \r
181         <div id="pagination">\r
182         <?php \r
183             if ($type == 0 || $type == 2) {\r
184                 if ($isSelf) {\r
185                                 if ($prelist != 0) echo "<a id=\"more\" class=\"round more\" style=\"float: left;\" href=\"lists.php?t=$type&c=$prelist\">Back</a>";\r
186                                 if ($nextlist != 0) echo "<a id=\"more\" class=\"round more\" style=\"float: right;\" href=\"lists.php?t=$type&c=$nextlist\">Next</a>";\r
187                 } else {\r
188                                 if ($prelist != 0) echo "<a id=\"more\" class=\"round more\" style=\"float: left;\" href=\"lists.php?id=$id&t=$type&c=$prelist\">Back</a>";\r
189                                 if ($nextlist != 0) echo "<a id=\"more\" class=\"round more\" style=\"float: right;\" href=\"lists.php?id=$id&t=$type&c=$nextlist\">Next</a>";\r
190                 }\r
191                 }\r
192         ?>\r
193         </div>\r
194 </div>\r
195 \r
196 <?php \r
197         include ('inc/sidebar.php');\r
198 ?>\r
199 \r
200 <?php \r
201         include ('inc/footer.php');\r
202 ?>\r