You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							79 lines
						
					
					
						
							2.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							79 lines
						
					
					
						
							2.5 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Wrappers;
							 | 
						|
								
							 | 
						|
								use App\Common\UUID;
							 | 
						|
								use App\Configuration;
							 | 
						|
								use App\Enumerators\SessionElement;
							 | 
						|
								use App\Security;
							 | 
						|
								use App\TwigExtensions\FiltersExtension;
							 | 
						|
								use App\TwigExtensions\FunctionExtensions;
							 | 
						|
								use App\TwigExtensions\NavigationExtension;
							 | 
						|
								use App\TwigExtensions\StringManipulationExtension;
							 | 
						|
								use App\TwigExtensions\TextLinkExtension;
							 | 
						|
								use App\TwigTests\TwigTests;
							 | 
						|
								use Gravatar\Gravatar;
							 | 
						|
								use JetBrains\PhpStorm\NoReturn;
							 | 
						|
								use Twig\Environment;
							 | 
						|
								use Twig\Loader\FilesystemLoader;
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class TwigWrapper
							 | 
						|
								{
							 | 
						|
								    public FilesystemLoader $loader;
							 | 
						|
								    public Environment $twig;
							 | 
						|
								
							 | 
						|
								    public function __construct()
							 | 
						|
								    {
							 | 
						|
								        $this->loader = new FilesystemLoader(dirname($_SERVER["DOCUMENT_ROOT"]) . "/Templates/");
							 | 
						|
								        $this->twig = new Environment($this->loader, ["debug" => true]);
							 | 
						|
								
							 | 
						|
								        if (session_status() == PHP_SESSION_NONE) {
							 | 
						|
								            session_start();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        $this->twig->addGlobal('_SESSION_', $_SESSION);
							 | 
						|
								
							 | 
						|
								        $this->twig->addGlobal('_ALGOLIA_INDEX_NAME_', Configuration::GetConfig("Algolia", "IndexName"));
							 | 
						|
								        $this->twig->addGlobal('_ALGOLIA_APP_ID_', Configuration::GetConfig("Algolia", "AppID"));
							 | 
						|
								        $this->twig->addGlobal('_ALGOLIA_SEARCH_ONLY_API_KEY_', Configuration::GetConfig("Algolia", "APIKeys", "SearchOnly"));
							 | 
						|
								
							 | 
						|
								        $this->twig->addGlobal('_CURRENT_PAGE_', strtok($_SERVER['REQUEST_URI'], '?'));
							 | 
						|
								        $this->twig->addGlobal('_CURRENT_URI_', urlencode("http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"));
							 | 
						|
								        $this->twig->addGlobal('_USER_TIMEZONE_OFFSET_', 60);
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        $this->twig->addExtension(new FiltersExtension());
							 | 
						|
								        $this->twig->addExtension(new FunctionExtensions($this->twig));
							 | 
						|
								        $this->twig->addExtension(new NavigationExtension());
							 | 
						|
								        $this->twig->addExtension(new StringManipulationExtension());
							 | 
						|
								
							 | 
						|
								        $this->twig->addExtension(new TwigTests());
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    {
							 | 
						|
								        $twigRenderer = new TwigWrapper();
							 | 
						|
								        $twigRenderer->RenderTwig($twigRenderer->GuessTargetTwigFile(), $arguments);
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    {
							 | 
						|
								        $twigRenderer = new TwigWrapper();
							 | 
						|
								        echo $twigRenderer->twig->render($target, $arguments);
							 | 
						|
								        die();
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    private function GuessTargetTwigFile() : string
							 | 
						|
								    {
							 | 
						|
								        $twigFile = str_replace(search: ".php",replace: ".html.twig", subject: $_SERVER['REQUEST_URI']);
							 | 
						|
								        if($twigFile == "/")
							 | 
						|
								            $twigFile = "/index.html.twig";
							 | 
						|
								
							 | 
						|
								        $pageTemplateDirectory = __DIR__ . "/../../Templates/Pages";
							 | 
						|
								
							 | 
						|
								        if(!file_exists($pageTemplateDirectory . $twigFile))
							 | 
						|
								            return "ErrorPages/404.html.twig";
							 | 
						|
								
							 | 
						|
								        return "Pages" . $twigFile;
							 | 
						|
								    }
							 | 
						|
								}
							 | 
						|
								
							 |