3 * StatusNet, 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@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/noticeform.php';
36 require_once INSTALLDIR.'/lib/htmloutputter.php';
39 * Base class for all actions
41 * This is the base class for all actions in the package. An action is
42 * more or less a "view" in an MVC framework.
44 * Actions are responsible for extracting and validating parameters; using
45 * model classes to read and write to the database; and doing ouput.
49 * @author Evan Prodromou <evan@status.net>
50 * @author Sarven Capadisli <csarven@status.net>
51 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52 * @link http://status.net/
56 class Action extends HTMLOutputter // lawsuit
63 * Just wraps the HTMLOutputter constructor.
65 * @param string $output URI to output to, default = stdout
66 * @param boolean $indent Whether to indent output, default true
68 * @see XMLOutputter::__construct
69 * @see HTMLOutputter::__construct
71 function __construct($output='php://output', $indent=null)
73 parent::__construct($output, $indent);
77 * For initializing members of the class.
79 * @param array $argarray misc. arguments
81 * @return boolean true
83 function prepare($argarray)
85 $this->args =& common_copy_args($argarray);
90 * Show page, a template method.
96 if (Event::handle('StartShowHTML', array($this))) {
98 Event::handle('EndShowHTML', array($this));
100 if (Event::handle('StartShowHead', array($this))) {
102 Event::handle('EndShowHead', array($this));
104 if (Event::handle('StartShowBody', array($this))) {
106 Event::handle('EndShowBody', array($this));
108 if (Event::handle('StartEndHTML', array($this))) {
110 Event::handle('EndEndHTML', array($this));
115 * Show head, a template method.
121 // XXX: attributes (profile?)
122 $this->elementStart('head');
123 if (Event::handle('StartShowHeadElements', array($this))) {
125 $this->showShortcutIcon();
126 $this->showStylesheets();
127 $this->showOpenSearch();
129 $this->showDescription();
131 Event::handle('EndShowHeadElements', array($this));
133 $this->elementEnd('head');
137 * Show title, a template method.
143 $this->element('title', null,
144 sprintf(_("%1\$s - %2\$s"),
146 common_config('site', 'name')));
150 * Returns the page title
154 * @return string page title
159 return _("Untitled page");
163 * Show themed shortcut icon
167 function showShortcutIcon()
169 if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
170 $this->element('link', array('rel' => 'shortcut icon',
171 'href' => Theme::path('favicon.ico')));
173 $this->element('link', array('rel' => 'shortcut icon',
174 'href' => common_path('favicon.ico')));
177 if (common_config('site', 'mobile')) {
178 if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
179 $this->element('link', array('rel' => 'apple-touch-icon',
180 'href' => Theme::path('apple-touch-icon.png')));
182 $this->element('link', array('rel' => 'apple-touch-icon',
183 'href' => common_path('apple-touch-icon.png')));
193 function showStylesheets()
195 if (Event::handle('StartShowStyles', array($this))) {
197 // Use old name for StatusNet for compatibility on events
199 if (Event::handle('StartShowStatusNetStyles', array($this)) &&
200 Event::handle('StartShowLaconicaStyles', array($this))) {
201 $this->cssLink('css/display.css',null, 'screen, projection, tv, print');
202 Event::handle('EndShowStatusNetStyles', array($this));
203 Event::handle('EndShowLaconicaStyles', array($this));
206 if (Event::handle('StartShowUAStyles', array($this))) {
207 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
208 'href="'.Theme::path('css/ie.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
209 foreach (array(6,7) as $ver) {
210 if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
211 // Yes, IE people should be put in jail.
212 $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
213 'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
216 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
217 'href="'.Theme::path('css/ie.css', null).'?version='.STATUSNET_VERSION.'" /><![endif]');
218 Event::handle('EndShowUAStyles', array($this));
221 if (Event::handle('StartShowDesign', array($this))) {
223 $user = common_current_user();
225 if (empty($user) || $user->viewdesigns) {
226 $design = $this->getDesign();
228 if (!empty($design)) {
229 $design->showCSS($this);
233 Event::handle('EndShowDesign', array($this));
235 Event::handle('EndShowStyles', array($this));
240 * Show javascript headers
244 function showScripts()
246 if (Event::handle('StartShowScripts', array($this))) {
247 if (Event::handle('StartShowJQueryScripts', array($this))) {
248 $this->script('jquery.min.js');
249 $this->script('jquery.form.js');
250 $this->script('jquery.cookie.js');
251 $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }');
252 $this->script('jquery.joverlay.min.js');
253 Event::handle('EndShowJQueryScripts', array($this));
255 if (Event::handle('StartShowStatusNetScripts', array($this)) &&
256 Event::handle('StartShowLaconicaScripts', array($this))) {
257 $this->script('xbImportNode.js');
258 $this->script('util.js');
259 $this->script('geometa.js');
260 // Frame-busting code to avoid clickjacking attacks.
261 $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
262 Event::handle('EndShowStatusNetScripts', array($this));
263 Event::handle('EndShowLaconicaScripts', array($this));
265 Event::handle('EndShowScripts', array($this));
270 * Show OpenSearch headers
274 function showOpenSearch()
276 $this->element('link', array('rel' => 'search',
277 'type' => 'application/opensearchdescription+xml',
278 'href' => common_local_url('opensearch', array('type' => 'people')),
279 'title' => common_config('site', 'name').' People Search'));
280 $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
281 'href' => common_local_url('opensearch', array('type' => 'notice')),
282 'title' => common_config('site', 'name').' Notice Search'));
295 $feeds = $this->getFeeds();
298 foreach ($feeds as $feed) {
299 $this->element('link', array('rel' => $feed->rel(),
300 'href' => $feed->url,
301 'type' => $feed->mimeType(),
302 'title' => $feed->title));
314 function showDescription()
316 // does nothing by default
320 * Show extra stuff in <head>.
328 // does nothing by default
334 * Calls template methods
340 $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'),
341 'class' => 'user_in')
342 : array('id' => $this->trimmed('action')));
343 $this->elementStart('div', array('id' => 'wrap'));
344 if (Event::handle('StartShowHeader', array($this))) {
346 Event::handle('EndShowHeader', array($this));
349 if (Event::handle('StartShowFooter', array($this))) {
351 Event::handle('EndShowFooter', array($this));
353 $this->elementEnd('div');
354 $this->showScripts();
355 $this->elementEnd('body');
359 * Show header of the page.
361 * Calls template methods
365 function showHeader()
367 $this->elementStart('div', array('id' => 'header'));
369 $this->showPrimaryNav();
370 if (Event::handle('StartShowSiteNotice', array($this))) {
371 $this->showSiteNotice();
373 Event::handle('EndShowSiteNotice', array($this));
375 if (common_logged_in()) {
376 $this->showNoticeForm();
378 $this->showAnonymousMessage();
380 $this->elementEnd('div');
384 * Show configured logo.
390 $this->elementStart('address', array('id' => 'site_contact',
391 'class' => 'vcard'));
392 if (Event::handle('StartAddressData', array($this))) {
393 if (common_config('singleuser', 'enabled')) {
394 $url = common_local_url('showstream',
395 array('nickname' => common_config('singleuser', 'nickname')));
397 $url = common_local_url('public');
399 $this->elementStart('a', array('class' => 'url home bookmark',
401 if (common_config('site', 'logo') || file_exists(Theme::file('logo.png'))) {
402 $this->element('img', array('class' => 'logo photo',
403 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'),
404 'alt' => common_config('site', 'name')));
407 $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
408 $this->elementEnd('a');
409 Event::handle('EndAddressData', array($this));
411 $this->elementEnd('address');
415 * Show primary navigation.
419 function showPrimaryNav()
421 $user = common_current_user();
422 $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
423 $this->element('dt', null, _('Primary site navigation'));
424 $this->elementStart('dd');
425 $this->elementStart('ul', array('class' => 'nav'));
426 if (Event::handle('StartPrimaryNav', array($this))) {
428 // TRANS: Tooltip for main menu option "Personal"
429 $tooltip = _m('TOOLTIP', 'Personal profile and friends timeline');
430 // TRANS: Main menu option when logged in for access to personal profile and friends timeline
431 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
432 _m('MENU', 'Personal'), $tooltip, false, 'nav_home');
433 // TRANS: Tooltip for main menu option "Account"
434 $tooltip = _m('TOOLTIP', 'Change your email, avatar, password, profile');
435 // TRANS: Main menu option when logged in for access to user settings
436 $this->menuItem(common_local_url('profilesettings'),
437 _('Account'), $tooltip, false, 'nav_account');
438 // TRANS: Tooltip for main menu option "Services"
439 $tooltip = _m('TOOLTIP', 'Connect to services');
440 // TRANS: Main menu option when logged in and connection are possible for access to options to connect to other services
441 $this->menuItem(common_local_url('oauthconnectionssettings'),
442 _('Connect'), $tooltip, false, 'nav_connect');
443 if ($user->hasRight(Right::CONFIGURESITE)) {
444 // TRANS: Tooltip for menu option "Admin"
445 $tooltip = _m('TOOLTIP', 'Change site configuration');
446 // TRANS: Main menu option when logged in and site admin for access to site configuration
447 $this->menuItem(common_local_url('siteadminpanel'),
448 _m('MENU', 'Admin'), $tooltip, false, 'nav_admin');
450 if (common_config('invite', 'enabled')) {
451 // TRANS: Tooltip for main menu option "Invite"
452 $tooltip = _m('TOOLTIP', 'Invite friends and colleagues to join you on %s');
453 // TRANS: Main menu option when logged in and invitations are allowed for inviting new users
454 $this->menuItem(common_local_url('invite'),
455 _m('MENU', 'Invite'),
457 common_config('site', 'name')),
458 false, 'nav_invitecontact');
460 // TRANS: Tooltip for main menu option "Logout"
461 $tooltip = _m('TOOLTIP', 'Logout from the site');
462 // TRANS: Main menu option when logged in to log out the current user
463 $this->menuItem(common_local_url('logout'),
464 _m('MENU', 'Logout'), $tooltip, false, 'nav_logout');
467 if (!common_config('site', 'closed')) {
468 // TRANS: Tooltip for main menu option "Register"
469 $tooltip = _m('TOOLTIP', 'Create an account');
470 // TRANS: Main menu option when not logged in to register a new account
471 $this->menuItem(common_local_url('register'),
472 _m('MENU', 'Register'), $tooltip, false, 'nav_register');
474 // TRANS: Tooltip for main menu option "Login"
475 $tooltip = _m('TOOLTIP', 'Login to the site');
476 // TRANS: Main menu option when not logged in to log in
477 $this->menuItem(common_local_url('login'),
478 _m('MENU', 'Login'), $tooltip, false, 'nav_login');
480 // TRANS: Tooltip for main menu option "Help"
481 $tooltip = _m('TOOLTIP', 'Help me!');
482 // TRANS: Main menu option for help on the StatusNet site
483 $this->menuItem(common_local_url('doc', array('title' => 'help')),
484 _m('MENU', 'Help'), $tooltip, false, 'nav_help');
485 if ($user || !common_config('site', 'private')) {
486 // TRANS: Tooltip for main menu option "Search"
487 $tooltip = _m('TOOLTIP', 'Search for people or text');
488 // TRANS: Main menu option when logged in or when the StatusNet instance is not private
489 $this->menuItem(common_local_url('peoplesearch'),
490 _m('MENU', 'Search'), $tooltip, false, 'nav_search');
492 Event::handle('EndPrimaryNav', array($this));
494 $this->elementEnd('ul');
495 $this->elementEnd('dd');
496 $this->elementEnd('dl');
504 function showSiteNotice()
506 // Revist. Should probably do an hAtom pattern here
507 $text = common_config('site', 'notice');
509 $this->elementStart('dl', array('id' => 'site_notice',
510 'class' => 'system_notice'));
511 // TRANS: DT element for site notice. String is hidden in default CSS.
512 $this->element('dt', null, _('Site notice'));
513 $this->elementStart('dd', null);
515 $this->elementEnd('dd');
516 $this->elementEnd('dl');
523 * MAY overload if no notice form needed... or direct message box????
527 function showNoticeForm()
529 $notice_form = new NoticeForm($this);
530 $notice_form->show();
534 * Show anonymous message.
540 function showAnonymousMessage()
542 // needs to be defined by the class
548 * Shows local navigation, content block and aside.
554 $this->elementStart('div', array('id' => 'core'));
555 if (Event::handle('StartShowLocalNavBlock', array($this))) {
556 $this->showLocalNavBlock();
557 Event::handle('EndShowLocalNavBlock', array($this));
559 if (Event::handle('StartShowContentBlock', array($this))) {
560 $this->showContentBlock();
561 Event::handle('EndShowContentBlock', array($this));
563 if (Event::handle('StartShowAside', array($this))) {
565 Event::handle('EndShowAside', array($this));
567 $this->elementEnd('div');
571 * Show local navigation block.
575 function showLocalNavBlock()
577 $this->elementStart('dl', array('id' => 'site_nav_local_views'));
578 $this->element('dt', null, _('Local views'));
579 $this->elementStart('dd');
580 $this->showLocalNav();
581 $this->elementEnd('dd');
582 $this->elementEnd('dl');
586 * Show local navigation.
592 function showLocalNav()
594 // does nothing by default
598 * Show content block.
602 function showContentBlock()
604 $this->elementStart('div', array('id' => 'content'));
605 $this->showPageTitle();
606 $this->showPageNoticeBlock();
607 $this->elementStart('div', array('id' => 'content_inner'));
608 // show the actual content (forms, lists, whatever)
609 $this->showContent();
610 $this->elementEnd('div');
611 $this->elementEnd('div');
619 function showPageTitle()
621 $this->element('h1', null, $this->title());
625 * Show page notice block.
627 * Only show the block if a subclassed action has overrided
628 * Action::showPageNotice(), or an event handler is registered for
629 * the StartShowPageNotice event, in which case we assume the
630 * 'page_notice' definition list is desired. This is to prevent
631 * empty 'page_notice' definition lists from being output everywhere.
635 function showPageNoticeBlock()
637 $rmethod = new ReflectionMethod($this, 'showPageNotice');
638 $dclass = $rmethod->getDeclaringClass()->getName();
640 if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
642 $this->elementStart('dl', array('id' => 'page_notice',
643 'class' => 'system_notice'));
644 $this->element('dt', null, _('Page notice'));
645 $this->elementStart('dd');
646 if (Event::handle('StartShowPageNotice', array($this))) {
647 $this->showPageNotice();
648 Event::handle('EndShowPageNotice', array($this));
650 $this->elementEnd('dd');
651 $this->elementEnd('dl');
658 * SHOULD overload (unless there's not a notice)
662 function showPageNotice()
669 * MUST overload (unless there's not a notice)
673 function showContent()
685 $this->elementStart('div', array('id' => 'aside_primary',
686 'class' => 'aside'));
687 if (Event::handle('StartShowExportData', array($this))) {
688 $this->showExportData();
689 Event::handle('EndShowExportData', array($this));
691 if (Event::handle('StartShowSections', array($this))) {
692 $this->showSections();
693 Event::handle('EndShowSections', array($this));
695 $this->elementEnd('div');
699 * Show export data feeds.
704 function showExportData()
706 $feeds = $this->getFeeds();
708 $fl = new FeedList($this);
720 function showSections()
722 // for each section, show it
730 function showFooter()
732 $this->elementStart('div', array('id' => 'footer'));
733 $this->showSecondaryNav();
734 $this->showLicenses();
735 $this->elementEnd('div');
739 * Show secondary navigation.
743 function showSecondaryNav()
745 $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
746 $this->element('dt', null, _('Secondary site navigation'));
747 $this->elementStart('dd', null);
748 $this->elementStart('ul', array('class' => 'nav'));
749 if (Event::handle('StartSecondaryNav', array($this))) {
750 $this->menuItem(common_local_url('doc', array('title' => 'help')),
752 $this->menuItem(common_local_url('doc', array('title' => 'about')),
754 $this->menuItem(common_local_url('doc', array('title' => 'faq')),
756 $bb = common_config('site', 'broughtby');
758 $this->menuItem(common_local_url('doc', array('title' => 'tos')),
761 $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
763 $this->menuItem(common_local_url('doc', array('title' => 'source')),
765 $this->menuItem(common_local_url('version'),
767 $this->menuItem(common_local_url('doc', array('title' => 'contact')),
769 $this->menuItem(common_local_url('doc', array('title' => 'badge')),
771 Event::handle('EndSecondaryNav', array($this));
773 $this->elementEnd('ul');
774 $this->elementEnd('dd');
775 $this->elementEnd('dl');
783 function showLicenses()
785 $this->elementStart('dl', array('id' => 'licenses'));
786 $this->showStatusNetLicense();
787 $this->showContentLicense();
788 $this->elementEnd('dl');
792 * Show StatusNet license.
796 function showStatusNetLicense()
798 $this->element('dt', array('id' => 'site_statusnet_license'), _('StatusNet software license'));
799 $this->elementStart('dd', null);
800 // @fixme drop the final spaces in the messages when at good spot
801 // to let translations get updated.
802 if (common_config('site', 'broughtby')) {
803 $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
805 $instr = _('**%%site.name%%** is a microblogging service. ');
808 $instr .= sprintf(_('It runs the [StatusNet](http://status.net/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), STATUSNET_VERSION);
809 $output = common_markup_to_html($instr);
811 $this->elementEnd('dd');
816 * Show content license.
820 function showContentLicense()
822 if (Event::handle('StartShowContentLicense', array($this))) {
823 $this->element('dt', array('id' => 'site_content_license'), _('Site content license'));
824 $this->elementStart('dd', array('id' => 'site_content_license_cc'));
826 switch (common_config('license', 'type')) {
828 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
829 common_config('site', 'name')));
831 case 'allrightsreserved':
832 if (common_config('license', 'owner')) {
833 $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
834 common_config('license', 'owner')));
836 $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
839 case 'cc': // fall through
841 $this->elementStart('p');
842 $this->element('img', array('id' => 'license_cc',
843 'src' => common_config('license', 'image'),
844 'alt' => common_config('license', 'title'),
848 //TODO: This is dirty: i18n
849 $this->text(_('All '.common_config('site', 'name').' content and data are available under the '));
850 $this->element('a', array('class' => 'license',
851 'rel' => 'external license',
852 'href' => common_config('license', 'url')),
853 common_config('license', 'title'));
855 $this->text(_('license.'));
856 $this->elementEnd('p');
860 $this->elementEnd('dd');
861 Event::handle('EndShowContentLicense', array($this));
866 * Return last modified, if applicable.
870 * @return string last modified http header
872 function lastModified()
874 // For comparison with If-Last-Modified
875 // If not applicable, return null
880 * Return etag, if applicable.
884 * @return string etag http header
892 * Return true if read only.
896 * @param array $args other arguments
898 * @return boolean is read only action?
901 function isReadOnly($args)
907 * Returns query argument or default value if not found
909 * @param string $key requested argument
910 * @param string $def default value to return if $key is not provided
912 * @return boolean is read only action?
914 function arg($key, $def=null)
916 if (array_key_exists($key, $this->args)) {
917 return $this->args[$key];
924 * Returns trimmed query argument or default value if not found
926 * @param string $key requested argument
927 * @param string $def default value to return if $key is not provided
929 * @return boolean is read only action?
931 function trimmed($key, $def=null)
933 $arg = $this->arg($key, $def);
934 return is_string($arg) ? trim($arg) : $arg;
940 * @param array $argarray is ignored since it's now passed in in prepare()
942 * @return boolean is read only action?
944 function handle($argarray=null)
946 header('Vary: Accept-Encoding,Cookie');
947 $lm = $this->lastModified();
948 $etag = $this->etag();
950 header('ETag: ' . $etag);
953 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
954 if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
955 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
956 $ims = strtotime($if_modified_since);
958 $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
959 $_SERVER['HTTP_IF_NONE_MATCH'] : null;
960 if (!$if_none_match ||
962 $this->_hasEtag($etag, $if_none_match)) {
963 header('HTTP/1.1 304 Not Modified');
964 // Better way to do this?
973 * Has etag? (private)
975 * @param string $etag etag http header
976 * @param string $if_none_match ifNoneMatch http header
981 function _hasEtag($etag, $if_none_match)
983 $etags = explode(',', $if_none_match);
984 return in_array($etag, $etags) || in_array('*', $etags);
988 * Boolean understands english (yes, no, true, false)
990 * @param string $key query key we're interested in
991 * @param string $def default value
993 * @return boolean interprets yes/no strings as boolean
995 function boolean($key, $def=false)
997 $arg = strtolower($this->trimmed($key));
1001 } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1003 } else if (in_array($arg, array('false', 'no', '0'))) {
1011 * Integer value of an argument
1013 * @param string $key query key we're interested in
1014 * @param string $defValue optional default value (default null)
1015 * @param string $maxValue optional max value (default null)
1016 * @param string $minValue optional min value (default null)
1018 * @return integer integer value
1021 function int($key, $defValue=null, $maxValue=null, $minValue=null)
1023 $arg = strtolower($this->trimmed($key));
1025 if (is_null($arg) || !is_integer($arg)) {
1029 if (!is_null($maxValue)) {
1030 $arg = min($arg, $maxValue);
1033 if (!is_null($minValue)) {
1034 $arg = max($arg, $minValue);
1043 * @param string $msg error message to display
1044 * @param integer $code http error code, 500 by default
1049 function serverError($msg, $code=500)
1051 $action = $this->trimmed('action');
1052 common_debug("Server error '$code' on '$action': $msg", __FILE__);
1053 throw new ServerException($msg, $code);
1059 * @param string $msg error message to display
1060 * @param integer $code http error code, 400 by default
1065 function clientError($msg, $code=400)
1067 $action = $this->trimmed('action');
1068 common_debug("User error '$code' on '$action': $msg", __FILE__);
1069 throw new ClientException($msg, $code);
1073 * Returns the current URL
1075 * @return string current URL
1080 list($action, $args) = $this->returnToArgs();
1081 return common_local_url($action, $args);
1085 * Returns arguments sufficient for re-constructing URL
1087 * @return array two elements: action, other args
1090 function returnToArgs()
1092 $action = $this->trimmed('action');
1093 $args = $this->args;
1094 unset($args['action']);
1095 if (common_config('site', 'fancy')) {
1098 if (array_key_exists('submit', $args)) {
1099 unset($args['submit']);
1101 foreach (array_keys($_COOKIE) as $cookie) {
1102 unset($args[$cookie]);
1104 return array($action, $args);
1108 * Generate a menu item
1110 * @param string $url menu URL
1111 * @param string $text menu name
1112 * @param string $title title attribute, null by default
1113 * @param boolean $is_selected current menu item, false by default
1114 * @param string $id element id, null by default
1118 function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
1120 // Added @id to li for some control.
1121 // XXX: We might want to move this to htmloutputter.php
1124 $lattrs['class'] = 'current';
1127 (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
1129 $this->elementStart('li', $lattrs);
1130 $attrs['href'] = $url;
1132 $attrs['title'] = $title;
1134 $this->element('a', $attrs, $text);
1135 $this->elementEnd('li');
1139 * Generate pagination links
1141 * @param boolean $have_before is there something before?
1142 * @param boolean $have_after is there something after?
1143 * @param integer $page current page
1144 * @param string $action current action
1145 * @param array $args rest of query arguments
1149 function pagination($have_before, $have_after, $page, $action, $args=null)
1151 // Does a little before-after block for next/prev page
1152 if ($have_before || $have_after) {
1153 $this->elementStart('dl', 'pagination');
1154 $this->element('dt', null, _('Pagination'));
1155 $this->elementStart('dd', null);
1156 $this->elementStart('ul', array('class' => 'nav'));
1159 $pargs = array('page' => $page-1);
1160 $this->elementStart('li', array('class' => 'nav_prev'));
1161 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1164 $this->elementEnd('li');
1167 $pargs = array('page' => $page+1);
1168 $this->elementStart('li', array('class' => 'nav_next'));
1169 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1172 $this->elementEnd('li');
1174 if ($have_before || $have_after) {
1175 $this->elementEnd('ul');
1176 $this->elementEnd('dd');
1177 $this->elementEnd('dl');
1182 * An array of feeds for this action.
1184 * Returns an array of potential feeds for this action.
1186 * @return array Feed object to show in head and links
1195 * A design for this action
1197 * @return Design a design object to use
1200 function getDesign()
1202 return Design::siteDesign();
1206 * Check the session token.
1208 * Checks that the current form has the correct session token,
1209 * and throw an exception if it does not.
1214 function checkSessionToken()
1217 $token = $this->trimmed('token');
1218 if (empty($token) || $token != common_session_token()) {
1219 $this->clientError(_('There was a problem with your session token.'));