X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp.php;h=4def7fefa076208b5ba077fd128f7c7754d0ba5f;hb=eb024a3718a47aa596abfab4e611d5532eea8d2a;hp=e5ec66f5e3815bbe3ce724d039a5c162bf5cce02;hpb=64f51d337f3999afe234537c3704211656718462;p=friendica.git diff --git a/src/App.php b/src/App.php index e5ec66f5e3..4def7fefa0 100644 --- a/src/App.php +++ b/src/App.php @@ -8,10 +8,12 @@ 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\L10n\L10n; use Friendica\Core\Theme; +use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\Model\Profile; use Friendica\Network\HTTPException; @@ -122,10 +124,20 @@ class App */ private $profiler; + /** + * @var Database The Friendica database connection + */ + private $database; + + /** + * @var L10n The translator + */ + private $l10n; + /** * Returns the current config cache of this node * - * @return IConfigCache + * @return ConfigCache */ public function getConfigCache() { @@ -193,6 +205,22 @@ class App return $this->router; } + /** + * @return Database + */ + public function getDatabase() + { + return $this->database; + } + + /** + * @return L10n + */ + public function getL10n() + { + return $this->l10n; + } + /** * Register a stylesheet file path to be included in the tag of every page. * Inclusion is done in App->initHead(). @@ -232,26 +260,30 @@ 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 * @param BaseURL $baseURL The full base URL of this Friendica app * @param LoggerInterface $logger The current app logger * @param Profiler $profiler The profiler of this application + * @param L10n $l10n The translator instance * @param bool $isBackend Whether it is used for backend or frontend (Default true=backend) * * @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, L10n $l10n, $isBackend = true) { BaseObject::setApp($this); + $this->database = $database; $this->config = $config; $this->mode = $mode; $this->router = $router; $this->baseURL = $baseURL; $this->profiler = $profiler; $this->logger = $logger; + $this->l10n = $l10n; $this->profiler->reset(); @@ -357,8 +389,6 @@ class App } $this->loadDefaultTimezone(); - - Core\L10n::init(); } /** @@ -502,7 +532,7 @@ class App $this->page['htmlhead'] = Core\Renderer::replaceMacros($tpl, [ '$local_user' => local_user(), '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION, - '$delitem' => Core\L10n::t('Delete this item?'), + '$delitem' => $this->l10n->t('Delete this item?'), '$update_interval' => $interval, '$shortcut_icon' => $shortcut_icon, '$touch_icon' => $touch_icon, @@ -544,7 +574,7 @@ class App } $this->page['footer'] .= Core\Renderer::replaceMacros(Core\Renderer::getMarkupTemplate("toggle_mobile_footer.tpl"), [ '$toggle_link' => $link, - '$toggle_text' => Core\L10n::t('toggle mobile') + '$toggle_text' => $this->l10n->t('toggle mobile') ]); } @@ -860,7 +890,7 @@ class App { $system_theme = $this->config->get('system', 'theme'); if (!$system_theme) { - throw new Exception(Core\L10n::t('No system theme config value set.')); + throw new Exception($this->l10n->t('No system theme config value set.')); } // Sane default @@ -993,12 +1023,6 @@ class App ); } - if (strstr($this->query_string, '.well-known/host-meta') && ($this->query_string != '.well-known/host-meta')) { - Module\Special\HTTPException::rawContent( - new HTTPException\NotFoundException() - ); - } - if (!$this->getMode()->isInstall()) { // Force SSL redirection if ($this->baseURL->checkRedirectHttps()) { @@ -1016,8 +1040,8 @@ class App $stamp1 = microtime(true); session_start(); $this->profiler->saveTimestamp($stamp1, 'parser', Core\System::callstack()); - Core\L10n::setSessionVariable(); - Core\L10n::setLangFromSession(); + $this->l10n->setSessionVariable(); + $this->l10n->setLangFromSession(); } else { $_SESSION = []; Core\Worker::executeIfIdle(); @@ -1038,10 +1062,11 @@ 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 @@ -1066,9 +1091,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 @@ -1160,7 +1185,7 @@ class App //Check if module is an app and if public access to apps is allowed or not $privateapps = $this->config->get('config', 'private_addons', false); if ((!local_user()) && Core\Hook::isAddonApp($this->module) && $privateapps) { - info(Core\L10n::t("You must be logged in to use addons. ")); + info($this->l10n->t("You must be logged in to use addons. ")); } else { include_once "addon/{$this->module}/{$this->module}.php"; if (function_exists($this->module . '_module')) { @@ -1350,7 +1375,7 @@ class App $a = $this; // Used as is in view/php/default.php - $lang = Core\L10n::getCurrentLang(); + $lang = $this->l10n->getCurrentLang(); /// @TODO Looks unsafe (remote-inclusion), is maybe not but Core\Theme::getPathForFile() uses file_exists() but does not escape anything require_once $template;