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
49 function prepare($argarray)
51 parent::prepare($argarray);
53 common_debug("Facebookaction::prepare");
55 $this->facebook = get_facebook();
56 $this->fbuid = $this->facebook->require_login();
58 $this->action = $this->trimmed('action');
60 $app_props = $this->facebook->api_client->Admin_getAppProperties(
61 array('canvas_name', 'application_name'));
63 $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
64 $this->app_name = $app_props['application_name'];
66 $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
72 function showStylesheets()
75 $this->element('link', array('rel' => 'stylesheet',
77 'href' => getFacebookBaseCSS()));
79 $this->element('link', array('rel' => 'stylesheet',
81 'href' => getFacebookThemeCSS()));
84 function showScripts()
86 $this->element('script', array('type' => 'text/javascript',
87 'src' => getFacebookJS()),
92 * Start an Facebook ready HTML document
94 * For Facebook we don't want to actually output any headers,
97 * If $type isn't specified, will attempt to do content negotiation.
99 * @param string $type MIME type to use; default is to do negotation.
104 function startHTML($type=null)
106 $this->elementStart('div', array('class' => 'facebook-page'));
110 * Ends a Facebook ready HTML document
116 $this->elementEnd('div');
123 * MAY overload if no notice form needed... or direct message box????
127 function showNoticeForm()
129 // don't do it for most of the Facebook pages
134 $this->elementStart('div', 'wrap');
138 $this->elementEnd('div');
145 function showHead($error, $success)
147 $this->showStylesheets();
148 $this->showScripts();
151 $this->element("h1", null, $error);
155 $this->element("h1", null, $success);
158 $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
159 $this->elementStart('span', array('id' => 'add_to_profile'));
160 $this->element('fb:add-section-button', array('section' => 'profile'));
161 $this->elementEnd('span');
162 $this->elementEnd('fb:if-section-not-added');
167 // Make this into a widget later
168 function showLocalNav()
171 $this->elementStart('ul', array('class' => 'nav'));
173 $this->elementStart('li', array('class' =>
174 ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
176 array('href' => 'index.php', 'title' => _('Home')), _('Home'));
177 $this->elementEnd('li');
179 $this->elementStart('li',
181 ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
183 array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
184 $this->elementEnd('li');
186 $this->elementStart('li',
188 ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
190 array('href' => 'settings.php',
191 'title' => _('Settings')), _('Settings'));
192 $this->elementEnd('li');
194 $this->elementEnd('ul');
199 * Show primary navigation.
203 function showPrimaryNav()
205 // we don't want to show anything for this
209 * Show header of the page.
211 * Calls template methods
215 function showHeader()
217 $this->elementStart('div', array('id' => 'header'));
219 $this->showNoticeForm();
220 $this->showPrimaryNav();
221 $this->elementEnd('div');
225 * Show page, a template method.
229 function showPage($error = null, $success = null)
232 $this->showHead($error, $success);
238 function showInstructions()
242 $this->elementStart('dl', array('class' => 'system_notice'));
243 $this->element('dt', null, 'Page Notice');
245 $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
246 'with your username and password. Don\'t have a username yet? ');
248 $loginmsg_part2 = _(' a new account.');
250 $this->elementStart('dd');
251 $this->elementStart('p');
252 $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
254 array('href' => common_local_url('register')), _('Register'));
255 $this->text($loginmsg_part2);
256 $this->elementEnd('dd');
257 $this->elementEnd('dl');
261 function showLoginForm($msg = null)
264 $this->elementStart('div', array('class' => 'content'));
265 $this->element('h1', null, _('Login'));
268 $this->element('fb:error', array('message' => $msg));
271 $this->showInstructions();
273 $this->elementStart('div', array('id' => 'content_inner'));
275 $this->elementStart('form', array('method' => 'post',
276 'class' => 'form_settings',
278 'action' => 'index.php'));
280 $this->elementStart('fieldset');
281 $this->element('legend', null, _('Login to site'));
283 $this->elementStart('ul', array('class' => 'form_datas'));
284 $this->elementStart('li');
285 $this->input('nickname', _('Nickname'));
286 $this->elementEnd('li');
287 $this->elementStart('li');
288 $this->password('password', _('Password'));
289 $this->elementEnd('li');
290 $this->elementEnd('ul');
292 $this->submit('submit', _('Login'));
293 $this->elementEnd('form');
295 $this->elementStart('p');
296 $this->element('a', array('href' => common_local_url('recoverpassword')),
297 _('Lost or forgotten password?'));
298 $this->elementEnd('p');
300 $this->elementEnd('div');
305 function updateProfileBox($notice)
308 // Need to include inline CSS for styling the Profile box
315 list-style-type: none;
317 border-top: 1px solid #dec5b5;
320 text-decoration: underline;
326 padding: 5px 5px 5px 0;
328 font-family: Georgia, "Times New Roman", Times, serif;
331 border-bottom: 1px solid #dec5b5;
332 background-color:#FCFFF5;
335 .notice_single:hover {
336 background-color: #f7ebcc;
345 $this->xw->openMemory();
347 $item = new FacebookNoticeListItem($notice, $this);
350 $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
351 $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
353 $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
355 $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
357 $this->xw->openURI('php://output');
362 * Generate pagination links
364 * @param boolean $have_before is there something before?
365 * @param boolean $have_after is there something after?
366 * @param integer $page current page
367 * @param string $action current action
368 * @param array $args rest of query arguments
372 function pagination($have_before, $have_after, $page, $action, $args=null)
374 // Does a little before-after block for next/prev page
375 if ($have_before || $have_after) {
376 $this->elementStart('div', array('class' => 'pagination'));
377 $this->elementStart('dl', null);
378 $this->element('dt', null, _('Pagination'));
379 $this->elementStart('dd', null);
380 $this->elementStart('ul', array('class' => 'nav'));
383 $pargs = array('page' => $page-1);
384 $newargs = $args ? array_merge($args, $pargs) : $pargs;
385 $this->elementStart('li', array('class' => 'nav_prev'));
386 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'),
388 $this->elementEnd('li');
391 $pargs = array('page' => $page+1);
392 $newargs = $args ? array_merge($args, $pargs) : $pargs;
393 $this->elementStart('li', array('class' => 'nav_next'));
394 $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'),
396 $this->elementEnd('li');
398 if ($have_before || $have_after) {
399 $this->elementEnd('ul');
400 $this->elementEnd('dd');
401 $this->elementEnd('dl');
402 $this->elementEnd('div');
409 class FacebookNoticeForm extends NoticeForm
412 var $post_action = null;
417 * @param HTMLOutputter $out output channel
418 * @param string $action action to return to, if any
419 * @param string $content content to pre-fill
422 function __construct($out=null, $action=null, $content=null,
423 $post_action=null, $user=null)
425 parent::__construct($out, $action, $content, $user);
426 $this->post_action = $post_action;
432 * @return string URL of the action
437 return $this->post_action;
442 class FacebookNoticeList extends NoticeList
445 * show the list of notices
447 * "Uses up" the stream by looping through it. So, probably can't
448 * be called twice on the same list.
450 * @return int count of notices listed.
455 $this->out->elementStart('div', array('id' =>'notices_primary'));
456 $this->out->element('h2', null, _('Notices'));
457 $this->out->elementStart('ul', array('class' => 'notices'));
461 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
464 if ($cnt > NOTICES_PER_PAGE) {
468 $item = $this->newListItem($this->notice);
472 $this->out->elementEnd('ul');
473 $this->out->elementEnd('div');
479 * returns a new list item for the current notice
481 * Overridden to return a Facebook specific list item.
483 * @param Notice $notice the current notice
485 * @return FacebookNoticeListItem a list item for displaying the notice
486 * formatted for display in the Facebook App.
489 function newListItem($notice)
491 return new FacebookNoticeListItem($notice, $this);
496 class FacebookNoticeListItem extends NoticeListItem
499 * recipe function for displaying a single notice in the Facebook App.
501 * Overridden to strip out some of the controls that we don't
502 * want to be available.
511 $this->out->elementStart('div', 'entry-title');
513 $this->showContent();
514 $this->out->elementEnd('div');
516 $this->out->elementStart('div', 'entry-content');
517 $this->showNoticeLink();
518 $this->showNoticeSource();
519 $this->showReplyTo();
520 $this->out->elementEnd('div');
525 function showNoticeLink()
527 $noticeurl = common_local_url('shownotice',
528 array('notice' => $this->notice->id));
529 // XXX: we need to figure this out better. Is this right?
530 if (strcmp($this->notice->uri, $noticeurl) != 0 &&
531 preg_match('/^http/', $this->notice->uri)) {
532 $noticeurl = $this->notice->uri;
535 $this->out->elementStart('dl', 'timestamp');
536 $this->out->element('dt', null, _('Published'));
537 $this->out->elementStart('dd', null);
538 $this->out->elementStart('a', array('rel' => 'bookmark',
539 'href' => $noticeurl));
540 $dt = common_date_iso8601($this->notice->created);
541 $this->out->element('abbr', array('class' => 'published',
543 common_date_string($this->notice->created));
544 $this->out->elementEnd('a');
545 $this->out->elementEnd('dd');
546 $this->out->elementEnd('dl');