We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit dccf8374 authored by Zach Copley's avatar Zach Copley

trac750 - Exoskeleton of a nascent Facebook app

darcs-hash:20081206030132-7b5ce-96c38ab67edd3d58f8722ef25852a6143f05a86b.gz
parent 92ea88fd
<?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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebookhomeAction extends FacebookAction {
function handle($args) {
parent::handle($args);
$this->login();
}
function login() {
$user = null;
$facebook = $this->get_facebook();
$fbuid = $facebook->require_login();
# check to see whether there's already a Facebook link for this user
$flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
if ($flink) {
$this->display($facebook, $fbuid);
$user = $flink->getUser();
$notice = $user->getCurrentNotice();
echo $this->show_notices($user);
$this->update_profile_box($facebook, $fbuid, $user);
} else {
$nickname = common_canonical_nickname($this->trimmed('nickname'));
$password = $this->arg('password');
if ($nickname) {
if (common_check_user($nickname, $password)) {
echo '<h2>Successful authentication!</h2>';
$user = User::staticGet('nickname', $nickname);
if (!$user) {
echo '<h2>Couldn\'t get user!</h2>';
$this->show_login_form();
}
$flink = DB_DataObject::factory('foreign_link');
$flink->user_id = $user->id;
$flink->foreign_id = $fbuid;
$flink->service = 2; # Facebook
$flink->created = common_sql_now();
# $this->set_flags($flink, $noticesync, $replysync, $friendsync);
$flink_id = $flink->insert();
if ($flink_id) {
echo '<h2>Successfully made Identi.ca -> Facebook link</h2>';
}
$this->display($facebook, $fbuid);
return;
} else {
echo '<h2>Fail!</h2>';
}
}
$this->show_login_form();
}
}
function display($facebook, $fbuid) {
$this->show_header('Home');
// Greet the currently logged-in user!
echo "<p>Hello, <fb:name uid=\"$fbuid\" useyou=\"false\" />!</p>";
$this->show_footer();
}
function show_notices($user) {
$page = $this->trimmed('page');
if (!$page) {
$page = 1;
}
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
echo '<ul id="notices">';
$cnt = 0;
while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
$cnt++;
if ($cnt > NOTICES_PER_PAGE) {
break;
}
echo $this->render_notice($notice);
}
echo '<ul>';
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'all', array('nickname' => $user->nickname));
}
function update_profile_box($facebook, $fbuid, $user) {
$notice = $user->getCurrentNotice();
$html = $this->render_notice($notice);
$fbml = "<fb:wide>$html</fb:wide>";
$fbml .= "<fb:narrow>$html</fb:narrow>";
$fbml_main = "<fb:narrow>$html</fb:narrow>";
$facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
}
}
<?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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebookinviteAction extends FacebookAction {
function handle($args) {
parent::handle($args);
$this->display();
}
function display() {
$facebook = $this->get_facebook();
$fbuid = $facebook->require_login();
$this->show_header('Invite');
echo '<h2>Coming soon...</h2>';
$this->show_footer();
}
}
<?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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebooksettingsAction extends FacebookAction {
function handle($args) {
parent::handle($args);
$this->display();
}
function display() {
$facebook = $this->get_facebook();
$fbuid = $facebook->require_login();
$this->show_header('Settings');
echo '<h2>Coming soon...</h2>';
$this->show_footer();
}
}
......@@ -54,7 +54,7 @@ class Foreign_link extends Memcached_DataObject
return NULL;
}
// Convenience method
# Convenience methods
function getForeignUser() {
$fuser = new Foreign_user();
$fuser->service = $this->service;
......@@ -68,5 +68,9 @@ class Foreign_link extends Memcached_DataObject
return NULL;
}
function getUser() {
return User::staticGet($this->user_id);
}
}
......@@ -122,15 +122,3 @@ $config['sphinx']['port'] = 3312;
#Twitter integration source attribute. Note: default is Laconica
#$config['integration']['source'] = 'Laconica';
# Edit throttling. Off by default. If turned on, you can only post 20 notices
# every 10 minutes. Admins may want to play with the settings to minimize inconvenience for
# real users without getting uncontrollable floods from spammers or runaway bots.
#$config['throttle']['enabled'] = true;
#$config['throttle']['count'] = 100;
#$config['throttle']['timespan'] = 3600;
# List of users banned from posting (nicknames and/or IDs)
#$config['profile']['banned'][] = 'hacker';
#$config['profile']['banned'][] = 12345;
......@@ -2,4 +2,7 @@ insert into foreign_service
(id, name, description, created)
values
('1','Twitter', 'Twitter Micro-blogging service', now());
insert into foreign_service
(id, name, description, created)
values
('2','Facebook', 'Facebook', now());
......@@ -22,6 +22,11 @@ RewriteRule ^doc/openmublog$ index.php?action=doc&title=openmublog [L,QSA]
RewriteRule ^doc/privacy$ index.php?action=doc&title=privacy [L,QSA]
RewriteRule ^doc/source$ index.php?action=doc&title=source [L,QSA]
RewriteRule ^facebook/$ index.php?action=facebookhome [L,QSA]
RewriteRule ^facebook/index.php$ index.php?action=facebookhome [L,QSA]
RewriteRule ^facebook/settings.php$ index.php?action=facebooksettings [L,QSA]
RewriteRule ^facebook/invite.php$ index.php?action=facebookinvite [L,QSA]
RewriteRule ^main/login$ index.php?action=login [L,QSA]
RewriteRule ^main/logout$ index.php?action=logout [L,QSA]
RewriteRule ^main/register/(.*)$ index.php?action=register&code=$1 [L,QSA]
......
<?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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/extlib/facebook/facebook.php');
class FacebookAction extends Action {
function handle($args) {
parent::handle($args);
}
function get_facebook() {
$apikey = common_config('facebook', 'apikey');
$secret = common_config('facebook', 'secret');
return new Facebook($apikey, $secret);
}
# Display methods
function show_header($selected ='Home') {
# $header = '<link rel="stylesheet" type="text/css" href="" />';
# $header .='<script src="" ></script>';
$header .= '<fb:dashboard/>';
$header .=
'<fb:tabs>'
.'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
.'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />'
.'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />'
.'</fb:tabs>';
$header .= '<div id="main_body">';
echo $header;
}
function show_footer() {
$footer = '</div>';
echo $footer;
}
function show_login_form() {
$loginform =
' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
.'<a href="http://identi.ca/">'
.' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
.'</a>'
.'<h1 class="pagetitle">Login</h1>'
.'<div class="instructions">'
.' <p>Login with your username and password. Don\'t have a username yet?'
.' <a href="http://identi.ca/main/register">Register</a> a new account.'
.' </p>'
.'</div>'
.'<div id="content">'
.' <form method="post" id="login">'
.' <p>'
.' <label for="nickname">Nickname</label>'
.' <input name="nickname" type="text" class="input_text" id="nickname"/>'
.' </p>'
.' <p>'
.' <label for="password">Password</label>'
.' <input name="password" type="password" class="password" id="password"/>'
.' </p>'
.' <p>'
.' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
.' </p>'
.' </form>'
.' <p>'
.' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
.' </p>'
.'</div';
echo $loginform;
}
function render_notice($notice) {
global $config;
$profile = $notice->getProfile();
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
$noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
# XXX: we need to figure this out better. Is this right?
if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
$noticeurl = $notice->uri;
}
$html =
'<li class="notice_single" id="' . $notice->id . '">'
.'<a href="' . $profile->profileurl . '">'
.'<img src="';
if ($avatar) {
$html .= common_avatar_display_url($avatar);
} else {
$html .= common_default_avatar(AVATAR_STREAM_SIZE);
}
$html .=
'" class="avatar stream" width="'
. AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
.' alt="';
if ($profile->fullname) {
$html .= $profile->fullname;
} else {
$html .= $profile->nickname;
}
$html .=
'"></a>'
.'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
.'<p class="content">' . $notice->rendered . '</p>'
.'<p class="time">'
.'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
if ($notice->source) {
$html .= _(' from ');
$html .= $this->source_link($notice->source);
}
if ($notice->reply_to) {
$replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
$html .=
' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
}
$html .= '</p></li>';
return $html;
}
function source_link($source) {
$source_name = _($source);
$html = '<span class="noticesource">';
switch ($source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'api':
$html .= $source_name;
break;
default:
$ns = Notice_source::staticGet($source);
if ($ns) {
$html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
} else {
$html .= $source_name;
}
break;
}
$html .= '</span>';
return $html;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment