Ejemplo n.º 1
0
 /**
  * Returns true if the domain is currently in the HTTP_HOST
  * @return boolean
  */
 public function isActive()
 {
     if ($this->isAllowedPath($_SERVER['REQUEST_URI'])) {
         return false;
     }
     $current_host = $_SERVER['HTTP_HOST'];
     $allow_subdomains = MultiDomain::config()->allow_subdomains;
     $hostname = $this->getHostname();
     return $allow_subdomains ? preg_match('/(\\.|^)' . $hostname . '$/', $current_host) : $current_host == $hostname;
 }
 /**
  * Returns true if the domain is currently in the HTTP_HOST
  * @return boolean
  */
 public function isActive()
 {
     if ($this->isAllowedPath($_SERVER['REQUEST_URI'])) {
         return false;
     }
     $currentHost = $_SERVER['HTTP_HOST'];
     if (strpos(':', $currentHost) !== false) {
         list($currentHost, $currentPort) = explode(':', $currentHost, 2);
     }
     $allow_subdomains = MultiDomain::config()->allow_subdomains;
     $hostname = $this->getHostname();
     return $allow_subdomains ? preg_match('/(\\.|^)' . $hostname . '$/', $currentHost) : $currentHost == $hostname;
 }
 /**
  * Gets the active domain, and sets its URL to the native one, with a vanity
  * URL in the request
  * 
  * @param  SS_HTTPRequest $request 
  * @param  Session        $session 
  * @param  DataModel      $model 
  */
 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     if (Director::is_cli()) {
         return;
     }
     // Not the best place for validation, but _config.php is too early.
     if (!MultiDomain::get_primary_domain()) {
         throw new Exception('MultiDomain must define a "' . MultiDomain::KEY_PRIMARY . '" domain in the config, under "domains"');
     }
     foreach (MultiDomain::get_all_domains() as $domain) {
         if (!$domain->isActive()) {
             continue;
         }
         $url = $this->createNativeURLForDomain($domain);
         $parts = explode('?', $url);
         $request->setURL($parts[0]);
     }
 }
Ejemplo n.º 4
0
 function __construct($config)
 {
     self::$instance = $this;
     $this->domains = $config;
     $this->get_domain();
     // Register Filters
     if ($this->domain) {
         $properties = array('blogname', 'siteurl', 'home', 'blogdescription', 'template');
         foreach ($properties as $property) {
             if ($this->domain[$property]) {
                 add_filter("option_{$property}", array($this, $property), 1);
                 if ($property == 'template') {
                     add_filter("template", array($this, "template"), 1);
                     add_filter("option_stylesheet", array($this, "template"), 1);
                 }
             }
         }
     }
     // Register Shortcodes
     add_shortcode('MultiDomain_if', array($this, 'if_domain'));
     add_shortcode('MultiDomain_else', array($this, 'else_domain'));
     add_shortcode('MultiDomain_default', array($this, 'else_domain'));
 }