array(), 'css' => array(), 'themedcss' => array(), ); /** * @param Member $member * @return boolean */ function canView($member = null) { if(!$member && $member !== FALSE) { $member = Member::currentUser(); } // cms menus only for logged-in members if(!$member) return false; // alternative decorated checks if($this->hasMethod('alternateAccessCheck')) { $alternateAllowed = $this->alternateAccessCheck(); if($alternateAllowed === FALSE) return false; } // Default security check for LeftAndMain sub-class permissions if(!Permission::checkMember($member, "CMS_ACCESS_$this->class")) { return false; } return true; } /** * @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); } // 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.org' ); // set reading lang if(Object::has_extension('SiteTree', 'Translatable') && !Director::is_ajax()) { Translatable::choose_site_locale(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'); // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); 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/ui.core.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.datepicker.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.dialog.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.tabs.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.draggable.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.droppable.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/ui.accordion.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.core.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.slide.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.drop.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/effects.scale.js'); 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(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/ui.all.css'); // concrete Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-concrete/dist/jquery.concrete-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'); 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::css(CMS_DIR . '/css/unjquery.css'); // Javascript combined files Requirements::combine_files( 'assets/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/firebug-lite/firebug.js', 'sapphire/thirdparty/firebug-lite/firebugx.js', 'sapphire/javascript/i18n.js', ) ); Requirements::combine_files( 'assets/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/thirdparty/swfupload/swfupload/swfupload.js', 'cms/javascript/Upload.js', 'cms/javascript/TinyMCEImageEnhancement.js', 'sapphire/javascript/TreeSelectorField.js', 'cms/javascript/ThumbnailStripField.js', ) ); Requirements::combine_files( 'assets/cmsmain.js', array( 'cms/javascript/CMSMain_left.js', 'cms/javascript/CMSMain_right.js', ) ); $dummy = null; $this->extend('init', $dummy); } //------------------------------------------------------------------------------------------// // Main controllers /** * You should implement a Link() function in your subclass of LeftAndMain, * to point to the URL of that particular controller. * * @return string */ public function Link($action = null) { // Handle missing url_segments if(!$this->stat('url_segment', true)) self::$url_segment = $this->class; return Controller::join_links( $this->stat('url_base', true), $this->stat('url_segment', true), '/', // trailing slash needed if $action is null! "$action" ); } /** * Returns the menu title for the given LeftAndMain subclass. * Implemented static so that we can get this value without instantiating an object. * Menu title is *not* internationalised. */ static function menu_title_for_class($class) { $title = eval("return $class::\$menu_title;"); if(!$title) $title = preg_replace('/Admin$/', '', $class); return $title; } public function show($request) { // TODO Necessary for TableListField URLs to work properly if($request->param('ID')) $this->setCurrentPageID($request->param('ID')); if(Director::is_ajax()) { SSViewer::setOption('rewriteHashlinks', false); $form = $this->getEditForm($request->param('ID')); return $form->formHtmlContent(); } else { // Rendering is handled by template, which will call EditForm() eventually return $this->renderWith($this->getViewer('show')); } } /** * @deprecated 2.4 Please use show() */ public function getitem($request) { $form = $this->getEditForm($request->getVar('ID')); if($form) return $form->formHtmlContent(); else return ""; } //------------------------------------------------------------------------------------------// // Main UI components /** * Returns the main menu of the CMS. This is also used by init() * to work out which sections the user has access to. * * @return DataObjectSet */ public function MainMenu() { // Don't accidentally return a menu if you're not logged in - it's used to determine access. if(!Member::currentUser()) return new DataObjectSet(); // Encode into DO set $menu = new DataObjectSet(); $menuItems = CMSMenu::get_viewable_menu_items(); if($menuItems) foreach($menuItems as $code => $menuItem) { // alternate permission checks (in addition to LeftAndMain->canView()) if( isset($menuItem->controller) && $this->hasMethod('alternateMenuDisplayCheck') && !$this->alternateMenuDisplayCheck($menuItem->controller) ) { continue; } $linkingmode = ""; if(strpos($this->Link(), $menuItem->url) !== false) { if($this->Link() == $menuItem->url) { $linkingmode = "current"; // default menu is the one with a blank {@link url_segment} } else if(singleton($menuItem->controller)->stat('url_segment') == '') { if($this->Link() == $this->stat('url_base').'/') $linkingmode = "current"; } else { $linkingmode = "current"; } } // already set in CMSMenu::populate_menu(), but from a static pre-controller // context, so doesn't respect the current user locale in _t() calls - as a workaround, // we simply call LeftAndMain::menu_title_for_class() again // if we're dealing with a controller if($menuItem->controller) { $defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller); $title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle); } else { $title = $menuItem->title; } $menu->push(new ArrayData(array( "MenuItem" => $menuItem, "Title" => Convert::raw2xml($title), "Code" => $code, "Link" => $menuItem->url, "LinkingMode" => $linkingmode ))); } // if no current item is found, assume that first item is shown //if(!isset($foundCurrent)) return $menu; } public function CMSTopMenu() { return $this->renderWith(array('CMSTopMenu_alternative','CMSTopMenu')); } /** * Return a list of appropriate templates for this class, with the given suffix */ protected function getTemplatesWithSuffix($suffix) { $classes = array_reverse(ClassInfo::ancestry($this->class)); foreach($classes as $class) { $templates[] = $class . $suffix; if($class == 'LeftAndMain') break; } return $templates; } public function Left() { return $this->renderWith($this->getTemplatesWithSuffix('_left')); } public function Right() { return $this->renderWith($this->getTemplatesWithSuffix('_right')); } public function getRecord($id, $className = null) { if($id && is_numeric($id)) { if(!$className) $className = $this->stat('tree_class'); return DataObject::get_by_id($className, $id); } } /** * @return String HTML */ public function SiteTreeAsUL() { return $this->getSiteTreeFor($this->stat('tree_class')); } /** * Get a site tree HTML listing which displays the nodes under the given criteria. * * @param $className The class of the root object * @param $rootID The ID of the root object. If this is null then a complete tree will be * shown * @param $childrenMethod The method to call to get the children of the tree. For example, * Children, AllChildrenIncludingDeleted, or AllHistoricalChildren * @return String Nested
%s %s. %s
', _t('LeftAndMain_right.ss.WELCOMETO','Welcome to'), $this->getApplicationName(), _t('CHOOSEPAGE','Please choose an item from the left.') ) ) ), new FieldSet() ); $form->unsetValidator(); return $form; } /** * @return Form */ function AddForm() { $class = $this->stat('tree_class'); $typeMap = array($class => singleton($class)->i18n_singular_name()); $typeField = new DropdownField('Type', false, $typeMap, $class); $form = new Form( $this, 'AddForm', new FieldSet( new HiddenField('ParentID'), $typeField->performReadonlyTransformation() ), new FieldSet( new FormAction('doAdd', _t('AssetAdmin_left.ss.GO','Go')) ) ); $form->addExtraClass('actionparams'); return $form; } /** * Add a new group and return its details suitable for ajax. */ public function doAdd($data, $form) { $class = $this->stat('tree_class'); // check create permissions if(!singleton($class)->canCreate()) return Security::permissionFailure($this); // check addchildren permissions if( singleton($class)->hasDatabaseField('Hierarchy') && isset($data['ParentID']) && is_numeric($data['ParentID']) ) { $parentRecord = DataObject::get_by_id($class, $data['ParentID']); if( $parentRecord->hasMethod('canAddChildren') && !$parentRecord->canAddChildren() ) return Security::permissionFailure($this); } $record = Object::create($class); $form->saveInto($record); $record->write(); // Used in TinyMCE inline folder creation if(isset($data['returnID'])) { return $record->ID; } else { $form = $this->getEditForm($record->ID); return $form->formHtmlContent(); } } /** * Batch Actions Handler */ function batchactions() { return new CMSBatchActionHandler($this, 'batchactions', $this->stat('tree_class')); } /** * @return Form */ function BatchActionsForm() { $actions = $this->batchactions()->batchActionList(); $actionsMap = array(); foreach($actions as $action) $actionsMap[$action->Link] = $action->Title; $form = new Form( $this, 'BatchActionsForm', new FieldSet( new LiteralField( 'Intro', sprintf('%s
', _t( 'CMSMain_left.ss.SELECTPAGESACTIONS', 'Select the pages that you want to change & then click an action:' ) ) ), new HiddenField('csvIDs'), new DropdownField( 'Action', false, $actionsMap ) ), new FieldSet( // TODO i18n new FormAction('submit', "Go") ) ); $form->addExtraClass('actionparams'); $form->unsetValidator(); return $form; } public function myprofile() { $form = $this->Member_ProfileForm(); return $this->customise(array( 'Form' => $form ))->renderWith('BlankPage'); } public function Member_ProfileForm() { return new Member_ProfileForm($this, 'Member_ProfileForm', Member::currentUser()); } public function printable() { $form = $this->getEditForm($this->currentPageID()); if(!$form) return false; $form->transform(new PrintableTransformation()); $form->actions = null; Requirements::clear(); Requirements::css(CMS_DIR . '/css/LeftAndMain_printable.css'); return array( "PrintForm" => $form ); } /** * Identifier for the currently shown record, * in most cases a database ID. Inspects the following * sources (in this order): * - GET/POST parameter named 'ID' * - URL parameter named 'ID' * - Session value namespaced by classname, e.g. "CMSMain.currentPage" * * @return int */ public function currentPageID() { if($this->request->getVar('ID')) { return $this->request->getVar('ID'); } elseif ($this->request->param('ID') && is_numeric($this->request->param('ID'))) { return $this->request->param('ID'); } elseif(Session::get("{$this->class}.currentPage")) { return Session::get("{$this->class}.currentPage"); } else { return null; } } /** * Forces the current page to be set in session, * which can be retrieved later through {@link currentPageID()}. * Keep in mind that setting an ID through GET/POST or * as a URL parameter will overrule this value. * * @param int $id */ public function setCurrentPageID($id) { Session::set("{$this->class}.currentPage", $id); } /** * Uses {@link getRecord()} and {@link currentPageID()} * to get the currently selected record. * * @return DataObject */ public function currentPage() { return $this->getRecord($this->currentPageID()); } /** * Compares a given record to the currently selected one (if any). * Used for marking the current tree node. * * @return boolean */ public function isCurrentPage(DataObject $record) { return ($record->ID == $this->currentPageID()); } /** * Get the staus of a certain page and version. * * This function is used for concurrent editing, and providing alerts * when multiple users are editing a single page. It echoes a json * encoded string to the UA. */ /** * Return the CMS's HTML-editor toolbar */ public function EditorToolbar() { return Object::create('HtmlEditorField_Toolbar', $this, "EditorToolbar"); } /** * Return the version number of this application. * Uses the subversion path information in