3 * StatusNet, the distributed open-source microblogging tool
5 * Low-level generator for HTML
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2008 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA'))
35 require_once INSTALLDIR.'/lib/facebookutil.php';
36 require_once INSTALLDIR.'/lib/noticeform.php';
39 class FacebookAction extends Action
52 * Just wraps the HTMLOutputter constructor.
54 * @param string $output URI to output to, default = stdout
55 * @param boolean $indent Whether to indent output, default true
57 * @see XMLOutputter::__construct
58 * @see HTMLOutputter::__construct
60 function __construct($output='php://output', $indent=true, $facebook=null, $flink=null)
62 parent::__construct($output, $indent);
64 $this->facebook = $facebook;
65 $this->flink = $flink;
68 $this->fbuid = $flink->foreign_id;
69 $this->user = $flink->getUser();
72 $this->args = array();
75 function prepare($argarray)
77 parent::prepare($argarray);
79 $this->facebook = getFacebook();
80 $this->fbuid = $this->facebook->require_login();
82 $this->action = $this->trimmed('action');
84 $app_props = $this->facebook->api_client->Admin_getAppProperties(
85 array('canvas_name', 'application_name'));
87 $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
88 $this->app_name = $app_props['application_name'];
90 $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
96 function showStylesheets()
98 $this->cssLink('css/display.css', 'base');
99 $this->cssLink('css/display.css',null,'screen, projection, tv');
100 $this->cssLink('css/facebookapp.css', 'base');
103 function showScripts()
105 $this->script('js/facebookapp.js');
109 * Start an Facebook ready HTML document
111 * For Facebook we don't want to actually output any headers,
112 * DTD info, etc. Just Stylesheet and JavaScript links.
114 * If $type isn't specified, will attempt to do content negotiation.
116 * @param string $type MIME type to use; default is to do negotation.
121 function startHTML($type=null)
123 $this->showStylesheets();
124 $this->showScripts();
126 $this->elementStart('div', array('class' => 'facebook-page'));
130 * Ends a Facebook ready HTML document
136 $this->elementEnd('div');
143 * MAY overload if no notice form needed... or direct message box????
147 function showNoticeForm()
149 // don't do it for most of the Facebook pages
154 $this->elementStart('div', array('id' => 'wrap'));
158 $this->elementEnd('div');
165 function showHead($error, $success)
169 $this->element("h1", null, $error);
173 $this->element("h1", null, $success);
176 $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
177 $this->elementStart('span', array('id' => 'add_to_profile'));
178 $this->element('fb:add-section-button', array('section' => 'profile'));
179 $this->elementEnd('span');
180 $this->elementEnd('fb:if-section-not-added');
185 // Make this into a widget later
186 function showLocalNav()
188 $this->elementStart('ul', array('class' => 'nav'));
190 $this->elementStart('li', array('class' =>
191 ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
193 array('href' => 'index.php', 'title' => _('Home')), _('Home'));
194 $this->elementEnd('li');
196 if (common_config('invite', 'enabled')) {
197 $this->elementStart('li',
199 ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
201 array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
202 $this->elementEnd('li');
205 $this->elementStart('li',
207 ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
209 array('href' => 'settings.php',
210 'title' => _('Settings')), _('Settings'));
211 $this->elementEnd('li');
213 $this->elementEnd('ul');
217 * Show header of the page.
219 * Calls template methods
223 function showHeader()
225 $this->elementStart('div', array('id' => 'header'));
227 $this->showNoticeForm();
228 $this->elementEnd('div');
232 * Show page, a template method.
236 function showPage($error = null, $success = null)
239 $this->showHead($error, $success);
245 function showInstructions()
248 $this->elementStart('div', array('class' => 'facebook_guide'));
250 $this->elementStart('dl', array('class' => 'system_notice'));
251 $this->element('dt', null, 'Page Notice');
253 $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
254 'with your username and password. Don\'t have a username yet? ');
255 $loginmsg_part2 = _(' a new account.');
257 $this->elementStart('dd');
258 $this->elementStart('p');
259 $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
260 if (!common_config('site', 'openidonly')) {
262 array('href' => common_local_url('register')), _('Register'));
265 array('href' => common_local_url('openidlogin')), _('Register'));
267 $this->text($loginmsg_part2);
268 $this->elementEnd('p');
269 $this->elementEnd('dd');
271 $this->elementEnd('dl');
272 $this->elementEnd('div');
276 function showLoginForm($msg = null)
279 $this->elementStart('div', array('id' => 'content'));
280 $this->element('h1', null, _('Login'));
283 $this->element('fb:error', array('message' => $msg));
286 $this->showInstructions();
288 $this->elementStart('div', array('id' => 'content_inner'));
290 $this->elementStart('form', array('method' => 'post',
291 'class' => 'form_settings',
293 'action' => 'index.php'));
295 $this->elementStart('fieldset');
297 $this->elementStart('ul', array('class' => 'form_datas'));
298 $this->elementStart('li');
299 $this->input('nickname', _('Nickname'));
300 $this->elementEnd('li');
301 $this->elementStart('li');
302 $this->password('password', _('Password'));
303 $this->elementEnd('li');
304 $this->elementEnd('ul');
306 $this->submit('submit', _('Login'));
307 $this->elementEnd('fieldset');
308 $this->elementEnd('form');
310 $this->elementStart('p');
311 $this->element('a', array('href' => common_local_url('recoverpassword')),
312 _('Lost or forgotten password?'));
313 $this->elementEnd('p');
315 $this->elementEnd('div');
316 $this->elementEnd('div');
321 function updateProfileBox($notice)
324 // Need to include inline CSS for styling the Profile box
326 $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
327 $icon_url = $app_props['icon_url'];
333 font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
340 .entry-title .vcard .photo {
349 .entry-title p.entry-content {
357 div.entry-content dl,
358 div.entry-content dt,
359 div.entry-content dd {
361 text-transform:lowercase;
364 div.entry-content dd,
365 div.entry-content .device dt {
369 div.entry-content dl.timestamp dt,
370 div.entry-content dl.response dt {
373 div.entry-content dd a {
374 display:inline-block;
377 #facebook_statusnet_app {
382 background:url('.$icon_url.') no-repeat 0 0;
387 $this->xw->openMemory();
389 $item = new FacebookProfileBoxNotice($notice, $this);
392 $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
393 $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
395 $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
397 $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
399 $this->xw->openURI('php://output');
404 * Generate pagination links
406 * @param boolean $have_before is there something before?
407 * @param boolean $have_after is there something after?
408 * @param integer $page current page
409 * @param string $action current action
410 * @param array $args rest of query arguments
414 function pagination($have_before, $have_after, $page, $action, $args=null)
416 // Does a little before-after block for next/prev page
417 if ($have_before || $have_after) {
418 $this->elementStart('div', array('class' => 'pagination'));
419 $this->elementStart('dl', null);
420 $this->element('dt', null, _('Pagination'));
421 $this->elementStart('dd', null);
422 $this->elementStart('ul', array('class' => 'nav'));
425 $pargs = array('page' => $page-1);
426 $newargs = $args ? array_merge($args, $pargs) : $pargs;
427 $this->elementStart('li', array('class' => 'nav_prev'));
428 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'),
430 $this->elementEnd('li');
433 $pargs = array('page' => $page+1);
434 $newargs = $args ? array_merge($args, $pargs) : $pargs;
435 $this->elementStart('li', array('class' => 'nav_next'));
436 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'),
438 $this->elementEnd('li');
440 if ($have_before || $have_after) {
441 $this->elementEnd('ul');
442 $this->elementEnd('dd');
443 $this->elementEnd('dl');
444 $this->elementEnd('div');
448 function saveNewNotice()
451 $user = $this->flink->getUser();
453 $content = $this->trimmed('status_textarea');
456 $this->showPage(_('No notice content!'));
459 $content_shortened = common_shorten_links($content);
461 if (mb_strlen($content_shortened) > 140) {
462 $this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
467 $inter = new CommandInterpreter();
469 $cmd = $inter->handle_command($user, $content_shortened);
475 $cmd->execute(new WebChannel());
479 $replyto = $this->trimmed('inreplyto');
481 $notice = Notice::saveNew($user->id, $content,
482 'web', 1, ($replyto == 'false') ? null : $replyto);
484 if (is_string($notice)) {
485 $this->showPage($notice);
489 common_broadcast_notice($notice);
491 // Also update the user's Facebook status
492 facebookBroadcastNotice($notice);
498 class FacebookNoticeForm extends NoticeForm
501 var $post_action = null;
506 * @param HTMLOutputter $out output channel
507 * @param string $action action to return to, if any
508 * @param string $content content to pre-fill
511 function __construct($out=null, $action=null, $content=null,
512 $post_action=null, $user=null)
514 parent::__construct($out, $action, $content, $user);
515 $this->post_action = $post_action;
521 * @return string URL of the action
526 return $this->post_action;
531 class FacebookNoticeList extends NoticeList
537 * @param Notice $notice stream of notices from DB_DataObject
540 function __construct($notice, $out=null)
542 parent::__construct($notice, $out);
546 * show the list of notices
548 * "Uses up" the stream by looping through it. So, probably can't
549 * be called twice on the same list.
551 * @return int count of notices listed.
556 $this->out->elementStart('div', array('id' =>'notices_primary'));
557 $this->out->element('h2', null, _('Notices'));
558 $this->out->elementStart('ul', array('class' => 'notices'));
562 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
565 if ($cnt > NOTICES_PER_PAGE) {
569 $item = $this->newListItem($this->notice);
573 $this->out->elementEnd('ul');
574 $this->out->elementEnd('div');
580 * returns a new list item for the current notice
582 * Overridden to return a Facebook specific list item.
584 * @param Notice $notice the current notice
586 * @return FacebookNoticeListItem a list item for displaying the notice
587 * formatted for display in the Facebook App.
590 function newListItem($notice)
592 return new FacebookNoticeListItem($notice, $this);
597 class FacebookNoticeListItem extends NoticeListItem
603 * Also initializes the profile attribute.
605 * @param Notice $notice The notice we'll display
608 function __construct($notice, $out=null)
610 parent::__construct($notice, $out);
614 * recipe function for displaying a single notice in the Facebook App.
616 * Overridden to strip out some of the controls that we don't
617 * want to be available.
626 $this->showNoticeInfo();
628 // XXX: Need to update to show attachements and controls
635 class FacebookProfileBoxNotice extends FacebookNoticeListItem
641 * Also initializes the profile attribute.
643 * @param Notice $notice The notice we'll display
646 function __construct($notice, $out=null)
648 parent::__construct($notice, $out);
652 * Recipe function for displaying a single notice in the
653 * Facebook App profile notice box
661 $this->showNoticeInfo();
662 $this->showAppLink();
665 function showAppLink()
668 $this->facebook = getFacebook();
670 $app_props = $this->facebook->api_client->Admin_getAppProperties(
671 array('canvas_name', 'application_name'));
673 $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
674 $this->app_name = $app_props['application_name'];
676 $this->out->elementStart('a', array('id' => 'facebook_statusnet_app',
677 'href' => $this->app_uri));
678 $this->out->text($this->app_name);
679 $this->out->elementEnd('a');