<?php
namespace App\Controller;
use Empire\Core\Core;
use Empire\Legacy\Menu;
use Empire\Legacy\publicpage;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Annotation\Route;
use Twig\Markup;
/**
* Class LegacyController
* @package App\Controller
*
* Contains the controllers for the remaining public legacy pages.
*/
class LegacyController extends BaseController {
/**
* @Route("Public/Reference/showdocument.php")
* @param Request $request
* @return BinaryFileResponse|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function legacy_doclib(Request $request) {
$clearance = Core::user() !== null ? Core::user()->getClearance()->order : 0;
$file = $request->query->get('file', null);
if($file !== null) {
return $this->redirect("/p/library/" . $file);
} else {
$this->addFlash('error', 'Missing Reference Number');
return $this->redirect('/Public/Reference/doclibrary.php');
}
}
/**
* @Route("gejs.php")
* @param Request $request
* @return Response
*/
public function legacy_gejs(Request $request) {
ini_set('html_errors', 0);
$input = json_decode($request->getContent(), true);
$gejs = new \Empire\Core\GEjs(isset($input['gejsOptions']) ? $input['gejsOptions'] : null);
//var_dump($input, $gejs);
$response = new Response();
$response->setContent(json_encode($gejs->processSecureAjax(
$input['gejsFunction'],
isset($input['gejsValues']) ? $input['gejsValues'] : [],
isset($input['gejsCid']) ? $input['gejsCid'] : null
)));
$response->headers->set('Content-Type', 'application/json');
//Do not enable this for production!
//$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
/**
* @Route("/Public/{path}", requirements={"path"=".*"})
* @param $path
* @return object|Response
*/
public function legacy_public(Packages $assets, $path) {
if(preg_match('/\.php$/', $path) && file_exists(EMPIRE_APPLICATION . "/legacy/Public/" . $path)) {
/* Try and get the path category, otherwise fallback to Main */
$pageInfo = Menu::getPacaId(substr(Core::get('fullPage'), 1));
$menu_category = isset($pageInfo->PACA_ID) ? $pageInfo->PACA_ID : 0;
require_once EMPIRE_APPLICATION . '/legacy/globalfunctions.php';
/* Load legacy content and return it */
ob_start();
require EMPIRE_APPLICATION . "/legacy/Public/" . $path;
//Deal with GEjs
if(isset($gejs))
$gejs = array_unique(array_merge((array) $gejs, array("ajax")));
else
$gejs = ["ajax"];
return $this->render('legacy.twig', [
'content' => ob_get_clean(),
'headerDiv' => new Markup(publicpage::displayHeaderDiv($menu_category), 'UTF-8'),
'title' => is_object($pageInfo) ? $pageInfo->SEPA_TITLE : '',
'gejs' => $gejs,
]);
} elseif(file_exists(EMPIRE_APPLICATION . "/legacy/Public/" . $path)) {
if(is_dir(EMPIRE_APPLICATION . "/legacy/Public/" . $path)) {
return $this->redirect(Core::get('base_url') . "Public/" . $path . "index.php");
}
return new BinaryFileResponse(EMPIRE_APPLICATION . "/legacy/Public/" . $path);
} else {
return (new Response())->setStatusCode(404);
}
}
/**
* @Route("/Members/{file}")
* @param Packages $assets
* @param $file
* @return mixed
*/
public function legacy_members(Packages $assets, $file) {
$lc = Core::loginCheck();
if($lc) return new Response($lc);
if(preg_match('/\.php$/', $file) && file_exists(EMPIRE_APPLICATION . "/legacy/Members/" . $file)) {
/* Try and get the path category, otherwise fallback to Main */
$pageInfo = \Empire\Legacy\Menu::getPacaId(substr(Core::get('fullPage'), 1));
require EMPIRE_APPLICATION . '/legacy/globalfunctions.php';
/* Setup for the pages */
$objUser = Core::user();
$GLOBALS['gImagePath'] = $assets->getUrl('', 'gfx');
$GLOBALS['gLegacyImagePath'] = Core::get('base_url');
$GLOBALS['gJSPath'] = $assets->getUrl('', 'js');
$GLOBALS['gCSSPath'] = $assets->getUrl('', 'css');
$GLOBALS['gURLPath'] = Core::get('base_url');
$flash = \Empire\Core\GEContext::getContext()->getFlash();
/* Load legacy content and return it */
ob_start();
require EMPIRE_APPLICATION . "/legacy/Members/". $file;
/** Potential Redirect */
if(isset($redirect)) {
return $this->redirect($redirect[0]);
}
//Deal with GEjs
if(isset($gejs))
$gejs = array_unique(array_merge((array) $gejs, array("ajax")));
else
$gejs = ["ajax"];
//Deal with asset loading
Core::set('secure',isset($isSecure) ? $isSecure : false);
// Check for page security.
return $this->render('legacy.twig', [
'content' => ob_get_clean(),
'headerDiv' => new Markup(publicpage::displayHeaderDiv(0), 'UTF-8'),
'title' => $pageInfo->SEPA_TITLE,
'gejs' => $gejs,
]);
} elseif(file_exists(EMPIRE_APPLICATION . "/legacy/Members/" . $file)) {
if(is_dir(EMPIRE_APPLICATION . "/legacy/Members/" . $file)) {
return $this->redirect(Core::get('base_url') . "Members/" . $file . "index.php");
}
return new BinaryFileResponse(EMPIRE_APPLICATION . "/legacy/Members/" . $file);
} else {
return (new Response())->setStatusCode(404);
}
}
}