X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ffacebookaction.php;h=043a078cd5bbd2fa8b0849fa7dc3c5238927cc3f;hb=a13bfa5848705d23353783f195b67c088a72a8cb;hp=2dbe1597086daff4bd79ddc4965a8cc7fdd27117;hpb=8114676bd4fd783ba9580a5dbf8bf0029a1554c9;p=quix0rs-gnu-social.git diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 2dbe159708..043a078cd5 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -95,28 +95,41 @@ class FacebookAction extends Action function showStylesheets() { + // Add a timestamp to the file so Facebook cache wont ignore our changes + $ts = filemtime(INSTALLDIR.'/theme/base/css/display.css'); $this->element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => getFacebookBaseCSS())); - + 'href' => theme_path('css/display.css', 'base') . '?ts=' . $ts)); + + $theme = common_config('site', 'theme'); + + $ts = filemtime(INSTALLDIR. '/theme/' . $theme .'/css/display.css'); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => theme_path('css/display.css', null) . '?ts=' . $ts)); + + $ts = filemtime(INSTALLDIR.'/theme/base/css/facebookapp.css'); + $this->element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => getFacebookThemeCSS())); + 'href' => theme_path('css/facebookapp.css', 'base') . '?ts=' . $ts)); } function showScripts() { - $this->element('script', array('type' => 'text/javascript', - 'src' => getFacebookJS()), - ' '); + // Add a timestamp to the file so Facebook cache wont ignore our changes + $ts = filemtime(INSTALLDIR.'/js/facebookapp.js'); + + $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. * @@ -127,6 +140,9 @@ class FacebookAction extends Action function startHTML($type=null) { + $this->showStylesheets(); + $this->showScripts(); + $this->elementStart('div', array('class' => 'facebook-page')); } @@ -155,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(); @@ -168,8 +184,6 @@ class FacebookAction extends Action function showHead($error, $success) { - $this->showStylesheets(); - $this->showScripts(); if ($error) { $this->element("h1", null, $error); @@ -191,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' => @@ -216,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. @@ -241,7 +243,6 @@ class FacebookAction extends Action $this->elementStart('div', array('id' => 'header')); $this->showLogo(); $this->showNoticeForm(); - $this->showPrimaryNav(); $this->elementEnd('div'); } @@ -262,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'); @@ -276,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) { @@ -301,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'); @@ -313,6 +317,7 @@ class FacebookAction extends Action $this->elementEnd('ul'); $this->submit('submit', _('Login')); + $this->elementEnd('fieldset'); $this->elementEnd('form'); $this->elementStart('p'); @@ -321,6 +326,7 @@ class FacebookAction extends Action $this->elementEnd('p'); $this->elementEnd('div'); + $this->elementEnd('div'); } @@ -330,44 +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 = ''; $this->xw->openMemory(); - $item = new FacebookNoticeListItem($notice, $this); + $item = new FacebookProfileBoxNotice($notice, $this); $item->show(); $fbml = "$style " . $this->xw->outputMemory(false) . ""; @@ -426,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); + + } } @@ -464,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 * @@ -518,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. * @@ -570,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'); + } + +}