request->isAjax()) { Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree'))); } parent::init(); Requirements::css(CMS_DIR . '/css/screen.css'); Requirements::customCSS($this->generatePageIconsCss()); Requirements::combine_files( 'cmsmain.js', array_merge( array( CMS_DIR . '/javascript/CMSMain.js', CMS_DIR . '/javascript/CMSMain.EditForm.js', CMS_DIR . '/javascript/CMSMain.AddForm.js', CMS_DIR . '/javascript/CMSPageHistoryController.js', CMS_DIR . '/javascript/CMSMain.Tree.js', CMS_DIR . '/javascript/SilverStripeNavigator.js', CMS_DIR . '/javascript/SiteTreeURLSegmentField.js' ), Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang', true, true) ) ); CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish'); CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish'); CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete'); CMSBatchActionHandler::register('deletefromlive', 'CMSBatchAction_DeleteFromLive'); } public function index($request) { // In case we're not showing a specific record, explicitly remove any session state, // to avoid it being highlighted in the tree, and causing an edit form to show. if(!$request->param('Action')) $this->setCurrentPageId(null); return parent::index($request); } public function getResponseNegotiator() { $negotiator = parent::getResponseNegotiator(); $controller = $this; $negotiator->setCallback('ListViewForm', function() use(&$controller) { return $controller->ListViewForm()->forTemplate(); }); return $negotiator; } /** * If this is set to true, the "switchView" context in the * template is shown, with links to the staging and publish site. * * @return boolean */ public function ShowSwitchView() { return true; } /** * Overloads the LeftAndMain::ShowView. Allows to pass a page as a parameter, so we are able * to switch view also for archived versions. */ public function SwitchView($page = null) { if(!$page) { $page = $this->currentPage(); } if($page) { $nav = SilverStripeNavigator::get_for_record($page); return $nav['items']; } } //------------------------------------------------------------------------------------------// // Main controllers //------------------------------------------------------------------------------------------// // Main UI components /** * Override {@link LeftAndMain} Link to allow blank URL segment for CMSMain. * * @return string */ public function Link($action = null) { $link = Controller::join_links( $this->stat('url_base', true), $this->stat('url_segment', true), // in case we want to change the segment '/', // trailing slash needed if $action is null! "$action" ); $this->extend('updateLink', $link); return $link; } public function LinkPages() { return singleton('CMSPagesController')->Link(); } public function LinkPagesWithSearch() { return $this->LinkWithSearch($this->LinkPages()); } public function LinkTreeView() { return $this->LinkWithSearch(singleton('CMSMain')->Link('treeview')); } public function LinkListView() { return $this->LinkWithSearch(singleton('CMSMain')->Link('listview')); } public function LinkGalleryView() { return $this->LinkWithSearch(singleton('CMSMain')->Link('galleryview')); } public function LinkPageEdit($id = null) { if(!$id) $id = $this->currentPageID(); return $this->LinkWithSearch( Controller::join_links(singleton('CMSPageEditController')->Link('show'), $id) ); } public function LinkPageSettings() { if($id = $this->currentPageID()) { return $this->LinkWithSearch( Controller::join_links(singleton('CMSPageSettingsController')->Link('show'), $id) ); } } public function LinkPageHistory() { if($id = $this->currentPageID()) { return $this->LinkWithSearch( Controller::join_links(singleton('CMSPageHistoryController')->Link('show'), $id) ); } } public function LinkWithSearch($link) { // Whitelist to avoid side effects $params = array( 'q' => (array)$this->request->getVar('q'), 'ParentID' => $this->request->getVar('ParentID') ); $link = Controller::join_links( $link, array_filter(array_values($params)) ? '?' . http_build_query($params) : null ); $this->extend('updateLinkWithSearch', $link); return $link; } public function LinkPageAdd($extraArguments = null) { $link = singleton("CMSPageAddController")->Link(); $this->extend('updateLinkPageAdd', $link); if($extraArguments) $link = Controller::join_links ($link, $extraArguments); return $link; } /** * @return string */ public function LinkPreview() { $record = $this->getRecord($this->currentPageID()); $baseLink = ($record && $record instanceof Page) ? $record->Link('?stage=Stage') : Director::absoluteBaseURL(); return $baseLink; } /** * Return the entire site tree as a nested set of ULs */ public function SiteTreeAsUL() { // Pre-cache sitetree version numbers for querying efficiency Versioned::prepopulate_versionnumber_cache("SiteTree", "Stage"); Versioned::prepopulate_versionnumber_cache("SiteTree", "Live"); $html = $this->getSiteTreeFor($this->stat('tree_class')); $this->extend('updateSiteTreeAsUL', $html); return $html; } /** * @return boolean */ public function TreeIsFiltered() { return $this->request->getVar('q'); } public function ExtraTreeTools() { $html = ''; $this->extend('updateExtraTreeTools', $html); return $html; } /** * Returns a Form for page searching for use in templates. * * Can be modified from a decorator by a 'updateSearchForm' method * * @return Form */ public function SearchForm() { // Create the fields $content = new TextField('q[Term]', _t('CMSSearch.FILTERLABELTEXT', 'Content')); $dateHeader = new HeaderField('q[Date]', _t('CMSSearch.FILTERDATEHEADING', 'Date'), 4); $dateFrom = new DateField( 'q[LastEditedFrom]', _t('CMSSearch.FILTERDATEFROM', 'From') ); $dateFrom->setConfig('showcalendar', true); $dateTo = new DateField( 'q[LastEditedTo]', _t('CMSSearch.FILTERDATETO', 'To') ); $dateTo->setConfig('showcalendar', true); $pageFilter = new DropdownField( 'q[FilterClass]', _t('CMSMain.PAGES', 'Pages'), CMSSiteTreeFilter::get_all_filters() ); $pageClasses = new DropdownField( 'q[ClassName]', _t('CMSMain.PAGETYPEOPT', 'Page Type', 'Dropdown for limiting search to a page type'), $this->getPageTypes() ); $pageClasses->setEmptyString(_t('CMSMain.PAGETYPEANYOPT','Any')); // Group the Datefields $dateGroup = new FieldGroup( $dateHeader, $dateFrom, $dateTo ); $dateGroup->setFieldHolderTemplate('FieldGroup_DefaultFieldHolder')->addExtraClass('stacked'); // Create the Field list $fields = new FieldList( $content, $dateGroup, $pageFilter, $pageClasses ); // Create the Search and Reset action $actions = new FieldList( FormAction::create('doSearch', _t('CMSMain_left.ss.APPLY FILTER', 'Apply Filter')) ->addExtraClass('ss-ui-action-constructive'), Object::create('ResetFormAction', 'clear', _t('CMSMain_left.ss.RESET', 'Reset')) ); // Use