]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/facebookhome.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / 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
27     function handle($args)
28     {
29         parent::handle($args);
30
31         $this->login();
32     }
33
34     function login()
35     {
36
37         $user = null;
38
39         $facebook = $this->get_facebook();
40         $fbuid = $facebook->require_login();
41
42         # check to see whether there's already a Facebook link for this user
43         $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
44
45         if ($flink) {
46
47             $user = $flink->getUser();
48             $this->show_home($facebook, $fbuid, $user);
49
50         } else {
51
52             # Make the user put in her Laconica creds
53             $nickname = common_canonical_nickname($this->trimmed('nickname'));
54             $password = $this->arg('password');
55
56             if ($nickname) {
57
58                 if (common_check_user($nickname, $password)) {
59
60
61                     $user = User::staticGet('nickname', $nickname);
62
63                     if (!$user) {
64                         echo '<fb:error message="Coudln\'t get user!" />';
65                         $this->show_login_form();
66                     }
67
68                     $flink = DB_DataObject::factory('foreign_link');
69                     $flink->user_id = $user->id;
70                     $flink->foreign_id = $fbuid;
71                     $flink->service = 2; # Facebook
72                     $flink->created = common_sql_now();
73
74                     # $this->set_flags($flink, $noticesync, $replysync, $friendsync);
75
76                     $flink_id = $flink->insert();
77
78                     if ($flink_id) {
79                         echo '<fb:success message="You can now use the Identi.ca from Facebook!" />';
80                     }
81
82                     $this->show_home($facebook, $fbuid, $user);
83
84                     return;
85                 } else {
86                     echo '<fb:error message="Incorrect username or password." />';
87                 }
88             }
89
90             $this->show_login_form();
91         }
92
93     }
94
95     function show_home($facebook, $fbuid, $user)
96     {
97
98         $this->show_header('Home');
99
100         echo $this->show_notices($user);
101         $this->update_profile_box($facebook, $fbuid, $user);
102
103         $this->show_footer();
104     }
105
106     function show_notices($user)
107     {
108
109         $page = $this->trimmed('page');
110         if (!$page) {
111             $page = 1;
112         }
113
114         $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
115
116         echo '<ul id="notices">';
117
118         $cnt = 0;
119
120         while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
121             $cnt++;
122
123             if ($cnt > NOTICES_PER_PAGE) {
124                 break;
125             }
126
127             echo $this->render_notice($notice);
128         }
129
130         echo '<ul>';
131
132         $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
133                           $page, 'index.php', array('nickname' => $user->nickname));
134
135     }
136
137 }