3 * Laconica, the distributed open-source microblogging tool
5 * Base class for all actions (~views)
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 Evan Prodromou <evan@controlyourself.ca>
25 * @author Sarven Capadisli <csarven@controlyourself.ca>
26 * @copyright 2008 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
36 * Base class for all actions
38 * This is the base class for all actions in the package. An action is
39 * more or less a "view" in an MVC framework.
41 * Actions are responsible for extracting and validating parameters; using
42 * model classes to read and write to the database; and doing ouput.
46 * @author Evan Prodromou <evan@controlyourself.ca>
47 * @author Sarven Capadisli <csarven@controlyourself.ca>
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49 * @link http://laconi.ca/
54 class Action extends HTMLOutputter // lawsuit
62 // For initializing members of the class
64 function prepare($argarray)
66 $this->args =& common_copy_args($argarray);
80 // XXX: attributes (profile?)
81 $this->startElement('head');
83 $this->showStylesheets();
85 $this->showOpenSearch();
87 $this->showDescription();
89 $this->elementElement('head');
94 $this->element('title', null,
97 common_config('site', 'name')));
104 return _("Untitled page");
107 function showStylesheets()
109 $this->element('link', array('rel' => 'stylesheet',
110 'type' => 'text/css',
111 'href' => theme_path('display.css') . '?version=' . LACONICA_VERSION,
112 'media' => 'screen, projection, tv'));
113 foreach (array(6,7) as $ver) {
114 if (file_exists(theme_file('ie'.$ver.'.css'))) {
115 // Yes, IE people should be put in jail.
116 $xw->writeComment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
117 'href="'.theme_path('ie'.$ver.'.css').'?version='.LACONICA_VERSION.'" /><![endif]');
122 function showScripts()
124 $this->element('script', array('type' => 'text/javascript',
125 'src' => common_path('js/jquery.min.js')),
127 $this->element('script', array('type' => 'text/javascript',
128 'src' => common_path('js/jquery.form.js')),
130 $this->element('script', array('type' => 'text/javascript',
131 'src' => common_path('js/xbImportNode.js')),
133 $this->element('script', array('type' => 'text/javascript',
134 'src' => common_path('js/util.js?version='.LACONICA_VERSION)),
138 function showOpenSearch()
140 $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
141 'href' => common_local_url('opensearch', array('type' => 'people')),
142 'title' => common_config('site', 'name').' People Search'));
144 $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
145 'href' => common_local_url('opensearch', array('type' => 'notice')),
146 'title' => common_config('site', 'name').' Notice Search'));
153 // does nothing by default
158 function showDescription()
160 // does nothing by default
167 // does nothing by default
173 // output wrap element
179 function showHeader()
181 // start header div stuff
183 $this->showPrimaryNav();
184 $this->showSiteNotice();
185 $this->showNoticeForm();
186 // end header div stuff
191 $this->elementStart('address', array('id' => 'site_contact',
192 'class' => 'vcard'));
193 $this->elementStart('a', array('class' => 'url home bookmark',
194 'href' => common_local_url('public')));
195 if ((isset($config['site']['logo']) && is_string($config['site']['logo']) && (strlen($config['site']['logo']) > 0))
196 || file_exists(theme_file('logo.png')))
198 $this->element('img', array('class' => 'logo photo',
199 'src' => isset($config['site']['logo']) ?
200 ($config['site']['logo']) : theme_path('logo.png'),
201 'alt' => $config['site']['name']);
203 $this->element('span', array('class' => 'fn org'), $config['site']['name']));
204 $this->elementEnd('a');
205 $this->elementEnd('address');
208 function showPrimaryNav()
210 $user = common_current_user();
211 $this->elementStart('ul', array('id' => 'nav'));
213 common_menu_item(common_local_url('all', array('nickname' => $user->nickname)),
216 common_menu_item(common_local_url('peoplesearch'), _('Search'));
218 common_menu_item(common_local_url('profilesettings'),
220 common_menu_item(common_local_url('invite'),
222 common_menu_item(common_local_url('logout'),
225 common_menu_item(common_local_url('login'), _('Login'));
226 if (!common_config('site', 'closed')) {
227 common_menu_item(common_local_url('register'), _('Register'));
229 common_menu_item(common_local_url('openidlogin'), _('OpenID'));
231 common_menu_item(common_local_url('doc', array('title' => 'help')),
233 $this->elementEnd('ul');
236 function showSiteNotice()
238 // show the site notice here
241 // MAY overload if no notice form needed... or direct message box????
243 function showNoticeForm()
245 // show the notice form here
251 $this->showLocalNav();
252 $this->showContentBlock();
259 function showLocalNav()
263 function showContentBlock()
265 $this->showPageTitle();
266 $this->showPageNotice();
267 $this->showContent();
270 function showPageTitle() {
271 $this->element('h1', NULL, $this->title());
274 // SHOULD overload (unless there's not a notice)
276 function showPageNotice()
278 // output page notice div
283 function showContent()
285 // show the actual content (forms, lists, whatever)
290 $this->showExportData();
291 $this->showSections();
294 // MAY overload if there are feeds
296 function showExportData()
298 // is there structure to this?
299 // list of (visible!) feed links
300 // can we reuse list of feeds from showFeeds() ?
305 function showSections() {
306 // for each section, show it
309 function showFooter()
312 $this->showSecondaryNav();
313 $this->showLicenses();
316 function showSecondaryNav()
318 $this->elementStart('ul', array('id' => 'nav_sub'));
319 common_menu_item(common_local_url('doc', array('title' => 'help')),
321 common_menu_item(common_local_url('doc', array('title' => 'about')),
323 common_menu_item(common_local_url('doc', array('title' => 'faq')),
325 common_menu_item(common_local_url('doc', array('title' => 'privacy')),
327 common_menu_item(common_local_url('doc', array('title' => 'source')),
329 common_menu_item(common_local_url('doc', array('title' => 'contact')),
331 $this->elementEnd('ul');
334 function showLicenses()
337 $this->showLaconicaLicense();
338 $this->showContentLicense();
342 function showLaconicaLicense()
344 $this->elementStart('div', 'laconica');
345 if (common_config('site', 'broughtby')) {
346 $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
348 $instr = _('**%%site.name%%** is a microblogging service. ');
350 $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION);
351 $output = common_markup_to_html($instr);
353 $this->elementEnd('div');
357 function showContentLicense()
359 $this->elementStart('div', array('id' => 'footer'));
360 $this->element('img', array('id' => 'cc',
361 'src' => $config['license']['image'],
362 'alt' => $config['license']['title']));
363 $this->elementStart('p');
364 common_text(_('Unless otherwise specified, contents of this site are copyright by the contributors and available under the '));
365 $this->element('a', array('class' => 'license',
367 'href' => $config['license']['url']),
368 $config['license']['title']);
369 common_text(_('. Contributors should be attributed by full name or nickname.'));
370 $this->elementEnd('p');
371 $this->elementEnd('div');
374 // For comparison with If-Last-Modified
375 // If not applicable, return null
377 function last_modified()
387 function is_readonly()
392 function arg($key, $def=null)
394 if (array_key_exists($key, $this->args)) {
395 return $this->args[$key];
401 function trimmed($key, $def=null)
403 $arg = $this->arg($key, $def);
404 return (is_string($arg)) ? trim($arg) : $arg;
407 // Note: argarray ignored, since it's now passed in in prepare()
409 function handle($argarray=null)
412 $lm = $this->last_modified();
413 $etag = $this->etag();
416 header('ETag: ' . $etag);
420 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
421 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
422 if ($if_modified_since) {
423 $ims = strtotime($if_modified_since);
426 $this->_has_etag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) {
427 header('HTTP/1.1 304 Not Modified');
428 // Better way to do this?
436 function _has_etag($etag, $if_none_match)
438 return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
441 function boolean($key, $def=false)
443 $arg = strtolower($this->trimmed($key));
447 } else if (in_array($arg, array('true', 'yes', '1'))) {
449 } else if (in_array($arg, array('false', 'no', '0'))) {
456 function server_error($msg, $code=500)
458 $action = $this->trimmed('action');
459 common_debug("Server error '$code' on '$action': $msg", __FILE__);
460 common_server_error($msg, $code);
463 function client_error($msg, $code=400)
465 $action = $this->trimmed('action');
466 common_debug("User error '$code' on '$action': $msg", __FILE__);
467 common_user_error($msg, $code);
472 $action = $this->trimmed('action');
474 unset($args['action']);
475 foreach (array_keys($_COOKIE) as $cookie) {
476 unset($args[$cookie]);
478 return common_local_url($action, $args);
481 function nav_menu($menu)
483 $action = $this->trimmed('action');
484 $this->elementStart('ul', array('id' => 'nav_views'));
485 foreach ($menu as $menuaction => $menudesc) {
486 common_menu_item(common_local_url($menuaction,
487 isset($menudesc[2]) ? $menudesc[2] : null),
490 $action == $menuaction);
492 $this->elementEnd('ul');
495 function common_show_header($pagetitle, $callable=null, $data=null, $headercall=null)
498 global $action; /* XXX: kind of cheating here. */
502 $this->elementStart('head');
506 call_user_func($callable, $data);
508 call_user_func($callable);
511 $this->elementEnd('head');
512 $this->elementStart('body', $action);
513 $this->elementStart('div', array('id' => 'wrap'));
514 $this->elementStart('div', array('id' => 'header'));
517 $this->element('h1', 'pagetitle', $pagetitle);
521 call_user_func($headercall, $data);
523 call_user_func($headercall);
526 $this->elementEnd('div');
527 $this->elementStart('div', array('id' => 'content'));
530 function common_show_footer()
533 $this->elementEnd('div'); // content div
535 $this->elementEnd('div');
536 $this->elementEnd('body');
537 $this->elementEnd('html');
541 function common_menu_item($url, $text, $title=null, $is_selected=false)
545 $lattrs['class'] = 'current';
547 $this->elementStart('li', $lattrs);
548 $attrs['href'] = $url;
550 $attrs['title'] = $title;
552 $this->element('a', $attrs, $text);
553 $this->elementEnd('li');
556 // Does a little before-after block for next/prev page
558 function pagination($have_before, $have_after, $page, $action, $args=null)
560 if ($have_before || $have_after) {
561 $this->elementStart('div', array('id' => 'pagination'));
562 $this->elementStart('ul', array('id' => 'nav_pagination'));
566 $pargs = array('page' => $page-1);
567 $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
569 $this->elementStart('li', 'before');
570 $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'),
572 $this->elementEnd('li');
576 $pargs = array('page' => $page+1);
577 $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
578 $this->elementStart('li', 'after');
579 $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'),
581 $this->elementEnd('li');
584 if ($have_before || $have_after) {
585 $this->elementEnd('ul');
586 $this->elementEnd('div');