]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/pristine/actions/facebookhome.php
replace all tabs with four spaces
[quix0rs-gnu-social.git] / _darcs / pristine / actions / facebookhome.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/facebookaction.php');
23
24 class FacebookhomeAction extends FacebookAction {
25
26     function handle($args) {
27         parent::handle($args);
28
29         $this->login();
30     }
31
32     function login() {
33
34         $user = null;
35
36         $facebook = $this->get_facebook();
37         $fbuid = $facebook->require_login();
38
39         # check to see whether there's already a Facebook link for this user
40         $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
41
42         if ($flink) {
43
44             $user = $flink->getUser();
45             $this->show_home($facebook, $fbuid, $user);
46
47         } else {
48
49             # Make the user put in her Laconica creds
50             $nickname = common_canonical_nickname($this->trimmed('nickname'));
51             $password = $this->arg('password');
52
53             if ($nickname) {
54
55                 if (common_check_user($nickname, $password)) {
56
57
58                     $user = User::staticGet('nickname', $nickname);
59
60                     if (!$user) {
61                         echo '<fb:error message="Coudln\'t get user!" />';
62                         $this->show_login_form();
63                     }
64
65                     $flink = DB_DataObject::factory('foreign_link');
66                     $flink->user_id = $user->id;
67                     $flink->foreign_id = $fbuid;
68                     $flink->service = 2; # Facebook
69                     $flink->created = common_sql_now();
70
71                     # $this->set_flags($flink, $noticesync, $replysync, $friendsync);
72
73                     $flink_id = $flink->insert();
74
75                     if ($flink_id) {
76                         echo '<fb:success message="You can now use the Identi.ca from Facebook!" />';
77                     }
78
79                     $this->show_home($facebook, $fbuid, $user);
80
81                     return;
82                 } else {
83                     echo '<fb:error message="Incorrect username or password." />';
84                 }
85             }
86
87             $this->show_login_form();
88         }
89
90     }
91
92     function show_home($facebook, $fbuid, $user) {
93
94         $this->show_header('Home');
95
96         echo $this->show_notices($user);
97         $this->update_profile_box($facebook, $fbuid, $user);
98
99         $this->show_footer();
100     }
101
102     function show_notices($user) {
103
104         $page = $this->trimmed('page');
105         if (!$page) {
106             $page = 1;
107         }
108
109         $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
110
111         echo '<ul id="notices">';
112
113         $cnt = 0;
114
115         while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
116             $cnt++;
117
118             if ($cnt > NOTICES_PER_PAGE) {
119                 break;
120             }
121
122             echo $this->render_notice($notice);
123         }
124
125         echo '<ul>';
126
127         $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
128                           $page, 'index.php', array('nickname' => $user->nickname));
129
130     }
131
132 }