3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/facebookaction.php');
24 class FacebookhomeAction extends FacebookAction
27 function handle($args)
29 parent::handle($args);
39 $facebook = get_facebook();
40 $fbuid = $facebook->require_login();
42 # check to see whether there's already a Facebook link for this user
43 $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
47 $user = $flink->getUser();
48 $this->show_home($facebook, $fbuid, $user);
52 # Make the user put in her Laconica creds
53 $nickname = common_canonical_nickname($this->trimmed('nickname'));
54 $password = $this->arg('password');
58 if (common_check_user($nickname, $password)) {
61 $user = User::staticGet('nickname', $nickname);
64 echo '<fb:error message="Coudln\'t get user!" />';
65 $this->show_login_form();
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 $flink->set_flags(true, false, false);
75 $flink_id = $flink->insert();
78 echo '<fb:success message="You can now use Identi.ca from Facebook!" />';
81 $this->show_home($facebook, $fbuid, $user);
85 echo '<fb:error message="Incorrect username or password." />';
89 $this->show_login_form();
94 function show_home($facebook, $fbuid, $user)
97 $this->show_header('Home');
99 echo $this->show_notices($user);
100 $this->update_profile_box($facebook, $fbuid, $user);
102 $this->show_footer();
105 function show_notices($user)
108 $page = $this->trimmed('page');
113 $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
115 echo '<ul id="notices">';
119 while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
122 if ($cnt > NOTICES_PER_PAGE) {
126 echo $this->render_notice($notice);
131 $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
132 $page, 'index.php', array('nickname' => $user->nickname));