/** * Get all content as a javascript-compatible string (only if there is an Ajax-Request present). * Falls back to {non_ajax_content}, {redirect_url} or Director::redirectBack() (in this order). * * @return string */ static function respond() { // we don't want non-ajax calls to receive javascript if (isset($_REQUEST['forcehtml'])) { return self::$non_ajax_content; } else { if (isset($_REQUEST['forceajax']) || Director::is_ajax()) { // TODO figure out a way to stay backwards-compatible with Ajax.Evaluator and still use the automatic evaluating of Prototype //header("Content-type: text/javascript"); return self::get_javascript(); } elseif (!empty(self::$non_ajax_content)) { return self::$non_ajax_content; } elseif (!empty(self::$redirect_url)) { Director::redirect(self::$redirect_url); return null; } elseif (!Director::redirected_to()) { Director::redirectBack(); return null; } else { return null; } } }
/** * Get all content as a javascript-compatible string (only if there is an Ajax-Request present). * Falls back to {non_ajax_content}, {redirect_url} or Director::redirectBack() (in this order). * * @return string */ static function respond() { // we don't want non-ajax calls to receive javascript if (isset($_REQUEST['forcehtml'])) { return self::$non_ajax_content; } else { if (isset($_REQUEST['forceajax']) || Director::is_ajax()) { $response = Controller::curr()->getResponse(); $response->addHeader('Content-Type', 'text/javascript'); return self::get_javascript(); } elseif (!empty(self::$non_ajax_content)) { return self::$non_ajax_content; } elseif (!empty(self::$redirect_url)) { Director::redirect(self::$redirect_url); return null; } elseif (!Director::redirected_to()) { Director::redirectBack(); return null; } else { return null; } } }
/** * @uses LeftAndMainDecorator->init() * @uses LeftAndMainDecorator->accessedCMS() * @uses CMSMenu */ function init() { parent::init(); SSViewer::setOption('rewriteHashlinks', false); // set language $member = Member::currentUser(); if (!empty($member->Locale)) { i18n::set_locale($member->Locale); } if (!empty($member->DateFormat)) { i18n::set_date_format($member->DateFormat); } if (!empty($member->TimeFormat)) { i18n::set_time_format($member->TimeFormat); } // can't be done in cms/_config.php as locale is not set yet CMSMenu::add_link('Help', _t('LeftAndMain.HELP', 'Help', PR_HIGH, 'Menu title'), self::$help_link); // set reading lang if (Object::has_extension('SiteTree', 'Translatable') && !$this->isAjax()) { Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree'))); } // Allow customisation of the access check by a decorator // Also all the canView() check to execute Director::redirect() if (!$this->canView() && !$this->response->isFinished()) { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); foreach ($menu as $candidate) { if ($candidate->Link && $candidate->Link != $this->Link() && $candidate->MenuItem->controller && singleton($candidate->MenuItem->controller)->canView()) { return Director::redirect($candidate->Link); } } if (Member::currentUser()) { Session::set("BackURL", null); } // if no alternate menu items have matched, return a permission error $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY', "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN', "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.")); return Security::permissionFailure($this, $messageSet); } // Don't continue if there's already been a redirection request. if (Director::redirected_to()) { return; } // Audit logging hook if (empty($_REQUEST['executeForm']) && !$this->isAjax()) { $this->extend('accessedCMS'); } // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); // Set default values in the config if missing. These things can't be defined in the config // file because insufficient information exists when that is being processed $htmlEditorConfig = HtmlEditorConfig::get_active(); $htmlEditorConfig->setOption('language', i18n::get_tinymce_lang()); if (!$htmlEditorConfig->getOption('content_css')) { $cssFiles = 'cms/css/editor.css'; // Use theme from the site config if (($config = SiteConfig::current_site_config()) && $config->Theme) { $theme = $config->Theme; } elseif (SSViewer::current_theme()) { $theme = SSViewer::current_theme(); } else { $theme = false; } if ($theme) { $cssFiles .= ',' . THEMES_DIR . "/{$theme}/css/editor.css"; } else { if (project()) { $cssFiles .= ',' . project() . '/css/editor.css'; } } $htmlEditorConfig->setOption('content_css', $cssFiles); } Requirements::css(CMS_DIR . '/css/typography.css'); Requirements::css(CMS_DIR . '/css/layout.css'); Requirements::css(CMS_DIR . '/css/cms_left.css'); Requirements::css(CMS_DIR . '/css/cms_right.css'); Requirements::css(SAPPHIRE_DIR . '/css/Form.css'); if (isset($_REQUEST['debug_firebug'])) { // Firebug is a useful console for debugging javascript // Its available as a Firefox extension or a javascript library // for easy inclusion in other browsers (just append ?debug_firebug=1 to the URL) Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/firebug-lite/firebug.js'); } else { // By default, we include fake-objects for all firebug calls // to avoid javascript errors when referencing console.log() etc in javascript code Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/firebug-lite/firebugx.js'); } Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototypefix/intro.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototypefix/outro.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery_improvements.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); //import all of jquery ui Requirements::javascript(CMS_DIR . '/thirdparty/jquery-layout/jquery.layout.js'); Requirements::javascript(CMS_DIR . '/thirdparty/jquery-layout/jquery.layout.state.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/json-js/json2.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-metadata/jquery.metadata.js'); Requirements::javascript(CMS_DIR . '/javascript/jquery-fitheighttoparent/jquery.fitheighttoparent.js'); Requirements::javascript(CMS_DIR . '/javascript/ssui.core.js'); // @todo Load separately so the CSS files can be inlined Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery.ui.all.css'); // entwine Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); // Required for TreeTools panel above tree Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js'); Requirements::javascript(CMS_DIR . '/thirdparty/jquery-notice/jquery.notice.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery-ondemand/jquery.ondemand.js'); Requirements::javascript(CMS_DIR . '/javascript/jquery-changetracker/lib/jquery.changetracker.js'); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/effects.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/dragdrop.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/controls.js'); Requirements::javascript(THIRDPARTY_DIR . '/tree/tree.js'); Requirements::css(THIRDPARTY_DIR . '/tree/tree.css'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.Tree.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.EditForm.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.AddForm.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.BatchActions.js'); // navigator Requirements::css(SAPPHIRE_DIR . '/css/SilverStripeNavigator.css'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/SilverStripeNavigator.js'); Requirements::themedCSS('typography'); foreach (self::$extra_requirements['javascript'] as $file) { Requirements::javascript($file[0]); } foreach (self::$extra_requirements['css'] as $file) { Requirements::css($file[0], $file[1]); } foreach (self::$extra_requirements['themedcss'] as $file) { Requirements::themedCSS($file[0], $file[1]); } Requirements::css(CMS_DIR . '/css/unjquery.css'); // Javascript combined files Requirements::combine_files('base.js', array('sapphire/thirdparty/prototype/prototype.js', 'sapphire/thirdparty/behaviour/behaviour.js', 'sapphire/thirdparty/jquery/jquery.js', 'sapphire/thirdparty/jquery-livequery/jquery.livequery.js', 'sapphire/javascript/jquery-ondemand/jquery.ondemand.js', 'sapphire/thirdparty/jquery-ui/jquery-ui.js', 'sapphire/thirdparty/firebug-lite/firebug.js', 'sapphire/thirdparty/firebug-lite/firebugx.js', 'sapphire/javascript/i18n.js')); Requirements::combine_files('leftandmain.js', array('sapphire/thirdparty/scriptaculous/effects.js', 'sapphire/thirdparty/scriptaculous/dragdrop.js', 'sapphire/thirdparty/scriptaculous/controls.js', 'cms/javascript/LeftAndMain.js', 'sapphire/javascript/tree/tree.js', 'sapphire/javascript/TreeSelectorField.js', 'cms/javascript/ThumbnailStripField.js')); $dummy = null; $this->extend('init', $dummy); // The user's theme shouldn't affect the CMS, if, for example, they have replaced // TableListField.ss or Form.ss. SSViewer::set_theme(null); }
/** * Show the "login" page * * @return string Returns the "login" page as HTML code. */ public function login() { // Event handler for pre-login, with an option to let it break you out of the login form $eventResults = $this->extend('onBeforeSecurityLogin'); // If there was a redirection, return if (Director::redirected_to()) { return; } else { if ($eventResults) { foreach ($eventResults as $result) { if ($result instanceof SS_HTTPResponse) { return $result; } } } } $customCSS = project() . '/css/tabs.css'; if (Director::fileExists($customCSS)) { Requirements::css($customCSS); } if (class_exists('SiteTree')) { $tmpPage = new Page(); $tmpPage->Title = _t('Security.LOGIN', 'Log in'); $tmpPage->URLSegment = "Security"; // Disable ID-based caching of the log-in page by making it a random number $tmpPage->ID = -1 * rand(1, 10000000); $controller = new Page_Controller($tmpPage); $controller->setModel($this->model); $controller->init(); //Controller::$currentController = $controller; } else { $controller = $this; } $content = ''; $forms = $this->GetLoginForms(); if (!count($forms)) { user_error('No login-forms found, please use Authenticator::register_authenticator() to add one', E_USER_ERROR); } // only display tabs when more than one authenticator is provided // to save bandwidth and reduce the amount of custom styling needed if (count($forms) > 1) { Requirements::css(SAPPHIRE_DIR . "/css/Form.css"); // Needed because the <base href=".."> in the template makes problems // with the tabstrip library otherwise $link_base = Director::absoluteURL($this->Link("login")); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_improvements.js"); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); Requirements::css(SAPPHIRE_DIR . '/css/Security_login.css'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js'); $content = '<div id="Form_EditForm">'; $content .= '<div class="ss-tabset">'; $content .= '<ul>'; $content_forms = ''; foreach ($forms as $form) { $content .= "<li><a href=\"#{$form->FormName()}_tab\">{$form->getAuthenticator()->get_name()}</a></li>\n"; $content_forms .= '<div class="tab" id="' . $form->FormName() . '_tab">' . $form->forTemplate() . "</div>\n"; } $content .= "</ul>\n" . $content_forms . "\n</div>\n</div>\n"; } else { $content .= $forms[0]->forTemplate(); } if (strlen($message = Session::get('Security.Message.message')) > 0) { $message_type = Session::get('Security.Message.type'); if ($message_type == 'bad') { $message = "<p class=\"message {$message_type}\">{$message}</p>"; } else { $message = "<p>{$message}</p>"; } $customisedController = $controller->customise(array("Content" => $message, "Form" => $content)); } else { $customisedController = $controller->customise(array("Form" => $content)); } Session::clear('Security.Message'); // custom processing return $customisedController->renderWith(array('Security_login', 'Security', $this->stat('template_main'), 'BlankPage')); }
public function init() { parent::init(); // If we've accessed the homepage as /home/, then we should redirect to /. if ($this->dataRecord && $this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord) && (!isset($this->urlParams['Action']) || !$this->urlParams['Action']) && !$_POST && !$_FILES && !Director::redirected_to()) { $getVars = $_GET; unset($getVars['url']); if ($getVars) { $url = "?" . http_build_query($getVars); } else { $url = ""; } Director::redirect($url, 301); return; } if ($this->dataRecord) { $this->dataRecord->extend('contentcontrollerInit', $this); } else { singleton('SiteTree')->extend('contentcontrollerInit', $this); } if (Director::redirected_to()) { return; } // Check page permissions if ($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->canView()) { return Security::permissionFailure($this); } // Draft/Archive security check - only CMS users should be able to look at stage/archived content if ($this->URLSegment != 'Security' && !Session::get('unsecuredDraftSite') && (Versioned::current_archived_date() || Versioned::current_stage() && Versioned::current_stage() != 'Live')) { if (!$this->dataRecord->canViewStage(Versioned::current_stage())) { $link = $this->Link(); $message = _t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. <a href="%s">Click here to go back to the published site.</a>'); Session::clear('currentStage'); Session::clear('archiveDate'); return Security::permissionFailure($this, sprintf($message, Controller::join_links($link, "?stage=Live"))); } } // Use theme from the site config if (($config = SiteConfig::current_site_config()) && $config->Theme) { SSViewer::set_theme($config->Theme); } }
/** * @uses LeftAndMainExtension->init() * @uses LeftAndMainExtension->accessedCMS() * @uses CMSMenu */ function init() { parent::init(); SSViewer::setOption('rewriteHashlinks', false); // set language $member = Member::currentUser(); if (!empty($member->Locale)) { i18n::set_locale($member->Locale); } if (!empty($member->DateFormat)) { i18n::set_date_format($member->DateFormat); } if (!empty($member->TimeFormat)) { i18n::set_time_format($member->TimeFormat); } // can't be done in cms/_config.php as locale is not set yet CMSMenu::add_link('Help', _t('LeftAndMain.HELP', 'Help', PR_HIGH, 'Menu title'), self::$help_link); // Allow customisation of the access check by a extension // Also all the canView() check to execute Director::redirect() if (!$this->canView() && !$this->response->isFinished()) { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); foreach ($menu as $candidate) { if ($candidate->Link && $candidate->Link != $this->Link() && $candidate->MenuItem->controller && singleton($candidate->MenuItem->controller)->canView()) { return Director::redirect($candidate->Link); } } if (Member::currentUser()) { Session::set("BackURL", null); } // if no alternate menu items have matched, return a permission error $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY', "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN', "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.")); return Security::permissionFailure($this, $messageSet); } // Don't continue if there's already been a redirection request. if (Director::redirected_to()) { return; } // Audit logging hook if (empty($_REQUEST['executeForm']) && !$this->isAjax()) { $this->extend('accessedCMS'); } // Requirements Requirements::combine_files('lib.js', array(THIRDPARTY_DIR . '/prototype/prototype.js', THIRDPARTY_DIR . '/behaviour/behaviour.js', THIRDPARTY_DIR . '/jquery/jquery.js', SAPPHIRE_DIR . '/javascript/jquery_improvements.js', THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js', SAPPHIRE_DIR . '/javascript/jquery-ondemand/jquery.ondemand.js', THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js', THIRDPARTY_DIR . '/json-js/json2.js', THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js', THIRDPARTY_DIR . '/jquery-cookie/jquery.cookie.js', THIRDPARTY_DIR . '/jquery-query/jquery.query.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jquery-notice/jquery.notice.js', THIRDPARTY_DIR . '/jquery-metadata/jquery.metadata.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jsizes/lib/jquery.sizes.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jlayout/lib/jlayout.border.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jlayout/lib/jquery.jlayout.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.adapter.jquery.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.html4.js', THIRDPARTY_DIR . '/jstree/jquery.jstree.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jquery-hoverIntent/jquery.hoverIntent.js', SAPPHIRE_ADMIN_DIR . '/javascript/jquery-changetracker/lib/jquery.changetracker.js', SAPPHIRE_DIR . '/javascript/TreeDropdownField.js', SAPPHIRE_DIR . "/thirdparty/jquery-form/jquery.form.js", SAPPHIRE_DIR . '/javascript/DateField.js', SAPPHIRE_DIR . '/javascript/HtmlEditorField.js', SAPPHIRE_DIR . '/javascript/TabSet.js', SAPPHIRE_DIR . '/javascript/Validator.js', SAPPHIRE_DIR . '/javascript/i18n.js', SAPPHIRE_ADMIN_DIR . '/javascript/ssui.core.js')); Requirements::combine_files('leftandmain.js', array(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Content.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.AddForm.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Preview.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.BatchActions.js')); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(SAPPHIRE_ADMIN_DIR . '/javascript/lang'); Requirements::combine_files('lib.css', array(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css', SAPPHIRE_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.css', THIRDPARTY_DIR . '/jstree/themes/apple/style.css', SAPPHIRE_DIR . '/javascript/TreeDropdownField.css', SAPPHIRE_ADMIN_DIR . '/css/unjquery.css')); Requirements::css(SAPPHIRE_ADMIN_DIR . '/css/screen.css'); // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); // Set default values in the config if missing. These things can't be defined in the config // file because insufficient information exists when that is being processed $htmlEditorConfig = HtmlEditorConfig::get_active(); $htmlEditorConfig->setOption('language', i18n::get_tinymce_lang()); if (!$htmlEditorConfig->getOption('content_css')) { $cssFiles = array(); $cssFiles[] = 'sapphire/admin/css/editor.css'; // Use theme from the site config if (class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) { $theme = $config->Theme; } elseif (SSViewer::current_theme()) { $theme = SSViewer::current_theme(); } else { $theme = false; } if ($theme) { $cssFiles[] = THEMES_DIR . "/{$theme}/css/editor.css"; } else { if (project()) { $cssFiles[] = project() . '/css/editor.css'; } } // Remove files that don't exist foreach ($cssFiles as $k => $cssFile) { if (!file_exists(BASE_PATH . '/' . $cssFile)) { unset($cssFiles[$k]); } } $htmlEditorConfig->setOption('content_css', implode(',', $cssFiles)); } foreach (self::$extra_requirements['javascript'] as $file) { Requirements::javascript($file[0]); } foreach (self::$extra_requirements['css'] as $file) { Requirements::css($file[0], $file[1]); } foreach (self::$extra_requirements['themedcss'] as $file) { Requirements::themedCSS($file[0], $file[1]); } $dummy = null; $this->extend('init', $dummy); // The user's theme shouldn't affect the CMS, if, for example, they have replaced // TableListField.ss or Form.ss. SSViewer::set_theme(null); }
/** * @uses LeftAndMainDecorator->init() * @uses LeftAndMainDecorator->accessedCMS() * @uses CMSMenu * @uses Director::set_site_mode() */ function init() { parent::init(); Director::set_site_mode('cms'); // set language $member = Member::currentUser(); if(!empty($member->Locale)) { i18n::set_locale($member->Locale); } // can't be done in cms/_config.php as locale is not set yet CMSMenu::add_link( 'Help', _t('LeftAndMain.HELP', 'Help', PR_HIGH, 'Menu title'), 'http://userhelp.silverstripe.com' ); // set reading lang if(Translatable::is_enabled() && !Director::is_ajax()) { Translatable::choose_site_lang(array_keys(Translatable::get_existing_content_languages('SiteTree'))); } // Allow customisation of the access check by a decorator if(!$this->canView()) { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); foreach($menu as $candidate) { if( $candidate->Link && $candidate->Link != $this->Link() && $candidate->MenuItem->controller && singleton($candidate->MenuItem->controller)->canView() ) { return Director::redirect($candidate->Link); } } if(Member::currentUser()) { Session::set("BackURL", null); } // if no alternate menu items have matched, return a permission error $messageSet = array( 'default' => _t('LeftAndMain.PERMDEFAULT',"Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY',"I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN',"You have been logged out of the CMS. If you would like to log in again, enter a username and password below."), ); return Security::permissionFailure($this, $messageSet); } // Don't continue if there's already been a redirection request. if(Director::redirected_to()) return; // Audit logging hook if(empty($_REQUEST['executeForm']) && !Director::is_ajax()) $this->extend('accessedCMS'); Requirements::css(CMS_DIR . '/css/typography.css'); Requirements::css(CMS_DIR . '/css/layout.css'); Requirements::css(CMS_DIR . '/css/cms_left.css'); Requirements::css(CMS_DIR . '/css/cms_right.css'); Requirements::css(SAPPHIRE_DIR . '/css/Form.css'); if(isset($_REQUEST['debug_firebug'])) { // Firebug is a useful console for debugging javascript // Its available as a Firefox extension or a javascript library // for easy inclusion in other browsers (just append ?debug_firebug=1 to the URL) Requirements::javascript(THIRDPARTY_DIR . '/firebug/firebug-lite-compressed.js'); } else { // By default, we include fake-objects for all firebug calls // to avoid javascript errors when referencing console.log() etc in javascript code Requirements::javascript(THIRDPARTY_DIR . '/firebug/firebugx.js'); } Requirements::javascript(THIRDPARTY_DIR . '/prototype.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery_improvements.js'); Requirements::javascript(THIRDPARTY_DIR . '/behaviour.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/livequery/jquery.livequery.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/core/jquery.ondemand.js'); Requirements::javascript(THIRDPARTY_DIR . '/prototype_improvements.js'); Requirements::javascript(THIRDPARTY_DIR . '/loader.js'); Requirements::javascript(THIRDPARTY_DIR . '/hover.js'); Requirements::javascript(THIRDPARTY_DIR . '/layout_helpers.js'); Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js'); Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/dragdrop.js'); Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/controls.js'); Requirements::css(THIRDPARTY_DIR . '/greybox/greybox.css'); Requirements::javascript(THIRDPARTY_DIR . '/greybox/AmiJS.js'); Requirements::javascript(THIRDPARTY_DIR . '/greybox/greybox.js'); Requirements::javascript(THIRDPARTY_DIR . '/tree/tree.js'); Requirements::css(THIRDPARTY_DIR . '/tree/tree.css'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_left.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain_right.js'); Requirements::javascript(CMS_DIR . '/javascript/SideTabs.js'); Requirements::javascript(CMS_DIR . '/javascript/SideReports.js'); Requirements::javascript(CMS_DIR . '/javascript/LangSelector.js'); Requirements::javascript(CMS_DIR . '/javascript/TranslationTab.js'); Requirements::themedCSS('typography'); foreach (self::$extra_requirements['javascript'] as $file) { Requirements::javascript($file[0]); } foreach (self::$extra_requirements['css'] as $file) { Requirements::css($file[0], $file[1]); } foreach (self::$extra_requirements['themedcss'] as $file) { Requirements::css($file[0], $file[1]); } Requirements::customScript('Behaviour.addLoader(hideLoading);'); // Javascript combined files Requirements::combine_files( 'assets/base.js', array( 'jsparty/prototype.js', 'jsparty/behaviour.js', 'jsparty/prototype_improvements.js', 'jsparty/jquery/jquery.js', 'jsparty/jquery/plugins/livequery/jquery.livequery.js', 'jsparty/jquery/plugins/effen/jquery.fn.js', 'sapphire/javascript/core/jquery.ondemand.js', 'jsparty/jquery/jquery_improvements.js', 'jsparty/firebug/firebugx.js', 'sapphire/javascript/i18n.js', ) ); Requirements::combine_files( 'assets/leftandmain.js', array( 'jsparty/loader.js', 'jsparty/hover.js', 'jsparty/layout_helpers.js', 'jsparty/scriptaculous/effects.js', 'jsparty/scriptaculous/dragdrop.js', 'jsparty/scriptaculous/controls.js', 'jsparty/greybox/AmiJS.js', 'jsparty/greybox/greybox.js', 'cms/javascript/LeftAndMain.js', 'cms/javascript/LeftAndMain_left.js', 'cms/javascript/LeftAndMain_right.js', //'jsparty/tiny_mce2/tiny_mce_src.js', 'jsparty/tree/tree.js', 'jsparty/tabstrip/tabstrip.js', 'cms/javascript/TinyMCEImageEnhancement.js', 'jsparty/SWFUpload/SWFUpload.js', 'cms/javascript/Upload.js', 'sapphire/javascript/TreeSelectorField.js', 'cms/javascript/ThumbnailStripField.js', ) ); Requirements::combine_files( 'assets/cmsmain.js', array( 'cms/javascript/CMSMain.js', 'cms/javascript/CMSMain_left.js', 'cms/javascript/CMSMain_right.js', 'cms/javascript/SideTabs.js', 'cms/javascript/SideReports.js', 'cms/javascript/LangSelector.js', 'cms/javascript/TranslationTab.js', 'jsparty/calendar/calendar.js', 'jsparty/calendar/lang/calendar-en.js', 'jsparty/calendar/calendar-setup.js', ) ); // DEPRECATED 2.3: Use init() $dummy = null; $this->extend('augmentInit', $dummy); $dummy = null; $this->extend('init', $dummy); }
public function init() { parent::init(); // If we've accessed the homepage as /home/, then we should redirect to /. if($this->dataRecord && $this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord) && !$this->urlParams['Action'] && !$_POST && !$_FILES && !Director::redirected_to() ) { $getVars = $_GET; unset($getVars['url']); if($getVars) $url = "?" . http_build_query($getVars); else $url = ""; Director::redirect($url, 301); return; } if($this->dataRecord) $this->dataRecord->extend('contentcontrollerInit', $this); else singleton('SiteTree')->extend('contentcontrollerInit', $this); if(Director::redirected_to()) return; Director::set_site_mode('site'); // Check page permissions if($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->can('View')) { Security::permissionFailure($this); } // Draft/Archive security check - only CMS users should be able to look at stage/archived content if($this->URLSegment != 'Security' && !Session::get('unsecuredDraftSite') && (Versioned::current_archived_date() || (Versioned::current_stage() && Versioned::current_stage() != 'Live'))) { if(!Permission::check('CMS_ACCESS_CMSMain')) { $link = $this->Link(); $message = _t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. <a href="%s">Click here to go back to the published site.</a>'); Security::permissionFailure($this, sprintf($message, "$link?stage=Live")); return; } } }
function init() { Director::set_site_mode('cms'); // set language $member = Member::currentUser(); if (!empty($member->Locale)) { i18n::set_locale($member->Locale); } // set reading lang if (Translatable::is_enabled() && !Director::is_ajax()) { Translatable::choose_site_lang(array_keys(i18n::get_existing_content_languages('SiteTree'))); } parent::init(); // Allow customisation of the access check by a decorator if ($this->hasMethod('alternateAccessCheck')) { $isAllowed = $this->alternateAccessCheck(); // Default security check for LeftAndMain sub-class permissions } else { $isAllowed = Permission::check("CMS_ACCESS_{$this->class}"); if (!$isAllowed && $this->class == 'CMSMain') { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); if (($first = $menu->First()) && $first->Link) { Director::redirect($first->Link); } } } // Don't continue if there's already been a redirection request. if (Director::redirected_to()) { return; } // Access failure! if (!$isAllowed) { $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY', "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN', "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.")); Security::permissionFailure($this, $messageSet); return; } Requirements::javascript('jsparty/prototype.js'); Requirements::javascript('jsparty/behaviour.js'); Requirements::javascript('jsparty/prototype_improvements.js'); Requirements::javascript('jsparty/loader.js'); Requirements::javascript('jsparty/hover.js'); Requirements::javascript('jsparty/layout_helpers.js'); Requirements::javascript(MCE_ROOT . 'tiny_mce_src.js'); Requirements::javascript('cms/javascript/ImageEditor/Activator.js'); Requirements::javascript('jsparty/tiny_mce_improvements.js'); Requirements::javascript('jsparty/scriptaculous/effects.js'); Requirements::javascript('jsparty/scriptaculous/dragdrop.js'); Requirements::javascript('jsparty/scriptaculous/controls.js'); Requirements::css('jsparty/greybox/greybox.css'); Requirements::javascript('jsparty/greybox/AmiJS.js'); Requirements::javascript('jsparty/greybox/greybox.js'); Requirements::javascript('jsparty/tree/tree.js'); Requirements::css('jsparty/tree/tree.css'); Requirements::javascript('jsparty/tabstrip/tabstrip.js'); Requirements::css('jsparty/tabstrip/tabstrip.css'); Requirements::css('cms/css/TinyMCEImageEnhancement.css'); Requirements::javascript('cms/javascript/TinyMCEImageEnhancement.js'); Requirements::javascript('cms/javascript/LeftAndMain.js'); Requirements::javascript('cms/javascript/LeftAndMain_left.js'); Requirements::javascript('cms/javascript/LeftAndMain_right.js'); Requirements::css('sapphire/css/Form.css'); // Requirements::javascript('cms/javascript/MemberList.js'); Requirements::javascript('cms/javascript/ForumAdmin.js'); Requirements::javascript('cms/javascript/SideTabs.js'); Requirements::javascript('cms/javascript/TaskList.js'); Requirements::javascript('cms/javascript/CommentList.js'); Requirements::javascript('cms/javascript/SideReports.js'); Requirements::javascript('cms/javascript/LangSelector.js'); Requirements::javascript('cms/javascript/TranslationTab.js'); Requirements::javascript('sapphire/javascript/Validator.js'); Requirements::javascript('sapphire/javascript/UniqueFields.js'); Requirements::javascript('sapphire/javascript/RedirectorPage.js'); Requirements::javascript('sapphire/javascript/DataReport.js'); Requirements::javascript('sapphire/javascript/ToggleCompositeField.js'); Requirements::css('sapphire/css/SubmittedFormReportField.css'); Requirements::javascript('sapphire/javascript/FieldEditor.js'); Requirements::css('sapphire/css/FieldEditor.css'); Requirements::css('sapphire/css/TableListField.css'); Requirements::css('sapphire/css/ComplexTableField.css'); Requirements::javascript('sapphire/javascript/TableListField.js'); Requirements::javascript('sapphire/javascript/TableField.js'); Requirements::javascript('sapphire/javascript/ComplexTableField.js'); Requirements::javascript('sapphire/javascript/RelationComplexTableField.js'); Requirements::css('sapphire/css/TreeDropdownField.css'); Requirements::css('sapphire/css/CheckboxSetField.css'); Requirements::javascript('jsparty/calendar/calendar.js'); Requirements::javascript('jsparty/calendar/lang/calendar-en.js'); Requirements::javascript('jsparty/calendar/calendar-setup.js'); Requirements::css('sapphire/css/CalendarDateField.css'); Requirements::css('jsparty/calendar/calendar-win2k-1.css'); Requirements::javascript('sapphire/javascript/DropdownTimeField.js'); Requirements::css('sapphire/css/DropdownTimeField.css'); Requirements::css('sapphire/css/PopupDateTimeField.css'); Requirements::javascript('sapphire/javascript/SelectionGroup.js'); Requirements::css('sapphire/css/SelectionGroup.css'); Requirements::javascript('jsparty/SWFUpload/SWFUpload.js'); Requirements::javascript('cms/javascript/Upload.js'); Requirements::javascript('sapphire/javascript/HasManyFileField.js'); Requirements::css('sapphire/css/HasManyFileField.css'); Requirements::themedCSS('typography'); // For Widgets Requirements::css('cms/css/WidgetAreaEditor.css'); Requirements::javascript('cms/javascript/WidgetAreaEditor.js'); // For Blog Requirements::javascript('blog/javascript/bbcodehelp.js'); Requirements::javascript("sapphire/javascript/Security_login.js"); $dummy = null; $this->extend('augmentInit', $dummy); }
/** * Show the "login" page * * @return string Returns the "login" page as HTML code. */ public function login() { // Event handler for pre-login, with an option to let it break you out of the login form $eventResults = $this->extend('onBeforeSecurityLogin'); // If there was a redirection, return if (Director::redirected_to()) { return; } else { if ($eventResults) { foreach ($eventResults as $result) { if ($result instanceof HTTPResponse) { return $result; } } } } $customCSS = project() . '/css/tabs.css'; if (Director::fileExists($customCSS)) { Requirements::css($customCSS); } $tmpPage = new Page(); $tmpPage->Title = _t('Security.LOGIN', 'Log in'); $tmpPage->URLSegment = "Security"; $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children $controller = new Page_Controller($tmpPage); $controller->init(); //Controller::$currentController = $controller; $content = ''; $forms = $this->GetLoginForms(); if (!count($forms)) { user_error('No login-forms found, please use Authenticator::register_authenticator() to add one', E_USER_ERROR); } // only display tabs when more than one authenticator is provided // to save bandwidth and reduce the amount of custom styling needed if (count($forms) > 1) { Requirements::javascript(THIRDPARTY_DIR . "/loader.js"); Requirements::javascript(THIRDPARTY_DIR . "/prototype.js"); Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js"); Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js"); Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/effects.js"); Requirements::css(SAPPHIRE_DIR . "/css/Form.css"); // Needed because the <base href=".."> in the template makes problems // with the tabstrip library otherwise $link_base = Director::absoluteURL($this->Link("login")); Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js"); Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery_improvements.js"); Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/livequery/jquery.livequery.js'); Requirements::javascript(THIRDPARTY_DIR . "/tabstrip/tabstrip.js"); Requirements::css(THIRDPARTY_DIR . "/tabstrip/tabstrip.css"); $content = '<div id="Form_EditForm">'; $content .= '<ul class="tabstrip">'; $content_forms = ''; foreach ($forms as $form) { $content .= "<li><a href=\"{$link_base}#{$form->FormName()}_tab\">{$form->getAuthenticator()->get_name()}</a></li>\n"; $content_forms .= '<div class="tab" id="' . $form->FormName() . '_tab">' . $form->forTemplate() . "</div>\n"; } $content .= "</ul>\n" . $content_forms . "\n</div>\n"; } else { $content .= $forms[0]->forTemplate(); } if (strlen($message = Session::get('Security.Message.message')) > 0) { $message_type = Session::get('Security.Message.type'); if ($message_type == 'bad') { $message = "<p class=\"message {$message_type}\">{$message}</p>"; } else { $message = "<p>{$message}</p>"; } $customisedController = $controller->customise(array("Content" => $message, "Form" => $content)); } else { $customisedController = $controller->customise(array("Content" => $content)); } Session::clear('Security.Message'); // custom processing return $customisedController->renderWith(array('Security_login', 'Security', $this->stat('template_main'))); }
function init() { parent::init(); if (Director::redirected_to()) { return; } if (!$this->canView()) { $messageSet = array('default' => _t('Forum.LOGINDEFAULT', 'Enter your email address and password to view this forum.'), 'alreadyLoggedIn' => _t('Forum.LOGINALREADY', 'I\'m sorry, but you can\'t access this forum until you\'ve logged in. If you want to log in as someone else, do so below'), 'logInAgain' => _t('Forum.LOGINAGAIN', 'You have been logged out of the forums. If you would like to log in again, enter a username and password below.')); Security::permissionFailure($this, $messageSet); return; } // Log this visit to the ForumMember if they exist $member = Member::currentUser(); if ($member) { $member->LastViewed = date("Y-m-d H:i:s"); $member->write(); } Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js"); Requirements::javascript("forum/javascript/forum.js"); Requirements::javascript("forum/javascript/jquery.MultiFile.js"); Requirements::themedCSS('Forum'); RSSFeed::linkToFeed($this->Parent()->Link("rss/forum/{$this->ID}"), sprintf(_t('Forum.RSSFORUM', "Posts to the '%s' forum"), $this->Title)); RSSFeed::linkToFeed($this->Parent()->Link("rss"), _t('Forum.RSSFORUMS', 'Posts to all forums')); // Set the back url if (isset($_SERVER['REQUEST_URI'])) { Session::set('BackURL', $_SERVER['REQUEST_URI']); } else { Session::set('BackURL', $this->Link()); } }