/** * Determine if the referrer for this request is from a domain within this website's scope * * @return boolean */ protected function knownReferrer() { // Extract referrer if (empty($_SERVER['HTTP_REFERER'])) { return false; } $hostname = strtolower(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)); // Check if internal traffic if ($hostname == strtolower($_SERVER['HTTP_HOST'])) { return true; } // Check configured domains $domains = Fluent::domains(); return isset($domains[$hostname]); }
/** * Test output for helpers in domain mode */ public function testDomainsHelpers() { Config::inst()->update('Fluent', 'force_domain', true); // Test Fluent::domains $this->assertEquals(array('www.example.com', 'www.example.ca', 'www.example.co.nz'), array_keys(Fluent::domains())); // Test Fluent::default_locale $usDefault = $this->withURL('www.example.com', '/', '/', function ($test) { return Fluent::default_locale(true); }); $this->assertEquals('en_US', $usDefault); $this->assertEquals('en_US', Fluent::default_locale('www.example.com')); $this->assertEquals('fr_CA', Fluent::default_locale()); // Test Fluent::domain_for_locale $this->assertEquals(null, Fluent::domain_for_locale('nl_NL')); $this->assertEquals('www.example.com', Fluent::domain_for_locale('en_US')); $this->assertEquals('www.example.com', Fluent::domain_for_locale('es_ES')); $this->assertEquals('www.example.ca', Fluent::domain_for_locale('fr_CA')); $this->assertEquals('www.example.co.nz', Fluent::domain_for_locale('en_NZ')); // Test Fluent::locales $usLocales = $this->withURL('www.example.com', '/', '/', function ($test) { return Fluent::locales(true); }); $this->assertEquals(array('es_ES', 'en_US'), $usLocales); $this->assertEquals(array('es_ES', 'en_US'), Fluent::locales('www.example.com')); $this->assertEquals(array('fr_CA', 'en_NZ', 'en_US', 'es_ES'), Fluent::locales()); Config::inst()->update('Fluent', 'force_domain', false); }