$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
// Facebook status update permission, store that preference. Only
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 ($_POST['submit'] == 'Send') {
+ $this->saveNewNotice($flink);
+ return;
+ }
+
$user = $flink->getUser();
common_set_user($user);
$notice = $user->getCurrentNotice();
update_profile_box($facebook, $fbuid, $user, $notice);
-
- $this->showHeader('Home');
-
- if ($msg) {
- common_element('fb:success', array('message' => $msg));
- }
-
- echo $this->show_notices($user);
+ $this->showHeader($msg);
+ $this->showNoticeForm($user);
+ $this->showNav('Home');
+
+ echo $this->showNotices($user);
$this->showFooter();
}
- function show_notices($user)
+ function showNotices($user)
{
$page = $this->trimmed('page');
$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,
- $page, 'all', array('nickname' => $user->nickname));
+ facebookPagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'all', array('nickname' => $user->nickname));
}
- function show_notice_list($notice)
+ function showNoticeList($notice)
{
$nl = new FacebookNoticeList($notice);
return $nl->show();
$facebook = get_facebook();
$fbuid = $facebook->require_login();
- start_fbml();
+ startFBML();
- common_element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => getFacebookBaseCSS()));
-
- common_element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => getFacebookThemeCSS()));
-
- common_element('script', array('type' => 'text/javascript',
- 'src' => getFacebookJS()),
- ' ');
+ $this->showStylesheets();
+ $this->showScripts();
$this->showLogo();
common_end_xml();
}
+
+ 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!');
+ }
+
}
$facebook = get_facebook();
$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
$exclude_ids = $facebook->api_client->friends_getAppUsers();
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/lib/facebookaction.php');
+require_once INSTALLDIR.'/lib/facebookaction.php';
class FacebookremoveAction extends FacebookAction
{
$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')) {
global $xw;
- common_element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => getFacebookBaseCSS()));
-
- common_element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => getFacebookThemeCSS()));
-
- common_element('script', array('type' => 'text/javascript',
- 'src' => getFacebookJS()),
- ' ');
+ $this->showStylesheets();
+ $this->showScripts();
common_element_start('a', array('class' => 'url home bookmark',
'href' => common_local_url('public')));
}
- 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('span', array('id' => 'add_to_profile'));
common_element('fb:add-section-button', array('section' => 'profile'));
common_element_end('span');
common_element_end('fb:if-section-not-added');
-
+
$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('dt', null, _('Local Views'));
common_element_start('dd');
array('href' => 'index.php', 'title' => _('Home')), _('Home'));
common_element_end('li');
-
common_element_start('li',
array('class' =>
($selected == 'Invite') ? 'current' : 'facebook_invite'));
common_element_end('dd');
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()
common_element_end('dl');
}
- function showLoginForm($msg = null)
- {
- start_fbml();
+ function showStylesheets()
+ {
+ global $xw;
+
common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookBaseCSS()));
common_element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => getFacebookThemeCSS()));
-
+ }
+
+ function showScripts()
+ {
+ global $xw;
+
common_element('script', array('type' => 'text/javascript',
- 'src' => getFacebookJS()),
- ' ');
+ 'src' => getFacebookJS()));
+
+ }
+
+ function showLoginForm($msg = null)
+ {
+ startFBML();
+
+ $this->showStylesheets();
+ $this->showScripts();
$this->showLogo();
common_element_start('div', array('id' => 'content_inner'));
common_element_start('form', array('method' => 'post',
+ 'class' => 'form_settings',
'id' => 'login',
'action' => 'index.php'));
}
+ 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');
+ }
+
}
return new Facebook($apikey, $secret);
}
-function start_fbml($indent = true)
+function startFBML($indent = true)
{
global $xw;
$xw = new XMLWriter();
}
+// 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
{
/**
// 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) ||
(($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) {
- update_status($fbuid, $content);
- update_profile_box($facebook, $fbuid, $user, $notice);
- $cnt++;
+
+ // Avoid a Loop
+ if ($notice->source != 'Facebook') {
+ update_status($fbuid, $content);
+ update_profile_box($facebook, $fbuid, $user, $notice);
+ $cnt++;
+ }
}
}
}