3 * Laconica, 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@controlyourself.ca>
25 * @copyright 2008 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!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()
99 $this->element('link', array('rel' => 'stylesheet',
100 'type' => 'text/css',
101 'href' => getFacebookBaseCSS()));
103 $this->element('link', array('rel' => 'stylesheet',
104 'type' => 'text/css',
105 'href' => getFacebookThemeCSS()));
108 function showScripts()
110 $this->element('script', array('type' => 'text/javascript',
111 'src' => getFacebookJS()),
116 * Start an Facebook ready HTML document
118 * For Facebook we don't want to actually output any headers,
121 * If $type isn't specified, will attempt to do content negotiation.
123 * @param string $type MIME type to use; default is to do negotation.
128 function startHTML($type=null)
130 $this->elementStart('div', array('class' => 'facebook-page'));
134 * Ends a Facebook ready HTML document
140 $this->elementEnd('div');
147 * MAY overload if no notice form needed... or direct message box????
151 function showNoticeForm()
153 // don't do it for most of the Facebook pages
158 $this->elementStart('div', 'wrap');
162 $this->elementEnd('div');
169 function showHead($error, $success)
171 $this->showStylesheets();
172 $this->showScripts();
175 $this->element("h1", null, $error);
179 $this->element("h1", null, $success);
182 $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
183 $this->elementStart('span', array('id' => 'add_to_profile'));
184 $this->element('fb:add-section-button', array('section' => 'profile'));
185 $this->elementEnd('span');
186 $this->elementEnd('fb:if-section-not-added');
191 // Make this into a widget later
192 function showLocalNav()
195 $this->elementStart('ul', array('class' => 'nav'));
197 $this->elementStart('li', array('class' =>
198 ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
200 array('href' => 'index.php', 'title' => _('Home')), _('Home'));
201 $this->elementEnd('li');
203 $this->elementStart('li',
205 ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
207 array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
208 $this->elementEnd('li');
210 $this->elementStart('li',
212 ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
214 array('href' => 'settings.php',
215 'title' => _('Settings')), _('Settings'));
216 $this->elementEnd('li');
218 $this->elementEnd('ul');
223 * Show primary navigation.
227 function showPrimaryNav()
229 // we don't want to show anything for this
233 * Show header of the page.
235 * Calls template methods
239 function showHeader()
241 $this->elementStart('div', array('id' => 'header'));
243 $this->showNoticeForm();
244 $this->showPrimaryNav();
245 $this->elementEnd('div');
249 * Show page, a template method.
253 function showPage($error = null, $success = null)
256 $this->showHead($error, $success);
262 function showInstructions()
265 $this->elementStart('dl', array('class' => 'system_notice'));
266 $this->element('dt', null, 'Page Notice');
268 $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
269 'with your username and password. Don\'t have a username yet? ');
271 $loginmsg_part2 = _(' a new account.');
273 $this->elementStart('dd');
274 $this->elementStart('p');
275 $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
277 array('href' => common_local_url('register')), _('Register'));
278 $this->text($loginmsg_part2);
279 $this->elementEnd('dd');
280 $this->elementEnd('dl');
284 function showLoginForm($msg = null)
287 $this->elementStart('div', array('class' => 'content'));
288 $this->element('h1', null, _('Login'));
291 $this->element('fb:error', array('message' => $msg));
294 $this->showInstructions();
296 $this->elementStart('div', array('id' => 'content_inner'));
298 $this->elementStart('form', array('method' => 'post',
299 'class' => 'form_settings',
301 'action' => 'index.php'));
303 $this->elementStart('fieldset');
304 $this->element('legend', null, _('Login to site'));
306 $this->elementStart('ul', array('class' => 'form_datas'));
307 $this->elementStart('li');
308 $this->input('nickname', _('Nickname'));
309 $this->elementEnd('li');
310 $this->elementStart('li');
311 $this->password('password', _('Password'));
312 $this->elementEnd('li');
313 $this->elementEnd('ul');
315 $this->submit('submit', _('Login'));
316 $this->elementEnd('form');
318 $this->elementStart('p');
319 $this->element('a', array('href' => common_local_url('recoverpassword')),
320 _('Lost or forgotten password?'));
321 $this->elementEnd('p');
323 $this->elementEnd('div');
328 function updateProfileBox($notice)
331 // Need to include inline CSS for styling the Profile box
338 list-style-type: none;
340 border-top: 1px solid #dec5b5;
343 text-decoration: underline;
349 padding: 5px 5px 5px 0;
351 font-family: Georgia, "Times New Roman", Times, serif;
354 border-bottom: 1px solid #dec5b5;
355 background-color:#FCFFF5;
358 .notice_single:hover {
359 background-color: #f7ebcc;
368 $this->xw->openMemory();
370 $item = new FacebookNoticeListItem($notice, $this);
373 $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
374 $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
376 $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
378 $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
380 $this->xw->openURI('php://output');
385 * Generate pagination links
387 * @param boolean $have_before is there something before?
388 * @param boolean $have_after is there something after?
389 * @param integer $page current page
390 * @param string $action current action
391 * @param array $args rest of query arguments
395 function pagination($have_before, $have_after, $page, $action, $args=null)
397 // Does a little before-after block for next/prev page
398 if ($have_before || $have_after) {
399 $this->elementStart('div', array('class' => 'pagination'));
400 $this->elementStart('dl', null);
401 $this->element('dt', null, _('Pagination'));
402 $this->elementStart('dd', null);
403 $this->elementStart('ul', array('class' => 'nav'));
406 $pargs = array('page' => $page-1);
407 $newargs = $args ? array_merge($args, $pargs) : $pargs;
408 $this->elementStart('li', array('class' => 'nav_prev'));
409 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'),
411 $this->elementEnd('li');
414 $pargs = array('page' => $page+1);
415 $newargs = $args ? array_merge($args, $pargs) : $pargs;
416 $this->elementStart('li', array('class' => 'nav_next'));
417 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'),
419 $this->elementEnd('li');
421 if ($have_before || $have_after) {
422 $this->elementEnd('ul');
423 $this->elementEnd('dd');
424 $this->elementEnd('dl');
425 $this->elementEnd('div');
432 class FacebookNoticeForm extends NoticeForm
435 var $post_action = null;
440 * @param HTMLOutputter $out output channel
441 * @param string $action action to return to, if any
442 * @param string $content content to pre-fill
445 function __construct($out=null, $action=null, $content=null,
446 $post_action=null, $user=null)
448 parent::__construct($out, $action, $content, $user);
449 $this->post_action = $post_action;
455 * @return string URL of the action
460 return $this->post_action;
465 class FacebookNoticeList extends NoticeList
468 * show the list of notices
470 * "Uses up" the stream by looping through it. So, probably can't
471 * be called twice on the same list.
473 * @return int count of notices listed.
478 $this->out->elementStart('div', array('id' =>'notices_primary'));
479 $this->out->element('h2', null, _('Notices'));
480 $this->out->elementStart('ul', array('class' => 'notices'));
484 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
487 if ($cnt > NOTICES_PER_PAGE) {
491 $item = $this->newListItem($this->notice);
495 $this->out->elementEnd('ul');
496 $this->out->elementEnd('div');
502 * returns a new list item for the current notice
504 * Overridden to return a Facebook specific list item.
506 * @param Notice $notice the current notice
508 * @return FacebookNoticeListItem a list item for displaying the notice
509 * formatted for display in the Facebook App.
512 function newListItem($notice)
514 return new FacebookNoticeListItem($notice, $this);
519 class FacebookNoticeListItem extends NoticeListItem
522 * recipe function for displaying a single notice in the Facebook App.
524 * Overridden to strip out some of the controls that we don't
525 * want to be available.
534 $this->out->elementStart('div', 'entry-title');
536 $this->showContent();
537 $this->out->elementEnd('div');
539 $this->out->elementStart('div', 'entry-content');
540 $this->showNoticeLink();
541 $this->showNoticeSource();
542 $this->showReplyTo();
543 $this->out->elementEnd('div');
548 function showNoticeLink()
550 $noticeurl = common_local_url('shownotice',
551 array('notice' => $this->notice->id));
552 // XXX: we need to figure this out better. Is this right?
553 if (strcmp($this->notice->uri, $noticeurl) != 0 &&
554 preg_match('/^http/', $this->notice->uri)) {
555 $noticeurl = $this->notice->uri;
558 $this->out->elementStart('dl', 'timestamp');
559 $this->out->element('dt', null, _('Published'));
560 $this->out->elementStart('dd', null);
561 $this->out->elementStart('a', array('rel' => 'bookmark',
562 'href' => $noticeurl));
563 $dt = common_date_iso8601($this->notice->created);
564 $this->out->element('abbr', array('class' => 'published',
566 common_date_string($this->notice->created));
567 $this->out->elementEnd('a');
568 $this->out->elementEnd('dd');
569 $this->out->elementEnd('dl');