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';
38 class FacebookAction extends Action
51 * Just wraps the HTMLOutputter constructor.
53 * @param string $output URI to output to, default = stdout
54 * @param boolean $indent Whether to indent output, default true
56 * @see XMLOutputter::__construct
57 * @see HTMLOutputter::__construct
59 function __construct($output='php://output', $indent=true, $facebook=null, $flink=null)
61 parent::__construct($output, $indent);
63 $this->facebook = $facebook;
64 $this->flink = $flink;
67 $this->fbuid = $flink->foreign_id;
68 $this->user = $flink->getUser();
71 $this->args = array();
74 function prepare($argarray)
76 parent::prepare($argarray);
78 $this->facebook = getFacebook();
79 $this->fbuid = $this->facebook->require_login();
81 $this->action = $this->trimmed('action');
83 $app_props = $this->facebook->api_client->Admin_getAppProperties(
84 array('canvas_name', 'application_name'));
86 $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
87 $this->app_name = $app_props['application_name'];
89 $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
95 function showStylesheets()
97 $this->cssLink('css/display.css', 'base');
98 $this->cssLink('css/display.css',null,'screen, projection, tv');
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');
183 // Make this into a widget later
184 function showLocalNav()
186 $this->elementStart('ul', array('class' => 'nav'));
188 $this->elementStart('li', array('class' =>
189 ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
191 array('href' => 'index.php', 'title' => _('Home')), _('Home'));
192 $this->elementEnd('li');
194 if (common_config('invite', 'enabled')) {
195 $this->elementStart('li',
197 ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
199 array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
200 $this->elementEnd('li');
203 $this->elementStart('li',
205 ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
207 array('href' => 'settings.php',
208 'title' => _('Settings')), _('Settings'));
209 $this->elementEnd('li');
211 $this->elementEnd('ul');
215 * Show header of the page.
217 * Calls template methods
221 function showHeader()
223 $this->elementStart('div', array('id' => 'header'));
225 $this->showNoticeForm();
226 $this->elementEnd('div');
230 * Show page, a template method.
234 function showPage($error = null, $success = null)
237 $this->showHead($error, $success);
242 function showInstructions()
245 $this->elementStart('div', array('class' => 'facebook_guide'));
247 $this->elementStart('dl', array('class' => 'system_notice'));
248 $this->element('dt', null, 'Page Notice');
250 $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
251 'with your username and password. Don\'t have a username yet? ');
252 $loginmsg_part2 = _(' a new account.');
254 $this->elementStart('dd');
255 $this->elementStart('p');
256 $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
258 array('href' => common_local_url('register')), _('Register'));
259 $this->text($loginmsg_part2);
260 $this->elementEnd('p');
261 $this->elementEnd('dd');
263 $this->elementEnd('dl');
264 $this->elementEnd('div');
267 function showLoginForm($msg = null)
270 $this->elementStart('div', array('id' => 'content'));
271 $this->element('h1', null, _('Login'));
274 $this->element('fb:error', array('message' => $msg));
277 $this->showInstructions();
279 $this->elementStart('div', array('id' => 'content_inner'));
281 $this->elementStart('form', array('method' => 'post',
282 'class' => 'form_settings',
284 'action' => 'index.php'));
286 $this->elementStart('fieldset');
288 $this->elementStart('ul', array('class' => 'form_datas'));
289 $this->elementStart('li');
290 $this->input('nickname', _('Nickname'));
291 $this->elementEnd('li');
292 $this->elementStart('li');
293 $this->password('password', _('Password'));
294 $this->elementEnd('li');
295 $this->elementEnd('ul');
297 $this->submit('submit', _('Login'));
298 $this->elementEnd('fieldset');
299 $this->elementEnd('form');
301 $this->elementStart('p');
302 $this->element('a', array('href' => common_local_url('recoverpassword')),
303 _('Lost or forgotten password?'));
304 $this->elementEnd('p');
306 $this->elementEnd('div');
307 $this->elementEnd('div');
311 function updateProfileBox($notice)
314 // Need to include inline CSS for styling the Profile box
316 $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
317 $icon_url = $app_props['icon_url'];
323 font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
330 .entry-title .vcard .photo {
339 .entry-title p.entry-content {
347 div.entry-content dl,
348 div.entry-content dt,
349 div.entry-content dd {
351 text-transform:lowercase;
354 div.entry-content dd,
355 div.entry-content .device dt {
359 div.entry-content dl.timestamp dt,
360 div.entry-content dl.response dt {
363 div.entry-content dd a {
364 display:inline-block;
367 #facebook_statusnet_app {
372 background:url('.$icon_url.') no-repeat 0 0;
377 $this->xw->openMemory();
379 $item = new FacebookProfileBoxNotice($notice, $this);
382 $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
383 $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
385 $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
387 $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
389 $this->xw->openURI('php://output');
393 * Generate pagination links
395 * @param boolean $have_before is there something before?
396 * @param boolean $have_after is there something after?
397 * @param integer $page current page
398 * @param string $action current action
399 * @param array $args rest of query arguments
403 function pagination($have_before, $have_after, $page, $action, $args=null)
405 // Does a little before-after block for next/prev page
406 if ($have_before || $have_after) {
407 $this->elementStart('div', array('class' => 'pagination'));
408 $this->elementStart('dl', null);
409 $this->element('dt', null, _('Pagination'));
410 $this->elementStart('dd', null);
411 $this->elementStart('ul', array('class' => 'nav'));
414 $pargs = array('page' => $page-1);
415 $newargs = $args ? array_merge($args, $pargs) : $pargs;
416 $this->elementStart('li', array('class' => 'nav_prev'));
417 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'),
419 $this->elementEnd('li');
422 $pargs = array('page' => $page+1);
423 $newargs = $args ? array_merge($args, $pargs) : $pargs;
424 $this->elementStart('li', array('class' => 'nav_next'));
425 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'),
427 $this->elementEnd('li');
429 if ($have_before || $have_after) {
430 $this->elementEnd('ul');
431 $this->elementEnd('dd');
432 $this->elementEnd('dl');
433 $this->elementEnd('div');
437 function saveNewNotice()
440 $user = $this->flink->getUser();
442 $content = $this->trimmed('status_textarea');
445 $this->showPage(_('No notice content!'));
448 $content_shortened = common_shorten_links($content);
450 if (Notice::contentTooLong($content_shortened)) {
451 $this->showPage(sprintf(_('That\'s too long. Max notice size is %d chars.'),
452 Notice::maxContent()));
457 $inter = new CommandInterpreter();
459 $cmd = $inter->handle_command($user, $content_shortened);
465 $cmd->execute(new WebChannel());
469 $replyto = $this->trimmed('inreplyto');
472 $notice = Notice::saveNew($user->id, $content,
473 'web', 1, ($replyto == 'false') ? null : $replyto);
474 } catch (Exception $e) {
475 $this->showPage($e->getMessage());
479 common_broadcast_notice($notice);
481 // Also update the user's Facebook status
482 facebookBroadcastNotice($notice);
488 class FacebookNoticeForm extends NoticeForm
491 var $post_action = null;
496 * @param HTMLOutputter $out output channel
497 * @param string $action action to return to, if any
498 * @param string $content content to pre-fill
501 function __construct($out=null, $action=null, $content=null,
502 $post_action=null, $user=null)
504 parent::__construct($out, $action, $content, $user);
505 $this->post_action = $post_action;
511 * @return string URL of the action
516 return $this->post_action;
521 class FacebookNoticeList extends NoticeList
527 * @param Notice $notice stream of notices from DB_DataObject
530 function __construct($notice, $out=null)
532 parent::__construct($notice, $out);
536 * show the list of notices
538 * "Uses up" the stream by looping through it. So, probably can't
539 * be called twice on the same list.
541 * @return int count of notices listed.
546 $this->out->elementStart('div', array('id' =>'notices_primary'));
547 $this->out->element('h2', null, _('Notices'));
548 $this->out->elementStart('ul', array('class' => 'notices'));
552 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
555 if ($cnt > NOTICES_PER_PAGE) {
559 $item = $this->newListItem($this->notice);
563 $this->out->elementEnd('ul');
564 $this->out->elementEnd('div');
570 * returns a new list item for the current notice
572 * Overridden to return a Facebook specific list item.
574 * @param Notice $notice the current notice
576 * @return FacebookNoticeListItem a list item for displaying the notice
577 * formatted for display in the Facebook App.
580 function newListItem($notice)
582 return new FacebookNoticeListItem($notice, $this);
587 class FacebookNoticeListItem extends NoticeListItem
593 * Also initializes the profile attribute.
595 * @param Notice $notice The notice we'll display
598 function __construct($notice, $out=null)
600 parent::__construct($notice, $out);
604 * recipe function for displaying a single notice in the Facebook App.
606 * Overridden to strip out some of the controls that we don't
607 * want to be available.
616 $this->showNoticeInfo();
618 // XXX: Need to update to show attachements and controls
625 class FacebookProfileBoxNotice extends FacebookNoticeListItem
631 * Also initializes the profile attribute.
633 * @param Notice $notice The notice we'll display
636 function __construct($notice, $out=null)
638 parent::__construct($notice, $out);
642 * Recipe function for displaying a single notice in the
643 * Facebook App profile notice box
651 $this->showNoticeInfo();
652 $this->showAppLink();
655 function showAppLink()
658 $this->facebook = getFacebook();
660 $app_props = $this->facebook->api_client->Admin_getAppProperties(
661 array('canvas_name', 'application_name'));
663 $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
664 $this->app_name = $app_props['application_name'];
666 $this->out->elementStart('a', array('id' => 'facebook_statusnet_app',
667 'href' => $this->app_uri));
668 $this->out->text($this->app_name);
669 $this->out->elementEnd('a');