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'); } 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 */ 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. */ 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) ); } } protected 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; } function LinkPageAdd() { return singleton("CMSPageAddController")->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; } function SearchForm() { // get all page types in a dropdown-compatible format $pageTypes = SiteTree::page_type_classes(); $pageTypes = array_combine($pageTypes, $pageTypes); asort($pageTypes); // get all filter instances $filters = ClassInfo::subclassesFor('CMSSiteTreeFilter'); $filterMap = array(); // remove base class array_shift($filters); // add filters to map foreach($filters as $filter) { $filterMap[$filter] = call_user_func(array($filter, 'title')); } // ensure that 'all pages' filter is on top position uasort($filterMap, create_function('$a,$b', 'return ($a == "CMSSiteTreeFilter_Search") ? 1 : -1;') ); $fields = new FieldList( new TextField('q[Term]', _t('CMSSearch.FILTERLABELTEXT', 'Content')), $dateGroup = new FieldGroup( new HeaderField('q[Date]', _t('CMSSearch.FILTERDATEHEADING', 'Date'), 4), $dateFrom = new DateField('q[LastEditedFrom]', _t('CMSSearch.FILTERDATEFROM', 'From')), $dateTo = new DateField('q[LastEditedTo]', _t('CMSSearch.FILTERDATETO', 'To')) ), new DropdownField( 'q[FilterClass]', _t('CMSMain.PAGES', 'Pages'), $filterMap ), $classDropdown = new DropdownField( 'q[ClassName]', _t('CMSMain.PAGETYPEOPT','Page Type', 'Dropdown for limiting search to a page type'), $pageTypes ) // new TextField('MetaTags', _t('CMSMain.SearchMetaTags', 'Meta tags')) ); $dateGroup->subfieldParam = 'FieldHolder'; $dateFrom->setConfig('showcalendar', true); $dateTo->setConfig('showcalendar', true); $classDropdown->setEmptyString(_t('CMSMain.PAGETYPEANYOPT','Any')); $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