From c99710918ed71fdf5e2f76869b0c417600b0887b Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 17 Dec 2020 15:23:51 +0800 Subject: [PATCH] Fix #6504 - scss output in assets --- Asset.php | 1 + AssetTrait.php | 88 ++++++++++++++++++++++++++++++++++++- DataObjects/Core_person.php | 53 +++++++++++++++++++++- 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/Asset.php b/Asset.php index 92e43cbb..eb5c0538 100644 --- a/Asset.php +++ b/Asset.php @@ -138,6 +138,7 @@ class Pman_Core_Asset extends Pman { switch($type) { case 'js': case 'css': + case 'scss': $compile_dir .= implode("-", array( $ui['name'], $module, diff --git a/AssetTrait.php b/AssetTrait.php index 5199ef26..36ce8453 100644 --- a/AssetTrait.php +++ b/AssetTrait.php @@ -127,6 +127,7 @@ trait Pman_Core_AssetTrait { case 'js': echo ''."\n"; break; + case 'css': case 'css': echo ''."\n"; break; @@ -139,10 +140,10 @@ trait Pman_Core_AssetTrait { /** * usage in template - * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)} + * {outputCSSDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)} */ - function outputCssDir($path) + function outputCSSDir($path) { $relpath = $this->rootURL . '/' . $path .'/'; @@ -282,4 +283,87 @@ trait Pman_Core_AssetTrait { + function outputSCSS($smod) + { + // we cant output non-cached versions of this.... + $ff = HTML_FlexyFramework::get(); + $fp = "{$this->rootDir}/Pman/$smod/scss/{$smod}.scss"; + // var_dump($fp); + if (!file_exists($fp)) { + return; + } + + $ar = glob(dirname($fp) . '/*.scss'); + $maxtime = 0; + foreach($ar as $fn) { + $maxtime=max($maxtime, filemtime($fn)); + } + + + + //print_r($relfiles); + + require_once 'Pman/Core/Asset.php'; + $compiledir = Pman_Core_Asset::getCompileDir('css', '', true); + + + if (!file_exists($compiledir)) { + mkdir($compiledir,0700,true); + } + + + + + $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $ar))) .'.css'; + + $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/'; + + // where are we going to write all of this.. + // This has to be done via a + + + + if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) { + + + + require_once 'System.php'; + static $sassc = false; + if ($sassc === false) { + $sassc = System::which("sassc"); + } + if (empty($sassc)) { + die("INSTALL sassc"); + } + + $fd = dirname($fp); + + + $cmd = "{$sassc} --style=compressed --sourcemap=auto -I {$fd} -I {$this->rootDir}/roojs1/scss/bootstrap $smod.scss {$compiledir}/{$output}"; + //echo "$cmd\n"; echo `$cmd`; + `$cmd`; + + + clearstatcache(); + if (!file_exists($compiledir.'/'.$output) || + !filesize($compiledir.'/'.$routput)) { + echo "\n"; + echo "\n"; + return; + } + + } else { + // echo "\n"; + } + + + //$this->arrayToJsInclude( $files); + $this->assetArrayToHtml( array( + $this->baseURL.$asset. $output, + + ),'css'); + + } + + } \ No newline at end of file diff --git a/DataObjects/Core_person.php b/DataObjects/Core_person.php index 01611b57..b45eef49 100644 --- a/DataObjects/Core_person.php +++ b/DataObjects/Core_person.php @@ -537,7 +537,58 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $month = $m > -1 ? date('Y-m') : date('Y-m', strtotime('LAST MONTH')); return md5(implode(',' , array($month, $this->email , $this->passwd, $this->id))); - } + } + /** + * When we generate autologin urls: + * eg. /Somesite/Test/12 + * it will generate: + * /Somesite/Test/12/{datetime}/{sha256(url + expires_datetime + password)} + * + * eg. genAutoLoginURL($sub, $expires) + */ + function genAutoLoginURL($url, $expires = false) + { + $expires = $expires === false ? strtotime("NOW + 1 WEEK") : $expires; + //echo serialize(array($url, $expires, $this->email, $this->passwd)); + //echo hash('sha256', serialize(array($url, $expires, $this->email, $this->passwd))); + + return $url.'/'.$this->id .'/'.$expires.'/'. + hash('sha256', + serialize( + array($url, $expires, $this->email,$this->passwd) + ) + ); + + } + + function validateAutoLogin($called) + { + $bits = explode("/",$called); + if (count($bits) < 4) { + return false; // unrelated. + } + $hash = array_pop($bits); + $time = array_pop($bits); + + $id = array_pop($bits); + if (!is_numeric($time) || !is_numeric($id)) { + return false; // wrong format. + } + $u = DB_DataObject::Factory($this->tableName()); + $u->get($id); + $url = implode("/", $bits); + if ($time < time()) { + return "Expired"; + } + //echo serialize(array('/'.$url, $time, $u->email, $u->passwd)); + //echo hash('sha256', serialize(array('/'.$url, $time, $u->email, $u->passwd))); + if ($hash == hash('sha256', serialize(array('/'.$url, $time*1, $u->email, $u->passwd)))) { + $u->login(); + return $u; + } + return false; + } + function checkTwoFactorAuthentication($val) { -- 2.39.2