/** * Initializes the environment, the error handlers, includes the app index.php file, the addons index.php files, and registers the assests handler */ public function initialize() { if (!$this->initialized) { $this->initializeEnvironment(); $this->initializeErrorHandler(); $this->initializeRequest(); ob_start(); $app =& self::$instance; // needed for the app index file if (strlen($this->config->appDir) > 0 && is_file($this->config->appDir . DIRECTORY_SEPARATOR . 'index.php')) { $context = new App\AppContext($this->config->appDir); include realpath($this->config->appDir . DIRECTORY_SEPARATOR . 'index.php'); } if ($this->config->assetsPathPrefix !== null) { $this->routes->add($this->config->assetsPathPrefix . '*', function () use($app) { $filename = $app->assets->getFilename((string) $app->request->path); if ($filename === false) { return new App\Response\NotFound(); } else { $response = new App\Response\FileReader($filename); if ($app->config->assetsMaxAge !== null) { $response->setMaxAge((int) $app->config->assetsMaxAge); } $mimeType = $app->assets->getMimeType($filename); if ($mimeType !== null) { $response->headers[] = 'Content-Type: ' . $mimeType; } return $response; } }); } $this->hooks->execute('initialized'); ob_end_clean(); $this->initialized = true; } }
if (is_numeric($size)) { $size = (int) $size; if ($size >= 16 && $size <= 1000) { $url = $context->assets->getUrl('assets/logo' . ($size < 60 ? '-small' : '') . '.png', ['width' => $size, 'height' => $size]); $path = str_replace($app->request->base, '', $url); $response = new App\Response\FileReader($app->assets->getFilename($path)); $response->setContentType('image/png'); $response->setMaxAge(86400); return $response; } } return new App\Response\NotFound(); }); // Route for the image used by the social networks $app->routes->add('/assets/socialimage', function () use($context) { $response = new App\Response\FileReader($context->dir . 'assets/social-image.png'); $response->setContentType('image/png'); $response->setMaxAge(86400); return $response; }); // Update the response $app->hooks->add('responseCreated', function ($response) use($app, $context) { $addTemplate = false; if ($response instanceof App\Response\NotFound) { $response->setContentType('text/html'); $response->content = $app->components->process('<component src="file:' . $context->dir . 'components/systempage.php" text="Page not found" />'); $addTemplate = true; } elseif ($response instanceof App\Response\TemporaryUnavailable) { $response->setContentType('text/html'); $response->content = $app->components->process('<component src="file:' . $context->dir . 'components/systempage.php" text="Temporary unavailable. Try again in few moments." />'); $addTemplate = true;