Merge branch 'master' of evan@dev.controlyourself.ca:/var/www/trunk

This commit is contained in:
Evan Prodromou 2009-01-23 04:21:08 +01:00
commit ed09eece28
7 changed files with 666 additions and 488 deletions

View File

@ -21,62 +21,75 @@ if (!defined('LACONICA')) { exit(1); }
require_once INSTALLDIR.'/lib/facebookaction.php'; require_once INSTALLDIR.'/lib/facebookaction.php';
class FacebookhomeAction extends FacebookAction class FacebookhomeAction extends FacebookAction
{ {
var $page = null;
function prepare($argarray)
{
parent::prepare($argarray);
$this->page = $this->trimmed('page');
if (!$this->page) {
$this->page = 1;
}
return true;
}
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
$facebook = get_facebook();
$fbuid = $facebook->require_login();
// Check to see whether there's already a Facebook link for this user
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
// If the user has opted not to initially allow the app to have // If the user has opted not to initially allow the app to have
// Facebook status update permission, store that preference. Only // Facebook status update permission, store that preference. Only
// promt the user the first time she uses the app // promt the user the first time she uses the app
if ($this->arg('skip')) { if ($this->arg('skip')) {
$facebook->api_client->data_setUserPreference( $this->facebook->api_client->data_setUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); FACEBOOK_PROMPTED_UPDATE_PREF, 'true');
} }
if ($flink) { if ($this->flink) {
if ($_POST['submit'] == 'Send') { $this->user = $this->flink->getUser();
$this->saveNewNotice($flink);
return;
}
$user = $flink->getUser();
common_set_user($user);
// If this is the first time the user has started the app // If this is the first time the user has started the app
// prompt for Facebook status update permission // prompt for Facebook status update permission
if (!$facebook->api_client->users_hasAppPermission('status_update')) { if (!$this->facebook->api_client->users_hasAppPermission('status_update')) {
if ($facebook->api_client->data_getUserPreference( if ($this->facebook->api_client->data_getUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') {
$this->getUpdatePermission(); $this->getUpdatePermission();
return; return;
} }
} }
// Use is authenticated and has already been prompted once for // Make sure the user's profile box has the lastest notice
$notice = $this->user->getCurrentNotice();
$this->updateProfileBox($notice);
if ($this->arg('status_submit') == 'Send') {
$this->saveNewNotice();
}
// User is authenticated and has already been prompted once for
// Facebook status update permission? Then show the main page // Facebook status update permission? Then show the main page
// of the app // of the app
$this->showHome($flink, null); $this->showPage();
} else { } else {
// User hasn't authenticated yet, prompt for creds // User hasn't authenticated yet, prompt for creds
$this->login($fbuid); $this->login();
} }
} }
function login($fbuid) function login()
{ {
$nickname = common_canonical_nickname($this->trimmed('nickname')); $nickname = common_canonical_nickname($this->trimmed('nickname'));
$password = $this->arg('password'); $password = $this->arg('password');
@ -95,7 +108,7 @@ class FacebookhomeAction extends FacebookAction
$flink = DB_DataObject::factory('foreign_link'); $flink = DB_DataObject::factory('foreign_link');
$flink->user_id = $user->id; $flink->user_id = $user->id;
$flink->foreign_id = $fbuid; $flink->foreign_id = $this->fbuid;
$flink->service = FACEBOOK_SERVICE; $flink->service = FACEBOOK_SERVICE;
$flink->created = common_sql_now(); $flink->created = common_sql_now();
$flink->set_flags(true, false, false); $flink->set_flags(true, false, false);
@ -121,80 +134,62 @@ class FacebookhomeAction extends FacebookAction
function setDefaults() function setDefaults()
{ {
$facebook = get_facebook();
// A default prefix string for notices // A default prefix string for notices
$facebook->api_client->data_setUserPreference( $this->facebook->api_client->data_setUserPreference(
FACEBOOK_NOTICE_PREFIX, 'dented: '); FACEBOOK_NOTICE_PREFIX, 'dented: ');
$facebook->api_client->data_setUserPreference( $this->facebook->api_client->data_setUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF, 'false'); FACEBOOK_PROMPTED_UPDATE_PREF, 'false');
} }
function showHome($flink, $msg)
function showNoticeForm()
{ {
$facebook = get_facebook(); $post_action = "$this->app_uri/index.php";
$fbuid = $facebook->require_login();
$user = $flink->getUser(); $notice_form = new FacebookNoticeForm($this, $post_action, null,
$post_action, $this->user);
$notice = $user->getCurrentNotice(); $notice_form->show();
update_profile_box($facebook, $fbuid, $user, $notice);
$this->showHeader($msg);
$this->showNoticeForm($user);
$this->showNav('Home');
echo $this->showNotices($user);
$this->showFooter();
} }
function showNotices($user) function title()
{
if ($this->page > 1) {
return sprintf(_("%s and friends, page %d"), $this->user->nickname, $this->page);
} else {
return sprintf(_("%s and friends"), $this->user->nickname);
}
}
function showContent()
{ {
$page = $this->trimmed('page'); $notice = $this->user->noticesWithFriends(($this->page-1) *
if (!$page) { NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$page = 1;
}
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); $nl = new NoticeList($notice, $this);
$cnt = $this->showNoticeList($notice); $cnt = $nl->show();
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'index.php', array('nickname' => $this->user->nickname));
facebookPagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'all', array('nickname' => $user->nickname));
} }
function showNoticeList($notice) function showNoticeList($notice)
{ {
$nl = new FacebookNoticeList($notice);
$nl = new NoticeList($notice, $this);
return $nl->show(); return $nl->show();
} }
function getUpdatePermission() { function getUpdatePermission() {
$facebook = get_facebook();
$fbuid = $facebook->require_login();
startFBML();
$this->showStylesheets();
$this->showScripts();
$this->showLogo();
$this->elementStart('div', array('class' => 'content')); $this->elementStart('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 ' . $instructions = sprintf(_('If you would like the %s app to automatically update ' .
'your Facebook status with your latest notice, you need ' . 'your Facebook status with your latest notice, you need ' .
'to give it permission.'), $app_name); 'to give it permission.'), $this->app_name);
$this->elementStart('p'); $this->elementStart('p');
$this->element('span', array('id' => 'permissions_notice'), $instructions); $this->element('span', array('id' => 'permissions_notice'), $instructions);
@ -207,33 +202,31 @@ class FacebookhomeAction extends FacebookAction
$this->elementStart('ul', array('id' => 'fb-permissions-list')); $this->elementStart('ul', array('id' => 'fb-permissions-list'));
$this->elementStart('li', array('id' => 'fb-permissions-item')); $this->elementStart('li', array('id' => 'fb-permissions-item'));
$this->elementStart('fb:prompt-permission', array('perms' => 'status_update', $this->elementStart('fb:prompt-permission', array('perms' => 'status_update',
'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); 'next_fbjs' => 'document.setLocation(\'' . $this->app_uri . '\')'));
$this->element('span', array('class' => 'facebook-button'), $this->element('span', array('class' => 'facebook-button'),
_('Allow Identi.ca to update my Facebook status')); sprintf(_('Allow %s to update my Facebook status'), $this->app_name));
$this->elementEnd('fb:prompt-permission'); $this->elementEnd('fb:prompt-permission');
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementStart('li', array('id' => 'fb-permissions-item')); $this->elementStart('li', array('id' => 'fb-permissions-item'));
common_submit('skip', _('Skip')); $this->submit('skip', _('Skip'));
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->elementEnd('form'); $this->elementEnd('form');
$this->elementEnd('div'); $this->elementEnd('div');
common_end_xml();
} }
function saveNewNotice($flink) function saveNewNotice()
{ {
$user = $flink->getUser(); $user = $this->flink->getUser();
$content = $_POST['status_textarea']; $content = $this->trimmed('status_textarea');
if (!$content) { if (!$content) {
$this->showHome($flink, _('No content!')); $this->showPage(_('No notice content!'));
return; return;
} else { } else {
$content_shortened = common_shorten_links($content); $content_shortened = common_shorten_links($content);
@ -241,7 +234,7 @@ class FacebookhomeAction extends FacebookAction
if (mb_strlen($content_shortened) > 140) { if (mb_strlen($content_shortened) > 140) {
common_debug("Content = '$content_shortened'", __FILE__); common_debug("Content = '$content_shortened'", __FILE__);
common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__); common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
$this->showHome($flink, _('That\'s too long. Max notice size is 140 chars.')); $this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
return; return;
} }
} }
@ -251,6 +244,9 @@ class FacebookhomeAction extends FacebookAction
$cmd = $inter->handle_command($user, $content_shortened); $cmd = $inter->handle_command($user, $content_shortened);
if ($cmd) { if ($cmd) {
// XXX fix this
$cmd->execute(new WebChannel()); $cmd->execute(new WebChannel());
return; return;
} }
@ -261,12 +257,62 @@ class FacebookhomeAction extends FacebookAction
'Facebook', 1, ($replyto == 'false') ? null : $replyto); 'Facebook', 1, ($replyto == 'false') ? null : $replyto);
if (is_string($notice)) { if (is_string($notice)) {
$this->showHome($flink, 'Error!'); $this->showPage($notice);
return; return;
} }
common_broadcast_notice($notice); common_broadcast_notice($notice);
$this->showHome($flink, 'Success!');
} }
/**
* Generate pagination links
*
* @param boolean $have_before is there something before?
* @param boolean $have_after is there something after?
* @param integer $page current page
* @param string $action current action
* @param array $args rest of query arguments
*
* @return nothing
*/
function pagination($have_before, $have_after, $page, $action, $args=null)
{
// Does a little before-after block for next/prev page
// XXX: Fix so this uses common_local_url() if possible.
if ($have_before || $have_after) {
$this->elementStart('div', array('class' => 'pagination'));
$this->elementStart('dl', null);
$this->element('dt', null, _('Pagination'));
$this->elementStart('dd', null);
$this->elementStart('ul', array('class' => 'nav'));
}
if ($have_before) {
$pargs = array('page' => $page-1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_prev'));
$this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'),
_('After'));
$this->elementEnd('li');
}
if ($have_after) {
$pargs = array('page' => $page+1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_next'));
$this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'next'),
_('Before'));
$this->elementEnd('li');
}
if ($have_before || $have_after) {
$this->elementEnd('ul');
$this->elementEnd('dd');
$this->elementEnd('dl');
$this->elementEnd('div');
}
}
} }

View File

@ -27,26 +27,51 @@ class FacebookinviteAction extends FacebookAction
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
$this->showForm();
if ($this->arg('ids')) {
$this->showThankYou();
} else {
$this->showInviteForm();
}
} }
/**
* Wrapper for showing a page
*
* Stores an error and shows the page
*
* @param string $error Error, if any
*
* @return void
*/
function showThankYou() function showForm($error=null)
{ {
$facebook = get_facebook(); $this->error = $error;
$fbuid = $facebook->require_login(); $this->showPage();
}
$this->showHeader('Invite'); /**
* Show the page content
*
* Either shows the registration form or, if registration was successful,
* instructions for using the site.
*
* @return void
*/
$this->element('h2', null, _('Thanks for inviting your friends to use Identi.ca!')); function showContent()
{
if ($this->arg('ids')) {
$this->showSuccessContent();
} else {
$this->showFormContent();
}
}
function showSuccessContent()
{
$this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'),
common_config('site', 'name')));
$this->element('p', null, _('Invitations have been sent to the following users:')); $this->element('p', null, _('Invitations have been sent to the following users:'));
$friend_ids = $_POST['ids']; // Hmm... $this->arg('ids') doesn't seem to work $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to acces the list?
$this->elementStart("ul"); $this->elementStart("ul");
@ -60,31 +85,24 @@ class FacebookinviteAction extends FacebookAction
$this->elementEnd("ul"); $this->elementEnd("ul");
$this->showFooter();
} }
function showInviteForm() function showFormContent()
{ {
$facebook = get_facebook();
$fbuid = $facebook->require_login();
$this->showHeader();
$this->showNav('Invite');
// Get a list of users who are already using the app for exclusion // Get a list of users who are already using the app for exclusion
$exclude_ids = $facebook->api_client->friends_getAppUsers(); $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
$content = _('You have been invited to Identi.ca!') . $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
htmlentities('<fb:req-choice url="http://apps.facebook.com/identica_app/" label="Add"/>'); htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
$this->elementStart('fb:request-form', array('action' => 'invite.php', $this->elementStart('fb:request-form', array('action' => 'invite.php',
'method' => 'post', 'method' => 'post',
'invite' => 'true', 'invite' => 'true',
'type' => 'Identi.ca', 'type' => common_config('site', 'name'),
'content' => $content)); 'content' => $content));
$this->hidden('invite', 'true'); $this->hidden('invite', 'true');
$actiontext = 'Invite your friends to use Identi.ca.'; $actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
$this->element('fb:multi-friend-selector', array('showborder' => 'false', $this->element('fb:multi-friend-selector', array('showborder' => 'false',
'actiontext' => $actiontext, 'actiontext' => $actiontext,
'exclude_ids' => implode(',', $exclude_ids), 'exclude_ids' => implode(',', $exclude_ids),
@ -92,7 +110,8 @@ class FacebookinviteAction extends FacebookAction
$this->elementEnd('fb:request-form'); $this->elementEnd('fb:request-form');
$this->element('h2', null, _('Friends already using Identi.ca:')); $this->element('h2', null, sprintf(_('Friends already using %s:'),
common_config('site', 'name')));
$this->elementStart("ul"); $this->elementStart("ul");
foreach ($exclude_ids as $friend) { foreach ($exclude_ids as $friend) {
@ -104,9 +123,11 @@ class FacebookinviteAction extends FacebookAction
} }
$this->elementEnd("ul"); $this->elementEnd("ul");
}
$this->showFooter(); function title()
{
return sprintf(_('Send invitations'));
} }
} }

View File

@ -27,7 +27,20 @@ class FacebooksettingsAction extends FacebookAction
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
$this->showPage();
}
/**
* Show the page content
*
* Either shows the registration form or, if registration was successful,
* instructions for using the site.
*
* @return void
*/
function showContent()
{
if ($this->arg('save')) { if ($this->arg('save')) {
$this->saveSettings(); $this->saveSettings();
} else { } else {
@ -41,68 +54,76 @@ class FacebooksettingsAction extends FacebookAction
$replysync = $this->arg('replysync'); $replysync = $this->arg('replysync');
$prefix = $this->trimmed('prefix'); $prefix = $this->trimmed('prefix');
$facebook = get_facebook(); $original = clone($this->flink);
$fbuid = $facebook->require_login(); $this->flink->set_flags($noticesync, $replysync, false);
$result = $this->flink->update($original);
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
$original = clone($flink);
$flink->set_flags($noticesync, $replysync, false);
$result = $flink->update($original);
$facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
substr($prefix, 0, 128)); substr($prefix, 0, 128));
if ($result) { if ($result === false) {
$this->showForm('Sync preferences saved.', true); $this->showForm(_('There was a problem saving your sync preferences!'));
} else { } else {
$this->showForm('There was a problem saving your sync preferences!'); $this->showForm(_('Sync preferences saved.'), true);
} }
} }
function showForm($msg = null, $success = false) { function showForm($msg = null, $success = false) {
$facebook = get_facebook(); if ($msg) {
$fbuid = $facebook->require_login(); if ($success) {
$this->element('fb:success', array('message' => $msg));
} else {
$this->element('fb:error', array('message' => $msg));
}
}
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); if ($this->facebook->api_client->users_hasAppPermission('status_update')) {
$this->showHeader($msg, $success);
$this->showNav('Settings');
if ($facebook->api_client->users_hasAppPermission('status_update')) {
$this->elementStart('form', array('method' => 'post', $this->elementStart('form', array('method' => 'post',
'id' => 'facebook_settings')); 'id' => 'facebook_settings'));
$this->element('h2', null, _('Sync preferences')); $this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'), $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true); ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('replysync', _('Send "@" replies to Facebook.'), $this->checkbox('replysync', _('Send "@" replies to Facebook.'),
($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
$prefix = $facebook->api_client->data_getUserPreference(1); $this->elementEnd('li');
$this->elementStart('li');
$prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX);
$this->input('prefix', _('Prefix'), $this->input('prefix', _('Prefix'),
($prefix) ? $prefix : null, ($prefix) ? $prefix : null,
_('A string to prefix notices with.')); _('A string to prefix notices with.'));
$this->elementEnd('li');
$this->elementStart('li');
$this->submit('save', _('Save')); $this->submit('save', _('Save'));
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementEnd('form'); $this->elementEnd('form');
} else { } else {
// Figure what the URL of our app is. $instructions = sprintf(_('If you would like %s to automatically update ' .
$app_props = $facebook->api_client->Admin_getAppProperties(
array('canvas_name', 'application_name'));
$app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/settings.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 ' . 'your Facebook status with your latest notice, you need ' .
'to give it permission.'), $app_name); 'to give it permission.'), $this->app_name);
$this->elementStart('p'); $this->elementStart('p');
$this->element('span', array('id' => 'permissions_notice'), $instructions); $this->element('span', array('id' => 'permissions_notice'), $instructions);
@ -111,15 +132,19 @@ class FacebooksettingsAction extends FacebookAction
$this->elementStart('ul', array('id' => 'fb-permissions-list')); $this->elementStart('ul', array('id' => 'fb-permissions-list'));
$this->elementStart('li', array('id' => 'fb-permissions-item')); $this->elementStart('li', array('id' => 'fb-permissions-item'));
$this->elementStart('fb:prompt-permission', array('perms' => 'status_update', $this->elementStart('fb:prompt-permission', array('perms' => 'status_update',
'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); 'next_fbjs' => 'document.setLocation(\'' . "$this->app_url/settings.php" . '\')'));
$this->element('span', array('class' => 'facebook-button'), $this->element('span', array('class' => 'facebook-button'),
_('Allow Identi.ca to update my Facebook status')); sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name')));
$this->elementEnd('fb:prompt-permission'); $this->elementEnd('fb:prompt-permission');
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementEnd('ul'); $this->elementEnd('ul');
} }
$this->showFooter(); }
function title()
{
return _('Sync preferences');
} }
} }

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,9 +1,12 @@
<?php <?php
/* /**
* Laconica - a distributed open-source microblogging tool * Laconica, the distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
* *
* This program is free software: you can redistribute it and/or modify * Low-level generator for HTML
*
* PHP version 5
*
* LICENCE: 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
@ -15,92 +18,174 @@
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Faceboook
* @package Laconica
* @author Zach Copley <zach@controlyourself.ca>
* @copyright 2008 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/ */
if (!defined('LACONICA')) { if (!defined('LACONICA'))
{
exit(1); exit(1);
} }
require_once INSTALLDIR.'/lib/facebookutil.php'; require_once INSTALLDIR.'/lib/facebookutil.php';
require_once INSTALLDIR.'/lib/noticeform.php';
class FacebookAction extends Action class FacebookAction extends Action
{ {
function handle($args) var $facebook = null;
var $fbuid = null;
var $flink = null;
var $action = null;
var $app_uri = null;
var $app_name = null;
function prepare($argarray)
{ {
parent::handle($args); parent::prepare($argarray);
common_debug("Facebookaction::prepare");
$this->facebook = get_facebook();
$this->fbuid = $this->facebook->require_login();
$this->action = $this->trimmed('action');
$app_props = $this->facebook->api_client->Admin_getAppProperties(
array('canvas_name', 'application_name'));
$this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
$this->app_name = $app_props['application_name'];
$this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
return true;
} }
function showLogo(){ function showStylesheets()
{
global $xw; $this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookBaseCSS()));
$this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookThemeCSS()));
}
function showScripts()
{
$this->element('script', array('type' => 'text/javascript',
'src' => getFacebookJS()),
' ');
}
/**
* Start an Facebook ready HTML document
*
* For Facebook we don't want to actually output any headers,
* DTD info, etc.
*
* If $type isn't specified, will attempt to do content negotiation.
*
* @param string $type MIME type to use; default is to do negotation.
*
* @return void
*/
function startHTML($type=null)
{
$this->elementStart('div', array('class' => 'facebook-page'));
}
/**
* Ends a Facebook ready HTML document
*
* @return void
*/
function endHTML()
{
$this->elementEnd('div');
$this->endXML();
}
/**
* Show notice form.
*
* MAY overload if no notice form needed... or direct message box????
*
* @return nothing
*/
function showNoticeForm()
{
// don't do it for most of the Facebook pages
}
function showBody()
{
$this->elementStart('div', 'wrap');
$this->showHeader();
$this->showCore();
$this->showFooter();
$this->elementEnd('div');
}
function showAside()
{
}
function showHead($error, $success)
{
$this->showStylesheets(); $this->showStylesheets();
$this->showScripts(); $this->showScripts();
$this->elementStart('a', array('class' => 'url home bookmark', if ($error) {
'href' => common_local_url('public'))); $this->element("h1", null, $error);
if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) {
$this->element('img', array('class' => 'logo photo',
'src' => (common_config('site', 'logo')) ?
common_config('site', 'logo') : theme_path('logo.png'),
'alt' => common_config('site', 'name')));
} }
$this->element('span', array('class' => 'fn org'), common_config('site', 'name')); if ($success) {
$this->elementEnd('a'); $this->element("h1", null, $success);
} }
function showHeader($msg = null, $success = false)
{
startFBML();
$this->elementStart('fb:if-section-not-added', array('section' => 'profile')); $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
$this->elementStart('span', array('id' => 'add_to_profile')); $this->elementStart('span', array('id' => 'add_to_profile'));
$this->element('fb:add-section-button', array('section' => 'profile')); $this->element('fb:add-section-button', array('section' => 'profile'));
$this->elementEnd('span'); $this->elementEnd('span');
$this->elementEnd('fb:if-section-not-added'); $this->elementEnd('fb:if-section-not-added');
$this->showLogo();
if ($msg) {
if ($success) {
$this->element('fb:success', array('message' => $msg));
} else {
// XXX do an error message here
}
} }
$this->elementStart('div', 'main_body');
} // Make this into a widget later
function showLocalNav()
function showNav($selected = 'Home')
{ {
$this->elementStart('dl', array("id" => 'site_nav_local_views'));
$this->element('dt', null, _('Local Views'));
$this->elementStart('dd');
$this->elementStart('ul', array('class' => 'nav')); $this->elementStart('ul', array('class' => 'nav'));
$this->elementStart('li', array('class' => $this->elementStart('li', array('class' =>
($selected == 'Home') ? 'current' : 'facebook_home')); ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
$this->element('a', $this->element('a',
array('href' => 'index.php', 'title' => _('Home')), _('Home')); array('href' => 'index.php', 'title' => _('Home')), _('Home'));
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementStart('li', $this->elementStart('li',
array('class' => array('class' =>
($selected == 'Invite') ? 'current' : 'facebook_invite')); ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
$this->element('a', $this->element('a',
array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementStart('li', $this->elementStart('li',
array('class' => array('class' =>
($selected == 'Settings') ? 'current' : 'facebook_settings')); ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
$this->element('a', $this->element('a',
array('href' => 'settings.php', array('href' => 'settings.php',
'title' => _('Settings')), _('Settings')); 'title' => _('Settings')), _('Settings'));
@ -108,17 +193,48 @@ class FacebookAction extends Action
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->elementEnd('dd');
$this->elementEnd('dl');
} }
function showFooter() /**
* Show primary navigation.
*
* @return nothing
*/
function showPrimaryNav()
{ {
$this->elementEnd('div'); // we don't want to show anything for this
$this->endXml();
} }
/**
* Show header of the page.
*
* Calls template methods
*
* @return nothing
*/
function showHeader()
{
$this->elementStart('div', array('id' => 'header'));
$this->showLogo();
$this->showNoticeForm();
$this->showPrimaryNav();
$this->elementEnd('div');
}
/**
* Show page, a template method.
*
* @return nothing
*/
function showPage($error = null, $success = null)
{
$this->startHTML();
$this->showHead($error, $success);
$this->showBody();
$this->endHTML();
}
function showInstructions() function showInstructions()
{ {
global $xw; global $xw;
@ -141,36 +257,9 @@ class FacebookAction extends Action
$this->elementEnd('dl'); $this->elementEnd('dl');
} }
function showStylesheets()
{
global $xw;
$this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookBaseCSS()));
$this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookThemeCSS()));
}
function showScripts()
{
global $xw;
$this->element('script', array('type' => 'text/javascript',
'src' => getFacebookJS()));
}
function showLoginForm($msg = null) function showLoginForm($msg = null)
{ {
startFBML();
$this->showStylesheets();
$this->showScripts();
$this->showLogo();
$this->elementStart('div', array('class' => 'content')); $this->elementStart('div', array('class' => 'content'));
$this->element('h1', null, _('Login')); $this->element('h1', null, _('Login'));
@ -210,57 +299,251 @@ class FacebookAction extends Action
$this->elementEnd('div'); $this->elementEnd('div');
$this->endXml();
} }
function showNoticeForm($user)
function updateProfileBox($notice)
{ {
global $xw; // Need to include inline CSS for styling the Profile box
$this->elementStart('form', array('id' => 'form_notice', $style = '<style>
'method' => 'post', #notices {
'action' => 'index.php')); clear: both;
margin: 0 auto;
padding: 0;
list-style-type: none;
width: 600px;
border-top: 1px solid #dec5b5;
}
#notices a:hover {
text-decoration: underline;
}
.notice_single {
clear: both;
display: block;
margin: 0;
padding: 5px 5px 5px 0;
min-height: 48px;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 13px;
line-height: 16px;
border-bottom: 1px solid #dec5b5;
background-color:#FCFFF5;
opacity:1;
}
.notice_single:hover {
background-color: #f7ebcc;
}
.notice_single p {
display: inline;
margin: 0;
padding: 0;
}
</style>';
$this->elementStart('fieldset'); $this->xw->openMemory();
$this->element('legend', null, 'Send a notice');
$this->elementStart('ul', 'form_datas'); $item = new FacebookNoticeListItem($notice, $this);
$this->elementStart('li', array('id' => 'noticcommon_elemente_text')); $item->show();
$this->element('label', array('for' => 'notice_data-text'),
sprintf(_('What\'s up, %s?'), $user->nickname));
$this->element('textarea', array('id' => 'notice_data-text', $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
'cols' => 35, $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
'rows' => 4,
'name' => 'status_textarea'));
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementStart('dl', 'form_note'); $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
$this->element('dt', null, _('Available characters'));
$this->element('dd', array('id' => 'notice_text-count'),
'140');
$this->elementEnd('dl');
$this->elementStart('ul', array('class' => 'form_actions')); $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
$this->elementStart('li', array('id' => 'notice_submit')); $this->xw->openURI('php://output');
}
$this->submit('submit', _('Send'));
/* /**
$this->element('input', array('id' => 'notice_action-submit', * Generate pagination links
'class' => 'submit', *
'name' => 'status_submit', * @param boolean $have_before is there something before?
'type' => 'submit', * @param boolean $have_after is there something after?
'value' => _('Send'))); * @param integer $page current page
* @param string $action current action
* @param array $args rest of query arguments
*
* @return nothing
*/ */
function pagination($have_before, $have_after, $page, $action, $args=null)
{
// Does a little before-after block for next/prev page
if ($have_before || $have_after) {
$this->elementStart('div', array('class' => 'pagination'));
$this->elementStart('dl', null);
$this->element('dt', null, _('Pagination'));
$this->elementStart('dd', null);
$this->elementStart('ul', array('class' => 'nav'));
}
if ($have_before) {
$pargs = array('page' => $page-1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_prev'));
$this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'),
_('After'));
$this->elementEnd('li'); $this->elementEnd('li');
}
if ($have_after) {
$pargs = array('page' => $page+1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_next'));
$this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'),
_('Before'));
$this->elementEnd('li');
}
if ($have_before || $have_after) {
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->elementEnd('fieldset'); $this->elementEnd('dd');
$this->elementEnd('form'); $this->elementEnd('dl');
$this->elementEnd('div');
}
}
}
class FacebookNoticeForm extends NoticeForm
{
var $post_action = null;
/**
* Constructor
*
* @param HTMLOutputter $out output channel
* @param string $action action to return to, if any
* @param string $content content to pre-fill
*/
function __construct($out=null, $action=null, $content=null,
$post_action=null, $user=null)
{
parent::__construct($out, $action, $content, $user);
$this->post_action = $post_action;
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
return $this->post_action;
}
}
class FacebookNoticeList extends NoticeList
{
/**
* show the list of notices
*
* "Uses up" the stream by looping through it. So, probably can't
* be called twice on the same list.
*
* @return int count of notices listed.
*/
function show()
{
$this->out->elementStart('div', array('id' =>'notices_primary'));
$this->out->element('h2', null, _('Notices'));
$this->out->elementStart('ul', array('class' => 'notices'));
$cnt = 0;
while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
$cnt++;
if ($cnt > NOTICES_PER_PAGE) {
break;
}
$item = $this->newListItem($this->notice);
$item->show();
}
$this->out->elementEnd('ul');
$this->out->elementEnd('div');
return $cnt;
}
/**
* returns a new list item for the current notice
*
* Overridden to return a Facebook specific list item.
*
* @param Notice $notice the current notice
*
* @return FacebookNoticeListItem a list item for displaying the notice
* formatted for display in the Facebook App.
*/
function newListItem($notice)
{
return new FacebookNoticeListItem($notice, $this);
}
}
class FacebookNoticeListItem extends NoticeListItem
{
/**
* recipe function for displaying a single notice in the Facebook App.
*
* Overridden to strip out some of the controls that we don't
* want to be available.
*
* @return void
*/
function show()
{
$this->showStart();
$this->out->elementStart('div', 'entry-title');
$this->showAuthor();
$this->showContent();
$this->out->elementEnd('div');
$this->out->elementStart('div', 'entry-content');
$this->showNoticeLink();
$this->showNoticeSource();
$this->showReplyTo();
$this->out->elementEnd('div');
$this->showEnd();
}
function showNoticeLink()
{
$noticeurl = common_local_url('shownotice',
array('notice' => $this->notice->id));
// XXX: we need to figure this out better. Is this right?
if (strcmp($this->notice->uri, $noticeurl) != 0 &&
preg_match('/^http/', $this->notice->uri)) {
$noticeurl = $this->notice->uri;
}
$this->out->elementStart('dl', 'timestamp');
$this->out->element('dt', null, _('Published'));
$this->out->elementStart('dd', null);
$this->out->elementStart('a', array('rel' => 'bookmark',
'href' => $noticeurl));
$dt = common_date_iso8601($this->notice->created);
$this->out->element('abbr', array('class' => 'published',
'title' => $dt),
common_date_string($this->notice->created));
$this->out->elementEnd('a');
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');
} }
} }

View File

@ -52,61 +52,6 @@ function startFBML($indent = true)
$xw->setIndent($indent); $xw->setIndent($indent);
} }
function update_profile_box($facebook, $fbuid, $user, $notice)
{
// Need to include inline CSS for styling the Profile box
$style = '<style>
#notices {
clear: both;
margin: 0 auto;
padding: 0;
list-style-type: none;
width: 600px;
border-top: 1px solid #dec5b5;
}
#notices a:hover {
text-decoration: underline;
}
.notice_single {
clear: both;
display: block;
margin: 0;
padding: 5px 5px 5px 0;
min-height: 48px;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 13px;
line-height: 16px;
border-bottom: 1px solid #dec5b5;
background-color:#FCFFF5;
opacity:1;
}
.notice_single:hover {
background-color: #f7ebcc;
}
.notice_single p {
display: inline;
margin: 0;
padding: 0;
}
</style>';
global $xw;
$xw = new XMLWriter();
$xw->openMemory();
$item = new FacebookNoticeListItem($notice);
$item->show();
$fbml = "<fb:wide>$style " . $xw->outputMemory(false) . "</fb:wide>";
$fbml .= "<fb:narrow>$style " . $xw->outputMemory(false) . "</fb:narrow>";
$fbml_main = "<fb:narrow>$style " . $xw->outputMemory(false) . "</fb:narrow>";
$facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main);
}
function getFacebookBaseCSS() function getFacebookBaseCSS()
{ {
# Add a timestamp to the CSS file so Facebook cache wont ignore our changes # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
@ -131,157 +76,3 @@ function getFacebookJS() {
return $jsurl; return $jsurl;
} }
// Does a little before-after block for next/prev page
function facebookPagination($have_before, $have_after, $page, $action, $args=null)
{
if ($have_before || $have_after) {
common_element_start('div', array('id' => 'pagination'));
common_element_start('ul', array('id' => 'nav_pagination'));
}
if ($have_before) {
$pargs = array('page' => $page-1);
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
common_element_start('li', 'before');
common_element('a', array('href' => "index.php?page=$newargs[page]", 'rel' => 'prev'),
_('« After'));
common_element_end('li');
}
if ($have_after) {
$pargs = array('page' => $page+1);
$newargs = ($args) ? array_merge($args,$pargs) : $pargs;
common_element_start('li', 'after');
common_element('a', array('href' => "index.php?page=$newargs[page]", 'rel' => 'next'),
_('Before »'));
common_element_end('li');
}
if ($have_before || $have_after) {
common_element_end('ul');
common_element_end('div');
}
}
class FacebookNoticeList extends NoticeList
{
/**
* show the list of notices
*
* "Uses up" the stream by looping through it. So, probably can't
* be called twice on the same list.
*
* @return int count of notices listed.
*/
function show()
{
common_element_start('div', array('id' =>'notices_primary'));
common_element('h2', null, _('Notices'));
common_element_start('ul', array('class' => 'notices'));
$cnt = 0;
while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
$cnt++;
if ($cnt > NOTICES_PER_PAGE) {
break;
}
$item = $this->newListItem($this->notice);
$item->show();
}
common_element_end('ul');
common_element_end('div');
return $cnt;
}
/**
* returns a new list item for the current notice
*
* Overridden to return a Facebook specific list item.
*
* @param Notice $notice the current notice
*
* @return FacebookNoticeListItem a list item for displaying the notice
* formatted for display in the Facebook App.
*/
function newListItem($notice)
{
return new FacebookNoticeListItem($notice);
}
}
class FacebookNoticeListItem extends NoticeListItem
{
/**
* recipe function for displaying a single notice in the Facebook App.
*
* Overridden to strip out some of the controls that we don't
* want to be available.
*
* @return void
*/
function show()
{
$this->showStart();
common_element_start('div', 'entry-title');
$this->showAuthor();
$this->showContent();
common_element_end('div');
common_element_start('div', 'entry-content');
$this->showNoticeLink();
$this->showNoticeSource();
$this->showReplyTo();
common_element_end('div');
$this->showEnd();
}
function showStart()
{
// XXX: RDFa
// TODO: add notice_type class e.g., notice_video, notice_image
common_element_start('li', array('class' => 'hentry notice',
'id' => 'notice-' . $this->notice->id));
}
function showNoticeLink()
{
$noticeurl = common_local_url('shownotice',
array('notice' => $this->notice->id));
// XXX: we need to figure this out better. Is this right?
if (strcmp($this->notice->uri, $noticeurl) != 0 &&
preg_match('/^http/', $this->notice->uri)) {
$noticeurl = $this->notice->uri;
}
common_element_start('dl', 'timestamp');
common_element('dt', null, _('Published'));
common_element_start('dd', null);
common_element_start('a', array('rel' => 'bookmark',
'href' => $noticeurl));
$dt = common_date_iso8601($this->notice->created);
common_element('abbr', array('class' => 'published',
'title' => $dt),
common_date_string($this->notice->created));
common_element_end('a');
common_element_end('dd');
common_element_end('dl');
}
}

View File

@ -63,6 +63,12 @@ class NoticeForm extends Form
var $content = null; var $content = null;
/**
* The current user
*/
var $user = null;
/** /**
* Constructor * Constructor
* *
@ -71,12 +77,19 @@ class NoticeForm extends Form
* @param string $content content to pre-fill * @param string $content content to pre-fill
*/ */
function __construct($out=null, $action=null, $content=null) function __construct($out=null, $action=null, $content=null, $user=null)
{ {
parent::__construct($out); parent::__construct($out);
$this->action = $action; $this->action = $action;
$this->content = $content; $this->content = $content;
if ($user) {
$this->user = $user;
} else {
$this->user = common_current_user();
}
} }
/** /**
@ -121,12 +134,11 @@ class NoticeForm extends Form
function formData() function formData()
{ {
$user = common_current_user();
$this->out->elementStart('ul', 'form_data'); $this->out->elementStart('ul', 'form_data');
$this->out->elementStart('li', array('id' => 'notice_text')); $this->out->elementStart('li', array('id' => 'notice_text'));
$this->out->element('label', array('for' => 'notice_data-text'), $this->out->element('label', array('for' => 'notice_data-text'),
sprintf(_('What\'s up, %s?'), $user->nickname)); sprintf(_('What\'s up, %s?'), $this->user->nickname));
// XXX: vary by defined max size // XXX: vary by defined max size
$this->out->element('textarea', array('id' => 'notice_data-text', $this->out->element('textarea', array('id' => 'notice_data-text',
'cols' => 35, 'cols' => 35,