Moved BaseURL to App namespace (because similar type as Arguments/Modules/Modes)
This commit is contained in:
parent
fa1b783052
commit
08be92a862
18
src/App.php
18
src/App.php
|
@ -9,6 +9,7 @@ use DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\App\Arguments;
|
use Friendica\App\Arguments;
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Core\Config\Cache\ConfigCache;
|
use Friendica\Core\Config\Cache\ConfigCache;
|
||||||
use Friendica\Core\Config\Configuration;
|
use Friendica\Core\Config\Configuration;
|
||||||
use Friendica\Core\Config\PConfiguration;
|
use Friendica\Core\Config\PConfiguration;
|
||||||
|
@ -20,7 +21,6 @@ use Friendica\Model\Profile;
|
||||||
use Friendica\Module\Login;
|
use Friendica\Module\Login;
|
||||||
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Util\ConfigFileLoader;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
@ -536,21 +536,13 @@ class App
|
||||||
* @param string $origURL
|
* @param string $origURL
|
||||||
*
|
*
|
||||||
* @return string The cleaned url
|
* @return string The cleaned url
|
||||||
* @throws HTTPException\InternalServerErrorException
|
*
|
||||||
|
* @deprecated 2019.09 - Use BaseURL->remove() instead
|
||||||
|
* @see BaseURL::remove()
|
||||||
*/
|
*/
|
||||||
public function removeBaseURL($origURL)
|
public function removeBaseURL($origURL)
|
||||||
{
|
{
|
||||||
// Remove the hostname from the url if it is an internal link
|
return $this->baseURL->remove($origURL);
|
||||||
$nurl = Util\Strings::normaliseLink($origURL);
|
|
||||||
$base = Util\Strings::normaliseLink($this->getBaseURL());
|
|
||||||
$url = str_replace($base . '/', '', $nurl);
|
|
||||||
|
|
||||||
// if it is an external link return the orignal value
|
|
||||||
if ($url == Util\Strings::normaliseLink($origURL)) {
|
|
||||||
return $origURL;
|
|
||||||
} else {
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Friendica\Util;
|
namespace Friendica\App;
|
||||||
|
|
||||||
use Friendica\Core\Config\Configuration;
|
use Friendica\Core\Config\Configuration;
|
||||||
|
use Friendica\Util\Network;
|
||||||
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which checks and contains the basic
|
* A class which checks and contains the basic
|
||||||
|
@ -32,48 +34,56 @@ class BaseURL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Friendica Config
|
* The Friendica Config
|
||||||
|
*
|
||||||
* @var Configuration
|
* @var Configuration
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The server side variables
|
* The server side variables
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hostname of the Base URL
|
* The hostname of the Base URL
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $hostname;
|
private $hostname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SSL_POLICY of the Base URL
|
* The SSL_POLICY of the Base URL
|
||||||
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $sslPolicy;
|
private $sslPolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL sub-path of the Base URL
|
* The URL sub-path of the Base URL
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $urlPath;
|
private $urlPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full URL
|
* The full URL
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $url;
|
private $url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current scheme of this call
|
* The current scheme of this call
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $scheme;
|
private $scheme;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hostname of this node
|
* Returns the hostname of this node
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getHostname()
|
public function getHostname()
|
||||||
|
@ -83,6 +93,7 @@ class BaseURL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current scheme of this call
|
* Returns the current scheme of this call
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getScheme()
|
public function getScheme()
|
||||||
|
@ -92,6 +103,7 @@ class BaseURL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the SSL policy of this node
|
* Returns the SSL policy of this node
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getSSLPolicy()
|
public function getSSLPolicy()
|
||||||
|
@ -101,6 +113,7 @@ class BaseURL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sub-path of this URL
|
* Returns the sub-path of this URL
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getUrlPath()
|
public function getUrlPath()
|
||||||
|
@ -229,12 +242,12 @@ class BaseURL
|
||||||
*/
|
*/
|
||||||
public function checkRedirectHttps()
|
public function checkRedirectHttps()
|
||||||
{
|
{
|
||||||
return $this->config->get('system', 'force_ssl')
|
return $this->config->get('system', 'force_ssl') &&
|
||||||
&& ($this->getScheme() == "http")
|
($this->getScheme() == "http") &&
|
||||||
&& intval($this->getSSLPolicy()) == BaseURL::SSL_POLICY_FULL
|
intval($this->getSSLPolicy()) == BaseURL::SSL_POLICY_FULL &&
|
||||||
&& strpos($this->get(), 'https://') === 0
|
strpos($this->get(), 'https://') === 0 &&
|
||||||
&& !empty($this->server['REQUEST_METHOD'])
|
!empty($this->server['REQUEST_METHOD']) &&
|
||||||
&& $this->server['REQUEST_METHOD'] === 'GET';
|
$this->server['REQUEST_METHOD'] === 'GET';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -359,7 +372,7 @@ class BaseURL
|
||||||
$scheme = 'https';
|
$scheme = 'https';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->url = $scheme . '://' . $this->hostname . (!empty($this->urlPath) ? '/' . $this->urlPath : '' );
|
$this->url = $scheme . '://' . $this->hostname . (!empty($this->urlPath) ? '/' . $this->urlPath : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -379,4 +392,26 @@ class BaseURL
|
||||||
$this->scheme = 'https';
|
$this->scheme = 'https';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the base url from an url. This avoids some mixed content problems.
|
||||||
|
*
|
||||||
|
* @param string $origURL
|
||||||
|
*
|
||||||
|
* @return string The cleaned url
|
||||||
|
*/
|
||||||
|
public function remove(string $origURL)
|
||||||
|
{
|
||||||
|
// Remove the hostname from the url if it is an internal link
|
||||||
|
$nurl = Strings::normaliseLink($origURL);
|
||||||
|
$base = Strings::normaliseLink($this->get());
|
||||||
|
$url = str_replace($base . '/', '', $nurl);
|
||||||
|
|
||||||
|
// if it is an external link return the orignal value
|
||||||
|
if ($url == Strings::normaliseLink($origURL)) {
|
||||||
|
return $origURL;
|
||||||
|
} else {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,9 +9,7 @@ use Friendica\App;
|
||||||
use Friendica\Core\Session\CacheSessionHandler;
|
use Friendica\Core\Session\CacheSessionHandler;
|
||||||
use Friendica\Core\Session\DatabaseSessionHandler;
|
use Friendica\Core\Session\DatabaseSessionHandler;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Model\Contact;
|
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +28,7 @@ class Session
|
||||||
ini_set('session.use_only_cookies', 1);
|
ini_set('session.use_only_cookies', 1);
|
||||||
ini_set('session.cookie_httponly', 1);
|
ini_set('session.cookie_httponly', 1);
|
||||||
|
|
||||||
if (Config::get('system', 'ssl_policy') == BaseURL::SSL_POLICY_FULL) {
|
if (Config::get('system', 'ssl_policy') == App\BaseURL::SSL_POLICY_FULL) {
|
||||||
ini_set('session.cookie_secure', 1);
|
ini_set('session.cookie_secure', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
*/
|
*/
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
namespace Friendica\Model;
|
namespace Friendica\Model;
|
||||||
|
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
use Friendica\Content\Pager;
|
use Friendica\Content\Pager;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
@ -22,7 +23,6 @@ use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
use Friendica\Protocol\PortableContact;
|
use Friendica\Protocol\PortableContact;
|
||||||
use Friendica\Protocol\Salmon;
|
use Friendica\Protocol\Salmon;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
|
@ -14,7 +14,6 @@ use Friendica\Module\BaseAdminModule;
|
||||||
use Friendica\Module\Register;
|
use Friendica\Module\Register;
|
||||||
use Friendica\Protocol\PortableContact;
|
use Friendica\Protocol\PortableContact;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Worker\Delivery;
|
use Friendica\Worker\Delivery;
|
||||||
|
|
||||||
|
@ -246,7 +245,7 @@ class Site extends BaseAdminModule
|
||||||
$diaspora_enabled = false;
|
$diaspora_enabled = false;
|
||||||
}
|
}
|
||||||
if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) {
|
if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) {
|
||||||
if ($ssl_policy == BaseURL::SSL_POLICY_FULL) {
|
if ($ssl_policy == App\BaseURL::SSL_POLICY_FULL) {
|
||||||
DBA::e("UPDATE `contact` SET
|
DBA::e("UPDATE `contact` SET
|
||||||
`url` = REPLACE(`url` , 'http:' , 'https:'),
|
`url` = REPLACE(`url` , 'http:' , 'https:'),
|
||||||
`photo` = REPLACE(`photo` , 'http:' , 'https:'),
|
`photo` = REPLACE(`photo` , 'http:' , 'https:'),
|
||||||
|
@ -264,7 +263,7 @@ class Site extends BaseAdminModule
|
||||||
`thumb` = REPLACE(`thumb` , 'http:' , 'https:')
|
`thumb` = REPLACE(`thumb` , 'http:' , 'https:')
|
||||||
WHERE 1 "
|
WHERE 1 "
|
||||||
);
|
);
|
||||||
} elseif ($ssl_policy == BaseURL::SSL_POLICY_SELFSIGN) {
|
} elseif ($ssl_policy == App\BaseURL::SSL_POLICY_SELFSIGN) {
|
||||||
DBA::e("UPDATE `contact` SET
|
DBA::e("UPDATE `contact` SET
|
||||||
`url` = REPLACE(`url` , 'https:' , 'http:'),
|
`url` = REPLACE(`url` , 'https:' , 'http:'),
|
||||||
`photo` = REPLACE(`photo` , 'https:' , 'http:'),
|
`photo` = REPLACE(`photo` , 'https:' , 'http:'),
|
||||||
|
@ -512,9 +511,9 @@ class Site extends BaseAdminModule
|
||||||
];
|
];
|
||||||
|
|
||||||
$ssl_choices = [
|
$ssl_choices = [
|
||||||
BaseURL::SSL_POLICY_NONE => L10n::t('No SSL policy, links will track page SSL state'),
|
App\BaseURL::SSL_POLICY_NONE => L10n::t('No SSL policy, links will track page SSL state'),
|
||||||
BaseURL::SSL_POLICY_FULL => L10n::t('Force all links to use SSL'),
|
App\BaseURL::SSL_POLICY_FULL => L10n::t('Force all links to use SSL'),
|
||||||
BaseURL::SSL_POLICY_SELFSIGN => L10n::t('Self-signed certificate, use SSL for local links only (discouraged)')
|
App\BaseURL::SSL_POLICY_SELFSIGN => L10n::t('Self-signed certificate, use SSL for local links only (discouraged)')
|
||||||
];
|
];
|
||||||
|
|
||||||
$check_git_version_choices = [
|
$check_git_version_choices = [
|
||||||
|
|
|
@ -10,7 +10,6 @@ use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
|
|
||||||
|
@ -180,9 +179,9 @@ class Install extends BaseModule
|
||||||
|
|
||||||
case self::BASE_CONFIG:
|
case self::BASE_CONFIG:
|
||||||
$ssl_choices = [
|
$ssl_choices = [
|
||||||
BaseURL::SSL_POLICY_NONE => L10n::t("No SSL policy, links will track page SSL state"),
|
App\BaseURL::SSL_POLICY_NONE => L10n::t("No SSL policy, links will track page SSL state"),
|
||||||
BaseURL::SSL_POLICY_FULL => L10n::t("Force all links to use SSL"),
|
App\BaseURL::SSL_POLICY_FULL => L10n::t("Force all links to use SSL"),
|
||||||
BaseURL::SSL_POLICY_SELFSIGN => L10n::t("Self-signed certificate, use SSL for local links only \x28discouraged\x29")
|
App\BaseURL::SSL_POLICY_SELFSIGN => L10n::t("Self-signed certificate, use SSL for local links only \x28discouraged\x29")
|
||||||
];
|
];
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('install_base.tpl');
|
$tpl = Renderer::getMarkupTemplate('install_base.tpl');
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Friendica\Protocol;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Content\OEmbed;
|
use Friendica\Content\OEmbed;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Content\Text\HTML;
|
use Friendica\Content\Text\HTML;
|
||||||
|
@ -31,7 +32,6 @@ use Friendica\Model\Profile;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
|
|
@ -85,12 +85,12 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* Creates the Util\BaseURL
|
* Creates the App\BaseURL
|
||||||
*
|
*
|
||||||
* Same as:
|
* Same as:
|
||||||
* $baseURL = new Util\BaseURL($configuration, $_SERVER);
|
* $baseURL = new App\BaseURL($configuration, $_SERVER);
|
||||||
*/
|
*/
|
||||||
Util\BaseURL::class => [
|
App\BaseURL::class => [
|
||||||
'constructParams' => [
|
'constructParams' => [
|
||||||
$_SERVER,
|
$_SERVER,
|
||||||
],
|
],
|
||||||
|
|
|
@ -15,7 +15,6 @@ use Friendica\Test\Util\DBAMockTrait;
|
||||||
use Friendica\Test\Util\DBStructureMockTrait;
|
use Friendica\Test\Util\DBStructureMockTrait;
|
||||||
use Friendica\Test\Util\RendererMockTrait;
|
use Friendica\Test\Util\RendererMockTrait;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
use Friendica\Util\Logger\VoidLogger;
|
use Friendica\Util\Logger\VoidLogger;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
|
@ -353,7 +352,7 @@ FIN;
|
||||||
$this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
|
$this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
|
||||||
$this->assertConfigEntry('system', 'url', $assertion);
|
$this->assertConfigEntry('system', 'url', $assertion);
|
||||||
$this->assertConfigEntry('system', 'urlpath', $assertion);
|
$this->assertConfigEntry('system', 'urlpath', $assertion);
|
||||||
$this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? BaseURL::DEFAULT_SSL_SCHEME : null);
|
$this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? App\BaseURL::DEFAULT_SSL_SCHEME : null);
|
||||||
$this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
|
$this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Content\Text;
|
namespace Friendica\Test\src\Content\Text;
|
||||||
|
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\L10n\L10n;
|
use Friendica\Core\L10n\L10n;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Test\Util\AppMockTrait;
|
use Friendica\Test\Util\AppMockTrait;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
|
|
||||||
class BBCodeTest extends MockedTest
|
class BBCodeTest extends MockedTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Friendica\Test\src\Util;
|
namespace Friendica\Test\src\Util;
|
||||||
|
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Core\Config\Configuration;
|
use Friendica\Core\Config\Configuration;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Util\BaseURL;
|
|
||||||
|
|
||||||
class BaseURLTest extends MockedTest
|
class BaseURLTest extends MockedTest
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue