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/facebookapp.css', 'base');
102 function showScripts()
104 $this->script('js/facebookapp.js');
108 * Start an Facebook ready HTML document
110 * For Facebook we don't want to actually output any headers,
111 * DTD info, etc. Just Stylesheet and JavaScript links.
113 * If $type isn't specified, will attempt to do content negotiation.
115 * @param string $type MIME type to use; default is to do negotation.
120 function startHTML($type=null)
122 $this->showStylesheets();
123 $this->showScripts();
125 $this->elementStart('div', array('class' => 'facebook-page'));
129 * Ends a Facebook ready HTML document
135 $this->elementEnd('div');
142 * MAY overload if no notice form needed... or direct message box????
146 function showNoticeForm()
148 // don't do it for most of the Facebook pages
153 $this->elementStart('div', array('id' => 'wrap'));
157 $this->elementEnd('div');
164 function showHead($error, $success)
168 $this->element("h1", null, $error);
172 $this->element("h1", null, $success);
175 $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
176 $this->elementStart('span', array('id' => 'add_to_profile'));
177 $this->element('fb:add-section-button', array('section' => 'profile'));
178 $this->elementEnd('span');
179 $this->elementEnd('fb:if-section-not-added');
184 // Make this into a widget later
185 function showLocalNav()
187 $this->elementStart('ul', array('class' => 'nav'));
189 $this->elementStart('li', array('class' =>
190 ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
192 array('href' => 'index.php', 'title' => _('Home')), _('Home'));
193 $this->elementEnd('li');
195 if (common_config('invite', 'enabled')) {
196 $this->elementStart('li',
198 ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
200 array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
201 $this->elementEnd('li');
204 $this->elementStart('li',
206 ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
208 array('href' => 'settings.php',
209 'title' => _('Settings')), _('Settings'));
210 $this->elementEnd('li');
212 $this->elementEnd('ul');
216 * Show header of the page.
218 * Calls template methods
222 function showHeader()
224 $this->elementStart('div', array('id' => 'header'));
226 $this->showNoticeForm();
227 $this->elementEnd('div');
231 * Show page, a template method.
235 function showPage($error = null, $success = null)
238 $this->showHead($error, $success);
244 function showInstructions()
247 $this->elementStart('div', array('class' => 'facebook_guide'));
249 $this->elementStart('dl', array('class' => 'system_notice'));
250 $this->element('dt', null, 'Page Notice');
252 $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
253 'with your username and password. Don\'t have a username yet? ');
254 $loginmsg_part2 = _(' a new account.');
256 $this->elementStart('dd');
257 $this->elementStart('p');
258 $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
259 if (!common_config('site', 'openidonly')) {
261 array('href' => common_local_url('register')), _('Register'));
264 array('href' => common_local_url('openidlogin')), _('Register'));
266 $this->text($loginmsg_part2);
267 $this->elementEnd('p');
268 $this->elementEnd('dd');
270 $this->elementEnd('dl');
271 $this->elementEnd('div');
275 function showLoginForm($msg = null)
278 $this->elementStart('div', array('id' => 'content'));
279 $this->element('h1', null, _('Login'));
282 $this->element('fb:error', array('message' => $msg));
285 $this->showInstructions();
287 $this->elementStart('div', array('id' => 'content_inner'));
289 $this->elementStart('form', array('method' => 'post',
290 'class' => 'form_settings',
292 'action' => 'index.php'));
294 $this->elementStart('fieldset');
296 $this->elementStart('ul', array('class' => 'form_datas'));
297 $this->elementStart('li');
298 $this->input('nickname', _('Nickname'));
299 $this->elementEnd('li');
300 $this->elementStart('li');
301 $this->password('password', _('Password'));
302 $this->elementEnd('li');
303 $this->elementEnd('ul');
305 $this->submit('submit', _('Login'));
306 $this->elementEnd('fieldset');
307 $this->elementEnd('form');
309 $this->elementStart('p');
310 $this->element('a', array('href' => common_local_url('recoverpassword')),
311 _('Lost or forgotten password?'));
312 $this->elementEnd('p');
314 $this->elementEnd('div');
315 $this->elementEnd('div');
320 function updateProfileBox($notice)
323 // Need to include inline CSS for styling the Profile box
325 $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
326 $icon_url = $app_props['icon_url'];
332 font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
339 .entry-title .vcard .photo {
348 .entry-title p.entry-content {
356 div.entry-content dl,
357 div.entry-content dt,
358 div.entry-content dd {
360 text-transform:lowercase;
363 div.entry-content dd,
364 div.entry-content .device dt {
368 div.entry-content dl.timestamp dt,
369 div.entry-content dl.response dt {
372 div.entry-content dd a {
373 display:inline-block;
376 #facebook_statusnet_app {
381 background:url('.$icon_url.') no-repeat 0 0;
386 $this->xw->openMemory();
388 $item = new FacebookProfileBoxNotice($notice, $this);
391 $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
392 $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
394 $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
396 $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
398 $this->xw->openURI('php://output');
403 * Generate pagination links
405 * @param boolean $have_before is there something before?
406 * @param boolean $have_after is there something after?
407 * @param integer $page current page
408 * @param string $action current action
409 * @param array $args rest of query arguments
413 function pagination($have_before, $have_after, $page, $action, $args=null)
415 // Does a little before-after block for next/prev page
416 if ($have_before || $have_after) {
417 $this->elementStart('div', array('class' => 'pagination'));
418 $this->elementStart('dl', null);
419 $this->element('dt', null, _('Pagination'));
420 $this->elementStart('dd', null);
421 $this->elementStart('ul', array('class' => 'nav'));
424 $pargs = array('page' => $page-1);
425 $newargs = $args ? array_merge($args, $pargs) : $pargs;
426 $this->elementStart('li', array('class' => 'nav_prev'));
427 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'),
429 $this->elementEnd('li');
432 $pargs = array('page' => $page+1);
433 $newargs = $args ? array_merge($args, $pargs) : $pargs;
434 $this->elementStart('li', array('class' => 'nav_next'));
435 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'),
437 $this->elementEnd('li');
439 if ($have_before || $have_after) {
440 $this->elementEnd('ul');
441 $this->elementEnd('dd');
442 $this->elementEnd('dl');
443 $this->elementEnd('div');
447 function saveNewNotice()
450 $user = $this->flink->getUser();
452 $content = $this->trimmed('status_textarea');
455 $this->showPage(_('No notice content!'));
458 $content_shortened = common_shorten_links($content);
460 if (mb_strlen($content_shortened) > 140) {
461 $this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
466 $inter = new CommandInterpreter();
468 $cmd = $inter->handle_command($user, $content_shortened);
474 $cmd->execute(new WebChannel());
478 $replyto = $this->trimmed('inreplyto');
480 $notice = Notice::saveNew($user->id, $content,
481 'web', 1, ($replyto == 'false') ? null : $replyto);
483 if (is_string($notice)) {
484 $this->showPage($notice);
488 common_broadcast_notice($notice);
490 // Also update the user's Facebook status
491 facebookBroadcastNotice($notice);
497 class FacebookNoticeForm extends NoticeForm
500 var $post_action = null;
505 * @param HTMLOutputter $out output channel
506 * @param string $action action to return to, if any
507 * @param string $content content to pre-fill
510 function __construct($out=null, $action=null, $content=null,
511 $post_action=null, $user=null)
513 parent::__construct($out, $action, $content, $user);
514 $this->post_action = $post_action;
520 * @return string URL of the action
525 return $this->post_action;
530 class FacebookNoticeList extends NoticeList
536 * @param Notice $notice stream of notices from DB_DataObject
539 function __construct($notice, $out=null)
541 parent::__construct($notice, $out);
545 * show the list of notices
547 * "Uses up" the stream by looping through it. So, probably can't
548 * be called twice on the same list.
550 * @return int count of notices listed.
555 $this->out->elementStart('div', array('id' =>'notices_primary'));
556 $this->out->element('h2', null, _('Notices'));
557 $this->out->elementStart('ul', array('class' => 'notices'));
561 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
564 if ($cnt > NOTICES_PER_PAGE) {
568 $item = $this->newListItem($this->notice);
572 $this->out->elementEnd('ul');
573 $this->out->elementEnd('div');
579 * returns a new list item for the current notice
581 * Overridden to return a Facebook specific list item.
583 * @param Notice $notice the current notice
585 * @return FacebookNoticeListItem a list item for displaying the notice
586 * formatted for display in the Facebook App.
589 function newListItem($notice)
591 return new FacebookNoticeListItem($notice, $this);
596 class FacebookNoticeListItem extends NoticeListItem
602 * Also initializes the profile attribute.
604 * @param Notice $notice The notice we'll display
607 function __construct($notice, $out=null)
609 parent::__construct($notice, $out);
613 * recipe function for displaying a single notice in the Facebook App.
615 * Overridden to strip out some of the controls that we don't
616 * want to be available.
625 $this->showNoticeInfo();
627 // XXX: Need to update to show attachements and controls
634 class FacebookProfileBoxNotice extends FacebookNoticeListItem
640 * Also initializes the profile attribute.
642 * @param Notice $notice The notice we'll display
645 function __construct($notice, $out=null)
647 parent::__construct($notice, $out);
651 * Recipe function for displaying a single notice in the
652 * Facebook App profile notice box
660 $this->showNoticeInfo();
661 $this->showAppLink();
664 function showAppLink()
667 $this->facebook = getFacebook();
669 $app_props = $this->facebook->api_client->Admin_getAppProperties(
670 array('canvas_name', 'application_name'));
672 $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
673 $this->app_name = $app_props['application_name'];
675 $this->out->elementStart('a', array('id' => 'facebook_statusnet_app',
676 'href' => $this->app_uri));
677 $this->out->text($this->app_name);
678 $this->out->elementEnd('a');