X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ffacebookaction.php;h=5be2f2fe6603f9296a870e4ad7f99ae9b47dcb0f;hb=4a1d7ad0829aeeece7a392ed64bce3d95c21f87e;hp=dcd4e33d0a50a5499db82e0bddeecbbadbd4d066;hpb=adf77944e84a1d08bcc3d2a89533dff5bc58f3e3;p=quix0rs-gnu-social.git diff --git a/lib/facebookaction.php b/lib/facebookaction.php index dcd4e33d0a..5be2f2fe66 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -38,61 +38,98 @@ require_once INSTALLDIR.'/lib/noticeform.php'; class FacebookAction extends Action { - + var $facebook = null; var $fbuid = null; var $flink = null; var $action = null; var $app_uri = null; var $app_name = null; - + + /** + * Constructor + * + * Just wraps the HTMLOutputter constructor. + * + * @param string $output URI to output to, default = stdout + * @param boolean $indent Whether to indent output, default true + * + * @see XMLOutputter::__construct + * @see HTMLOutputter::__construct + */ + function __construct($output='php://output', $indent=true, $facebook=null, $flink=null) + { + parent::__construct($output, $indent); + + $this->facebook = $facebook; + $this->flink = $flink; + + if ($this->flink) { + $this->fbuid = $flink->foreign_id; + $this->user = $flink->getUser(); + } + + $this->args = array(); + } + function prepare($argarray) - { + { parent::prepare($argarray); - - common_debug("Facebookaction::prepare"); - - $this->facebook = get_facebook(); + + $this->facebook = getFacebook(); $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 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' => 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' => getFacebookBaseCSS())); + '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. * @@ -101,8 +138,11 @@ class FacebookAction extends Action * @return void */ - function startHTML($type=null) - { + function startHTML($type=null) + { + $this->showStylesheets(); + $this->showScripts(); + $this->elementStart('div', array('class' => 'facebook-page')); } @@ -131,26 +171,24 @@ class FacebookAction extends Action function showBody() { - $this->elementStart('div', 'wrap'); + $this->elementStart('div', array('id' => 'wrap')); $this->showHeader(); $this->showCore(); $this->showFooter(); $this->elementEnd('div'); } - + function showAside() { } function showHead($error, $success) { - $this->showStylesheets(); - $this->showScripts(); - + if ($error) { $this->element("h1", null, $error); } - + if ($success) { $this->element("h1", null, $success); } @@ -160,14 +198,13 @@ class FacebookAction extends Action $this->element('fb:add-section-button', array('section' => 'profile')); $this->elementEnd('span'); $this->elementEnd('fb:if-section-not-added'); - + } - + // Make this into a widget later function showLocalNav() { - $this->elementStart('ul', array('class' => 'nav')); $this->elementStart('li', array('class' => @@ -176,12 +213,14 @@ class FacebookAction extends Action array('href' => 'index.php', 'title' => _('Home')), _('Home')); $this->elementEnd('li'); - $this->elementStart('li', - array('class' => - ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite')); - $this->element('a', - array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); - $this->elementEnd('li'); + if (common_config('invite', 'enabled')) { + $this->elementStart('li', + array('class' => + ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite')); + $this->element('a', + array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); + $this->elementEnd('li'); + } $this->elementStart('li', array('class' => @@ -192,19 +231,8 @@ 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. * @@ -217,10 +245,9 @@ class FacebookAction extends Action $this->elementStart('div', array('id' => 'header')); $this->showLogo(); $this->showNoticeForm(); - $this->showPrimaryNav(); $this->elementEnd('div'); } - + /** * Show page, a template method. * @@ -233,18 +260,18 @@ class FacebookAction extends Action $this->showBody(); $this->endHTML(); } - + function showInstructions() { - global $xw; + + $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'); @@ -253,15 +280,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) { @@ -278,7 +308,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'); @@ -290,6 +319,7 @@ class FacebookAction extends Action $this->elementEnd('ul'); $this->submit('submit', _('Login')); + $this->elementEnd('fieldset'); $this->elementEnd('form'); $this->elementStart('p'); @@ -298,53 +328,80 @@ class FacebookAction extends Action $this->elementEnd('p'); $this->elementEnd('div'); + $this->elementEnd('div'); } - - + + function updateProfileBox($notice) { // 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 = ''; + 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; + } + '; $this->xw->openMemory(); - $item = new FacebookNoticeListItem($notice, $this); + $item = new FacebookProfileBoxNotice($notice, $this); $item->show(); $fbml = "$style " . $this->xw->outputMemory(false) . ""; @@ -352,12 +409,12 @@ class FacebookAction extends Action $fbml_main = "$style " . $this->xw->outputMemory(false) . ""; - $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main); + $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main); $this->xw->openURI('php://output'); } - - + + /** * Generate pagination links * @@ -402,15 +459,62 @@ class FacebookAction extends Action $this->elementEnd('div'); } } - + + 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, + 'web', 1, ($replyto == 'false') ? null : $replyto); + + if (is_string($notice)) { + $this->showPage($notice); + return; + } + + common_broadcast_notice($notice); + + // Also update the user's Facebook status + facebookBroadcastNotice($notice); + + } } -class FacebookNoticeForm extends NoticeForm +class FacebookNoticeForm extends NoticeForm { - + var $post_action = null; - + /** * Constructor * @@ -419,13 +523,13 @@ class FacebookNoticeForm extends NoticeForm * @param string $content content to pre-fill */ - function __construct($out=null, $action=null, $content=null, + 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 * @@ -441,6 +545,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 * @@ -494,7 +610,21 @@ 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. * @@ -507,43 +637,61 @@ class FacebookNoticeListItem extends NoticeListItem function show() { $this->showStart(); + $this->showNotice(); + $this->showNoticeInfo(); - $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'); + // XXX: Need to update to show attachements and controls $this->showEnd(); } - function showNoticeLink() +} + +class FacebookProfileBoxNotice extends FacebookNoticeListItem +{ + + /** + * constructor + * + * Also initializes the profile attribute. + * + * @param Notice $notice The notice we'll display + */ + + function __construct($notice, $out=null) { - $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; - } + parent::__construct($notice, $out); + } + + /** + * Recipe function for displaying a single notice in the + * Facebook App profile notice box + * + * @return void + */ + + function show() + { + $this->showNotice(); + $this->showNoticeInfo(); + $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('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->elementStart('a', array('id' => 'facebook_laconica_app', + 'href' => $this->app_uri)); + $this->out->text($this->app_name); $this->out->elementEnd('a'); - $this->out->elementEnd('dd'); - $this->out->elementEnd('dl'); } }