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 {
26 function handle($args) {
27 parent::handle($args);
36 $facebook = $this->get_facebook();
37 $fbuid = $facebook->require_login();
39 # check to see whether there's already a Facebook link for this user
40 $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
44 $user = $flink->getUser();
45 $this->show_home($facebook, $fbuid, $user);
49 # Make the user put in her Laconica creds
50 $nickname = common_canonical_nickname($this->trimmed('nickname'));
51 $password = $this->arg('password');
55 if (common_check_user($nickname, $password)) {
58 $user = User::staticGet('nickname', $nickname);
61 echo '<fb:error message="Coudln\'t get user!" />';
62 $this->show_login_form();
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();
71 # $this->set_flags($flink, $noticesync, $replysync, $friendsync);
73 $flink_id = $flink->insert();
76 echo '<fb:success message="You can now use the Identi.ca from Facebook!" />';
79 $this->show_home($facebook, $fbuid, $user);
83 echo '<fb:error message="Incorrect username or password." />';
87 $this->show_login_form();
92 function show_home($facebook, $fbuid, $user) {
94 $this->show_header('Home');
96 echo $this->show_notices($user);
97 $this->update_profile_box($facebook, $fbuid, $user);
102 function show_notices($user) {
104 $page = $this->trimmed('page');
109 $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
111 echo '<ul id="notices">';
115 while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
118 if ($cnt > NOTICES_PER_PAGE) {
122 echo $this->render_notice($notice);
127 $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
128 $page, 'index.php', array('nickname' => $user->nickname));