You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
5.5 KiB
PHP
171 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace NN\Module;
|
|
require_once SETUP_PATH.'vendor/autoload.php';
|
|
use Jenssegers\Blade\Blade;
|
|
use NN\Files;
|
|
|
|
class View {
|
|
|
|
public static function render($name = '', $arg = []){
|
|
$chache = SETUP_PATH.'views/chache';
|
|
if(!file_exists($chache)){
|
|
mkdir($chache, 777,true);
|
|
}
|
|
$blade = new Blade(SETUP_PATH.'views', 'cache');
|
|
$bld = $blade->make($name, $arg)->render();
|
|
echo $bld;
|
|
}
|
|
|
|
public static function tailwind($name = '', $arg = []){
|
|
$blade = new Blade(SETUP_PATH.'tailwind', 'cache');
|
|
$bld = $blade->make($name, $arg)->render();
|
|
echo $bld;
|
|
}
|
|
|
|
public static function sc($file, $type="script"){
|
|
$f = SETUP_PATH."script/".$file;
|
|
if(file_exists($f)){
|
|
$dt = filemtime($f);
|
|
$j = base64_encode($file)."||".$dt;
|
|
if($type == 'module'){
|
|
return "<script type='module' src='".PATH."/script/".$j."'></script>";
|
|
}
|
|
return "<script src='".PATH."/script/".$j."'></script>";
|
|
}else{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public static function ip(){
|
|
$ipaddress = '';
|
|
if (getenv('HTTP_CLIENT_IP'))
|
|
$ipaddress = getenv('HTTP_CLIENT_IP');
|
|
else if(getenv('HTTP_X_FORWARDED_FOR'))
|
|
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
|
|
else if(getenv('HTTP_X_FORWARDED'))
|
|
$ipaddress = getenv('HTTP_X_FORWARDED');
|
|
else if(getenv('HTTP_FORWARDED_FOR'))
|
|
$ipaddress = getenv('HTTP_FORWARDED_FOR');
|
|
else if(getenv('HTTP_FORWARDED'))
|
|
$ipaddress = getenv('HTTP_FORWARDED');
|
|
else if(getenv('REMOTE_ADDR'))
|
|
$ipaddress = getenv('REMOTE_ADDR');
|
|
else
|
|
$ipaddress = 'UNKNOWN';
|
|
return $ipaddress;
|
|
}
|
|
|
|
public function ffiletimes(string $dir): ?string
|
|
{
|
|
if (!is_dir($dir)) throw new \ValueError('Expecting a valid directory!');
|
|
|
|
$latest = null;
|
|
$latestTime = 0;
|
|
foreach (scandir($dir) as $path) if (!in_array($path, ['.', '..'], true)) {
|
|
$filename = $dir . DIRECTORY_SEPARATOR . $path;
|
|
|
|
if (is_dir($filename)) {
|
|
$directoryLastModifiedFile = $this->ffiletimes($filename);
|
|
|
|
if (null === $directoryLastModifiedFile) {
|
|
continue;
|
|
} else {
|
|
$filename = $directoryLastModifiedFile;
|
|
}
|
|
}
|
|
|
|
$lastModified = filemtime($filename);
|
|
if ($lastModified > $latestTime) {
|
|
$latestTime = $lastModified;
|
|
$latest = $filename;
|
|
}
|
|
}
|
|
|
|
return $latest;
|
|
}
|
|
|
|
public static function filetimes(){
|
|
$w = filemtime((new self)->ffiletimes(SETUP_PATH . "script"));
|
|
return $w;
|
|
}
|
|
|
|
public static function js($path = ""){
|
|
$w = filemtime((new self)->ffiletimes(SETUP_PATH . "script"));
|
|
if($path != ""){
|
|
return "<script type=\"module\" src=\"".PATH.'/assets-js/'. join("-", explode("/",$path) ) ."?=".$w."\"></script>";
|
|
}
|
|
return $w;
|
|
}
|
|
|
|
public static function jsm($path = ""){
|
|
$w = filemtime((new self)->ffiletimes(SETUP_PATH . "script"));
|
|
if($path != ""){
|
|
return "<script type=\"module\" src=\"".PATH.'/assets-jsm/'. join("-", explode("/",$path) ) ."?=".$w."-clear-chace\"></script>";
|
|
}
|
|
return $w;
|
|
}
|
|
|
|
public static function jsx($path = ""){
|
|
$w = filemtime((new self)->ffiletimes(SETUP_PATH . "script"));
|
|
if($path != ""){
|
|
return "<script type=\"module\" src=\"" . PATH . "/assets-jsx/". "bundle.js" ."?=".$w."\"></script>";
|
|
}
|
|
return $w;
|
|
}
|
|
|
|
public static function time(){
|
|
$w = filemtime((new self)->ffiletimes(SETUP_PATH . "script"));
|
|
return $w;
|
|
}
|
|
|
|
public function single($name = "") {
|
|
$w = filemtime((new self)->ffiletimes(SETUP_PATH . "script"));
|
|
$file = SETUP_PATH . "script/". join("/", explode("-", explode("?", $name )[0] ) ) ;
|
|
if(file_exists($file)){
|
|
$x = Files::read($file);
|
|
$x = str_replace("{time}", $w, $x);
|
|
$x = str_replace("{js}", PATH."/assets-js/", $x);
|
|
$x = str_replace("{{PATH}}", PATH, $x);
|
|
$x = str_replace("{{ PATH }}", PATH, $x);
|
|
$x = str_replace("{{APPNAME}}",APPNAME, $x);
|
|
$x = str_replace("{{ APPNAME }}",APPNAME, $x);
|
|
$x = str_replace("{{ SETUP_PATH }}", SETUP_PATH, $x);
|
|
$x = str_replace("{{ASSET}}", ASSET, $x);
|
|
$x = str_replace("{{ ASSET }}", ASSET, $x);
|
|
return $x;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public static function multijs($t = "") {
|
|
ini_set('memory_limit', '-1');
|
|
$j = SETUP_PATH."json/asset.json";
|
|
$j = json_decode( Files::read($j) );
|
|
$h = "";
|
|
$h .= (new self)->single($t);
|
|
foreach($j->asset as $asset){
|
|
$asset = str_replace("/", "-", $asset);
|
|
$h .= (new self)->single( $asset );
|
|
$h .= " \n ";
|
|
}
|
|
$h = str_replace("window", "\n window", $h);
|
|
echo $h;
|
|
}
|
|
|
|
public static function multijsx() {
|
|
ini_set('memory_limit', '-1');
|
|
$j = SETUP_PATH."json/main.json";
|
|
$j = json_decode( Files::read($j) );
|
|
$h = "";
|
|
foreach($j->asset as $asset){
|
|
$asset = str_replace("/", "-", $asset);
|
|
$h .= (new self)->single( $asset );
|
|
$h .= " \n ";
|
|
}
|
|
echo $h;
|
|
}
|
|
|
|
}
|