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/hermitage.creativefellows.nl/src/Action/View/PreviewAction.php
<?php

namespace App\Action\View;

use App\Action\Action;

use App\Domain\Page\Service\PageReader;
use App\Domain\Navigation\Service\NavigationReader;
use App\Domain\Language\LanguageData;
use App\Domain\Breadcrumb\Data\BreadcrumbData;

use App\Handler\DefaultErrorHandler;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Container\ContainerInterface;
use Slim\Views\PhpRenderer;


final class PreviewAction extends Action
{	
	
    protected $container;	
	protected $responder;
	protected $pageReader;
	protected $navigationReader;
	protected $breadcrumbs;
	protected $errorHandler;
	protected $language;
	
		
	
    public function __construct(
		ContainerInterface $container, 
		PhpRenderer $responder, 
		PageReader $pageReader, 
		NavigationReader $navigationReader,
		BreadcrumbData $breadcrumbs,
		LanguageData $language,
		DefaultErrorHandler $errorHandler
	) {
        $this->container 		= $container;
        $this->responder 		= $responder;
		$this->pageReader 		= $pageReader;
		$this->navigationReader = $navigationReader;
		$this->breadcrumbs		= $breadcrumbs;
		$this->language 		= $language;
		$this->errorHandler 	= $errorHandler;
		
		$this->hash_salt 		= $this->container->get('settings')['hash_key'];
		
    }
	
    public function action() : ResponseInterface
	{
		// set breadcrumbs
		$this->breadcrumbs->setUrl( $this->request->getUri()->getPath() );
		
		// check of a post url is set
	    $page_id = ($this->args['id'] ?? null);
	    $hash = ($this->args['hash'] ?? null);
				
		
		// get data of page
        $this->page = $this->pageReader->previewPage($page_id);
			

		// get menu elements
		$this->navigation = $this->navigationReader->getNavigationData("");	
			
		// 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->navigation);
		
		// localize labels
		$localization = $this->language->localizedLanguageData()->setting("labels");

		// return
		return $this->responder->render($this->response, $this->page->getTemplateName(), [
			"navigation" => $this->navigation,
			"page" => $this->page,
			"breadcrumbs" => $this->breadcrumbs,
			"localization" => $localization,
		]);
		
    }
		
	public function getHash($id)
	{
		return hash("sha256",$id.$this->hash_salt);
	}
		
}