OSDN Git Service

133209d4729d8d2007c584961738cc8c4eb769cf
[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 src="js/lists.js"></script>\r
10 \r
11 <div id="statuses">\r
12         <?php \r
13                 $t = getTwitter();\r
14                 if ( isset($_POST['list_name']) ) {\r
15                         if ($_POST['is_edit'] == 0) {\r
16                                 if (trim($_POST['list_name']) == '') {\r
17                                                 echo "<div id=\"otherTip\">Fail to create list, the name CANNOT be empty</div>";\r
18                                 } else {\r
19                                         $isProtect = isset($_POST['list_protect']) ? true : false;\r
20                                         $result = $t->createList($_POST['list_name'], $_POST['list_description'], $isProtect);\r
21                                         if ($result) {\r
22                                                 echo "<div id=\"otherTip\">Success</div>";\r
23                                         } else {\r
24                                                 echo "<div id=\"otherTip\">Failed, please retry</div>";\r
25                                         }\r
26                                 }\r
27                         } else {\r
28                                 if (trim($_POST['list_name']) == '') {\r
29                                                 echo "<div id=\"otherTip\">Fail to create list, the name CANNOT be empty</div>";\r
30                                 } else {\r
31                                         $isProtect = isset($_POST['list_protect']) ? true : false;\r
32                                         $result = $t->editList($_POST['pre_list_name'], $_POST['list_name'], $_POST['list_description'], $isProtect);\r
33                                         if ($result) {\r
34                                                 echo "<div id=\"otherTip\">Success</div>";\r
35                                         } else {\r
36                                                 echo "<div id=\"otherTip\">Failed, please retry</div>";\r
37                                         }\r
38                                 }\r
39                         }\r
40                 }\r
41                 \r
42                 if ( isset($_POST['list_members']) ) {\r
43                         if (trim($_POST['list_members']) == '') {\r
44                                         echo "<div id=\"otherTip\">Fail to add members, the member list is empty!</div>";\r
45                         } else {\r
46                                 $listId = $_POST['member_list_name'];\r
47                                 $result = $t->addListMember($listId, $_POST['list_members']);\r
48                                 if (isset($result->error)) {\r
49                                         echo "<div id=\"otherTip\">Failed, please retry!</div>";\r
50                                 } else {\r
51                                         echo "<div id=\"otherTip\">Success!</div>";\r
52                                 }\r
53                         }\r
54                 }\r
55         ?>\r
56         <?php \r
57                 $isSelf = true;\r
58                 if (isset($_GET['id'])) {\r
59                         $id = $_GET['id'];\r
60                         $isSelf = false;\r
61                 } else {\r
62                         $id = $t->username;\r
63                 }\r
64                 $type = isset($_GET['t'])? $_GET['t'] : 1;\r
65                 $c = isset($_GET['c'])? $_GET['c'] : -1;\r
66                 switch ($type) {\r
67                         case 0:\r
68                                 $lists = $t->followedLists($id, $c);\r
69                                 break;\r
70                         case 1:\r
71                                 $lists = $t->createdLists($id, $c);\r
72                                 break;\r
73                         case 2:\r
74                                 $lists = $t->beAddedLists($id, $c);\r
75                                 break;\r
76                         default:\r
77                                 $lists = false;\r
78                 }\r
79                 $nextlist = $lists->next_cursor;\r
80                 $prelist = $lists->previous_cursor;\r
81                 $lists = $lists->lists; \r
82                 if ($lists === false) {\r
83                         header('location: error.php');exit();\r
84                 } \r
85                 \r
86                 \r
87         ?>\r
88         <div id="subnav">\r
89         <?php if ($isSelf) { ?>\r
90                 <?php if ($type == 0) {?>\r
91                 <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
92                 <?php } else if ($type == 1) {?>\r
93                 <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
94                 <?php } else {?>\r
95                         <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
96                 <?php } ?>\r
97         <?php } else {?>\r
98                 <?php if ($type == 0) {?>\r
99                 <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
100                 <?php } else if ($type == 1) {?>\r
101                 <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
102                 <?php } else {?>\r
103                         <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
104                 <?php } ?>\r
105         <?php } ?>\r
106     </div>\r
107     \r
108         <?php \r
109                 \r
110                 $empty = count($lists) == 0? true: false;\r
111                 if ($empty) {\r
112                         echo "<div id=\"empty\">No Tweet To Display</div>";\r
113                 } else {\r
114                         $output = '<ol class="rank_list">';                     \r
115                         foreach ($lists as $list) {\r
116                 \r
117                                 $listurl = substr($list->uri,1);\r
118                                 $user = $list->user;\r
119                                 $listname = explode('/',$list->full_name);\r
120                                 $mode = $list->mode == 'private' ? "Private" : "";\r
121                                 \r
122                                 $output .= "\r
123                                 <li>\r
124                                         <span class=\"rank_img\"><img src=\"".getAvatar($user->profile_image_url)."\" /></span>\r
125                                         <div class=\"rank_content\">\r
126                                                 <span class=\"rank_num\"><span class=\"rank_name\"><a href=\"list.php?id=$listurl\"><em>$listname[0]/</em>$listname[1]</a></span></span>\r
127                                                 <span class=\"rank_count\">Followers:$list->subscriber_count  Members:$list->member_count  $mode</span> \r
128                                 ";\r
129                                 if ($list->description != '') $output .= "<span class=\"rank_description\">Description: $list->description</span>";\r
130                                 if ($type == 0) $output .= "<span id=\"list_action\"><a id=\"btn\" href=\"javascript:void()\" class=\"unfollow_list\">Unfollow</a></span>";\r
131                                 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
132                                 $output .= "\r
133                                         </div>\r
134                                 </li>\r
135                                 ";\r
136                         }\r
137                         \r
138                         $output .= "</ol>";\r
139                         \r
140                         echo $output;\r
141                 }\r
142                 \r
143         ?>\r
144         \r
145         <?php if ($isSelf && $type == 1) {?>\r
146             <a href="javascript:void()" class="more round" id="list_create_btn" style="margin: 20px auto;">Create a new list</a>\r
147             <form method="POST" action="./lists.php?t=1" id="list_form">\r
148                 <input type="hidden" name="pre_list_name" value="" id="pre_list_name" />\r
149                 <input type="hidden" name="is_edit" value="0" id="is_edit" />\r
150                 <span><label for="list_name">List name</label><input type="text" name="list_name" id="list_name" /></span>\r
151                 <span><label for="list_description">Description</label><textarea type="text" name="list_description" id="list_description"></textarea></span>\r
152                 <span><label for="list_protect">Private</label><input type="checkbox" name="list_protect" id="list_protect"  />\r
153                         <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
154                         <input type="submit" class="btn" id="list_submit" value="Creat" />\r
155                         \r
156                         </span>\r
157                 <span></span>\r
158             </form>\r
159             \r
160             \r
161         <?php }?>\r
162         \r
163         <div id="pagination">\r
164         <?php \r
165             if ($type == 0 || $type == 2) {\r
166                 if ($isSelf) {\r
167                                 if ($prelist != 0) echo "<a id=\"more\" class=\"round more\" style=\"float: left;\" href=\"lists.php?t=$type&c=$prelist\">Back</a>";\r
168                                 if ($nextlist != 0) echo "<a id=\"more\" class=\"round more\" style=\"float: right;\" href=\"lists.php?t=$type&c=$nextlist\">Next</a>";\r
169                 } else {\r
170                                 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
171                                 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
172                 }\r
173                 }\r
174         ?>\r
175         </div>\r
176 </div>\r
177 \r
178 <?php \r
179         include ('inc/sidebar.php');\r
180         include ('inc/footer.php');\r
181 ?>\r