ptut-vhost/build/router/controller/js.php

78 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace router\controller;
class js{
private $page;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
$this->page = isset($url['page']) ? $url['page'] : '';
$this->page = preg_match('/^@[a-z]+$/', $this->page) ? substr($this->page, 1) : null;
}
/* Generate _SERVER.js
*
*/
public function server(){
header('Content-Type: text/javascript; charset=utf-8');
echo "window._SERVER = ".json_encode([
'session' => [
'name' => $_SESSION['CAS']['login'],
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false,
'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartment']),
'department_id' => $_SESSION['CurrentDepartementId']
]
])."\n";
}
/* Manage bundle hash
*
*/
public function bundle(){
2018-02-20 16:45:02 +00:00
if( is_null($this->page) )
include __PUBLIC__.'/page/404.php';
/* (1) Extract /public_html/js/ all .js files */
$js_scripts = glob(__PUBLIC__.'/js/bundle/'.$this->page.'@*.js');
/* (2) If match pattern 'bundle@home@*.js' */
foreach($js_scripts as $fname){
$bname = basename($fname);
// if match -> load it and exit
header("Location: /js/bundle/$bname");
die();
}
/* (3) If nothing found */
2018-02-20 16:45:02 +00:00
include __PUBLIC__.'/page/404.php';
}
/* POST-CALL
*
*/
public function __destruct(){
}
}