trac750 Add notice input box to FB app and ability to post notices

This commit is contained in:
Zach Copley 2009-01-19 07:24:12 +00:00
parent cd6b9d6c46
commit 739baf0396
7 changed files with 205 additions and 69 deletions

View File

@ -31,6 +31,9 @@ class FacebookhomeAction extends FacebookAction
$facebook = get_facebook(); $facebook = get_facebook();
$fbuid = $facebook->require_login(); $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
@ -39,11 +42,13 @@ class FacebookhomeAction extends FacebookAction
FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); FACEBOOK_PROMPTED_UPDATE_PREF, 'true');
} }
// Check to see whether there's already a Facebook link for this user
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
if ($flink) { if ($flink) {
if ($_POST['submit'] == 'Send') {
$this->saveNewNotice($flink);
return;
}
$user = $flink->getUser(); $user = $flink->getUser();
common_set_user($user); common_set_user($user);
@ -136,19 +141,16 @@ class FacebookhomeAction extends FacebookAction
$notice = $user->getCurrentNotice(); $notice = $user->getCurrentNotice();
update_profile_box($facebook, $fbuid, $user, $notice); update_profile_box($facebook, $fbuid, $user, $notice);
$this->showHeader($msg);
$this->showNoticeForm($user);
$this->showNav('Home');
$this->showHeader('Home'); echo $this->showNotices($user);
if ($msg) {
common_element('fb:success', array('message' => $msg));
}
echo $this->show_notices($user);
$this->showFooter(); $this->showFooter();
} }
function show_notices($user) function showNotices($user)
{ {
$page = $this->trimmed('page'); $page = $this->trimmed('page');
@ -158,13 +160,13 @@ class FacebookhomeAction extends FacebookAction
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$cnt = $this->show_notice_list($notice); $cnt = $this->showNoticeList($notice);
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, facebookPagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'all', array('nickname' => $user->nickname)); $page, 'all', array('nickname' => $user->nickname));
} }
function show_notice_list($notice) function showNoticeList($notice)
{ {
$nl = new FacebookNoticeList($notice); $nl = new FacebookNoticeList($notice);
return $nl->show(); return $nl->show();
@ -175,19 +177,10 @@ class FacebookhomeAction extends FacebookAction
$facebook = get_facebook(); $facebook = get_facebook();
$fbuid = $facebook->require_login(); $fbuid = $facebook->require_login();
start_fbml(); startFBML();
common_element('link', array('rel' => 'stylesheet', $this->showStylesheets();
'type' => 'text/css', $this->showScripts();
'href' => getFacebookBaseCSS()));
common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookThemeCSS()));
common_element('script', array('type' => 'text/javascript',
'src' => getFacebookJS()),
' ');
$this->showLogo(); $this->showLogo();
@ -232,4 +225,48 @@ class FacebookhomeAction extends FacebookAction
} }
function saveNewNotice($flink)
{
$user = $flink->getUser();
$content = $_POST['status_textarea'];
if (!$content) {
$this->showHome($flink, _('No content!'));
return;
} else {
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
common_debug("Content = '$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.'));
return;
}
}
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $content_shortened);
if ($cmd) {
$cmd->execute(new WebChannel());
return;
}
$replyto = $this->trimmed('inreplyto');
$notice = Notice::saveNew($user->id, $content,
'Facebook', 1, ($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
$this->showHome($flink, 'Error!');
return;
}
common_broadcast_notice($notice);
$this->showHome($flink, 'Success!');
}
} }

View File

@ -69,7 +69,8 @@ class FacebookinviteAction extends FacebookAction
$facebook = get_facebook(); $facebook = get_facebook();
$fbuid = $facebook->require_login(); $fbuid = $facebook->require_login();
$this->showHeader('Invite'); $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 = $facebook->api_client->friends_getAppUsers();

View File

@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); } if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/facebookaction.php'); require_once INSTALLDIR.'/lib/facebookaction.php';
class FacebookremoveAction extends FacebookAction class FacebookremoveAction extends FacebookAction
{ {

View File

@ -67,8 +67,8 @@ class FacebooksettingsAction extends FacebookAction
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
$this->showHeader('Settings', $msg, $success); $this->showHeader($msg, $success);
$this->showNav('Settings');
if ($facebook->api_client->users_hasAppPermission('status_update')) { if ($facebook->api_client->users_hasAppPermission('status_update')) {

View File

@ -35,17 +35,8 @@ class FacebookAction extends Action
global $xw; global $xw;
common_element('link', array('rel' => 'stylesheet', $this->showStylesheets();
'type' => 'text/css', $this->showScripts();
'href' => getFacebookBaseCSS()));
common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookThemeCSS()));
common_element('script', array('type' => 'text/javascript',
'src' => getFacebookJS()),
' ');
common_element_start('a', array('class' => 'url home bookmark', common_element_start('a', array('class' => 'url home bookmark',
'href' => common_local_url('public'))); 'href' => common_local_url('public')));
@ -61,10 +52,10 @@ class FacebookAction extends Action
} }
function showHeader($selected = 'Home', $msg = null, $success = false)
{
start_fbml(); function showHeader($msg = null, $success = false)
{
startFBML();
common_element_start('fb:if-section-not-added', array('section' => 'profile')); common_element_start('fb:if-section-not-added', array('section' => 'profile'));
common_element_start('span', array('id' => 'add_to_profile')); common_element_start('span', array('id' => 'add_to_profile'));
@ -74,6 +65,21 @@ class FacebookAction extends Action
$this->showLogo(); $this->showLogo();
if ($msg) {
if ($success) {
common_element('fb:success', array('message' => $msg));
} else {
// XXX do an error message here
}
}
common_element_start('div', 'main_body');
}
function showNav($selected = 'Home')
{
common_element_start('dl', array("id" => 'site_nav_local_views')); common_element_start('dl', array("id" => 'site_nav_local_views'));
common_element('dt', null, _('Local Views')); common_element('dt', null, _('Local Views'));
common_element_start('dd'); common_element_start('dd');
@ -86,7 +92,6 @@ class FacebookAction extends Action
array('href' => 'index.php', 'title' => _('Home')), _('Home')); array('href' => 'index.php', 'title' => _('Home')), _('Home'));
common_element_end('li'); common_element_end('li');
common_element_start('li', common_element_start('li',
array('class' => array('class' =>
($selected == 'Invite') ? 'current' : 'facebook_invite')); ($selected == 'Invite') ? 'current' : 'facebook_invite'));
@ -107,17 +112,6 @@ class FacebookAction extends Action
common_element_end('dd'); common_element_end('dd');
common_element_end('dl'); common_element_end('dl');
if ($msg) {
if ($success) {
common_element('fb:success', array('message' => $msg));
} else {
// XXX do an error message here
}
}
common_element_start('div', 'main_body');
} }
function showFooter() function showFooter()
@ -149,9 +143,10 @@ class FacebookAction extends Action
common_element_end('dl'); common_element_end('dl');
} }
function showLoginForm($msg = null)
function showStylesheets()
{ {
start_fbml(); global $xw;
common_element('link', array('rel' => 'stylesheet', common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
@ -160,10 +155,23 @@ class FacebookAction extends Action
common_element('link', array('rel' => 'stylesheet', common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
'href' => getFacebookThemeCSS())); 'href' => getFacebookThemeCSS()));
}
function showScripts()
{
global $xw;
common_element('script', array('type' => 'text/javascript', common_element('script', array('type' => 'text/javascript',
'src' => getFacebookJS()), 'src' => getFacebookJS()));
' ');
}
function showLoginForm($msg = null)
{
startFBML();
$this->showStylesheets();
$this->showScripts();
$this->showLogo(); $this->showLogo();
@ -179,6 +187,7 @@ class FacebookAction extends Action
common_element_start('div', array('id' => 'content_inner')); common_element_start('div', array('id' => 'content_inner'));
common_element_start('form', array('method' => 'post', common_element_start('form', array('method' => 'post',
'class' => 'form_settings',
'id' => 'login', 'id' => 'login',
'action' => 'index.php')); 'action' => 'index.php'));
@ -209,4 +218,53 @@ class FacebookAction extends Action
} }
function showNoticeForm($user)
{
global $xw;
common_element_start('form', array('id' => 'form_notice',
'method' => 'post',
'action' => 'index.php'));
common_element_start('fieldset');
common_element('legend', null, 'Send a notice');
common_element_start('ul', 'form_datas');
common_element_start('li', array('id' => 'noticcommon_elemente_text'));
common_element('label', array('for' => 'notice_data-text'),
sprintf(_('What\'s up, %s?'), $user->nickname));
common_element('textarea', array('id' => 'notice_data-text',
'cols' => 35,
'rows' => 4,
'name' => 'status_textarea'));
common_element_end('li');
common_element_end('ul');
common_element_start('dl', 'form_note');
common_element('dt', null, _('Available characters'));
common_element('dd', array('id' => 'notice_text-count'),
'140');
common_element_end('dl');
common_element_start('ul', array('class' => 'form_actions'));
common_element_start('li', array('id' => 'notice_submit'));
common_submit('submit', _('Send'));
/*
common_element('input', array('id' => 'notice_action-submit',
'class' => 'submit',
'name' => 'status_submit',
'type' => 'submit',
'value' => _('Send')));
*/
common_element_end('li');
common_element_end('ul');
common_element_end('fieldset');
common_element_end('form');
}
} }

View File

@ -44,7 +44,7 @@ function get_facebook()
return new Facebook($apikey, $secret); return new Facebook($apikey, $secret);
} }
function start_fbml($indent = true) function startFBML($indent = true)
{ {
global $xw; global $xw;
$xw = new XMLWriter(); $xw = new XMLWriter();
@ -132,6 +132,42 @@ function getFacebookJS() {
} }
// 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 class FacebookNoticeList extends NoticeList
{ {
/** /**

View File

@ -67,9 +67,13 @@ while($notice->fetch()) {
// If it's not a reply, or if the user WANTS to send replies... // If it's not a reply, or if the user WANTS to send replies...
if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) || if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) ||
(($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) { (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) {
update_status($fbuid, $content);
update_profile_box($facebook, $fbuid, $user, $notice); // Avoid a Loop
$cnt++; if ($notice->source != 'Facebook') {
update_status($fbuid, $content);
update_profile_box($facebook, $fbuid, $user, $notice);
$cnt++;
}
} }
} }
} }