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 common_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 common_element('script', array('type' => 'text/javascript',
125 'src' => common_path('js/jquery.min.js')),
127 common_element('script', array('type' => 'text/javascript',
128 'src' => common_path('js/jquery.form.js')),
130 common_element('script', array('type' => 'text/javascript',
131 'src' => common_path('js/xbImportNode.js')),
133 common_element('script', array('type' => 'text/javascript',
134 'src' => common_path('js/util.js?version='.LACONICA_VERSION)),
138 function showOpenSearch()
140 common_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 common_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 // show the logo here
194 function showPrimaryNav()
196 $user = common_current_user();
197 common_element_start('ul', array('id' => 'nav'));
199 common_menu_item(common_local_url('all', array('nickname' => $user->nickname)),
202 common_menu_item(common_local_url('peoplesearch'), _('Search'));
204 common_menu_item(common_local_url('profilesettings'),
206 common_menu_item(common_local_url('invite'),
208 common_menu_item(common_local_url('logout'),
211 common_menu_item(common_local_url('login'), _('Login'));
212 if (!common_config('site', 'closed')) {
213 common_menu_item(common_local_url('register'), _('Register'));
215 common_menu_item(common_local_url('openidlogin'), _('OpenID'));
217 common_menu_item(common_local_url('doc', array('title' => 'help')),
219 common_element_end('ul');
222 function showSiteNotice()
224 // show the site notice here
227 // MAY overload if no notice form needed... or direct message box????
229 function showNoticeForm()
231 // show the notice form here
237 $this->showLocalNav();
238 $this->showContentBlock();
245 function showLocalNav()
249 function showContentBlock()
251 $this->showPageTitle();
252 $this->showPageNotice();
253 $this->showContent();
256 function showPageTitle() {
257 $this->element('h1', NULL, $this->title());
260 // SHOULD overload (unless there's not a notice)
262 function showPageNotice()
264 // output page notice div
269 function showContent()
271 // show the actual content (forms, lists, whatever)
276 $this->showExportData();
277 $this->showSections();
280 // MAY overload if there are feeds
282 function showExportData()
284 // is there structure to this?
285 // list of (visible!) feed links
286 // can we reuse list of feeds from showFeeds() ?
291 function showSections() {
292 // for each section, show it
295 function showFooter()
298 $this->showSecondaryNav();
299 $this->showLicenses();
302 function showSecondaryNav()
304 common_element_start('ul', array('id' => 'nav_sub'));
305 common_menu_item(common_local_url('doc', array('title' => 'help')),
307 common_menu_item(common_local_url('doc', array('title' => 'about')),
309 common_menu_item(common_local_url('doc', array('title' => 'faq')),
311 common_menu_item(common_local_url('doc', array('title' => 'privacy')),
313 common_menu_item(common_local_url('doc', array('title' => 'source')),
315 common_menu_item(common_local_url('doc', array('title' => 'contact')),
317 common_element_end('ul');
320 function showLicenses()
323 $this->showLaconicaLicense();
324 $this->showContentLicense();
328 function showLaconicaLicense()
330 common_element_start('div', 'laconica');
331 if (common_config('site', 'broughtby')) {
332 $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
334 $instr = _('**%%site.name%%** is a microblogging service. ');
336 $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);
337 $output = common_markup_to_html($instr);
339 common_element_end('div');
343 function showContentLicense()
345 common_element_start('div', array('id' => 'footer'));
346 common_element('img', array('id' => 'cc',
347 'src' => $config['license']['image'],
348 'alt' => $config['license']['title']));
349 common_element_start('p');
350 common_text(_('Unless otherwise specified, contents of this site are copyright by the contributors and available under the '));
351 common_element('a', array('class' => 'license',
353 'href' => $config['license']['url']),
354 $config['license']['title']);
355 common_text(_('. Contributors should be attributed by full name or nickname.'));
356 common_element_end('p');
357 common_element_end('div');
360 // For comparison with If-Last-Modified
361 // If not applicable, return null
363 function last_modified()
373 function is_readonly()
378 function arg($key, $def=null)
380 if (array_key_exists($key, $this->args)) {
381 return $this->args[$key];
387 function trimmed($key, $def=null)
389 $arg = $this->arg($key, $def);
390 return (is_string($arg)) ? trim($arg) : $arg;
393 // Note: argarray ignored, since it's now passed in in prepare()
395 function handle($argarray=null)
398 $lm = $this->last_modified();
399 $etag = $this->etag();
402 header('ETag: ' . $etag);
406 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
407 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
408 if ($if_modified_since) {
409 $ims = strtotime($if_modified_since);
412 $this->_has_etag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) {
413 header('HTTP/1.1 304 Not Modified');
414 // Better way to do this?
422 function _has_etag($etag, $if_none_match)
424 return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
427 function boolean($key, $def=false)
429 $arg = strtolower($this->trimmed($key));
433 } else if (in_array($arg, array('true', 'yes', '1'))) {
435 } else if (in_array($arg, array('false', 'no', '0'))) {
442 function server_error($msg, $code=500)
444 $action = $this->trimmed('action');
445 common_debug("Server error '$code' on '$action': $msg", __FILE__);
446 common_server_error($msg, $code);
449 function client_error($msg, $code=400)
451 $action = $this->trimmed('action');
452 common_debug("User error '$code' on '$action': $msg", __FILE__);
453 common_user_error($msg, $code);
458 $action = $this->trimmed('action');
460 unset($args['action']);
461 foreach (array_keys($_COOKIE) as $cookie) {
462 unset($args[$cookie]);
464 return common_local_url($action, $args);
467 function nav_menu($menu)
469 $action = $this->trimmed('action');
470 common_element_start('ul', array('id' => 'nav_views'));
471 foreach ($menu as $menuaction => $menudesc) {
472 common_menu_item(common_local_url($menuaction,
473 isset($menudesc[2]) ? $menudesc[2] : null),
476 $action == $menuaction);
478 common_element_end('ul');
481 function common_show_header($pagetitle, $callable=null, $data=null, $headercall=null)
484 global $action; /* XXX: kind of cheating here. */
488 common_element_start('head');
492 call_user_func($callable, $data);
494 call_user_func($callable);
497 common_element_end('head');
498 common_element_start('body', $action);
499 common_element_start('div', array('id' => 'wrap'));
500 common_element_start('div', array('id' => 'header'));
502 if ((isset($config['site']['logo']) && is_string($config['site']['logo']) && (strlen($config['site']['logo']) > 0))
503 || file_exists(theme_file('logo.png')))
505 common_element_start('a', array('href' => common_local_url('public')));
506 common_element('img', array('src' => isset($config['site']['logo']) ?
507 ($config['site']['logo']) : theme_path('logo.png'),
508 'alt' => $config['site']['name'],
510 common_element_end('a');
512 common_element_start('p', array('id' => 'branding'));
513 common_element('a', array('href' => common_local_url('public')),
514 $config['site']['name']);
515 common_element_end('p');
518 common_element('h1', 'pagetitle', $pagetitle);
522 call_user_func($headercall, $data);
524 call_user_func($headercall);
527 common_element_end('div');
528 common_element_start('div', array('id' => 'content'));
531 function common_show_footer()
534 common_element_end('div'); // content div
536 common_element_end('div');
537 common_element_end('body');
538 common_element_end('html');
542 function common_menu_item($url, $text, $title=null, $is_selected=false)
546 $lattrs['class'] = 'current';
548 common_element_start('li', $lattrs);
549 $attrs['href'] = $url;
551 $attrs['title'] = $title;
553 common_element('a', $attrs, $text);
554 common_element_end('li');