1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Fixes #4826 - redirect dynamic content on static domain.

This commit is contained in:
Cameron
2022-07-19 16:32:33 -07:00
parent 1792aee537
commit c4bcf0a663
4 changed files with 156 additions and 6 deletions

View File

@@ -10,10 +10,19 @@
*
*/
if (!defined('e107_INIT')) { exit; }
if(!defined('USER_AREA')) { define('USER_AREA',TRUE); }
if(!defined('ADMIN_AREA')) { define('ADMIN_AREA', false); }
if($redirect = e107::getRedirect()->redirectStaticDomain())
{
e107::redirect($redirect);
}
e107::getDebug()->logTime('(Header Top)');
e_theme::initThemeLayout(); // set THEME_LAYOUT

View File

@@ -42,7 +42,18 @@ class redirection
* @var array
*/
protected $query_exceptions = array();
public $staticDomains;
public $domain;
public $subdomain;
public $self;
public $siteurl;
/**
* Manage Member-Only Mode.
*
@@ -53,6 +64,10 @@ class redirection
$this->self_exceptions = array(e_SIGNUP, SITEURL.'fpw.php', e_LOGIN, SITEURL.'membersonly.php');
$this->page_exceptions = array('e_ajax.php', 'e_js.php', 'e_jslib.php', 'sitedown.php',e_LOGIN, 'secimg.php');
$this->query_exceptions = array('logout');
$this->staticDomains = defset('e_HTTP_STATIC');
$this->domain = defset('e_DOMAIN');
$this->subdomain = defset('e_SUBDOMAIN');
$this->self = $this->getSelf(true);
// Remove from self_exceptions: SITEURL, SITEURL.'index.php', // allows a custom frontpage to be viewed while logged out and membersonly active.
}
@@ -242,10 +257,7 @@ class redirection
$this->redirect(SITEURL.'sitedown.php', TRUE, 307);
}
}
else
{
return;
}
}
@@ -440,4 +452,27 @@ class redirection
exit();
}
/**
* If a static subdomain is detected, returns the equivalent non-static domain.
* @return string|false
*/
public function redirectStaticDomain()
{
if(empty($this->staticDomains))
{
return false;
}
if(strpos($this->subdomain, 'static') !== false)
{
return str_replace($this->subdomain.'.'.$this->domain.'/', $this->domain.'/', $this->self);
}
return false;
}
}

View File

@@ -665,7 +665,7 @@ class news_front
$options['query'] = ['page'=> $page];
}
if(!deftrue('e_FRONTPAGE')) // Use site title when on frontpage.
if(!deftrue('e_FRONTPAGE') && !empty($this->caption)) // Use site title when on frontpage.
{
e107::title($this->caption);
}

View File

@@ -0,0 +1,106 @@
<?php
class redirectionTest extends \Codeception\Test\Unit
{
/** @var redirection */
protected $rd;
protected function _before()
{
try
{
$this->rd = $this->make('redirection');
}
catch(Exception $e)
{
$this->fail($e->getMessage());
}
}
/* public function testRedirect()
{
}
public function testGetPreviousUrl()
{
}
public function testGo()
{
}
public function testCheckMaintenance()
{
}
public function testSetPreviousUrl()
{
}
public function testRedirectPrevious()
{
}
public function testGetSelfExceptions()
{
}
public function testGetCookie()
{
}
public function testCheckMembersOnly()
{
}
public function testSetCookie()
{
}
public function testClearCookie()
{
}
public function testGetSelf()
{
}*/
public function testRedirectStaticDomain()
{
$result = $this->rd->redirectStaticDomain();
$this->assertEmpty($result);
$this->rd->domain = 'e107.org';
$this->rd->subdomain = 'static1';
$this->rd->staticDomains = ['https://static1.e107.org', 'https://static2.e107.org'];
$this->rd->self = 'https://static1.e107.org/blogs';
$this->rd->siteurl = 'https://e107.org/';
$result = $this->rd->redirectStaticDomain();
$this->assertSame("https://e107.org/blogs", $result);
}
}