X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp.php;h=8b2d50512b80b695f3b770db337e5e395e7e5791;hb=e9511b4f34189e3839f9c54f98835dc1374fc316;hp=e89f450ba6c6d49f99cd5872ffe559d83db0475f;hpb=bbd30719400d74f1ceb0c30b368dd5a8301ea885;p=friendica.git diff --git a/src/App.php b/src/App.php index e89f450ba6..8b2d50512b 100644 --- a/src/App.php +++ b/src/App.php @@ -8,10 +8,11 @@ use Detection\MobileDetect; use DOMDocument; use DOMXPath; use Exception; -use Friendica\Core\Config\Cache\IConfigCache; +use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\Config\Configuration; use Friendica\Core\Hook; use Friendica\Core\Theme; +use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\Model\Profile; use Friendica\Network\HTTPException; @@ -87,11 +88,6 @@ class App */ private $baseURL; - /** - * @var bool true, if the call is from the Friendica APP, otherwise false - */ - private $isFriendicaApp; - /** * @var bool true, if the call is from an backend node (f.e. worker) */ @@ -127,10 +123,15 @@ class App */ private $profiler; + /** + * @var Database The Friendica database connection + */ + private $database; + /** * Returns the current config cache of this node * - * @return IConfigCache + * @return ConfigCache */ public function getConfigCache() { @@ -154,7 +155,8 @@ class App */ public function getBasePath() { - return $this->config->get('system', 'basepath'); + // Don't use the basepath of the config table for basepath (it should always be the config-file one) + return $this->config->getCache()->get('system', 'basepath'); } /** @@ -197,6 +199,14 @@ class App return $this->router; } + /** + * @return Database + */ + public function getDatabase() + { + return $this->database; + } + /** * Register a stylesheet file path to be included in the tag of every page. * Inclusion is done in App->initHead(). @@ -236,6 +246,7 @@ class App /** * @brief App constructor. * + * @param Database $database The Friendica Database * @param Configuration $config The Configuration * @param App\Mode $mode The mode of this Friendica app * @param App\Router $router The router of this Friendica app @@ -246,10 +257,11 @@ class App * * @throws Exception if the Basepath is not usable */ - public function __construct(Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, $isBackend = true) + public function __construct(Database $database, Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, $isBackend = true) { BaseObject::setApp($this); + $this->database = $database; $this->config = $config; $this->mode = $mode; $this->router = $router; @@ -257,8 +269,6 @@ class App $this->profiler = $profiler; $this->logger = $logger; - $this->checkFriendicaApp(); - $this->profiler->reset(); $this->reload(); @@ -601,28 +611,6 @@ class App $this->getBaseURL(); } - /** - * Checks, if the call is from the Friendica App - * - * Reason: - * The friendica client has problems with the GUID in the notify. this is some workaround - */ - private function checkFriendicaApp() - { - // Friendica-Client - $this->isFriendicaApp = isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)'; - } - - /** - * Is the call via the Friendica app? (not a "normale" call) - * - * @return bool true if it's from the Friendica app - */ - public function isFriendicaApp() - { - return $this->isFriendicaApp; - } - /** * @brief Checks if the site is called via a backend process * @@ -1006,10 +994,9 @@ class App { // Missing DB connection: ERROR if ($this->getMode()->has(App\Mode::LOCALCONFIGPRESENT) && !$this->getMode()->has(App\Mode::DBAVAILABLE)) { - echo Module\Special\HTTPException::rawContent( + Module\Special\HTTPException::rawContent( new HTTPException\InternalServerErrorException('Apologies but the website is unavailable at the moment.') ); - exit; } // Max Load Average reached: ERROR @@ -1017,17 +1004,9 @@ class App header('Retry-After: 120'); header('Refresh: 120; url=' . $this->getBaseURL() . "/" . $this->query_string); - echo Module\Special\HTTPException::rawContent( - new HTTPException\ServiceUnavaiableException('The node is currently overloaded. Please try again later.') + Module\Special\HTTPException::rawContent( + new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.') ); - exit; - } - - if (strstr($this->query_string, '.well-known/host-meta') && ($this->query_string != '.well-known/host-meta')) { - echo Module\Special\HTTPException::rawContent( - new HTTPException\NotFoundException() - ); - exit; } if (!$this->getMode()->isInstall()) { @@ -1069,19 +1048,19 @@ class App // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") && strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) { - if (defaults($_SESSION, "visitor_home", "") != $_GET["zrl"]) { - $_SESSION['my_url'] = $_GET['zrl']; - $_SESSION['authenticated'] = 0; + if (Core\Session::get('visitor_home') != $_GET["zrl"]) { + Core\Session::set('my_url', $_GET['zrl']); + Core\Session::set('authenticated', 0); } + Model\Profile::zrlInit($this); } else { // Someone came with an invalid parameter, maybe as a DDoS attempt // We simply stop processing here Core\Logger::log("Invalid ZRL parameter " . $_GET['zrl'], Core\Logger::DEBUG); - echo Module\Special\HTTPException::rawContent( + Module\Special\HTTPException::rawContent( new HTTPException\ForbiddenException() ); - exit; } } } @@ -1098,9 +1077,9 @@ class App header('X-Account-Management-Status: none'); } - $_SESSION['sysmsg'] = defaults($_SESSION, 'sysmsg' , []); - $_SESSION['sysmsg_info'] = defaults($_SESSION, 'sysmsg_info' , []); - $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []); + $_SESSION['sysmsg'] = Core\Session::get('sysmsg', []); + $_SESSION['sysmsg_info'] = Core\Session::get('sysmsg_info', []); + $_SESSION['last_updated'] = Core\Session::get('last_updated', []); /* * check_config() is responsible for running update scripts. These automatically @@ -1110,10 +1089,10 @@ class App // in install mode, any url loads install module // but we need "view" module for stylesheet - if ($this->getMode()->isInstall() && $this->module != 'view') { - $this->module = 'install'; - } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module != 'view') { - $this->module = 'maintenance'; + if ($this->getMode()->isInstall() && $this->module !== 'install') { + $this->internalRedirect('install'); + } elseif (!$this->getMode()->isInstall() && !$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module !== 'maintenance') { + $this->internalRedirect('maintenance'); } else { $this->checkURL(); Core\Update::check($this->getBasePath(), false, $this->getMode()); @@ -1136,7 +1115,7 @@ class App // Compatibility with the Android Diaspora client if ($this->module == 'stream') { - $this->internalRedirect('network?f=&order=post'); + $this->internalRedirect('network?order=post'); } if ($this->module == 'conversations') { @@ -1144,15 +1123,15 @@ class App } if ($this->module == 'commented') { - $this->internalRedirect('network?f=&order=comment'); + $this->internalRedirect('network?order=comment'); } if ($this->module == 'liked') { - $this->internalRedirect('network?f=&order=comment'); + $this->internalRedirect('network?order=comment'); } if ($this->module == 'activity') { - $this->internalRedirect('network/?f=&conv=1'); + $this->internalRedirect('network?conv=1'); } if (($this->module == 'status_messages') && ($this->cmd == 'status_messages/new')) { @@ -1267,8 +1246,7 @@ class App Core\Hook::callAll($this->module . '_mod_afterpost', $placeholder); call_user_func([$this->module_class, 'afterpost']); } catch(HTTPException $e) { - echo Module\Special\HTTPException::rawContent($e); - exit; + Module\Special\HTTPException::rawContent($e); } $content = '';