code/LeftAndMainSubsites.php
/**
	 * Alternative security checker for LeftAndMain.
	 * If security isn't found, then it will switch to a subsite where we do have access.
	 */
Alternative security checker for LeftAndMain.
If security isn't found, then it will switch to a subsite where we do have access.
Alternative security checker for LeftAndMain . If security isn ' t found then it will switch to a subsite where we do have access .
public function alternateAccessCheck() {
		$className = $this->owner->class;
		if ($this->owner->class == 'CMSMain' && $currentPage = $this->owner->currentPage()) {
			if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) {
				Subsite::changeSubsite($currentPage->SubsiteID);
			}
		}
		$member = Member::currentUser();
		if ($member && $member->isAdmin()) return true;	
		$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->toDropdownMap();
		if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
			$siteIDs = array_keys($sites);
			Subsite::changeSubsite($siteIDs[0]);
			return true;
		}
		$menu = CMSMenu::get_menu_items();
		foreach($menu as $candidate) {
			if($candidate->controller != $this->owner->class) {
				$sites = Subsite::accessible_sites("CMS_ACCESS_{$candidate->controller}")->toDropdownMap();
				if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
					$siteIDs = array_keys($sites);
					Subsite::changeSubsite($siteIDs[0]);
					$cClass = $candidate->controller;
					$cObj = new $cClass();
					Director::redirect($cObj->Link());
					return null;
				}
			}
		}
		return null;
	}
public function alternateAccessCheck ( ) { $ className = $ this -> owner -> class ; if ( $ this -> owner -> class == 'CMSMain' && $ currentPage = $ this -> owner -> currentPage ( ) ) { if ( Subsite :: currentSubsiteID ( ) != $ currentPage -> SubsiteID ) { Subsite :: changeSubsite ( $ currentPage -> SubsiteID ) ; } } $ member = Member :: currentUser ( ) ; if ( $ member && $ member -> isAdmin ( ) ) return true ; $ sites = Subsite :: accessible_sites ( " CMS_ACCESS_ { $ this -> owner -> class } " ) -> toDropdownMap ( ) ; if ( $ sites && ! isset ( $ sites [ Subsite :: currentSubsiteID ( ) ] ) ) { $ siteIDs = array_keys ( $ sites ) ; Subsite :: changeSubsite ( $ siteIDs [ 0 ] ) ; return true ; } $ menu = CMSMenu :: get_menu_items ( ) ; foreach ( $ menu as $ candidate ) { if ( $ candidate -> controller != $ this -> owner -> class ) { $ sites = Subsite :: accessible_sites ( " CMS_ACCESS_ { $ candidate -> controller } " ) -> toDropdownMap ( ) ; if ( $ sites && ! isset ( $ sites [ Subsite :: currentSubsiteID ( ) ] ) ) { $ siteIDs = array_keys ( $ sites ) ; Subsite :: changeSubsite ( $ siteIDs [ 0 ] ) ; $ cClass = $ candidate -> controller ; $ cObj = new $ cClass ( ) ; Director :: redirect ( $ cObj -> Link ( ) ) ; return null ; } } } return null ; }
Alternative security checker for LeftAndMain.
Alternative security checker for LeftAndMain .
// Switch to the subsite of the current page // Switch to a subsite that this user can actually access. //admin can access all subsites // Switch to a different top-level menu item // If all of those fail, you really don't have access to the CMS		