X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Faction.php;h=10394c78956775490e1365cc31b19f4958b0693d;hb=f969d6349c244e2ec32c3ebe7eb355426006f4db;hp=d9b5afa9925d79094570c21521c159eb72309da9;hpb=8284b3cb82f4dec6e0f2bf74dea6e1a3bc7f4eac;p=quix0rs-gnu-social.git diff --git a/lib/action.php b/lib/action.php index d9b5afa992..10394c7895 100644 --- a/lib/action.php +++ b/lib/action.php @@ -68,7 +68,7 @@ class Action extends HTMLOutputter // lawsuit * @see XMLOutputter::__construct * @see HTMLOutputter::__construct */ - function __construct($output='php://output', $indent=true) + function __construct($output='php://output', $indent=null) { parent::__construct($output, $indent); } @@ -120,16 +120,15 @@ class Action extends HTMLOutputter // lawsuit { // XXX: attributes (profile?) $this->elementStart('head'); - if (Event::handle('StartHeadChildren', array($this))) { + if (Event::handle('StartShowHeadElements', array($this))) { $this->showTitle(); $this->showShortcutIcon(); $this->showStylesheets(); - $this->showScripts(); $this->showOpenSearch(); $this->showFeeds(); $this->showDescription(); $this->extraHead(); - Event::handle('EndHeadChildren', array($this)); + Event::handle('EndShowHeadElements', array($this)); } $this->elementEnd('head'); } @@ -142,7 +141,7 @@ class Action extends HTMLOutputter // lawsuit function showTitle() { $this->element('title', null, - sprintf(_("%s - %s"), + sprintf(_("%1\$s - %2\$s"), $this->title(), common_config('site', 'name'))); } @@ -169,7 +168,7 @@ class Action extends HTMLOutputter // lawsuit { if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) { $this->element('link', array('rel' => 'shortcut icon', - 'href' => theme_path('favicon.ico'))); + 'href' => Theme::path('favicon.ico'))); } else { $this->element('link', array('rel' => 'shortcut icon', 'href' => common_path('favicon.ico'))); @@ -178,7 +177,7 @@ class Action extends HTMLOutputter // lawsuit if (common_config('site', 'mobile')) { if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) { $this->element('link', array('rel' => 'apple-touch-icon', - 'href' => theme_path('apple-touch-icon.png'))); + 'href' => Theme::path('apple-touch-icon.png'))); } else { $this->element('link', array('rel' => 'apple-touch-icon', 'href' => common_path('apple-touch-icon.png'))); @@ -200,10 +199,6 @@ class Action extends HTMLOutputter // lawsuit if (Event::handle('StartShowStatusNetStyles', array($this)) && Event::handle('StartShowLaconicaStyles', array($this))) { $this->cssLink('css/display.css',null,'screen, projection, tv'); - if (common_config('site', 'mobile')) { - // TODO: "handheld" CSS for other mobile devices - $this->cssLink('css/mobile.css','base','only screen and (max-device-width: 480px)'); // Mobile WebKit - } $this->cssLink('css/print.css','base','print'); Event::handle('EndShowStatusNetStyles', array($this)); Event::handle('EndShowLaconicaStyles', array($this)); @@ -211,16 +206,16 @@ class Action extends HTMLOutputter // lawsuit if (Event::handle('StartShowUAStyles', array($this))) { $this->comment('[if IE]>comment('[if lte IE '.$ver.']>comment('[if IE]>script('js/jquery.min.js'); - $this->script('js/jquery.form.js'); - $this->script('js/jquery.joverlay.min.js'); + $this->script('jquery.min.js'); + $this->script('jquery.form.js'); + $this->script('jquery.cookie.js'); + $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }'); + $this->script('jquery.joverlay.min.js'); Event::handle('EndShowJQueryScripts', array($this)); } if (Event::handle('StartShowStatusNetScripts', array($this)) && Event::handle('StartShowLaconicaScripts', array($this))) { - $this->script('js/xbImportNode.js'); - $this->script('js/util.js'); + $this->script('xbImportNode.js'); + $this->script('util.js'); + $this->script('geometa.js'); // Frame-busting code to avoid clickjacking attacks. - $this->element('script', array('type' => 'text/javascript'), - 'if (window.top !== window.self) { window.top.location.href = window.self.location.href; }'); + $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }'); Event::handle('EndShowStatusNetScripts', array($this)); Event::handle('EndShowLaconicaScripts', array($this)); } @@ -355,6 +352,7 @@ class Action extends HTMLOutputter // lawsuit Event::handle('EndShowFooter', array($this)); } $this->elementEnd('div'); + $this->showScripts(); $this->elementEnd('body'); } @@ -370,7 +368,11 @@ class Action extends HTMLOutputter // lawsuit $this->elementStart('div', array('id' => 'header')); $this->showLogo(); $this->showPrimaryNav(); - $this->showSiteNotice(); + if (Event::handle('StartShowSiteNotice', array($this))) { + $this->showSiteNotice(); + + Event::handle('EndShowSiteNotice', array($this)); + } if (common_logged_in()) { $this->showNoticeForm(); } else { @@ -389,13 +391,20 @@ class Action extends HTMLOutputter // lawsuit $this->elementStart('address', array('id' => 'site_contact', 'class' => 'vcard')); if (Event::handle('StartAddressData', array($this))) { + if (common_config('singleuser', 'enabled')) { + $url = common_local_url('showstream', + array('nickname' => common_config('singleuser', 'nickname'))); + } else { + $url = common_local_url('public'); + } $this->elementStart('a', array('class' => 'url home bookmark', - 'href' => common_local_url('public'))); - if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) { + 'href' => $url)); + if (common_config('site', 'logo') || file_exists(Theme::file('logo.png'))) { $this->element('img', array('class' => 'logo photo', - 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : theme_path('logo.png'), + 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'), 'alt' => common_config('site', 'name'))); } + $this->text(' '); $this->element('span', array('class' => 'fn org'), common_config('site', 'name')); $this->elementEnd('a'); Event::handle('EndAddressData', array($this)); @@ -411,52 +420,75 @@ class Action extends HTMLOutputter // lawsuit function showPrimaryNav() { $user = common_current_user(); - $connect = ''; - if (common_config('xmpp', 'enabled')) { - $connect = 'imsettings'; - } else if (common_config('sms', 'enabled')) { - $connect = 'smssettings'; - } else if (common_config('twitter', 'enabled')) { - $connect = 'twittersettings'; - } - $this->elementStart('dl', array('id' => 'site_nav_global_primary')); $this->element('dt', null, _('Primary site navigation')); $this->elementStart('dd'); $this->elementStart('ul', array('class' => 'nav')); if (Event::handle('StartPrimaryNav', array($this))) { if ($user) { + // TRANS: Tooltip for main menu option "Personal" + $tooltip = _m('TOOLTIP', 'Personal profile and friends timeline'); + // TRANS: Main menu option when logged in for access to personal profile and friends timeline $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)), - _('Home'), _('Personal profile and friends timeline'), false, 'nav_home'); + _m('MENU', 'Personal'), $tooltip, false, 'nav_home'); + // TRANS: Tooltip for main menu option "Account" + $tooltip = _m('TOOLTIP', 'Change your email, avatar, password, profile'); + // TRANS: Main menu option when logged in for access to user settings $this->menuItem(common_local_url('profilesettings'), - _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account'); - if ($connect) { - $this->menuItem(common_local_url($connect), - _('Connect'), _('Connect to services'), false, 'nav_connect'); + _('Account'), $tooltip, false, 'nav_account'); + // TRANS: Tooltip for main menu option "Services" + $tooltip = _m('TOOLTIP', 'Connect to services'); + // TRANS: Main menu option when logged in and connection are possible for access to options to connect to other services + $this->menuItem(common_local_url('oauthconnectionssettings'), + _('Connect'), $tooltip, false, 'nav_connect'); + if ($user->hasRight(Right::CONFIGURESITE)) { + // TRANS: Tooltip for menu option "Admin" + $tooltip = _m('TOOLTIP', 'Change site configuration'); + // TRANS: Main menu option when logged in and site admin for access to site configuration + $this->menuItem(common_local_url('siteadminpanel'), + _m('MENU', 'Admin'), $tooltip, false, 'nav_admin'); } if (common_config('invite', 'enabled')) { + // TRANS: Tooltip for main menu option "Invite" + $tooltip = _m('TOOLTIP', 'Invite friends and colleagues to join you on %s'); + // TRANS: Main menu option when logged in and invitations are allowed for inviting new users $this->menuItem(common_local_url('invite'), - _('Invite'), - sprintf(_('Invite friends and colleagues to join you on %s'), + _m('MENU', 'Invite'), + sprintf($tooltip, common_config('site', 'name')), false, 'nav_invitecontact'); } + // TRANS: Tooltip for main menu option "Logout" + $tooltip = _m('TOOLTIP', 'Logout from the site'); + // TRANS: Main menu option when logged in to log out the current user $this->menuItem(common_local_url('logout'), - _('Logout'), _('Logout from the site'), false, 'nav_logout'); + _m('MENU', 'Logout'), $tooltip, false, 'nav_logout'); } else { if (!common_config('site', 'closed')) { + // TRANS: Tooltip for main menu option "Register" + $tooltip = _m('TOOLTIP', 'Create an account'); + // TRANS: Main menu option when not logged in to register a new account $this->menuItem(common_local_url('register'), - _('Register'), _('Create an account'), false, 'nav_register'); + _m('MENU', 'Register'), $tooltip, false, 'nav_register'); } + // TRANS: Tooltip for main menu option "Login" + $tooltip = _m('TOOLTIP', 'Login to the site'); + // TRANS: Main menu option when not logged in to log in $this->menuItem(common_local_url('login'), - _('Login'), _('Login to the site'), false, 'nav_login'); + _m('MENU', 'Login'), $tooltip, false, 'nav_login'); } + // TRANS: Tooltip for main menu option "Help" + $tooltip = _m('TOOLTIP', 'Help me!'); + // TRANS: Main menu option for help on the StatusNet site $this->menuItem(common_local_url('doc', array('title' => 'help')), - _('Help'), _('Help me!'), false, 'nav_help'); + _m('MENU', 'Help'), $tooltip, false, 'nav_help'); if ($user || !common_config('site', 'private')) { + // TRANS: Tooltip for main menu option "Search" + $tooltip = _m('TOOLTIP', 'Search for people or text'); + // TRANS: Main menu option when logged in or when the StatusNet instance is not private $this->menuItem(common_local_url('peoplesearch'), - _('Search'), _('Search for people or text'), false, 'nav_search'); + _m('MENU', 'Search'), $tooltip, false, 'nav_search'); } Event::handle('EndPrimaryNav', array($this)); } @@ -477,6 +509,7 @@ class Action extends HTMLOutputter // lawsuit if ($text) { $this->elementStart('dl', array('id' => 'site_notice', 'class' => 'system_notice')); + // TRANS: DT element for site notice. String is hidden in default CSS. $this->element('dt', null, _('Site notice')); $this->elementStart('dd', null); $this->raw($text); @@ -528,7 +561,10 @@ class Action extends HTMLOutputter // lawsuit $this->showContentBlock(); Event::handle('EndShowContentBlock', array($this)); } - $this->showAside(); + if (Event::handle('StartShowAside', array($this))) { + $this->showAside(); + Event::handle('EndShowAside', array($this)); + } $this->elementEnd('div'); } @@ -727,6 +763,8 @@ class Action extends HTMLOutputter // lawsuit _('Privacy')); $this->menuItem(common_local_url('doc', array('title' => 'source')), _('Source')); + $this->menuItem(common_local_url('version'), + _('Version')); $this->menuItem(common_local_url('doc', array('title' => 'contact')), _('Contact')); $this->menuItem(common_local_url('doc', array('title' => 'badge')), @@ -779,23 +817,47 @@ class Action extends HTMLOutputter // lawsuit */ function showContentLicense() { - $this->element('dt', array('id' => 'site_content_license'), _('Site content license')); - $this->elementStart('dd', array('id' => 'site_content_license_cc')); - $this->elementStart('p'); - $this->element('img', array('id' => 'license_cc', - 'src' => common_config('license', 'image'), - 'alt' => common_config('license', 'title'), - 'width' => '80', - 'height' => '15')); - //TODO: This is dirty: i18n - $this->text(_('All '.common_config('site', 'name').' content and data are available under the ')); - $this->element('a', array('class' => 'license', - 'rel' => 'external license', - 'href' => common_config('license', 'url')), - common_config('license', 'title')); - $this->text(_('license.')); - $this->elementEnd('p'); - $this->elementEnd('dd'); + if (Event::handle('StartShowContentLicense', array($this))) { + $this->element('dt', array('id' => 'site_content_license'), _('Site content license')); + $this->elementStart('dd', array('id' => 'site_content_license_cc')); + + switch (common_config('license', 'type')) { + case 'private': + $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'), + common_config('site', 'name'))); + // fall through + case 'allrightsreserved': + if (common_config('license', 'owner')) { + $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'), + common_config('license', 'owner'))); + } else { + $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.')); + } + break; + case 'cc': // fall through + default: + $this->elementStart('p'); + $this->element('img', array('id' => 'license_cc', + 'src' => common_config('license', 'image'), + 'alt' => common_config('license', 'title'), + 'width' => '80', + 'height' => '15')); + $this->text(' '); + //TODO: This is dirty: i18n + $this->text(_('All '.common_config('site', 'name').' content and data are available under the ')); + $this->element('a', array('class' => 'license', + 'rel' => 'external license', + 'href' => common_config('license', 'url')), + common_config('license', 'title')); + $this->text(' '); + $this->text(_('license.')); + $this->elementEnd('p'); + break; + } + + $this->elementEnd('dd'); + Event::handle('EndShowContentLicense', array($this)); + } } /** @@ -934,7 +996,7 @@ class Action extends HTMLOutputter // lawsuit if (is_null($arg)) { return $def; - } else if (in_array($arg, array('true', 'yes', '1'))) { + } else if (in_array($arg, array('true', 'yes', '1', 'on'))) { return true; } else if (in_array($arg, array('false', 'no', '0'))) { return false; @@ -943,6 +1005,36 @@ class Action extends HTMLOutputter // lawsuit } } + /** + * Integer value of an argument + * + * @param string $key query key we're interested in + * @param string $defValue optional default value (default null) + * @param string $maxValue optional max value (default null) + * @param string $minValue optional min value (default null) + * + * @return integer integer value + */ + + function int($key, $defValue=null, $maxValue=null, $minValue=null) + { + $arg = strtolower($this->trimmed($key)); + + if (is_null($arg) || !is_integer($arg)) { + return $defValue; + } + + if (!is_null($maxValue)) { + $arg = min($arg, $maxValue); + } + + if (!is_null($minValue)) { + $arg = max($arg, $minValue); + } + + return $arg; + } + /** * Server error * @@ -982,6 +1074,18 @@ class Action extends HTMLOutputter // lawsuit */ function selfUrl() + { + list($action, $args) = $this->returnToArgs(); + return common_local_url($action, $args); + } + + /** + * Returns arguments sufficient for re-constructing URL + * + * @return array two elements: action, other args + */ + + function returnToArgs() { $action = $this->trimmed('action'); $args = $this->args; @@ -995,8 +1099,7 @@ class Action extends HTMLOutputter // lawsuit foreach (array_keys($_COOKIE) as $cookie) { unset($args[$cookie]); } - - return common_local_url($action, $args); + return array($action, $args); } /** @@ -1045,8 +1148,7 @@ class Action extends HTMLOutputter // lawsuit { // Does a little before-after block for next/prev page if ($have_before || $have_after) { - $this->elementStart('div', array('class' => 'pagination')); - $this->elementStart('dl', null); + $this->elementStart('dl', 'pagination'); $this->element('dt', null, _('Pagination')); $this->elementStart('dd', null); $this->elementStart('ul', array('class' => 'nav')); @@ -1071,7 +1173,6 @@ class Action extends HTMLOutputter // lawsuit $this->elementEnd('ul'); $this->elementEnd('dd'); $this->elementEnd('dl'); - $this->elementEnd('div'); } } @@ -1098,4 +1199,22 @@ class Action extends HTMLOutputter // lawsuit { return Design::siteDesign(); } + + /** + * Check the session token. + * + * Checks that the current form has the correct session token, + * and throw an exception if it does not. + * + * @return void + */ + + function checkSessionToken() + { + // CSRF protection + $token = $this->trimmed('token'); + if (empty($token) || $token != common_session_token()) { + $this->clientError(_('There was a problem with your session token.')); + } + } }