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 // TRANS: Page title. %1$s is the title, %2$s is the site name.
145 sprintf(_("%1\$s - %2\$s"),
147 common_config('site', 'name')));
151 * Returns the page title
155 * @return string page title
160 // TRANS: Page title for a page without a title set.
161 return _("Untitled page");
165 * Show themed shortcut icon
169 function showShortcutIcon()
171 if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
172 $this->element('link', array('rel' => 'shortcut icon',
173 'href' => Theme::path('favicon.ico')));
175 $this->element('link', array('rel' => 'shortcut icon',
176 'href' => common_path('favicon.ico')));
179 if (common_config('site', 'mobile')) {
180 if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
181 $this->element('link', array('rel' => 'apple-touch-icon',
182 'href' => Theme::path('apple-touch-icon.png')));
184 $this->element('link', array('rel' => 'apple-touch-icon',
185 'href' => common_path('apple-touch-icon.png')));
195 function showStylesheets()
197 if (Event::handle('StartShowStyles', array($this))) {
199 // Use old name for StatusNet for compatibility on events
201 if (Event::handle('StartShowStatusNetStyles', array($this)) &&
202 Event::handle('StartShowLaconicaStyles', array($this))) {
203 $this->cssLink('css/display.css',null, 'screen, projection, tv, print');
204 Event::handle('EndShowStatusNetStyles', array($this));
205 Event::handle('EndShowLaconicaStyles', array($this));
208 if (Event::handle('StartShowUAStyles', array($this))) {
209 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
210 'href="'.Theme::path('css/ie.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
211 foreach (array(6,7) as $ver) {
212 if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
213 // Yes, IE people should be put in jail.
214 $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
215 'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
218 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
219 'href="'.Theme::path('css/ie.css', null).'?version='.STATUSNET_VERSION.'" /><![endif]');
220 Event::handle('EndShowUAStyles', array($this));
223 if (Event::handle('StartShowDesign', array($this))) {
225 $user = common_current_user();
227 if (empty($user) || $user->viewdesigns) {
228 $design = $this->getDesign();
230 if (!empty($design)) {
231 $design->showCSS($this);
235 Event::handle('EndShowDesign', array($this));
237 Event::handle('EndShowStyles', array($this));
242 * Show javascript headers
246 function showScripts()
248 if (Event::handle('StartShowScripts', array($this))) {
249 if (Event::handle('StartShowJQueryScripts', array($this))) {
250 $this->script('jquery.min.js');
251 $this->script('jquery.form.js');
252 $this->script('jquery.cookie.js');
253 $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }');
254 $this->script('jquery.joverlay.min.js');
255 Event::handle('EndShowJQueryScripts', array($this));
257 if (Event::handle('StartShowStatusNetScripts', array($this)) &&
258 Event::handle('StartShowLaconicaScripts', array($this))) {
259 $this->script('xbImportNode.js');
260 $this->script('util.js');
261 $this->script('geometa.js');
262 // Frame-busting code to avoid clickjacking attacks.
263 $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
264 Event::handle('EndShowStatusNetScripts', array($this));
265 Event::handle('EndShowLaconicaScripts', array($this));
267 Event::handle('EndShowScripts', array($this));
272 * Show OpenSearch headers
276 function showOpenSearch()
278 $this->element('link', array('rel' => 'search',
279 'type' => 'application/opensearchdescription+xml',
280 'href' => common_local_url('opensearch', array('type' => 'people')),
281 'title' => common_config('site', 'name').' People Search'));
282 $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
283 'href' => common_local_url('opensearch', array('type' => 'notice')),
284 'title' => common_config('site', 'name').' Notice Search'));
297 $feeds = $this->getFeeds();
300 foreach ($feeds as $feed) {
301 $this->element('link', array('rel' => $feed->rel(),
302 'href' => $feed->url,
303 'type' => $feed->mimeType(),
304 'title' => $feed->title));
316 function showDescription()
318 // does nothing by default
322 * Show extra stuff in <head>.
330 // does nothing by default
336 * Calls template methods
342 $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'),
343 'class' => 'user_in')
344 : array('id' => $this->trimmed('action')));
345 $this->elementStart('div', array('id' => 'wrap'));
346 if (Event::handle('StartShowHeader', array($this))) {
348 Event::handle('EndShowHeader', array($this));
351 if (Event::handle('StartShowFooter', array($this))) {
353 Event::handle('EndShowFooter', array($this));
355 $this->elementEnd('div');
356 $this->showScripts();
357 $this->elementEnd('body');
361 * Show header of the page.
363 * Calls template methods
367 function showHeader()
369 $this->elementStart('div', array('id' => 'header'));
371 $this->showPrimaryNav();
372 if (Event::handle('StartShowSiteNotice', array($this))) {
373 $this->showSiteNotice();
375 Event::handle('EndShowSiteNotice', array($this));
377 if (common_logged_in()) {
378 $this->showNoticeForm();
380 $this->showAnonymousMessage();
382 $this->elementEnd('div');
386 * Show configured logo.
392 $this->elementStart('address', array('id' => 'site_contact',
393 'class' => 'vcard'));
394 if (Event::handle('StartAddressData', array($this))) {
395 if (common_config('singleuser', 'enabled')) {
396 $url = common_local_url('showstream',
397 array('nickname' => common_config('singleuser', 'nickname')));
399 $url = common_local_url('public');
401 $this->elementStart('a', array('class' => 'url home bookmark',
403 if (common_config('site', 'logo') || file_exists(Theme::file('logo.png'))) {
404 $this->element('img', array('class' => 'logo photo',
405 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'),
406 'alt' => common_config('site', 'name')));
409 $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
410 $this->elementEnd('a');
411 Event::handle('EndAddressData', array($this));
413 $this->elementEnd('address');
417 * Show primary navigation.
421 function showPrimaryNav()
423 $user = common_current_user();
424 $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
425 // TRANS: DT element for primary navigation menu. String is hidden in default CSS.
426 $this->element('dt', null, _('Primary site navigation'));
427 $this->elementStart('dd');
428 $this->elementStart('ul', array('class' => 'nav'));
429 if (Event::handle('StartPrimaryNav', array($this))) {
431 // TRANS: Tooltip for main menu option "Personal"
432 $tooltip = _m('TOOLTIP', 'Personal profile and friends timeline');
433 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
434 // TRANS: Main menu option when logged in for access to personal profile and friends timeline
435 _m('MENU', 'Personal'), $tooltip, false, 'nav_home');
436 // TRANS: Tooltip for main menu option "Account"
437 $tooltip = _m('TOOLTIP', 'Change your email, avatar, password, profile');
438 $this->menuItem(common_local_url('profilesettings'),
439 // TRANS: Main menu option when logged in for access to user settings
440 _('Account'), $tooltip, false, 'nav_account');
441 // TRANS: Tooltip for main menu option "Services"
442 $tooltip = _m('TOOLTIP', 'Connect to services');
443 $this->menuItem(common_local_url('oauthconnectionssettings'),
444 // TRANS: Main menu option when logged in and connection are possible for access to options to connect to other services
445 _('Connect'), $tooltip, false, 'nav_connect');
446 if ($user->hasRight(Right::CONFIGURESITE)) {
447 // TRANS: Tooltip for menu option "Admin"
448 $tooltip = _m('TOOLTIP', 'Change site configuration');
449 $this->menuItem(common_local_url('siteadminpanel'),
450 // TRANS: Main menu option when logged in and site admin for access to site configuration
451 _m('MENU', 'Admin'), $tooltip, false, 'nav_admin');
453 if (common_config('invite', 'enabled')) {
454 // TRANS: Tooltip for main menu option "Invite"
455 $tooltip = _m('TOOLTIP', 'Invite friends and colleagues to join you on %s');
456 $this->menuItem(common_local_url('invite'),
457 // TRANS: Main menu option when logged in and invitations are allowed for inviting new users
458 _m('MENU', 'Invite'),
460 common_config('site', 'name')),
461 false, 'nav_invitecontact');
463 // TRANS: Tooltip for main menu option "Logout"
464 $tooltip = _m('TOOLTIP', 'Logout from the site');
465 $this->menuItem(common_local_url('logout'),
466 // TRANS: Main menu option when logged in to log out the current user
467 _m('MENU', 'Logout'), $tooltip, false, 'nav_logout');
470 if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
471 // TRANS: Tooltip for main menu option "Register"
472 $tooltip = _m('TOOLTIP', 'Create an account');
473 $this->menuItem(common_local_url('register'),
474 // TRANS: Main menu option when not logged in to register a new account
475 _m('MENU', 'Register'), $tooltip, false, 'nav_register');
477 // TRANS: Tooltip for main menu option "Login"
478 $tooltip = _m('TOOLTIP', 'Login to the site');
479 // TRANS: Main menu option when not logged in to log in
480 $this->menuItem(common_local_url('login'),
481 _m('MENU', 'Login'), $tooltip, false, 'nav_login');
483 // TRANS: Tooltip for main menu option "Help"
484 $tooltip = _m('TOOLTIP', 'Help me!');
485 // TRANS: Main menu option for help on the StatusNet site
486 $this->menuItem(common_local_url('doc', array('title' => 'help')),
487 _m('MENU', 'Help'), $tooltip, false, 'nav_help');
488 if ($user || !common_config('site', 'private')) {
489 // TRANS: Tooltip for main menu option "Search"
490 $tooltip = _m('TOOLTIP', 'Search for people or text');
491 // TRANS: Main menu option when logged in or when the StatusNet instance is not private
492 $this->menuItem(common_local_url('peoplesearch'),
493 _m('MENU', 'Search'), $tooltip, false, 'nav_search');
495 Event::handle('EndPrimaryNav', array($this));
497 $this->elementEnd('ul');
498 $this->elementEnd('dd');
499 $this->elementEnd('dl');
507 function showSiteNotice()
509 // Revist. Should probably do an hAtom pattern here
510 $text = common_config('site', 'notice');
512 $this->elementStart('dl', array('id' => 'site_notice',
513 'class' => 'system_notice'));
514 // TRANS: DT element for site notice. String is hidden in default CSS.
515 $this->element('dt', null, _('Site notice'));
516 $this->elementStart('dd', null);
518 $this->elementEnd('dd');
519 $this->elementEnd('dl');
526 * MAY overload if no notice form needed... or direct message box????
530 function showNoticeForm()
532 $notice_form = new NoticeForm($this);
533 $notice_form->show();
537 * Show anonymous message.
543 function showAnonymousMessage()
545 // needs to be defined by the class
551 * Shows local navigation, content block and aside.
557 $this->elementStart('div', array('id' => 'core'));
558 if (Event::handle('StartShowLocalNavBlock', array($this))) {
559 $this->showLocalNavBlock();
560 Event::handle('EndShowLocalNavBlock', array($this));
562 if (Event::handle('StartShowContentBlock', array($this))) {
563 $this->showContentBlock();
564 Event::handle('EndShowContentBlock', array($this));
566 if (Event::handle('StartShowAside', array($this))) {
568 Event::handle('EndShowAside', array($this));
570 $this->elementEnd('div');
574 * Show local navigation block.
578 function showLocalNavBlock()
580 $this->elementStart('dl', array('id' => 'site_nav_local_views'));
581 // TRANS: DT element for local views block. String is hidden in default CSS.
582 $this->element('dt', null, _('Local views'));
583 $this->elementStart('dd');
584 $this->showLocalNav();
585 $this->elementEnd('dd');
586 $this->elementEnd('dl');
590 * Show local navigation.
596 function showLocalNav()
598 // does nothing by default
602 * Show content block.
606 function showContentBlock()
608 $this->elementStart('div', array('id' => 'content'));
609 $this->showPageTitle();
610 $this->showPageNoticeBlock();
611 $this->elementStart('div', array('id' => 'content_inner'));
612 // show the actual content (forms, lists, whatever)
613 $this->showContent();
614 $this->elementEnd('div');
615 $this->elementEnd('div');
623 function showPageTitle()
625 $this->element('h1', null, $this->title());
629 * Show page notice block.
631 * Only show the block if a subclassed action has overrided
632 * Action::showPageNotice(), or an event handler is registered for
633 * the StartShowPageNotice event, in which case we assume the
634 * 'page_notice' definition list is desired. This is to prevent
635 * empty 'page_notice' definition lists from being output everywhere.
639 function showPageNoticeBlock()
641 $rmethod = new ReflectionMethod($this, 'showPageNotice');
642 $dclass = $rmethod->getDeclaringClass()->getName();
644 if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
646 $this->elementStart('dl', array('id' => 'page_notice',
647 'class' => 'system_notice'));
648 // TRANS: DT element for page notice. String is hidden in default CSS.
649 $this->element('dt', null, _('Page notice'));
650 $this->elementStart('dd');
651 if (Event::handle('StartShowPageNotice', array($this))) {
652 $this->showPageNotice();
653 Event::handle('EndShowPageNotice', array($this));
655 $this->elementEnd('dd');
656 $this->elementEnd('dl');
663 * SHOULD overload (unless there's not a notice)
667 function showPageNotice()
674 * MUST overload (unless there's not a notice)
678 function showContent()
690 $this->elementStart('div', array('id' => 'aside_primary',
691 'class' => 'aside'));
692 if (Event::handle('StartShowExportData', array($this))) {
693 $this->showExportData();
694 Event::handle('EndShowExportData', array($this));
696 if (Event::handle('StartShowSections', array($this))) {
697 $this->showSections();
698 Event::handle('EndShowSections', array($this));
700 $this->elementEnd('div');
704 * Show export data feeds.
709 function showExportData()
711 $feeds = $this->getFeeds();
713 $fl = new FeedList($this);
725 function showSections()
727 // for each section, show it
735 function showFooter()
737 $this->elementStart('div', array('id' => 'footer'));
738 $this->showSecondaryNav();
739 $this->showLicenses();
740 $this->elementEnd('div');
744 * Show secondary navigation.
748 function showSecondaryNav()
750 $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
751 // TRANS: DT element for secondary navigation menu. String is hidden in default CSS.
752 $this->element('dt', null, _('Secondary site navigation'));
753 $this->elementStart('dd', null);
754 $this->elementStart('ul', array('class' => 'nav'));
755 if (Event::handle('StartSecondaryNav', array($this))) {
756 $this->menuItem(common_local_url('doc', array('title' => 'help')),
757 // TRANS: Secondary navigation menu option leading to help on StatusNet.
759 $this->menuItem(common_local_url('doc', array('title' => 'about')),
760 // TRANS: Secondary navigation menu option leading to text about StatusNet site.
762 $this->menuItem(common_local_url('doc', array('title' => 'faq')),
763 // TRANS: Secondary navigation menu option leading to Frequently Asked Questions.
765 $bb = common_config('site', 'broughtby');
767 $this->menuItem(common_local_url('doc', array('title' => 'tos')),
768 // TRANS: Secondary navigation menu option leading to Terms of Service.
771 $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
772 // TRANS: Secondary navigation menu option leading to privacy policy.
774 $this->menuItem(common_local_url('doc', array('title' => 'source')),
775 // TRANS: Secondary navigation menu option.
777 $this->menuItem(common_local_url('version'),
778 // TRANS: Secondary navigation menu option leading to version information on the StatusNet site.
780 $this->menuItem(common_local_url('doc', array('title' => 'contact')),
781 // TRANS: Secondary navigation menu option leading to contact information on the StatusNet site.
783 $this->menuItem(common_local_url('doc', array('title' => 'badge')),
785 Event::handle('EndSecondaryNav', array($this));
787 $this->elementEnd('ul');
788 $this->elementEnd('dd');
789 $this->elementEnd('dl');
797 function showLicenses()
799 $this->elementStart('dl', array('id' => 'licenses'));
800 $this->showStatusNetLicense();
801 $this->showContentLicense();
802 $this->elementEnd('dl');
806 * Show StatusNet license.
810 function showStatusNetLicense()
812 // TRANS: DT element for StatusNet software license.
813 $this->element('dt', array('id' => 'site_statusnet_license'), _('StatusNet software license'));
814 $this->elementStart('dd', null);
815 if (common_config('site', 'broughtby')) {
816 // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is set.
817 $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%).');
819 // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is not set.
820 $instr = _('**%%site.name%%** is a microblogging service.');
823 // TRANS: Second sentence of the StatusNet site license. Mentions the StatusNet source code license.
824 $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);
825 $output = common_markup_to_html($instr);
827 $this->elementEnd('dd');
832 * Show content license.
836 function showContentLicense()
838 if (Event::handle('StartShowContentLicense', array($this))) {
839 // TRANS: DT element for StatusNet site content license.
840 $this->element('dt', array('id' => 'site_content_license'), _('Site content license'));
841 $this->elementStart('dd', array('id' => 'site_content_license_cc'));
843 switch (common_config('license', 'type')) {
845 // TRANS: Content license displayed when license is set to 'private'.
846 // TRANS: %1$s is the site name.
847 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
848 common_config('site', 'name')));
850 case 'allrightsreserved':
851 if (common_config('license', 'owner')) {
852 // TRANS: Content license displayed when license is set to 'allrightsreserved'.
853 // TRANS: %1$s is the copyright owner.
854 $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
855 common_config('license', 'owner')));
857 // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
858 $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
861 case 'cc': // fall through
863 $this->elementStart('p');
864 $this->element('img', array('id' => 'license_cc',
865 'src' => common_config('license', 'image'),
866 'alt' => common_config('license', 'title'),
870 // 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.
871 $notice = _('All %1$s content and data are available under the %2$s license.');
872 $link = "<a class=\"license\" rel=\"external license\" href=\"" .
873 htmlspecialchars(common_config('license', 'url')) .
875 htmlspecialchars(common_config('license', 'title')) .
877 $this->raw(sprintf(htmlspecialchars($notice),
878 htmlspecialchars(common_config('site', 'name')),
880 $this->elementEnd('p');
884 $this->elementEnd('dd');
885 Event::handle('EndShowContentLicense', array($this));
890 * Return last modified, if applicable.
894 * @return string last modified http header
896 function lastModified()
898 // For comparison with If-Last-Modified
899 // If not applicable, return null
904 * Return etag, if applicable.
908 * @return string etag http header
916 * Return true if read only.
920 * @param array $args other arguments
922 * @return boolean is read only action?
925 function isReadOnly($args)
931 * Returns query argument or default value if not found
933 * @param string $key requested argument
934 * @param string $def default value to return if $key is not provided
936 * @return boolean is read only action?
938 function arg($key, $def=null)
940 if (array_key_exists($key, $this->args)) {
941 return $this->args[$key];
948 * Returns trimmed query argument or default value if not found
950 * @param string $key requested argument
951 * @param string $def default value to return if $key is not provided
953 * @return boolean is read only action?
955 function trimmed($key, $def=null)
957 $arg = $this->arg($key, $def);
958 return is_string($arg) ? trim($arg) : $arg;
964 * @param array $argarray is ignored since it's now passed in in prepare()
966 * @return boolean is read only action?
968 function handle($argarray=null)
970 header('Vary: Accept-Encoding,Cookie');
971 $lm = $this->lastModified();
972 $etag = $this->etag();
974 header('ETag: ' . $etag);
977 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
978 if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
979 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
980 $ims = strtotime($if_modified_since);
982 $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
983 $_SERVER['HTTP_IF_NONE_MATCH'] : null;
984 if (!$if_none_match ||
986 $this->_hasEtag($etag, $if_none_match)) {
987 header('HTTP/1.1 304 Not Modified');
988 // Better way to do this?
997 * HasĀ etag? (private)
999 * @param string $etag etag http header
1000 * @param string $if_none_match ifNoneMatch http header
1005 function _hasEtag($etag, $if_none_match)
1007 $etags = explode(',', $if_none_match);
1008 return in_array($etag, $etags) || in_array('*', $etags);
1012 * Boolean understands english (yes, no, true, false)
1014 * @param string $key query key we're interested in
1015 * @param string $def default value
1017 * @return boolean interprets yes/no strings as boolean
1019 function boolean($key, $def=false)
1021 $arg = strtolower($this->trimmed($key));
1023 if (is_null($arg)) {
1025 } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1027 } else if (in_array($arg, array('false', 'no', '0'))) {
1035 * Integer value of an argument
1037 * @param string $key query key we're interested in
1038 * @param string $defValue optional default value (default null)
1039 * @param string $maxValue optional max value (default null)
1040 * @param string $minValue optional min value (default null)
1042 * @return integer integer value
1045 function int($key, $defValue=null, $maxValue=null, $minValue=null)
1047 $arg = strtolower($this->trimmed($key));
1049 if (is_null($arg) || !is_integer($arg)) {
1053 if (!is_null($maxValue)) {
1054 $arg = min($arg, $maxValue);
1057 if (!is_null($minValue)) {
1058 $arg = max($arg, $minValue);
1067 * @param string $msg error message to display
1068 * @param integer $code http error code, 500 by default
1073 function serverError($msg, $code=500)
1075 $action = $this->trimmed('action');
1076 common_debug("Server error '$code' on '$action': $msg", __FILE__);
1077 throw new ServerException($msg, $code);
1083 * @param string $msg error message to display
1084 * @param integer $code http error code, 400 by default
1089 function clientError($msg, $code=400)
1091 $action = $this->trimmed('action');
1092 common_debug("User error '$code' on '$action': $msg", __FILE__);
1093 throw new ClientException($msg, $code);
1097 * Returns the current URL
1099 * @return string current URL
1104 list($action, $args) = $this->returnToArgs();
1105 return common_local_url($action, $args);
1109 * Returns arguments sufficient for re-constructing URL
1111 * @return array two elements: action, other args
1114 function returnToArgs()
1116 $action = $this->trimmed('action');
1117 $args = $this->args;
1118 unset($args['action']);
1119 if (common_config('site', 'fancy')) {
1122 if (array_key_exists('submit', $args)) {
1123 unset($args['submit']);
1125 foreach (array_keys($_COOKIE) as $cookie) {
1126 unset($args[$cookie]);
1128 return array($action, $args);
1132 * Generate a menu item
1134 * @param string $url menu URL
1135 * @param string $text menu name
1136 * @param string $title title attribute, null by default
1137 * @param boolean $is_selected current menu item, false by default
1138 * @param string $id element id, null by default
1142 function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
1144 // Added @id to li for some control.
1145 // XXX: We might want to move this to htmloutputter.php
1148 $lattrs['class'] = 'current';
1151 (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
1153 $this->elementStart('li', $lattrs);
1154 $attrs['href'] = $url;
1156 $attrs['title'] = $title;
1158 $this->element('a', $attrs, $text);
1159 $this->elementEnd('li');
1163 * Generate pagination links
1165 * @param boolean $have_before is there something before?
1166 * @param boolean $have_after is there something after?
1167 * @param integer $page current page
1168 * @param string $action current action
1169 * @param array $args rest of query arguments
1173 // XXX: The messages in this pagination method only tailor to navigating
1174 // notices. In other lists, "Previous"/"Next" type navigation is
1175 // desirable, but not available.
1176 function pagination($have_before, $have_after, $page, $action, $args=null)
1178 // Does a little before-after block for next/prev page
1179 if ($have_before || $have_after) {
1180 $this->elementStart('dl', 'pagination');
1181 // TRANS: DT element for pagination (previous/next, etc.).
1182 $this->element('dt', null, _('Pagination'));
1183 $this->elementStart('dd', null);
1184 $this->elementStart('ul', array('class' => 'nav'));
1187 $pargs = array('page' => $page-1);
1188 $this->elementStart('li', array('class' => 'nav_prev'));
1189 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1191 // TRANS: Pagination message to go to a page displaying information more in the
1192 // TRANS: present than the currently displayed information.
1194 $this->elementEnd('li');
1197 $pargs = array('page' => $page+1);
1198 $this->elementStart('li', array('class' => 'nav_next'));
1199 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1201 // TRANS: Pagination message to go to a page displaying information more in the
1202 // TRANS: past than the currently displayed information.
1204 $this->elementEnd('li');
1206 if ($have_before || $have_after) {
1207 $this->elementEnd('ul');
1208 $this->elementEnd('dd');
1209 $this->elementEnd('dl');
1214 * An array of feeds for this action.
1216 * Returns an array of potential feeds for this action.
1218 * @return array Feed object to show in head and links
1227 * A design for this action
1229 * @return Design a design object to use
1232 function getDesign()
1234 return Design::siteDesign();
1238 * Check the session token.
1240 * Checks that the current form has the correct session token,
1241 * and throw an exception if it does not.
1246 // XXX: Finding this type of check with the same message about 50 times.
1247 // Possible to refactor?
1248 function checkSessionToken()
1251 $token = $this->trimmed('token');
1252 if (empty($token) || $token != common_session_token()) {
1253 $this->clientError(_('There was a problem with your session token.'));