public function subsiteCMSShowInMenu()
 {
     if (Subsite::currentSubsite()) {
         return false;
     }
     return true;
 }
 /**
  * @return void
  */
 public function onBeforeInit()
 {
     // Check if we are runing a dev build, if so check if DB needs
     // upgrading
     $controller = $this->owner->request->param("Controller");
     $action = $this->owner->request->param("Action");
     global $project;
     // Only check if the DB needs upgrading on a dev build
     if ($controller == "DevelopmentAdmin" && $action == "build") {
         // Now check if the files we need are installed
         // Check if we have the files we need, if not, create them
         if (!class_exists("Category")) {
             copy(BASE_PATH . "/catalogue/scaffold/Category", BASE_PATH . "/{$project}/code/model/Category.php");
         }
         if (!class_exists("Category_Controller")) {
             copy(BASE_PATH . "/catalogue/scaffold/Category_Controller", BASE_PATH . "/{$project}/code/control/Category_Controller.php");
         }
         if (!class_exists("Product")) {
             copy(BASE_PATH . "/catalogue/scaffold/Product", BASE_PATH . "/{$project}/code/model/Product.php");
         }
         if (!class_exists("Product_Controller")) {
             copy(BASE_PATH . "/catalogue/scaffold/Product_Controller", BASE_PATH . "/{$project}/code/control/Product_Controller.php");
         }
     }
     if ($controller != "DevelopmentAdmin") {
         if (class_exists('Subsite') && Subsite::currentSubsite()) {
             // Set the location
             i18n::set_locale(Subsite::currentSubsite()->Language);
         }
     }
 }
 /**
  * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites 
  *
  * @see Error::get_filepath_for_errorcode()
  *
  * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between 
  * opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly. 
  */
 function alternateFilepathForErrorcode($statusCode, $locale = null)
 {
     $static_filepath = Object::get_static($this->owner->ClassName, 'static_filepath');
     $subdomainPart = "";
     // Try to get current subsite from session
     $subsite = Subsite::currentSubsite(false);
     // since this function is called from Page class before the controller is created, we have to get subsite from domain instead
     if (!$subsite) {
         $subsiteID = Subsite::getSubsiteIDForDomain();
         if ($subsiteID != 0) {
             $subsite = DataObject::get_by_id("Subsite", $subsiteID);
         } else {
             $subsite = null;
         }
     }
     if ($subsite) {
         $subdomain = $subsite->domain();
         $subdomainPart = "-{$subdomain}";
     }
     if (singleton('SiteTree')->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
         $filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
     } else {
         $filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
     }
     return $filepath;
 }
 public function getURLPrefix()
 {
     $url = parent::getURLPrefix();
     if (Director::isDev() || Director::isTest()) {
         $urlarray = parse_url($url);
         // define override
         if (defined('DEV_SUBSITE_' . Subsite::currentSubsiteID())) {
             $subsiteurl = 'DEV_SUBSITE_' . Subsite::currentSubsiteID();
             return constant($subsiteurl) . $urlarray['path'];
         }
         if (!Subsite::currentSubsite() instanceof Subsite) {
             return $url;
         }
         // if set in config settings
         $currentDomain = Subsite::currentSubsite()->getPrimarySubsiteDomain();
         if (Director::isTest()) {
             $currentDomain = Subsite::currentSubsite()->TestDomainID ? Subsite::currentSubsite()->TestDomain() : $currentDomain;
         }
         if (Director::isDev()) {
             $currentDomain = Subsite::currentSubsite()->DevDomainID ? Subsite::currentSubsite()->DevDomain() : $currentDomain;
         }
         if (!$currentDomain) {
             return $url;
         }
         return $currentDomain->getFullProtocol() . $currentDomain->Domain . $urlarray['path'];
     }
     return $url;
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // If subsites enabled
     if (class_exists('Subsite') && ($subsite = Subsite::currentSubsite())) {
         $this->SubsiteID = $subsite->ID;
     }
     // Ensure the slug is URL safe
     $this->Slug = $this->Slug ? Convert::raw2url($this->Slug) : Convert::raw2url($this->Title);
 }
 /**
  * Getting subsite directory based on it's assets folder
  * 
  * @return bool|mixed
  */
 public static function get_directory_for_current_subsite()
 {
     $subsite = Subsite::currentSubsite();
     if ($subsite) {
         if ((int) $subsite->AssetsFolderID > 0) {
             $dirObj = $subsite->AssetsFolder();
             $dirName = str_replace('assets/', '', $dirObj->Filename);
             //make sure we've got no trailing slashes
             $dirName = str_replace('/', '', $dirName);
             return $dirName;
         }
     } else {
         return false;
     }
 }
 /**
  * @return void
  */
 public function onBeforeInit()
 {
     if (class_exists('Subsite') && Subsite::currentSubsite()) {
         // Set the location
         i18n::set_locale(Subsite::currentSubsite()->Language);
         // Check if url is primary domain, if not, re-direct
         if ($_SERVER['HTTP_HOST'] != Subsite::currentSubsite()->getPrimaryDomain()) {
             $this->owner->redirect(Subsite::currentSubsite()->absoluteBaseURL());
         }
     }
     // Setup currency globally based on what is set in admin
     $config = SiteConfig::current_site_config();
     if ($config->Currency()) {
         Currency::setCurrencySymbol($config->Currency()->HTMLNotation);
     }
 }
 /**
  * Get folder for a given class
  * 
  * @param mixed $class
  * @return string
  */
 public static function getFolderForClass($class)
 {
     $folderName = 'Uploads';
     if (is_object($class)) {
         if (method_exists($class, 'hasMethod') && $class->hasMethod('BaseFolder')) {
             $folderName = $class->BaseFolder();
         } else {
             if ($class instanceof Page) {
                 $folderName = get_class($class);
             } else {
                 if ($class instanceof DataObject) {
                     $folderName = $class->baseTable();
                 } else {
                     if ($class instanceof DataExtension) {
                         $folderName = $class->getOwner()->baseTable();
                     } else {
                         $folderName = get_class($class);
                     }
                 }
             }
         }
     } else {
         if (is_string($class)) {
             $folderName = $class;
         }
     }
     if (class_exists('Subsite') && Config::inst()->get(__CLASS__, 'use_subsite_integration')) {
         $subsite = Subsite::currentSubsite();
         if ($subsite) {
             // Subsite extras integration$
             if ($subsite->hasField('BaseFolder')) {
                 $baseFolder = $subsite->BaseFolder;
             } else {
                 $filter = new URLSegmentFilter();
                 $baseFolder = $filter->filter($subsite->getTitle());
                 $baseFolder = str_replace(' ', '', ucwords(str_replace('-', ' ', $baseFolder)));
             }
             if (!empty($baseFolder)) {
                 $folderName = $baseFolder . '/' . $folderName;
             }
         }
     }
     return $folderName;
 }
 /**
  * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites 
  *
  * {@see Error::get_error_filename()}
  *
  * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between 
  * opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly.
  *
  * @param string $name Filename to write to
  * @param int $statusCode Integer error code
  */
 public function updateErrorFilename(&$name, $statusCode)
 {
     // Try to get current subsite from session
     $subsite = Subsite::currentSubsite(false);
     // since this function is called from Page class before the controller is created, we have to get subsite from domain instead
     if (!$subsite) {
         $subsiteID = Subsite::getSubsiteIDForDomain();
         if ($subsiteID != 0) {
             $subsite = DataObject::get_by_id("Subsite", $subsiteID);
         }
     }
     // Without subsite, don't rewrite
     if ($subsite) {
         // Add subdomain to end of filename, just before .html
         // This should preserve translatable locale in the filename as well
         $subdomain = $subsite->domain();
         $name = substr($name, 0, -5) . "-{$subdomain}.html";
     }
 }
 /**
  * Called by ContentController::init();
  */
 public static function contentcontrollerInit($controller)
 {
     $subsite = Subsite::currentSubsite();
     if ($subsite && $subsite->Theme) {
         Config::inst()->update('SSViewer', 'theme', Subsite::currentSubsite()->Theme);
     }
 }
 /**
  * @param Member
  * @return boolean|null
  */
 function canCreate($member = null)
 {
     // Typically called on a singleton, so we're not using the Subsite() relation
     $subsite = Subsite::currentSubsite();
     if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
         $blacklisted = explode(',', $subsite->PageTypeBlacklist);
         // All subclasses need to be listed explicitly
         if (in_array($this->owner->class, $blacklisted)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Get all available themes that haven't been marked as disabled.
  * @param string $baseDir Optional alternative theme base directory for testing
  * @return array of theme directory names
  */
 public function getAvailableThemesExtended($baseDir = null)
 {
     if (class_exists('Subsite') && Subsite::currentSubsiteID()) {
         $subsiteThemes = Subsite::config()->allowed_themes;
         // Make sure set theme is allowed
         $subsite = Subsite::currentSubsite();
         if ($subsite->Theme && !in_array($subsite->Theme, $subsiteThemes)) {
             $subsiteThemes[] = $subsite->Theme;
         }
         // Make sure default theme is allowed
         $theme = Config::inst()->get('SSViewer', 'theme');
         if ($theme && !in_array($theme, $subsiteThemes)) {
             $subsiteThemes[] = $theme;
         }
         return array_combine($subsiteThemes, $subsiteThemes);
     }
     $themes = SSViewer::get_themes($baseDir);
     $disabled = (array) $this->owner->config()->disabled_themes;
     foreach ($disabled as $theme) {
         if (isset($themes[$theme])) {
             unset($themes[$theme]);
         }
     }
     return $themes;
 }
 /**
  * Called by ContentController::init();
  */
 public static function contentcontrollerInit($controller)
 {
     $subsite = Subsite::currentSubsite();
     if ($subsite && $subsite->Theme) {
         SSViewer::set_theme(Subsite::currentSubsite()->Theme);
     }
 }
 public static function enable($force_profile = null)
 {
     if ($force_profile) {
         self::$_current_profile = $force_profile;
         $force_profile::enable_custom_translations();
         $force_profile::enable_custom_code();
         return;
     }
     if (self::$_current_profile) {
         return;
     }
     if (!class_exists('Subsite')) {
         return;
     }
     if (!Subsite::currentSubsiteID()) {
         return;
     }
     $profile = Subsite::currentSubsite()->Profile;
     if (!$profile) {
         return;
     }
     self::$_current_profile = $profile;
     $profile::enable_custom_translations();
     $profile::enable_custom_code();
 }
 /**
  * Called by ContentController::init();
  */
 static function contentcontrollerInit($controller)
 {
     // Need to set the SubsiteID to null incase we've been in the CMS
     Session::set('SubsiteID', null);
     $subsite = Subsite::currentSubsite();
     if ($subsite && $subsite->Theme) {
         SSViewer::set_theme(Subsite::currentSubsite()->Theme);
     }
 }
 /**
  *
  * Check that you have entered values in a config file that match the constant set in the subsite Settings by the developer
  *
  * @param string $key Name of the array in the _config.yml file
  * @param string $value Array value set under the name
  * @return bool
  */
 public static function display($key, $value)
 {
     $subSiteConstant = SiteConfig::current_site_config()->SubSiteConstant;
     $config = Config::inst()->get($key, $value);
     return Subsite::currentSubsite() && in_array($subSiteConstant, $config) ? true : false;
 }
 function CurrentSubsite()
 {
     if ($subsite = Subsite::currentSubsite()) {
         return $subsite;
     }
 }