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));
239 if (common_config('custom_css', 'enabled')) {
240 $css = common_config('custom_css', 'css');
241 if (Event::handle('StartShowCustomCss', array($this, &$css))) {
242 if (trim($css) != '') {
245 Event::handle('EndShowCustomCss', array($this));
252 * Show javascript headers
256 function showScripts()
258 if (Event::handle('StartShowScripts', array($this))) {
259 if (Event::handle('StartShowJQueryScripts', array($this))) {
260 $this->script('jquery.min.js');
261 $this->script('jquery.form.js');
262 $this->script('jquery.cookie.js');
263 $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }');
264 $this->script('jquery.joverlay.min.js');
265 Event::handle('EndShowJQueryScripts', array($this));
267 if (Event::handle('StartShowStatusNetScripts', array($this)) &&
268 Event::handle('StartShowLaconicaScripts', array($this))) {
269 $this->script('xbImportNode.js');
270 $this->script('util.js');
271 $this->script('geometa.js');
272 // Frame-busting code to avoid clickjacking attacks.
273 $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
274 Event::handle('EndShowStatusNetScripts', array($this));
275 Event::handle('EndShowLaconicaScripts', array($this));
277 Event::handle('EndShowScripts', array($this));
282 * Show OpenSearch headers
286 function showOpenSearch()
288 $this->element('link', array('rel' => 'search',
289 'type' => 'application/opensearchdescription+xml',
290 'href' => common_local_url('opensearch', array('type' => 'people')),
291 'title' => common_config('site', 'name').' People Search'));
292 $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
293 'href' => common_local_url('opensearch', array('type' => 'notice')),
294 'title' => common_config('site', 'name').' Notice Search'));
307 $feeds = $this->getFeeds();
310 foreach ($feeds as $feed) {
311 $this->element('link', array('rel' => $feed->rel(),
312 'href' => $feed->url,
313 'type' => $feed->mimeType(),
314 'title' => $feed->title));
326 function showDescription()
328 // does nothing by default
332 * Show extra stuff in <head>.
340 // does nothing by default
346 * Calls template methods
352 $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'),
353 'class' => 'user_in')
354 : array('id' => $this->trimmed('action')));
355 $this->elementStart('div', array('id' => 'wrap'));
356 if (Event::handle('StartShowHeader', array($this))) {
358 Event::handle('EndShowHeader', array($this));
361 if (Event::handle('StartShowFooter', array($this))) {
363 Event::handle('EndShowFooter', array($this));
365 $this->elementEnd('div');
366 $this->showScripts();
367 $this->elementEnd('body');
371 * Show header of the page.
373 * Calls template methods
377 function showHeader()
379 $this->elementStart('div', array('id' => 'header'));
381 $this->showPrimaryNav();
382 if (Event::handle('StartShowSiteNotice', array($this))) {
383 $this->showSiteNotice();
385 Event::handle('EndShowSiteNotice', array($this));
387 if (common_logged_in()) {
388 $this->showNoticeForm();
390 $this->showAnonymousMessage();
392 $this->elementEnd('div');
396 * Show configured logo.
402 $this->elementStart('address', array('id' => 'site_contact',
403 'class' => 'vcard'));
404 if (Event::handle('StartAddressData', array($this))) {
405 if (common_config('singleuser', 'enabled')) {
406 $url = common_local_url('showstream',
407 array('nickname' => common_config('singleuser', 'nickname')));
409 $url = common_local_url('public');
411 $this->elementStart('a', array('class' => 'url home bookmark',
413 if (common_config('site', 'logo') || file_exists(Theme::file('logo.png'))) {
414 $this->element('img', array('class' => 'logo photo',
415 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'),
416 'alt' => common_config('site', 'name')));
419 $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
420 $this->elementEnd('a');
421 Event::handle('EndAddressData', array($this));
423 $this->elementEnd('address');
427 * Show primary navigation.
431 function showPrimaryNav()
433 $user = common_current_user();
434 $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
435 // TRANS: DT element for primary navigation menu. String is hidden in default CSS.
436 $this->element('dt', null, _('Primary site navigation'));
437 $this->elementStart('dd');
438 $this->elementStart('ul', array('class' => 'nav'));
439 if (Event::handle('StartPrimaryNav', array($this))) {
441 // TRANS: Tooltip for main menu option "Personal"
442 $tooltip = _m('TOOLTIP', 'Personal profile and friends timeline');
443 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
444 // TRANS: Main menu option when logged in for access to personal profile and friends timeline
445 _m('MENU', 'Personal'), $tooltip, false, 'nav_home');
446 // TRANS: Tooltip for main menu option "Account"
447 $tooltip = _m('TOOLTIP', 'Change your email, avatar, password, profile');
448 $this->menuItem(common_local_url('profilesettings'),
449 // TRANS: Main menu option when logged in for access to user settings
450 _('Account'), $tooltip, false, 'nav_account');
451 // TRANS: Tooltip for main menu option "Services"
452 $tooltip = _m('TOOLTIP', 'Connect to services');
453 $this->menuItem(common_local_url('oauthconnectionssettings'),
454 // TRANS: Main menu option when logged in and connection are possible for access to options to connect to other services
455 _('Connect'), $tooltip, false, 'nav_connect');
456 if ($user->hasRight(Right::CONFIGURESITE)) {
457 // TRANS: Tooltip for menu option "Admin"
458 $tooltip = _m('TOOLTIP', 'Change site configuration');
459 $this->menuItem(common_local_url('siteadminpanel'),
460 // TRANS: Main menu option when logged in and site admin for access to site configuration
461 _m('MENU', 'Admin'), $tooltip, false, 'nav_admin');
463 if (common_config('invite', 'enabled')) {
464 // TRANS: Tooltip for main menu option "Invite"
465 $tooltip = _m('TOOLTIP', 'Invite friends and colleagues to join you on %s');
466 $this->menuItem(common_local_url('invite'),
467 // TRANS: Main menu option when logged in and invitations are allowed for inviting new users
468 _m('MENU', 'Invite'),
470 common_config('site', 'name')),
471 false, 'nav_invitecontact');
473 // TRANS: Tooltip for main menu option "Logout"
474 $tooltip = _m('TOOLTIP', 'Logout from the site');
475 $this->menuItem(common_local_url('logout'),
476 // TRANS: Main menu option when logged in to log out the current user
477 _m('MENU', 'Logout'), $tooltip, false, 'nav_logout');
480 if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
481 // TRANS: Tooltip for main menu option "Register"
482 $tooltip = _m('TOOLTIP', 'Create an account');
483 $this->menuItem(common_local_url('register'),
484 // TRANS: Main menu option when not logged in to register a new account
485 _m('MENU', 'Register'), $tooltip, false, 'nav_register');
487 // TRANS: Tooltip for main menu option "Login"
488 $tooltip = _m('TOOLTIP', 'Login to the site');
489 // TRANS: Main menu option when not logged in to log in
490 $this->menuItem(common_local_url('login'),
491 _m('MENU', 'Login'), $tooltip, false, 'nav_login');
493 // TRANS: Tooltip for main menu option "Help"
494 $tooltip = _m('TOOLTIP', 'Help me!');
495 // TRANS: Main menu option for help on the StatusNet site
496 $this->menuItem(common_local_url('doc', array('title' => 'help')),
497 _m('MENU', 'Help'), $tooltip, false, 'nav_help');
498 if ($user || !common_config('site', 'private')) {
499 // TRANS: Tooltip for main menu option "Search"
500 $tooltip = _m('TOOLTIP', 'Search for people or text');
501 // TRANS: Main menu option when logged in or when the StatusNet instance is not private
502 $this->menuItem(common_local_url('peoplesearch'),
503 _m('MENU', 'Search'), $tooltip, false, 'nav_search');
505 Event::handle('EndPrimaryNav', array($this));
507 $this->elementEnd('ul');
508 $this->elementEnd('dd');
509 $this->elementEnd('dl');
517 function showSiteNotice()
519 // Revist. Should probably do an hAtom pattern here
520 $text = common_config('site', 'notice');
522 $this->elementStart('dl', array('id' => 'site_notice',
523 'class' => 'system_notice'));
524 // TRANS: DT element for site notice. String is hidden in default CSS.
525 $this->element('dt', null, _('Site notice'));
526 $this->elementStart('dd', null);
528 $this->elementEnd('dd');
529 $this->elementEnd('dl');
536 * MAY overload if no notice form needed... or direct message box????
540 function showNoticeForm()
542 $notice_form = new NoticeForm($this);
543 $notice_form->show();
547 * Show anonymous message.
553 function showAnonymousMessage()
555 // needs to be defined by the class
561 * Shows local navigation, content block and aside.
567 $this->elementStart('div', array('id' => 'core'));
568 if (Event::handle('StartShowLocalNavBlock', array($this))) {
569 $this->showLocalNavBlock();
570 Event::handle('EndShowLocalNavBlock', array($this));
572 if (Event::handle('StartShowContentBlock', array($this))) {
573 $this->showContentBlock();
574 Event::handle('EndShowContentBlock', array($this));
576 if (Event::handle('StartShowAside', array($this))) {
578 Event::handle('EndShowAside', array($this));
580 $this->elementEnd('div');
584 * Show local navigation block.
588 function showLocalNavBlock()
590 $this->elementStart('dl', array('id' => 'site_nav_local_views'));
591 // TRANS: DT element for local views block. String is hidden in default CSS.
592 $this->element('dt', null, _('Local views'));
593 $this->elementStart('dd');
594 $this->showLocalNav();
595 $this->elementEnd('dd');
596 $this->elementEnd('dl');
600 * Show local navigation.
606 function showLocalNav()
608 // does nothing by default
612 * Show content block.
616 function showContentBlock()
618 $this->elementStart('div', array('id' => 'content'));
619 $this->showPageTitle();
620 $this->showPageNoticeBlock();
621 $this->elementStart('div', array('id' => 'content_inner'));
622 // show the actual content (forms, lists, whatever)
623 $this->showContent();
624 $this->elementEnd('div');
625 $this->elementEnd('div');
633 function showPageTitle()
635 $this->element('h1', null, $this->title());
639 * Show page notice block.
641 * Only show the block if a subclassed action has overrided
642 * Action::showPageNotice(), or an event handler is registered for
643 * the StartShowPageNotice event, in which case we assume the
644 * 'page_notice' definition list is desired. This is to prevent
645 * empty 'page_notice' definition lists from being output everywhere.
649 function showPageNoticeBlock()
651 $rmethod = new ReflectionMethod($this, 'showPageNotice');
652 $dclass = $rmethod->getDeclaringClass()->getName();
654 if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
656 $this->elementStart('dl', array('id' => 'page_notice',
657 'class' => 'system_notice'));
658 // TRANS: DT element for page notice. String is hidden in default CSS.
659 $this->element('dt', null, _('Page notice'));
660 $this->elementStart('dd');
661 if (Event::handle('StartShowPageNotice', array($this))) {
662 $this->showPageNotice();
663 Event::handle('EndShowPageNotice', array($this));
665 $this->elementEnd('dd');
666 $this->elementEnd('dl');
673 * SHOULD overload (unless there's not a notice)
677 function showPageNotice()
684 * MUST overload (unless there's not a notice)
688 function showContent()
700 $this->elementStart('div', array('id' => 'aside_primary',
701 'class' => 'aside'));
702 if (Event::handle('StartShowExportData', array($this))) {
703 $this->showExportData();
704 Event::handle('EndShowExportData', array($this));
706 if (Event::handle('StartShowSections', array($this))) {
707 $this->showSections();
708 Event::handle('EndShowSections', array($this));
710 $this->elementEnd('div');
714 * Show export data feeds.
719 function showExportData()
721 $feeds = $this->getFeeds();
723 $fl = new FeedList($this);
735 function showSections()
737 // for each section, show it
745 function showFooter()
747 $this->elementStart('div', array('id' => 'footer'));
748 $this->showSecondaryNav();
749 $this->showLicenses();
750 $this->elementEnd('div');
754 * Show secondary navigation.
758 function showSecondaryNav()
760 $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
761 // TRANS: DT element for secondary navigation menu. String is hidden in default CSS.
762 $this->element('dt', null, _('Secondary site navigation'));
763 $this->elementStart('dd', null);
764 $this->elementStart('ul', array('class' => 'nav'));
765 if (Event::handle('StartSecondaryNav', array($this))) {
766 $this->menuItem(common_local_url('doc', array('title' => 'help')),
767 // TRANS: Secondary navigation menu option leading to help on StatusNet.
769 $this->menuItem(common_local_url('doc', array('title' => 'about')),
770 // TRANS: Secondary navigation menu option leading to text about StatusNet site.
772 $this->menuItem(common_local_url('doc', array('title' => 'faq')),
773 // TRANS: Secondary navigation menu option leading to Frequently Asked Questions.
775 $bb = common_config('site', 'broughtby');
777 $this->menuItem(common_local_url('doc', array('title' => 'tos')),
778 // TRANS: Secondary navigation menu option leading to Terms of Service.
781 $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
782 // TRANS: Secondary navigation menu option leading to privacy policy.
784 $this->menuItem(common_local_url('doc', array('title' => 'source')),
785 // TRANS: Secondary navigation menu option.
787 $this->menuItem(common_local_url('version'),
788 // TRANS: Secondary navigation menu option leading to version information on the StatusNet site.
790 $this->menuItem(common_local_url('doc', array('title' => 'contact')),
791 // TRANS: Secondary navigation menu option leading to contact information on the StatusNet site.
793 $this->menuItem(common_local_url('doc', array('title' => 'badge')),
795 Event::handle('EndSecondaryNav', array($this));
797 $this->elementEnd('ul');
798 $this->elementEnd('dd');
799 $this->elementEnd('dl');
807 function showLicenses()
809 $this->elementStart('dl', array('id' => 'licenses'));
810 $this->showStatusNetLicense();
811 $this->showContentLicense();
812 $this->elementEnd('dl');
816 * Show StatusNet license.
820 function showStatusNetLicense()
822 // TRANS: DT element for StatusNet software license.
823 $this->element('dt', array('id' => 'site_statusnet_license'), _('StatusNet software license'));
824 $this->elementStart('dd', null);
825 if (common_config('site', 'broughtby')) {
826 // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is set.
827 $instr = _('**%%site.name%%** is a social network, courtesy of [%%site.broughtby%%](%%site.broughtbyurl%%).');
829 // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is not set.
830 $instr = _('**%%site.name%%** is a social network.');
833 // TRANS: Second sentence of the StatusNet site license. Mentions the StatusNet source code license.
834 $instr .= sprintf(_('It runs the [GNU social](http://www.gnu.org/software/social/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), STATUSNET_VERSION);
835 $output = common_markup_to_html($instr);
837 $this->elementEnd('dd');
842 * Show content license.
846 function showContentLicense()
848 if (Event::handle('StartShowContentLicense', array($this))) {
849 // TRANS: DT element for StatusNet site content license.
850 $this->element('dt', array('id' => 'site_content_license'), _('Site content license'));
851 $this->elementStart('dd', array('id' => 'site_content_license_cc'));
853 switch (common_config('license', 'type')) {
855 // TRANS: Content license displayed when license is set to 'private'.
856 // TRANS: %1$s is the site name.
857 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
858 common_config('site', 'name')));
860 case 'allrightsreserved':
861 if (common_config('license', 'owner')) {
862 // TRANS: Content license displayed when license is set to 'allrightsreserved'.
863 // TRANS: %1$s is the copyright owner.
864 $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
865 common_config('license', 'owner')));
867 // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
868 $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
871 case 'cc': // fall through
873 $this->elementStart('p');
874 $this->element('img', array('id' => 'license_cc',
875 'src' => common_config('license', 'image'),
876 'alt' => common_config('license', 'title'),
880 // 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.
881 $notice = _('All content and data are available under the %2$s license.');
882 $link = "<a class=\"license\" rel=\"external license\" href=\"" .
883 htmlspecialchars(common_config('license', 'url')) .
885 htmlspecialchars(common_config('license', 'title')) .
887 $this->raw(sprintf(htmlspecialchars($notice),
888 htmlspecialchars(common_config('site', 'name')),
890 $this->elementEnd('p');
894 $this->elementEnd('dd');
895 Event::handle('EndShowContentLicense', array($this));
900 * Return last modified, if applicable.
904 * @return string last modified http header
906 function lastModified()
908 // For comparison with If-Last-Modified
909 // If not applicable, return null
914 * Return etag, if applicable.
918 * @return string etag http header
926 * Return true if read only.
930 * @param array $args other arguments
932 * @return boolean is read only action?
935 function isReadOnly($args)
941 * Returns query argument or default value if not found
943 * @param string $key requested argument
944 * @param string $def default value to return if $key is not provided
946 * @return boolean is read only action?
948 function arg($key, $def=null)
950 if (array_key_exists($key, $this->args)) {
951 return $this->args[$key];
958 * Returns trimmed query argument or default value if not found
960 * @param string $key requested argument
961 * @param string $def default value to return if $key is not provided
963 * @return boolean is read only action?
965 function trimmed($key, $def=null)
967 $arg = $this->arg($key, $def);
968 return is_string($arg) ? trim($arg) : $arg;
974 * @param array $argarray is ignored since it's now passed in in prepare()
976 * @return boolean is read only action?
978 function handle($argarray=null)
980 header('Vary: Accept-Encoding,Cookie');
981 $lm = $this->lastModified();
982 $etag = $this->etag();
984 header('ETag: ' . $etag);
987 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
988 if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
989 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
990 $ims = strtotime($if_modified_since);
992 $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
993 $_SERVER['HTTP_IF_NONE_MATCH'] : null;
994 if (!$if_none_match ||
996 $this->_hasEtag($etag, $if_none_match)) {
997 header('HTTP/1.1 304 Not Modified');
998 // Better way to do this?
1007 * HasĀ etag? (private)
1009 * @param string $etag etag http header
1010 * @param string $if_none_match ifNoneMatch http header
1015 function _hasEtag($etag, $if_none_match)
1017 $etags = explode(',', $if_none_match);
1018 return in_array($etag, $etags) || in_array('*', $etags);
1022 * Boolean understands english (yes, no, true, false)
1024 * @param string $key query key we're interested in
1025 * @param string $def default value
1027 * @return boolean interprets yes/no strings as boolean
1029 function boolean($key, $def=false)
1031 $arg = strtolower($this->trimmed($key));
1033 if (is_null($arg)) {
1035 } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1037 } else if (in_array($arg, array('false', 'no', '0'))) {
1045 * Integer value of an argument
1047 * @param string $key query key we're interested in
1048 * @param string $defValue optional default value (default null)
1049 * @param string $maxValue optional max value (default null)
1050 * @param string $minValue optional min value (default null)
1052 * @return integer integer value
1055 function int($key, $defValue=null, $maxValue=null, $minValue=null)
1057 $arg = strtolower($this->trimmed($key));
1059 if (is_null($arg) || !is_integer($arg)) {
1063 if (!is_null($maxValue)) {
1064 $arg = min($arg, $maxValue);
1067 if (!is_null($minValue)) {
1068 $arg = max($arg, $minValue);
1077 * @param string $msg error message to display
1078 * @param integer $code http error code, 500 by default
1083 function serverError($msg, $code=500)
1085 $action = $this->trimmed('action');
1086 common_debug("Server error '$code' on '$action': $msg", __FILE__);
1087 throw new ServerException($msg, $code);
1093 * @param string $msg error message to display
1094 * @param integer $code http error code, 400 by default
1099 function clientError($msg, $code=400)
1101 $action = $this->trimmed('action');
1102 common_debug("User error '$code' on '$action': $msg", __FILE__);
1103 throw new ClientException($msg, $code);
1107 * Returns the current URL
1109 * @return string current URL
1114 list($action, $args) = $this->returnToArgs();
1115 return common_local_url($action, $args);
1119 * Returns arguments sufficient for re-constructing URL
1121 * @return array two elements: action, other args
1124 function returnToArgs()
1126 $action = $this->trimmed('action');
1127 $args = $this->args;
1128 unset($args['action']);
1129 if (common_config('site', 'fancy')) {
1132 if (array_key_exists('submit', $args)) {
1133 unset($args['submit']);
1135 foreach (array_keys($_COOKIE) as $cookie) {
1136 unset($args[$cookie]);
1138 return array($action, $args);
1142 * Generate a menu item
1144 * @param string $url menu URL
1145 * @param string $text menu name
1146 * @param string $title title attribute, null by default
1147 * @param boolean $is_selected current menu item, false by default
1148 * @param string $id element id, null by default
1152 function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
1154 // Added @id to li for some control.
1155 // XXX: We might want to move this to htmloutputter.php
1158 $lattrs['class'] = 'current';
1161 (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
1163 $this->elementStart('li', $lattrs);
1164 $attrs['href'] = $url;
1166 $attrs['title'] = $title;
1168 $this->element('a', $attrs, $text);
1169 $this->elementEnd('li');
1173 * Generate pagination links
1175 * @param boolean $have_before is there something before?
1176 * @param boolean $have_after is there something after?
1177 * @param integer $page current page
1178 * @param string $action current action
1179 * @param array $args rest of query arguments
1183 // XXX: The messages in this pagination method only tailor to navigating
1184 // notices. In other lists, "Previous"/"Next" type navigation is
1185 // desirable, but not available.
1186 function pagination($have_before, $have_after, $page, $action, $args=null)
1188 // Does a little before-after block for next/prev page
1189 if ($have_before || $have_after) {
1190 $this->elementStart('dl', 'pagination');
1191 // TRANS: DT element for pagination (previous/next, etc.).
1192 $this->element('dt', null, _('Pagination'));
1193 $this->elementStart('dd', null);
1194 $this->elementStart('ul', array('class' => 'nav'));
1197 $pargs = array('page' => $page-1);
1198 $this->elementStart('li', array('class' => 'nav_prev'));
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: present than the currently displayed information.
1204 $this->elementEnd('li');
1207 $pargs = array('page' => $page+1);
1208 $this->elementStart('li', array('class' => 'nav_next'));
1209 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1211 // TRANS: Pagination message to go to a page displaying information more in the
1212 // TRANS: past than the currently displayed information.
1214 $this->elementEnd('li');
1216 if ($have_before || $have_after) {
1217 $this->elementEnd('ul');
1218 $this->elementEnd('dd');
1219 $this->elementEnd('dl');
1224 * An array of feeds for this action.
1226 * Returns an array of potential feeds for this action.
1228 * @return array Feed object to show in head and links
1237 * A design for this action
1239 * @return Design a design object to use
1242 function getDesign()
1244 return Design::siteDesign();
1248 * Check the session token.
1250 * Checks that the current form has the correct session token,
1251 * and throw an exception if it does not.
1256 // XXX: Finding this type of check with the same message about 50 times.
1257 // Possible to refactor?
1258 function checkSessionToken()
1261 $token = $this->trimmed('token');
1262 if (empty($token) || $token != common_session_token()) {
1263 $this->clientError(_('There was a problem with your session token.'));