main/build/router/controller/js.php

69 lines
996 B
PHP
Raw Normal View History

<?php
namespace router\controller;
class js{
private $pagename;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
}
/* Generate _SERVER.js
*
*/
public function server(){
header('Content-Type: text/javascript; charset=utf-8');
echo "window._SERVER = ".json_encode([
'session' => [
'name' => $_SESSION['NAME'],
'connected' => count($_SESSION['ADMIN']) + count($_SESSION['USER']) > 0
]
])."\n";
}
/* Manage bundle hash
*
*/
public function bundle(){
/* (1) Extract /public_html/js/ all .js files */
$js_scripts = glob(__PUBLIC__.'/js/*.js');
/* (2) If match pattern 'bundle@*.js' */
foreach($js_scripts as $fname){
$bname = basename($fname);
// if match -> load it and exit
if( preg_match('/bundle@[\da-f]+\.js/', $bname) )
header("Location: /js/$bname");
}
}
/* POST-CALL
*
*/
public function __destruct(){
}
}