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 // TRANS: license message in footer. %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration.
849 $notice = _('All %1$s content and data are available under the %2$s license.');
850 $link = "<a class=\"license\" rel=\"external license\" href=\"" .
851 htmlspecialchars(common_config('license', 'url')) .
853 htmlspecialchars(common_config('license', 'title')) .
855 $this->raw(sprintf(htmlspecialchars($notice),
856 htmlspecialchars(common_config('site', 'name')),
858 $this->elementEnd('p');
862 $this->elementEnd('dd');
863 Event::handle('EndShowContentLicense', array($this));
868 * Return last modified, if applicable.
872 * @return string last modified http header
874 function lastModified()
876 // For comparison with If-Last-Modified
877 // If not applicable, return null
882 * Return etag, if applicable.
886 * @return string etag http header
894 * Return true if read only.
898 * @param array $args other arguments
900 * @return boolean is read only action?
903 function isReadOnly($args)
909 * Returns query argument or default value if not found
911 * @param string $key requested argument
912 * @param string $def default value to return if $key is not provided
914 * @return boolean is read only action?
916 function arg($key, $def=null)
918 if (array_key_exists($key, $this->args)) {
919 return $this->args[$key];
926 * Returns trimmed query argument or default value if not found
928 * @param string $key requested argument
929 * @param string $def default value to return if $key is not provided
931 * @return boolean is read only action?
933 function trimmed($key, $def=null)
935 $arg = $this->arg($key, $def);
936 return is_string($arg) ? trim($arg) : $arg;
942 * @param array $argarray is ignored since it's now passed in in prepare()
944 * @return boolean is read only action?
946 function handle($argarray=null)
948 header('Vary: Accept-Encoding,Cookie');
949 $lm = $this->lastModified();
950 $etag = $this->etag();
952 header('ETag: ' . $etag);
955 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
956 if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
957 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
958 $ims = strtotime($if_modified_since);
960 $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
961 $_SERVER['HTTP_IF_NONE_MATCH'] : null;
962 if (!$if_none_match ||
964 $this->_hasEtag($etag, $if_none_match)) {
965 header('HTTP/1.1 304 Not Modified');
966 // Better way to do this?
975 * Has etag? (private)
977 * @param string $etag etag http header
978 * @param string $if_none_match ifNoneMatch http header
983 function _hasEtag($etag, $if_none_match)
985 $etags = explode(',', $if_none_match);
986 return in_array($etag, $etags) || in_array('*', $etags);
990 * Boolean understands english (yes, no, true, false)
992 * @param string $key query key we're interested in
993 * @param string $def default value
995 * @return boolean interprets yes/no strings as boolean
997 function boolean($key, $def=false)
999 $arg = strtolower($this->trimmed($key));
1001 if (is_null($arg)) {
1003 } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1005 } else if (in_array($arg, array('false', 'no', '0'))) {
1013 * Integer value of an argument
1015 * @param string $key query key we're interested in
1016 * @param string $defValue optional default value (default null)
1017 * @param string $maxValue optional max value (default null)
1018 * @param string $minValue optional min value (default null)
1020 * @return integer integer value
1023 function int($key, $defValue=null, $maxValue=null, $minValue=null)
1025 $arg = strtolower($this->trimmed($key));
1027 if (is_null($arg) || !is_integer($arg)) {
1031 if (!is_null($maxValue)) {
1032 $arg = min($arg, $maxValue);
1035 if (!is_null($minValue)) {
1036 $arg = max($arg, $minValue);
1045 * @param string $msg error message to display
1046 * @param integer $code http error code, 500 by default
1051 function serverError($msg, $code=500)
1053 $action = $this->trimmed('action');
1054 common_debug("Server error '$code' on '$action': $msg", __FILE__);
1055 throw new ServerException($msg, $code);
1061 * @param string $msg error message to display
1062 * @param integer $code http error code, 400 by default
1067 function clientError($msg, $code=400)
1069 $action = $this->trimmed('action');
1070 common_debug("User error '$code' on '$action': $msg", __FILE__);
1071 throw new ClientException($msg, $code);
1075 * Returns the current URL
1077 * @return string current URL
1082 list($action, $args) = $this->returnToArgs();
1083 return common_local_url($action, $args);
1087 * Returns arguments sufficient for re-constructing URL
1089 * @return array two elements: action, other args
1092 function returnToArgs()
1094 $action = $this->trimmed('action');
1095 $args = $this->args;
1096 unset($args['action']);
1097 if (common_config('site', 'fancy')) {
1100 if (array_key_exists('submit', $args)) {
1101 unset($args['submit']);
1103 foreach (array_keys($_COOKIE) as $cookie) {
1104 unset($args[$cookie]);
1106 return array($action, $args);
1110 * Generate a menu item
1112 * @param string $url menu URL
1113 * @param string $text menu name
1114 * @param string $title title attribute, null by default
1115 * @param boolean $is_selected current menu item, false by default
1116 * @param string $id element id, null by default
1120 function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
1122 // Added @id to li for some control.
1123 // XXX: We might want to move this to htmloutputter.php
1126 $lattrs['class'] = 'current';
1129 (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
1131 $this->elementStart('li', $lattrs);
1132 $attrs['href'] = $url;
1134 $attrs['title'] = $title;
1136 $this->element('a', $attrs, $text);
1137 $this->elementEnd('li');
1141 * Generate pagination links
1143 * @param boolean $have_before is there something before?
1144 * @param boolean $have_after is there something after?
1145 * @param integer $page current page
1146 * @param string $action current action
1147 * @param array $args rest of query arguments
1151 function pagination($have_before, $have_after, $page, $action, $args=null)
1153 // Does a little before-after block for next/prev page
1154 if ($have_before || $have_after) {
1155 $this->elementStart('dl', 'pagination');
1156 $this->element('dt', null, _('Pagination'));
1157 $this->elementStart('dd', null);
1158 $this->elementStart('ul', array('class' => 'nav'));
1161 $pargs = array('page' => $page-1);
1162 $this->elementStart('li', array('class' => 'nav_prev'));
1163 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1166 $this->elementEnd('li');
1169 $pargs = array('page' => $page+1);
1170 $this->elementStart('li', array('class' => 'nav_next'));
1171 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1174 $this->elementEnd('li');
1176 if ($have_before || $have_after) {
1177 $this->elementEnd('ul');
1178 $this->elementEnd('dd');
1179 $this->elementEnd('dl');
1184 * An array of feeds for this action.
1186 * Returns an array of potential feeds for this action.
1188 * @return array Feed object to show in head and links
1197 * A design for this action
1199 * @return Design a design object to use
1202 function getDesign()
1204 return Design::siteDesign();
1208 * Check the session token.
1210 * Checks that the current form has the correct session token,
1211 * and throw an exception if it does not.
1216 function checkSessionToken()
1219 $token = $this->trimmed('token');
1220 if (empty($token) || $token != common_session_token()) {
1221 $this->clientError(_('There was a problem with your session token.'));