summaryrefslogtreecommitdiff
path: root/lib/facebookaction.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/facebookaction.php')
-rw-r--r--lib/facebookaction.php232
1 files changed, 199 insertions, 33 deletions
diff --git a/lib/facebookaction.php b/lib/facebookaction.php
index c781b86f4..043a078cd 100644
--- a/lib/facebookaction.php
+++ b/lib/facebookaction.php
@@ -122,15 +122,14 @@ class FacebookAction extends Action
// Add a timestamp to the file so Facebook cache wont ignore our changes
$ts = filemtime(INSTALLDIR.'/js/facebookapp.js');
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/facebookapp.js') . '?ts=' . $ts));
+ $this->element('script', array('src' => common_path('js/facebookapp.js') . '?ts=' . $ts));
}
/**
* Start an Facebook ready HTML document
*
* For Facebook we don't want to actually output any headers,
- * DTD info, etc.
+ * DTD info, etc. Just Stylesheet and JavaScript links.
*
* If $type isn't specified, will attempt to do content negotiation.
*
@@ -141,6 +140,9 @@ class FacebookAction extends Action
function startHTML($type=null)
{
+ $this->showStylesheets();
+ $this->showScripts();
+
$this->elementStart('div', array('class' => 'facebook-page'));
}
@@ -169,7 +171,7 @@ class FacebookAction extends Action
function showBody()
{
- $this->elementStart('div', 'wrap');
+ $this->elementStart('div', array('id' => 'wrap'));
$this->showHeader();
$this->showCore();
$this->showFooter();
@@ -182,8 +184,6 @@ class FacebookAction extends Action
function showHead($error, $success)
{
- $this->showStylesheets();
- $this->showScripts();
if ($error) {
$this->element("h1", null, $error);
@@ -205,7 +205,6 @@ class FacebookAction extends Action
// Make this into a widget later
function showLocalNav()
{
-
$this->elementStart('ul', array('class' => 'nav'));
$this->elementStart('li', array('class' =>
@@ -230,18 +229,7 @@ class FacebookAction extends Action
$this->elementEnd('li');
$this->elementEnd('ul');
-
}
-
- /**
- * Show primary navigation.
- *
- * @return nothing
- */
- function showPrimaryNav()
- {
- // we don't want to show anything for this
- }
/**
* Show header of the page.
@@ -255,7 +243,6 @@ class FacebookAction extends Action
$this->elementStart('div', array('id' => 'header'));
$this->showLogo();
$this->showNoticeForm();
- $this->showPrimaryNav();
$this->elementEnd('div');
}
@@ -276,12 +263,13 @@ class FacebookAction extends Action
function showInstructions()
{
+ $this->elementStart('div', array('class' => 'facebook_guide'));
+
$this->elementStart('dl', array('class' => 'system_notice'));
$this->element('dt', null, 'Page Notice');
$loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
'with your username and password. Don\'t have a username yet? ');
-
$loginmsg_part2 = _(' a new account.');
$this->elementStart('dd');
@@ -290,15 +278,18 @@ class FacebookAction extends Action
$this->element('a',
array('href' => common_local_url('register')), _('Register'));
$this->text($loginmsg_part2);
+ $this->elementEnd('p');
$this->elementEnd('dd');
+
$this->elementEnd('dl');
+ $this->elementEnd('div');
}
function showLoginForm($msg = null)
{
- $this->elementStart('div', array('class' => 'content'));
+ $this->elementStart('div', array('id' => 'content'));
$this->element('h1', null, _('Login'));
if ($msg) {
@@ -315,7 +306,6 @@ class FacebookAction extends Action
'action' => 'index.php'));
$this->elementStart('fieldset');
- $this->element('legend', null, _('Login to site'));
$this->elementStart('ul', array('class' => 'form_datas'));
$this->elementStart('li');
@@ -327,6 +317,7 @@ class FacebookAction extends Action
$this->elementEnd('ul');
$this->submit('submit', _('Login'));
+ $this->elementEnd('fieldset');
$this->elementEnd('form');
$this->elementStart('p');
@@ -335,6 +326,7 @@ class FacebookAction extends Action
$this->elementEnd('p');
$this->elementEnd('div');
+ $this->elementEnd('div');
}
@@ -344,42 +336,70 @@ class FacebookAction extends Action
// Need to include inline CSS for styling the Profile box
+ $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
+ $icon_url = $app_props['icon_url'];
+
$style = '<style>
+ .entry-title *,
+ .entry-content * {
+ font-size:14px;
+ font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
+ }
+ .entry-title a,
+ .entry-content a {
+ color:#002E6E;
+ }
+
.entry-title .vcard .photo {
float:left;
display:inline;
+ margin-right:11px;
+ margin-bottom:11px
}
- .entry-title .vcard .nickname {
- margin-left:5px;
- }
-
+ .entry-title {
+ margin-bottom:11px;
+ }
.entry-title p.entry-content {
display:inline;
- margin-left:5px;
+ margin-left:5px;
}
+ div.entry-content {
+ clear:both;
+ }
div.entry-content dl,
div.entry-content dt,
div.entry-content dd {
display:inline;
+ text-transform:lowercase;
}
- div.entry-content dt,
- div.entry-content dd {
- display:inline;
- margin-left:5px;
+ div.entry-content dd,
+ div.entry-content .device dt {
+ margin-left:0;
+ margin-right:5px;
}
- div.entry-content dl.timestamp dt {
+ div.entry-content dl.timestamp dt,
+ div.entry-content dl.response dt {
display:none;
}
div.entry-content dd a {
display:inline-block;
}
+
+ #facebook_laconica_app {
+ text-indent:-9999px;
+ height:16px;
+ width:16px;
+ display:block;
+ background:url('.$icon_url.') no-repeat 0 0;
+ float:right;
+ }
</style>';
$this->xw->openMemory();
- $item = new FacebookNoticeListItem($notice, $this);
+ $item = new FacebookProfileBoxNotice($notice, $this);
$item->show();
$fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
@@ -438,6 +458,64 @@ class FacebookAction extends Action
}
}
+ function updateFacebookStatus($notice)
+ {
+ $prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $this->fbuid);
+ $content = "$prefix $notice->content";
+
+ if ($this->facebook->api_client->users_hasAppPermission('status_update', $this->fbuid)) {
+ $this->facebook->api_client->users_setStatus($content, $this->fbuid, false, true);
+ }
+ }
+
+ function saveNewNotice()
+ {
+
+ $user = $this->flink->getUser();
+
+ $content = $this->trimmed('status_textarea');
+
+ if (!$content) {
+ $this->showPage(_('No notice content!'));
+ return;
+ } else {
+ $content_shortened = common_shorten_links($content);
+
+ if (mb_strlen($content_shortened) > 140) {
+ $this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
+ return;
+ }
+ }
+
+ $inter = new CommandInterpreter();
+
+ $cmd = $inter->handle_command($user, $content_shortened);
+
+ if ($cmd) {
+
+ // XXX fix this
+
+ $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->showPage($notice);
+ return;
+ }
+
+ common_broadcast_notice($notice);
+
+ // Also update the user's Facebook status
+ $this->updateFacebookStatus($notice);
+ $this->updateProfileBox($notice);
+
+ }
}
@@ -476,6 +554,18 @@ class FacebookNoticeForm extends NoticeForm
class FacebookNoticeList extends NoticeList
{
+
+ /**
+ * constructor
+ *
+ * @param Notice $notice stream of notices from DB_DataObject
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
/**
* show the list of notices
*
@@ -530,6 +620,20 @@ class FacebookNoticeList extends NoticeList
class FacebookNoticeListItem extends NoticeListItem
{
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
/**
* recipe function for displaying a single notice in the Facebook App.
*
@@ -582,3 +686,65 @@ class FacebookNoticeListItem extends NoticeListItem
}
}
+
+
+class FacebookProfileBoxNotice extends FacebookNoticeListItem
+{
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
+ /**
+ * Recipe function for displaying a single notice in the
+ * Facebook App's Profile
+ *
+ * @return void
+ */
+
+ function show()
+ {
+
+ $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->showAppLink();
+
+ }
+
+ function showAppLink()
+ {
+
+ $this->facebook = getFacebook();
+
+ $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->out->elementStart('a', array('id' => 'facebook_laconica_app',
+ 'href' => $this->app_uri));
+ $this->out->text($this->app_name);
+ $this->out->elementEnd('a');
+ }
+
+}