2008-12-06 03:01:32 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-12-23 19:19:07 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-12-06 03:01:32 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2008-12-23 19:19:07 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-06 03:01:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
|
|
|
|
2009-01-18 01:31:39 +00:00
|
|
|
require_once INSTALLDIR.'/lib/facebookaction.php';
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2008-12-23 19:49:23 +00:00
|
|
|
class FacebookhomeAction extends FacebookAction
|
|
|
|
{
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2008-12-23 19:33:23 +00:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-23 19:19:07 +00:00
|
|
|
parent::handle($args);
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-05 01:04:07 +00:00
|
|
|
$facebook = get_facebook();
|
2008-12-23 19:19:07 +00:00
|
|
|
$fbuid = $facebook->require_login();
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-19 00:50:45 +00:00
|
|
|
// If the user has opted not to initially allow the app to have
|
|
|
|
// Facebook status update permission, store that preference. Only
|
|
|
|
// promt the user the first time she uses the app
|
|
|
|
if ($this->arg('skip')) {
|
|
|
|
$facebook->api_client->data_setUserPreference(
|
|
|
|
FACEBOOK_PROMPTED_UPDATE_PREF, 'true');
|
|
|
|
}
|
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
// Check to see whether there's already a Facebook link for this user
|
|
|
|
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
if ($flink) {
|
2009-01-19 00:50:45 +00:00
|
|
|
|
2009-01-18 01:31:39 +00:00
|
|
|
$user = $flink->getUser();
|
|
|
|
common_set_user($user);
|
2009-01-19 00:50:45 +00:00
|
|
|
|
|
|
|
// If this is the first time the user has started the app
|
|
|
|
// prompt for Facebook status update permission
|
|
|
|
if (!$facebook->api_client->users_hasAppPermission('status_update')) {
|
|
|
|
|
|
|
|
if ($facebook->api_client->data_getUserPreference(
|
|
|
|
FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') {
|
|
|
|
$this->getUpdatePermission();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use is authenticated and has already been prompted once for
|
|
|
|
// Facebook status update permission? Then show the main page
|
|
|
|
// of the app
|
2009-01-11 07:03:59 +00:00
|
|
|
$this->showHome($flink, null);
|
2009-01-19 00:50:45 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
} else {
|
2009-01-19 00:50:45 +00:00
|
|
|
|
|
|
|
// User hasn't authenticated yet, prompt for creds
|
2009-01-11 07:03:59 +00:00
|
|
|
$this->login($fbuid);
|
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
function login($fbuid)
|
|
|
|
{
|
|
|
|
$nickname = common_canonical_nickname($this->trimmed('nickname'));
|
|
|
|
$password = $this->arg('password');
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
$msg = null;
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
if ($nickname) {
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
if (common_check_user($nickname, $password)) {
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
$user = User::staticGet('nickname', $nickname);
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
if (!$user) {
|
|
|
|
$this->showLoginForm(_("Server error - couldn't get user!"));
|
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
$flink = DB_DataObject::factory('foreign_link');
|
|
|
|
$flink->user_id = $user->id;
|
|
|
|
$flink->foreign_id = $fbuid;
|
|
|
|
$flink->service = FACEBOOK_SERVICE;
|
|
|
|
$flink->created = common_sql_now();
|
|
|
|
$flink->set_flags(true, false, false);
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
$flink_id = $flink->insert();
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
// XXX: Do some error handling here
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-12 05:25:07 +00:00
|
|
|
$this->setDefaults();
|
2009-01-19 00:50:45 +00:00
|
|
|
//$this->showHome($flink, _('You can now use Identi.ca from Facebook!'));
|
|
|
|
|
|
|
|
$this->getUpdatePermission();
|
2009-01-16 20:19:49 +00:00
|
|
|
return;
|
2009-01-19 00:50:45 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
} else {
|
|
|
|
$msg = _('Incorrect username or password.');
|
|
|
|
}
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
$this->showLoginForm($msg);
|
2009-01-19 00:50:45 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-12 05:25:07 +00:00
|
|
|
function setDefaults()
|
|
|
|
{
|
|
|
|
$facebook = get_facebook();
|
|
|
|
|
|
|
|
// A default prefix string for notices
|
2009-01-19 00:50:45 +00:00
|
|
|
$facebook->api_client->data_setUserPreference(
|
|
|
|
FACEBOOK_NOTICE_PREFIX, 'dented: ');
|
|
|
|
$facebook->api_client->data_setUserPreference(
|
|
|
|
FACEBOOK_PROMPTED_UPDATE_PREF, 'false');
|
2009-01-12 05:25:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
function showHome($flink, $msg)
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-01-12 05:25:07 +00:00
|
|
|
|
2009-01-11 08:33:28 +00:00
|
|
|
$facebook = get_facebook();
|
|
|
|
$fbuid = $facebook->require_login();
|
2009-01-12 05:25:07 +00:00
|
|
|
|
2009-01-11 08:33:28 +00:00
|
|
|
$user = $flink->getUser();
|
2009-01-12 05:25:07 +00:00
|
|
|
|
2009-01-11 08:33:28 +00:00
|
|
|
$notice = $user->getCurrentNotice();
|
|
|
|
update_profile_box($facebook, $fbuid, $user, $notice);
|
2009-01-12 05:25:07 +00:00
|
|
|
|
|
|
|
|
2009-01-18 01:31:39 +00:00
|
|
|
$this->showHeader('Home');
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
if ($msg) {
|
|
|
|
common_element('fb:success', array('message' => $msg));
|
|
|
|
}
|
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
echo $this->show_notices($user);
|
2009-01-11 07:03:59 +00:00
|
|
|
|
2009-01-18 01:31:39 +00:00
|
|
|
$this->showFooter();
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2008-12-23 19:33:23 +00:00
|
|
|
function show_notices($user)
|
|
|
|
{
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$page = $this->trimmed('page');
|
|
|
|
if (!$page) {
|
|
|
|
$page = 1;
|
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
$cnt = $this->show_notice_list($notice);
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
|
|
|
|
$page, 'all', array('nickname' => $user->nickname));
|
|
|
|
}
|
2008-12-07 23:59:25 +00:00
|
|
|
|
2009-01-11 07:03:59 +00:00
|
|
|
function show_notice_list($notice)
|
|
|
|
{
|
2009-01-18 01:31:39 +00:00
|
|
|
$nl = new FacebookNoticeList($notice);
|
2009-01-11 07:03:59 +00:00
|
|
|
return $nl->show();
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-12-06 03:01:32 +00:00
|
|
|
|
2009-01-19 00:50:45 +00:00
|
|
|
function getUpdatePermission() {
|
|
|
|
|
|
|
|
$facebook = get_facebook();
|
|
|
|
$fbuid = $facebook->require_login();
|
|
|
|
|
|
|
|
start_fbml();
|
|
|
|
|
|
|
|
common_element('link', array('rel' => 'stylesheet',
|
|
|
|
'type' => 'text/css',
|
|
|
|
'href' => getFacebookCSS()));
|
|
|
|
|
|
|
|
$this->showLogo();
|
|
|
|
|
|
|
|
common_element_start('div', array('class' => 'content'));
|
|
|
|
|
|
|
|
// Figure what the URL of our app is.
|
|
|
|
$app_props = $facebook->api_client->Admin_getAppProperties(
|
|
|
|
array('canvas_name', 'application_name'));
|
|
|
|
$app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/index.php';
|
|
|
|
$app_name = $app_props['application_name'];
|
|
|
|
|
|
|
|
$instructions = sprintf(_('If you would like the %s app to automatically update ' .
|
|
|
|
'your Facebook status with your latest notice, you need ' .
|
|
|
|
'to give it permission.'), $app_name);
|
|
|
|
|
|
|
|
common_element_start('p');
|
|
|
|
common_element('span', array('id' => 'permissions_notice'), $instructions);
|
|
|
|
common_element_end('p');
|
|
|
|
|
|
|
|
common_element_start('form', array('method' => 'post',
|
|
|
|
'action' => $app_url,
|
|
|
|
'id' => 'facebook-skip-permissions'));
|
|
|
|
|
|
|
|
common_element_start('ul', array('id' => 'fb-permissions-list'));
|
|
|
|
common_element_start('li', array('id' => 'fb-permissions-item'));
|
|
|
|
common_element_start('fb:prompt-permission', array('perms' => 'status_update',
|
|
|
|
'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')'));
|
|
|
|
common_element('span', array('class' => 'facebook-button'),
|
|
|
|
_('Allow Identi.ca to update my Facebook status'));
|
|
|
|
common_element_end('fb:prompt-permission');
|
|
|
|
common_element_end('li');
|
|
|
|
|
|
|
|
common_element_start('li', array('id' => 'fb-permissions-item'));
|
|
|
|
common_submit('skip', _('Skip'));
|
|
|
|
common_element_end('li');
|
|
|
|
common_element_end('ul');
|
|
|
|
|
|
|
|
common_element_end('form');
|
|
|
|
common_element_end('div');
|
|
|
|
|
|
|
|
common_end_xml();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-06 03:01:32 +00:00
|
|
|
}
|