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
58 // This should be protected/private in the future
59 public $args = array();
61 // Action properties, set per-class
62 protected $action = false;
63 protected $ajax = false;
64 protected $menus = true;
66 // The currently scoped profile
67 protected $scoped = null;
69 // Messages to the front-end user
70 protected $error = null;
71 protected $msg = null;
76 * Just wraps the HTMLOutputter constructor.
78 * @param string $output URI to output to, default = stdout
79 * @param boolean $indent Whether to indent output, default true
81 * @see XMLOutputter::__construct
82 * @see HTMLOutputter::__construct
84 function __construct($output='php://output', $indent=null)
86 parent::__construct($output, $indent);
99 static public function run(array $args=array(), $output='php://output', $indent=null) {
100 $class = get_called_class();
101 $action = new $class($output, $indent);
102 $action->execute($args);
106 public function execute(array $args=array()) {
108 if (common_config('db', 'mirror') && $this->isReadOnly($args)) {
109 if (is_array(common_config('db', 'mirror'))) {
110 // "load balancing", ha ha
111 $arr = common_config('db', 'mirror');
112 $k = array_rand($arr);
115 $mirror = common_config('db', 'mirror');
118 // everyone else uses the mirror
119 common_config_set('db', 'database', $mirror);
122 if ($this->prepare($args)) {
123 $this->handle($args);
128 * For initializing members of the class.
130 * @param array $argarray misc. arguments
132 * @return boolean true
134 protected function prepare(array $args=array())
136 $this->args = common_copy_args($args);
138 $this->action = $this->trimmed('action');
140 if ($this->ajax || $this->boolean('ajax')) {
141 // check with StatusNet::isAjax()
142 StatusNet::setAjax(true);
145 $this->scoped = Profile::current();
151 * Show page, a template method.
157 if (Event::handle('StartShowHTML', array($this))) {
160 Event::handle('EndShowHTML', array($this));
162 if (Event::handle('StartShowHead', array($this))) {
165 Event::handle('EndShowHead', array($this));
167 if (Event::handle('StartShowBody', array($this))) {
169 Event::handle('EndShowBody', array($this));
171 if (Event::handle('StartEndHTML', array($this))) {
173 Event::handle('EndEndHTML', array($this));
181 if (isset($_startTime)) {
182 $endTime = microtime(true);
183 $diff = round(($endTime - $_startTime) * 1000);
184 $this->raw("<!-- ${diff}ms -->");
187 return parent::endHTML();
191 * Show head, a template method.
197 // XXX: attributes (profile?)
198 $this->elementStart('head');
199 if (Event::handle('StartShowHeadElements', array($this))) {
200 if (Event::handle('StartShowHeadTitle', array($this))) {
202 Event::handle('EndShowHeadTitle', array($this));
204 $this->showShortcutIcon();
205 $this->showStylesheets();
206 $this->showOpenSearch();
208 $this->showDescription();
210 Event::handle('EndShowHeadElements', array($this));
212 $this->elementEnd('head');
216 * Show title, a template method.
222 $this->element('title', null,
223 // TRANS: Page title. %1$s is the title, %2$s is the site name.
224 sprintf(_('%1$s - %2$s'),
226 common_config('site', 'name')));
230 * Returns the page title
234 * @return string page title
239 // TRANS: Page title for a page without a title set.
240 return _('Untitled page');
244 * Show themed shortcut icon
248 function showShortcutIcon()
250 if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
251 $this->element('link', array('rel' => 'shortcut icon',
252 'href' => Theme::path('favicon.ico')));
254 // favicon.ico should be HTTPS if the rest of the page is
255 $this->element('link', array('rel' => 'shortcut icon',
256 'href' => common_path('favicon.ico', StatusNet::isHTTPS())));
259 if (common_config('site', 'mobile')) {
260 if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
261 $this->element('link', array('rel' => 'apple-touch-icon',
262 'href' => Theme::path('apple-touch-icon.png')));
264 $this->element('link', array('rel' => 'apple-touch-icon',
265 'href' => common_path('apple-touch-icon.png')));
275 function showStylesheets()
277 if (Event::handle('StartShowStyles', array($this))) {
279 // Use old name for StatusNet for compatibility on events
281 if (Event::handle('StartShowStatusNetStyles', array($this)) &&
282 Event::handle('StartShowLaconicaStyles', array($this))) {
283 $this->primaryCssLink(null, 'screen, projection, tv, print');
284 Event::handle('EndShowStatusNetStyles', array($this));
285 Event::handle('EndShowLaconicaStyles', array($this));
288 $this->cssLink(common_path('js/css/smoothness/jquery-ui.css', StatusNet::isHTTPS()));
290 if (Event::handle('StartShowUAStyles', array($this))) {
291 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
292 'href="'.Theme::path('css/ie.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
293 foreach (array(6,7) as $ver) {
294 if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
295 // Yes, IE people should be put in jail.
296 $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
297 'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
300 if (file_exists(Theme::file('css/ie.css'))) {
301 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
302 'href="'.Theme::path('css/ie.css', null).'?version='.STATUSNET_VERSION.'" /><![endif]');
304 Event::handle('EndShowUAStyles', array($this));
307 Event::handle('EndShowStyles', array($this));
309 if (common_config('custom_css', 'enabled')) {
310 $css = common_config('custom_css', 'css');
311 if (Event::handle('StartShowCustomCss', array($this, &$css))) {
312 if (trim($css) != '') {
315 Event::handle('EndShowCustomCss', array($this));
321 function primaryCssLink($mainTheme=null, $media=null)
323 $theme = new Theme($mainTheme);
325 // Some themes may have external stylesheets, such as using the
326 // Google Font APIs to load webfonts.
327 foreach ($theme->getExternals() as $url) {
328 $this->cssLink($url, $mainTheme, $media);
331 // If the currently-selected theme has dependencies on other themes,
332 // we'll need to load their display.css files as well in order.
333 $baseThemes = $theme->getDeps();
334 foreach ($baseThemes as $baseTheme) {
335 $this->cssLink('css/display.css', $baseTheme, $media);
337 $this->cssLink('css/display.css', $mainTheme, $media);
339 // Additional styles for RTL languages
340 if (is_rtl(common_language())) {
341 if (file_exists(Theme::file('css/rtl.css'))) {
342 $this->cssLink('css/rtl.css', $mainTheme, $media);
348 * Show javascript headers
352 function showScripts()
354 if (Event::handle('StartShowScripts', array($this))) {
355 if (Event::handle('StartShowJQueryScripts', array($this))) {
356 if (common_config('site', 'minify')) {
357 $this->script('jquery.min.js');
358 $this->script('jquery.form.min.js');
359 $this->script('jquery-ui.min.js');
360 $this->script('jquery.cookie.min.js');
361 $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.min.js', StatusNet::isHTTPS()).'"); }');
362 $this->script('jquery.joverlay.min.js');
363 $this->script('jquery.infieldlabel.min.js');
365 $this->script('jquery.js');
366 $this->script('jquery.form.js');
367 $this->script('jquery-ui.min.js');
368 $this->script('jquery.cookie.js');
369 $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js', StatusNet::isHTTPS()).'"); }');
370 $this->script('jquery.joverlay.js');
371 $this->script('jquery.infieldlabel.js');
374 Event::handle('EndShowJQueryScripts', array($this));
376 if (Event::handle('StartShowStatusNetScripts', array($this)) &&
377 Event::handle('StartShowLaconicaScripts', array($this))) {
378 if (common_config('site', 'minify')) {
379 $this->script('util.min.js');
381 $this->script('util.js');
382 $this->script('xbImportNode.js');
383 $this->script('geometa.js');
385 // This route isn't available in single-user mode.
386 // Not sure why, but it causes errors here.
387 $this->inlineScript('var _peopletagAC = "' .
388 common_local_url('peopletagautocomplete') . '";');
389 $this->showScriptMessages();
390 // Anti-framing code to avoid clickjacking attacks in older browsers.
391 // This will show a blank page if the page is being framed, which is
392 // consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
393 // header, which prevents framing in newer browser.
394 if (common_config('javascript', 'bustframes')) {
395 $this->inlineScript('if (window.top !== window.self) { document.write = ""; window.top.location = window.self.location; setTimeout(function () { document.body.innerHTML = ""; }, 1); window.self.onload = function () { document.body.innerHTML = ""; }; }');
397 Event::handle('EndShowStatusNetScripts', array($this));
398 Event::handle('EndShowLaconicaScripts', array($this));
400 Event::handle('EndShowScripts', array($this));
405 * Exports a map of localized text strings to JavaScript code.
407 * Plugins can add to what's exported by hooking the StartScriptMessages or EndScriptMessages
408 * events and appending to the array. Try to avoid adding strings that won't be used, as
409 * they'll be added to HTML output.
411 function showScriptMessages()
415 if (Event::handle('StartScriptMessages', array($this, &$messages))) {
416 // Common messages needed for timeline views etc...
418 // TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
419 $messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
421 // TRANS: Inline reply form submit button: submits a reply comment.
422 $messages['reply_submit'] = _m('BUTTON', 'Reply');
424 // TRANS: Placeholder text for inline reply form. Clicking in this box will turn it into a mini notice form.
425 $messages['reply_placeholder'] = _m('Write a reply...');
427 $messages = array_merge($messages, $this->getScriptMessages());
429 Event::handle('EndScriptMessages', array($this, &$messages));
432 if (!empty($messages)) {
433 $this->inlineScript('SN.messages=' . json_encode($messages));
440 * If the action will need localizable text strings, export them here like so:
442 * return array('pool_deepend' => _('Deep end'),
443 * 'pool_shallow' => _('Shallow end'));
445 * The exported map will be available via SN.msg() to JS code:
447 * $('#pool').html('<div class="deepend"></div><div class="shallow"></div>');
448 * $('#pool .deepend').text(SN.msg('pool_deepend'));
449 * $('#pool .shallow').text(SN.msg('pool_shallow'));
451 * Exports a map of localized text strings to JavaScript code.
453 * Plugins can add to what's exported on any action by hooking the StartScriptMessages or
454 * EndScriptMessages events and appending to the array. Try to avoid adding strings that won't
455 * be used, as they'll be added to HTML output.
457 function getScriptMessages()
463 * Show OpenSearch headers
467 function showOpenSearch()
469 $this->element('link', array('rel' => 'search',
470 'type' => 'application/opensearchdescription+xml',
471 'href' => common_local_url('opensearch', array('type' => 'people')),
472 'title' => common_config('site', 'name').' People Search'));
473 $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
474 'href' => common_local_url('opensearch', array('type' => 'notice')),
475 'title' => common_config('site', 'name').' Notice Search'));
487 $feeds = $this->getFeeds();
490 foreach ($feeds as $feed) {
491 $this->element('link', array('rel' => $feed->rel(),
492 'href' => $feed->url,
493 'type' => $feed->mimeType(),
494 'title' => $feed->title));
506 function showDescription()
508 // does nothing by default
512 * Show extra stuff in <head>.
520 // does nothing by default
526 * Calls template methods
532 $this->elementStart('body', (common_current_user()) ? array('id' => strtolower($this->trimmed('action')),
533 'class' => 'user_in')
534 : array('id' => strtolower($this->trimmed('action'))));
535 $this->elementStart('div', array('id' => 'wrap'));
536 if (Event::handle('StartShowHeader', array($this))) {
539 Event::handle('EndShowHeader', array($this));
543 if (Event::handle('StartShowFooter', array($this))) {
546 Event::handle('EndShowFooter', array($this));
548 $this->elementEnd('div');
549 $this->showScripts();
550 $this->elementEnd('body');
554 * Show header of the page.
556 * Calls template methods
560 function showHeader()
562 $this->elementStart('div', array('id' => 'header'));
564 $this->showPrimaryNav();
565 if (Event::handle('StartShowSiteNotice', array($this))) {
566 $this->showSiteNotice();
568 Event::handle('EndShowSiteNotice', array($this));
571 $this->elementEnd('div');
575 * Show configured logo.
581 $this->elementStart('address', array('id' => 'site_contact',
582 'class' => 'vcard'));
583 if (Event::handle('StartAddressData', array($this))) {
584 if (common_config('singleuser', 'enabled')) {
585 $user = User::singleUser();
586 $url = common_local_url('showstream',
587 array('nickname' => $user->nickname));
588 } else if (common_logged_in()) {
589 $cur = common_current_user();
590 $url = common_local_url('all', array('nickname' => $cur->nickname));
592 $url = common_local_url('public');
595 $this->elementStart('a', array('class' => 'url home bookmark',
598 if (StatusNet::isHTTPS()) {
599 $logoUrl = common_config('site', 'ssllogo');
600 if (empty($logoUrl)) {
601 // if logo is an uploaded file, try to fall back to HTTPS file URL
602 $httpUrl = common_config('site', 'logo');
603 if (!empty($httpUrl)) {
604 $f = File::getKV('url', $httpUrl);
605 if (!empty($f) && !empty($f->filename)) {
606 // this will handle the HTTPS case
607 $logoUrl = File::url($f->filename);
612 $logoUrl = common_config('site', 'logo');
615 if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
616 // This should handle the HTTPS case internally
617 $logoUrl = Theme::path('logo.png');
620 if (!empty($logoUrl)) {
621 $this->element('img', array('class' => 'logo photo',
623 'alt' => common_config('site', 'name')));
627 $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
628 $this->elementEnd('a');
630 Event::handle('EndAddressData', array($this));
632 $this->elementEnd('address');
636 * Show primary navigation.
640 function showPrimaryNav()
642 $this->elementStart('div', array('id' => 'site_nav_global_primary'));
644 $user = common_current_user();
646 if (!empty($user) || !common_config('site', 'private')) {
647 $form = new SearchForm($this);
651 $pn = new PrimaryNav($this);
653 $this->elementEnd('div');
661 function showSiteNotice()
663 // Revist. Should probably do an hAtom pattern here
664 $text = common_config('site', 'notice');
666 $this->elementStart('div', array('id' => 'site_notice',
667 'class' => 'system_notice'));
669 $this->elementEnd('div');
676 * MAY overload if no notice form needed... or direct message box????
680 function showNoticeForm()
682 // TRANS: Tab on the notice form.
683 $tabs = array('status' => _m('TAB','Status'));
685 $this->elementStart('div', 'input_forms');
687 if (Event::handle('StartShowEntryForms', array(&$tabs))) {
688 $this->elementStart('ul', array('class' => 'nav',
689 'id' => 'input_form_nav'));
691 foreach ($tabs as $tag => $title) {
692 $attrs = array('id' => 'input_form_nav_'.$tag,
693 'class' => 'input_form_nav_tab');
695 if ($tag == 'status') {
696 // We're actually showing the placeholder form,
697 // but we special-case the 'Status' tab as if
698 // it were a small version of it.
699 $attrs['class'] .= ' current';
701 $this->elementStart('li', $attrs);
704 array('href' => 'javascript:SN.U.switchInputFormTab("'.$tag.'")'),
706 $this->elementEnd('li');
709 $this->elementEnd('ul');
711 $attrs = array('class' => 'input_form current',
712 'id' => 'input_form_placeholder');
713 $this->elementStart('div', $attrs);
714 $form = new NoticePlaceholderForm($this);
716 $this->elementEnd('div');
718 foreach ($tabs as $tag => $title) {
719 $attrs = array('class' => 'input_form',
720 'id' => 'input_form_'.$tag);
722 $this->elementStart('div', $attrs);
726 if (Event::handle('StartMakeEntryForm', array($tag, $this, &$form))) {
727 if ($tag == 'status') {
728 $options = $this->noticeFormOptions();
729 $form = new NoticeForm($this, $options);
731 Event::handle('EndMakeEntryForm', array($tag, $this, $form));
738 $this->elementEnd('div');
742 $this->elementEnd('div');
745 function noticeFormOptions()
751 * Show anonymous message.
757 function showAnonymousMessage()
759 // needs to be defined by the class
765 * Shows local navigation, content block and aside.
771 $this->elementStart('div', array('id' => 'core'));
772 $this->elementStart('div', array('id' => 'aside_primary_wrapper'));
773 $this->elementStart('div', array('id' => 'content_wrapper'));
774 $this->elementStart('div', array('id' => 'site_nav_local_views_wrapper'));
775 if (Event::handle('StartShowLocalNavBlock', array($this))) {
776 $this->showLocalNavBlock();
778 Event::handle('EndShowLocalNavBlock', array($this));
780 if (Event::handle('StartShowContentBlock', array($this))) {
781 $this->showContentBlock();
783 Event::handle('EndShowContentBlock', array($this));
785 if (Event::handle('StartShowAside', array($this))) {
788 Event::handle('EndShowAside', array($this));
790 $this->elementEnd('div');
791 $this->elementEnd('div');
792 $this->elementEnd('div');
793 $this->elementEnd('div');
797 * Show local navigation block.
801 function showLocalNavBlock()
803 // Need to have this ID for CSS; I'm too lazy to add it to
805 $this->elementStart('div', array('id' => 'site_nav_local_views'));
806 // Cheat cheat cheat!
807 $this->showLocalNav();
808 $this->elementEnd('div');
812 * If there's a logged-in user, show a bit of login context
816 function showProfileBlock()
818 if (common_logged_in()) {
819 $block = new DefaultProfileBlock($this);
825 * Show local navigation.
831 function showLocalNav()
833 $nav = new DefaultLocalNav($this);
838 * Show menu for an object (group, profile)
840 * This block will only show if a subclass has overridden
841 * the showObjectNav() method.
845 function showObjectNavBlock()
847 $rmethod = new ReflectionMethod($this, 'showObjectNav');
848 $dclass = $rmethod->getDeclaringClass()->getName();
850 if ($dclass != 'Action') {
851 // Need to have this ID for CSS; I'm too lazy to add it to
853 $this->elementStart('div', array('id' => 'site_nav_object',
854 'class' => 'section'));
855 $this->showObjectNav();
856 $this->elementEnd('div');
861 * Show object navigation.
863 * If there are things to do with this object, show it here.
867 function showObjectNav()
873 * Show content block.
877 function showContentBlock()
879 $this->elementStart('div', array('id' => 'content'));
880 if (common_logged_in()) {
881 if (Event::handle('StartShowNoticeForm', array($this))) {
882 $this->showNoticeForm();
883 Event::handle('EndShowNoticeForm', array($this));
886 if (Event::handle('StartShowPageTitle', array($this))) {
887 $this->showPageTitle();
888 Event::handle('EndShowPageTitle', array($this));
890 $this->showPageNoticeBlock();
891 $this->elementStart('div', array('id' => 'content_inner'));
892 // show the actual content (forms, lists, whatever)
893 $this->showContent();
894 $this->elementEnd('div');
895 $this->elementEnd('div');
903 function showPageTitle()
905 $this->element('h1', null, $this->title());
909 * Show page notice block.
911 * Only show the block if a subclassed action has overrided
912 * Action::showPageNotice(), or an event handler is registered for
913 * the StartShowPageNotice event, in which case we assume the
914 * 'page_notice' definition list is desired. This is to prevent
915 * empty 'page_notice' definition lists from being output everywhere.
919 function showPageNoticeBlock()
921 $rmethod = new ReflectionMethod($this, 'showPageNotice');
922 $dclass = $rmethod->getDeclaringClass()->getName();
924 if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
926 $this->elementStart('div', array('id' => 'page_notice',
927 'class' => 'system_notice'));
928 if (Event::handle('StartShowPageNotice', array($this))) {
929 $this->showPageNotice();
930 Event::handle('EndShowPageNotice', array($this));
932 $this->elementEnd('div');
939 * SHOULD overload (unless there's not a notice)
943 function showPageNotice()
950 * MUST overload (unless there's not a notice)
954 function showContent()
965 $this->elementStart('div', array('id' => 'aside_primary',
966 'class' => 'aside'));
967 $this->showProfileBlock();
968 if (Event::handle('StartShowObjectNavBlock', array($this))) {
969 $this->showObjectNavBlock();
970 Event::handle('EndShowObjectNavBlock', array($this));
972 if (Event::handle('StartShowSections', array($this))) {
973 $this->showSections();
974 Event::handle('EndShowSections', array($this));
976 if (Event::handle('StartShowExportData', array($this))) {
977 $this->showExportData();
978 Event::handle('EndShowExportData', array($this));
980 $this->elementEnd('div');
984 * Show export data feeds.
988 function showExportData()
990 $feeds = $this->getFeeds();
992 $fl = new FeedList($this);
1004 function showSections()
1006 // for each section, show it
1014 function showFooter()
1016 $this->elementStart('div', array('id' => 'footer'));
1017 if (Event::handle('StartShowInsideFooter', array($this))) {
1018 $this->showSecondaryNav();
1019 $this->showLicenses();
1020 Event::handle('EndShowInsideFooter', array($this));
1022 $this->elementEnd('div');
1026 * Show secondary navigation.
1030 function showSecondaryNav()
1032 $sn = new SecondaryNav($this);
1041 function showLicenses()
1043 $this->showStatusNetLicense();
1044 $this->showContentLicense();
1048 * Show StatusNet license.
1052 function showStatusNetLicense()
1054 if (common_config('site', 'broughtby')) {
1055 // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is set.
1056 // TRANS: Text between [] is a link description, text between () is the link itself.
1057 // TRANS: Make sure there is no whitespace between "]" and "(".
1058 // TRANS: "%%site.broughtby%%" is the value of the variable site.broughtby
1059 $instr = _('**%%site.name%%** is a social network, courtesy of [%%site.broughtby%%](%%site.broughtbyurl%%).');
1061 // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is not set.
1062 $instr = _('**%%site.name%%** is a social network.');
1065 // TRANS: Second sentence of the StatusNet site license. Mentions the StatusNet source code license.
1066 // TRANS: Make sure there is no whitespace between "]" and "(".
1067 // TRANS: Text between [] is a link description, text between () is the link itself.
1068 // TRANS: %s is the version of StatusNet that is being used.
1069 $instr .= sprintf(_('It runs on [GNU social](http://www.gnu.org/software/social/), version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), STATUSNET_VERSION);
1070 $output = common_markup_to_html($instr);
1071 $this->raw($output);
1076 * Show content license.
1080 function showContentLicense()
1082 if (Event::handle('StartShowContentLicense', array($this))) {
1083 switch (common_config('license', 'type')) {
1085 // TRANS: Content license displayed when license is set to 'private'.
1086 // TRANS: %1$s is the site name.
1087 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
1088 common_config('site', 'name')));
1090 case 'allrightsreserved':
1091 if (common_config('license', 'owner')) {
1092 // TRANS: Content license displayed when license is set to 'allrightsreserved'.
1093 // TRANS: %1$s is the copyright owner.
1094 $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
1095 common_config('license', 'owner')));
1097 // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
1098 $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
1101 case 'cc': // fall through
1103 $this->elementStart('p');
1105 $image = common_config('license', 'image');
1106 $sslimage = common_config('license', 'sslimage');
1108 if (StatusNet::isHTTPS()) {
1109 if (!empty($sslimage)) {
1111 } else if (preg_match('#^http://i.creativecommons.org/#', $image)) {
1112 // CC support HTTPS on their images
1113 $url = preg_replace('/^http/', 'https', $image);
1115 // Better to show mixed content than no content
1122 $this->element('img', array('id' => 'license_cc',
1124 'alt' => common_config('license', 'title'),
1128 // TRANS: license message in footer.
1129 // TRANS: %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration.
1130 $notice = _('All %1$s content and data are available under the %2$s license.');
1131 $link = "<a class=\"license\" rel=\"external license\" href=\"" .
1132 htmlspecialchars(common_config('license', 'url')) .
1134 htmlspecialchars(common_config('license', 'title')) .
1136 $this->raw(sprintf(htmlspecialchars($notice),
1137 htmlspecialchars(common_config('site', 'name')),
1139 $this->elementEnd('p');
1143 Event::handle('EndShowContentLicense', array($this));
1148 * Return last modified, if applicable.
1152 * @return string last modified http header
1154 function lastModified()
1156 // For comparison with If-Last-Modified
1157 // If not applicable, return null
1162 * Return etag, if applicable.
1166 * @return string etag http header
1174 * Return true if read only.
1178 * @param array $args other arguments
1180 * @return boolean is read only action?
1182 function isReadOnly($args)
1188 * Returns query argument or default value if not found
1190 * @param string $key requested argument
1191 * @param string $def default value to return if $key is not provided
1193 * @return boolean is read only action?
1195 function arg($key, $def=null)
1197 if (array_key_exists($key, $this->args)) {
1198 return $this->args[$key];
1205 * Returns trimmed query argument or default value if not found
1207 * @param string $key requested argument
1208 * @param string $def default value to return if $key is not provided
1210 * @return boolean is read only action?
1212 function trimmed($key, $def=null)
1214 $arg = $this->arg($key, $def);
1215 return is_string($arg) ? trim($arg) : $arg;
1221 * @return boolean is read only action?
1223 protected function handle()
1225 header('Vary: Accept-Encoding,Cookie');
1227 $lm = $this->lastModified();
1228 $etag = $this->etag();
1231 header('ETag: ' . $etag);
1235 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
1236 if ($this->isCacheable()) {
1237 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1238 header( "Cache-Control: private, must-revalidate, max-age=0" );
1245 $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
1246 $_SERVER['HTTP_IF_NONE_MATCH'] : null;
1247 if ($if_none_match) {
1248 // If this check fails, ignore the if-modified-since below.
1250 if ($this->_hasEtag($etag, $if_none_match)) {
1251 header('HTTP/1.1 304 Not Modified');
1252 // Better way to do this?
1258 if (!$checked && $lm && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
1259 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
1260 $ims = strtotime($if_modified_since);
1262 header('HTTP/1.1 304 Not Modified');
1263 // Better way to do this?
1270 * Is this action cacheable?
1272 * If the action returns a last-modified
1274 * @param array $argarray is ignored since it's now passed in in prepare()
1276 * @return boolean is read only action?
1278 function isCacheable()
1284 * Has etag? (private)
1286 * @param string $etag etag http header
1287 * @param string $if_none_match ifNoneMatch http header
1291 function _hasEtag($etag, $if_none_match)
1293 $etags = explode(',', $if_none_match);
1294 return in_array($etag, $etags) || in_array('*', $etags);
1298 * Boolean understands english (yes, no, true, false)
1300 * @param string $key query key we're interested in
1301 * @param string $def default value
1303 * @return boolean interprets yes/no strings as boolean
1305 function boolean($key, $def=false)
1307 $arg = strtolower($this->trimmed($key));
1309 if (is_null($arg)) {
1311 } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1313 } else if (in_array($arg, array('false', 'no', '0'))) {
1321 * Integer value of an argument
1323 * @param string $key query key we're interested in
1324 * @param string $defValue optional default value (default null)
1325 * @param string $maxValue optional max value (default null)
1326 * @param string $minValue optional min value (default null)
1328 * @return integer integer value
1330 function int($key, $defValue=null, $maxValue=null, $minValue=null)
1332 $arg = strtolower($this->trimmed($key));
1334 if (is_null($arg) || !is_integer($arg)) {
1338 if (!is_null($maxValue)) {
1339 $arg = min($arg, $maxValue);
1342 if (!is_null($minValue)) {
1343 $arg = max($arg, $minValue);
1352 * @param string $msg error message to display
1353 * @param integer $code http error code, 500 by default
1357 function serverError($msg, $code=500)
1359 $action = $this->trimmed('action');
1360 common_debug("Server error '$code' on '$action': $msg", __FILE__);
1361 throw new ServerException($msg, $code);
1367 * @param string $msg error message to display
1368 * @param integer $code http error code, 400 by default
1372 function clientError($msg, $code=400)
1374 $action = $this->trimmed('action');
1375 common_debug("User error '$code' on '$action': $msg", __FILE__);
1376 throw new ClientException($msg, $code);
1380 * Returns the current URL
1382 * @return string current URL
1386 list($action, $args) = $this->returnToArgs();
1387 return common_local_url($action, $args);
1391 * Returns arguments sufficient for re-constructing URL
1393 * @return array two elements: action, other args
1395 function returnToArgs()
1397 $action = $this->trimmed('action');
1398 $args = $this->args;
1399 unset($args['action']);
1400 if (common_config('site', 'fancy')) {
1403 if (array_key_exists('submit', $args)) {
1404 unset($args['submit']);
1406 foreach (array_keys($_COOKIE) as $cookie) {
1407 unset($args[$cookie]);
1409 return array($action, $args);
1413 * Generate a menu item
1415 * @param string $url menu URL
1416 * @param string $text menu name
1417 * @param string $title title attribute, null by default
1418 * @param boolean $is_selected current menu item, false by default
1419 * @param string $id element id, null by default
1423 function menuItem($url, $text, $title=null, $is_selected=false, $id=null, $class=null)
1425 // Added @id to li for some control.
1426 // XXX: We might want to move this to htmloutputter.php
1429 if ($class !== null) {
1430 $classes[] = trim($class);
1433 $classes[] = 'current';
1436 if (!empty($classes)) {
1437 $lattrs['class'] = implode(' ', $classes);
1440 if (!is_null($id)) {
1441 $lattrs['id'] = $id;
1444 $this->elementStart('li', $lattrs);
1445 $attrs['href'] = $url;
1447 $attrs['title'] = $title;
1449 $this->element('a', $attrs, $text);
1450 $this->elementEnd('li');
1454 * Generate pagination links
1456 * @param boolean $have_before is there something before?
1457 * @param boolean $have_after is there something after?
1458 * @param integer $page current page
1459 * @param string $action current action
1460 * @param array $args rest of query arguments
1464 // XXX: The messages in this pagination method only tailor to navigating
1465 // notices. In other lists, "Previous"/"Next" type navigation is
1466 // desirable, but not available.
1467 function pagination($have_before, $have_after, $page, $action, $args=null)
1469 // Does a little before-after block for next/prev page
1470 if ($have_before || $have_after) {
1471 $this->elementStart('ul', array('class' => 'nav',
1472 'id' => 'pagination'));
1475 $pargs = array('page' => $page-1);
1476 $this->elementStart('li', array('class' => 'nav_prev'));
1477 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1479 // TRANS: Pagination message to go to a page displaying information more in the
1480 // TRANS: present than the currently displayed information.
1482 $this->elementEnd('li');
1485 $pargs = array('page' => $page+1);
1486 $this->elementStart('li', array('class' => 'nav_next'));
1487 $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1489 // TRANS: Pagination message to go to a page displaying information more in the
1490 // TRANS: past than the currently displayed information.
1492 $this->elementEnd('li');
1494 if ($have_before || $have_after) {
1495 $this->elementEnd('ul');
1500 * An array of feeds for this action.
1502 * Returns an array of potential feeds for this action.
1504 * @return array Feed object to show in head and links
1512 * Check the session token.
1514 * Checks that the current form has the correct session token,
1515 * and throw an exception if it does not.
1519 // XXX: Finding this type of check with the same message about 50 times.
1520 // Possible to refactor?
1521 function checkSessionToken()
1524 $token = $this->trimmed('token');
1525 if (empty($token) || $token != common_session_token()) {
1526 // TRANS: Client error text when there is a problem with the session token.
1527 $this->clientError(_('There was a problem with your session token.'));
1532 * Check if the current request is a POST
1534 * @return boolean true if POST; otherwise false.
1539 return ($_SERVER['REQUEST_METHOD'] == 'POST');