HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/oudlondon.creativefellows.nl/src/Action/View/PreviewAction.php
<?php

namespace App\Action\View;

use App\Action\TwigAction;
use App\Domain\Page\Service\PageReader;
use App\Domain\Navigation\Service\NavigationReader;
use App\Domain\Language\LanguageData;
use App\Domain\Cookie\CookieData;


use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;

use App\Handler\DefaultErrorHandler;
use Psr\Container\ContainerInterface;

final class PreviewAction extends TwigAction
{	
	
   protected $container;	
	private $twig;
	private $pageReader;
	private $navigationReader;
	private $errorHandler;
	private $language;
	private $cookies;
	

    public function __construct(
		ContainerInterface $container, 
		Twig $twig,
		PageReader $pageReader, 
		NavigationReader $navigationReader,
		LanguageData $language,
		CookieData $cookies,
		DefaultErrorHandler $errorHandler
	) {
        $this->container 		= $container;	
        $this->twig 			= $twig;
		$this->pageReader 		= $pageReader;
		$this->navigationReader = $navigationReader;
		$this->language 		= $language;
		$this->cookies 			= $cookies;
		$this->errorHandler 	= $errorHandler;
		$this->hash_salt 		= $this->container->get('settings')['hash_key'];	
    }
	
    public function action() : Response
	{	
		
		
		$data 			= $this->request->getQueryParams();
		
	    $post_name 		= ($this->args['page'] ?? null);
	    $post_category	= ($this->args['category'] ?? null);
	    $post_section 	= ($this->args['section'] ?? null);
		
	    $page_id = ($this->args['id'] ?? null);
	    $hash = ($this->args['hash'] ?? null);
		
			
		
		$form_status = [
			"hash" => ($data["hash"] ?? null), 
			"status" => ($data["s"] ?? null), 
		];
		
		
		// form status	
		$this->pageReader->setFormStatus($form_status);
		
		// get data of page
		$this->page = $this->pageReader->previewPage($page_id);
		
		// return error page if no result in page				
		if( !$this->page->hasData() || $hash != $this->getHash($page_id)  ) return $this->errorHandler->respond($this->response,$this->page,$this->navigationReader->getNavigationData($post_section));
						
		
		$data = [
			"navigation" => $this->navigationReader->getNavigationData($post_section),
			"page" => $this->page->twigData(),
			"localization" => $this->language->localizedLanguageData()->setting("labels"),
			"cookies" => $this->cookies
		];
	
		return $this->twig->render($this->response, $this->page->getTemplateName(), $data);
		
    }
	
	public function getHash($id)
	{
		return hash("sha256",$id.$this->hash_salt);
	}
		
}