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);
31 $facebook = get_facebook();
32 $fbuid = $facebook->require_login();
34 // Check to see whether there's already a Facebook link for this user
35 $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
38 $user = $flink->getUser();
39 common_set_user($user);
40 $this->showHome($flink, null);
47 function login($fbuid)
49 $nickname = common_canonical_nickname($this->trimmed('nickname'));
50 $password = $this->arg('password');
56 if (common_check_user($nickname, $password)) {
58 $user = User::staticGet('nickname', $nickname);
61 $this->showLoginForm(_("Server error - couldn't get user!"));
64 $flink = DB_DataObject::factory('foreign_link');
65 $flink->user_id = $user->id;
66 $flink->foreign_id = $fbuid;
67 $flink->service = FACEBOOK_SERVICE;
68 $flink->created = common_sql_now();
69 $flink->set_flags(true, false, false);
71 $flink_id = $flink->insert();
73 // XXX: Do some error handling here
76 $this->showHome($flink, _('You can now use Identi.ca from Facebook!'));
80 $msg = _('Incorrect username or password.');
84 $this->showLoginForm($msg);
88 function setDefaults()
90 $facebook = get_facebook();
92 // A default prefix string for notices
93 $facebook->api_client->data_setUserPreference(1, 'dented: ');
96 function showHome($flink, $msg)
99 $facebook = get_facebook();
100 $fbuid = $facebook->require_login();
102 $user = $flink->getUser();
104 $notice = $user->getCurrentNotice();
105 update_profile_box($facebook, $fbuid, $user, $notice);
108 $this->showHeader('Home');
111 common_element('fb:success', array('message' => $msg));
114 echo $this->show_notices($user);
119 function show_notices($user)
122 $page = $this->trimmed('page');
127 $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
129 $cnt = $this->show_notice_list($notice);
131 common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
132 $page, 'all', array('nickname' => $user->nickname));
135 function show_notice_list($notice)
137 $nl = new FacebookNoticeList($notice);