vue: join

This commit is contained in:
2021-09-15 19:06:15 +00:00
committed by Gitea
parent 5e1267bc64
commit 7933336c25
25 changed files with 781 additions and 142 deletions
+6 -1
View File
@@ -12,11 +12,16 @@ class APIHelper
public static function launch(string $rootPath)
{
try {
$input = json_decode(file_get_contents('php://input'));
$rawInput = file_get_contents('php://input');
$input = Json::decode($rawInput);
} catch (\Exception $e) {
Json::dieWithReason($e->getMessage());
}
if(!$input){
Json::dieWithReason("input이 비어있습니다. {$rawInput}");
}
if (!key_exists('path', $input)) {
Json::dieWithReason('path가 지정되지 않았습니다.');
}
+12 -20
View File
@@ -88,50 +88,35 @@ class TimeUtil
public static function now(bool $withFraction = false): string
{
$obj = new \DateTime();
if (!$withFraction) {
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
return static::format($obj, $withFraction);
}
public static function nowAddDays($day, bool $withFraction = false): string
{
$obj = new \DateTime();
$obj->add(static::secondsToDateInterval($day * 3600 * 24));
if (!$withFraction) {
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
return static::format($obj, $withFraction);
}
public static function nowAddHours($hour, bool $withFraction = false): string
{
$obj = new \DateTime();
$obj->add(static::secondsToDateInterval($hour * 3600));
if (!$withFraction) {
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
return static::format($obj, $withFraction);
}
public static function nowAddMinutes($minute, bool $withFraction = false): string
{
$obj = new \DateTime();
$obj->add(static::secondsToDateInterval($minute * 60));
if (!$withFraction) {
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
return static::format($obj, $withFraction);
}
public static function nowAddSeconds($second, bool $withFraction = false): string
{
$obj = new \DateTime();
$obj->add(static::secondsToDateInterval($second));
if (!$withFraction) {
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
return static::format($obj, $withFraction);
}
public static function secondsToDateTime(float $fullSeconds, bool $isDateTimeImmutable = false, bool $isUTC = false): \DateTimeInterface
@@ -188,6 +173,13 @@ class TimeUtil
return $seconds;
}
public static function format(\DateTimeInterface $dateTime, bool $withFraction): string{
if (!$withFraction) {
return $dateTime->format('Y-m-d H:i:s');
}
return $dateTime->format('Y-m-d H:i:s.u');
}
/**
* $baseYear, $baseMonth 부터 $afterMonth 개월 이내인지. $afterMonth 포함.
*
+81 -64
View File
@@ -1,4 +1,5 @@
<?php
namespace sammo;
use phpDocumentor\Reflection\Types\Boolean;
@@ -14,7 +15,7 @@ class WebUtil
return str_replace('.', '\\.', $ip);
}
public static function resolveRelativePath(string $path, string $basepath) : string
public static function resolveRelativePath(string $path, string $basepath): string
{
return \phpUri::parse($basepath)->join($path);
}
@@ -30,15 +31,17 @@ class WebUtil
}
}
public static function isAJAX(){
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH']??null) === 'xmlhttprequest';
public static function isAJAX()
{
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH'] ?? null) === 'xmlhttprequest';
}
public static function requireAJAX():void{
if(!static::isAJAX()){
public static function requireAJAX(): void
{
if (!static::isAJAX()) {
Json::die([
'result'=>false,
'reason'=>'no ajax'
'result' => false,
'reason' => 'no ajax'
]);
}
}
@@ -81,23 +84,23 @@ class WebUtil
//Use a switch statement to figure out the exact error.
switch ($jsonError) {
case JSON_ERROR_DEPTH:
$error .= 'Maximum depth exceeded! : '.$content;
break;
$error .= 'Maximum depth exceeded! : ' . $content;
break;
case JSON_ERROR_STATE_MISMATCH:
$error .= 'Underflow or the modes mismatch! : '.$content;
break;
$error .= 'Underflow or the modes mismatch! : ' . $content;
break;
case JSON_ERROR_CTRL_CHAR:
$error .= 'Unexpected control character found : '.$content;
break;
$error .= 'Unexpected control character found : ' . $content;
break;
case JSON_ERROR_SYNTAX:
$error .= 'Malformed JSON : '.$content;
break;
$error .= 'Malformed JSON : ' . $content;
break;
case JSON_ERROR_UTF8:
$error .= 'Malformed UTF-8 characters found! : '.$content;
break;
$error .= 'Malformed UTF-8 characters found! : ' . $content;
break;
default:
$error .= 'Unknown error! : '.$content;
break;
$error .= 'Unknown error! : ' . $content;
break;
}
throw new \Exception($error);
}
@@ -105,89 +108,89 @@ class WebUtil
return $decoded;
}
public static function preloadAsset(string $path, string $type){
public static function preloadAsset(string $path, string $type)
{
$upath = \phpUri::parse($path);
$path = $upath->join('');
if(!$upath->scheme){
if(!file_exists($upath->path)){
if (!$upath->scheme) {
if (!file_exists($upath->path)) {
return "<!-- preload:{$type} '{$path}' -->\n";
}
$mtime = filemtime($upath->path);
if($upath->query){
$tail = '&'.$mtime;
if ($upath->query) {
$tail = '&' . $mtime;
} else {
$tail = '?' . $mtime;
}
else{
$tail = '?'.$mtime;
}
}
else{
} else {
$tail = '';
}
return "<link href='{$path}{$tail}' rel='preload' as='$type'>\n";
}
public static function preloadCSS(string $path){
public static function preloadCSS(string $path)
{
return static::preloadAsset($path, 'style');
}
public static function preloadJS(string $path){
public static function preloadJS(string $path)
{
return static::preloadAsset($path, 'script');
}
public static function printJS(string $path, bool $isDefer=false){
public static function printJS(string $path, bool $isDefer = false)
{
//async 옵션 고려?
$upath = \phpUri::parse($path);
$path = $upath->join('');
if(!$upath->scheme){
if(!file_exists($upath->path)){
if (!$upath->scheme) {
if (!file_exists($upath->path)) {
return "<!-- JS '{$path}' -->\n";
}
$mtime = filemtime($upath->path);
if($upath->query){
$tail = '&'.$mtime;
if ($upath->query) {
$tail = '&' . $mtime;
} else {
$tail = '?' . $mtime;
}
else{
$tail = '?'.$mtime;
}
}
else{
} else {
$tail = '';
}
$typeText = $isDefer?'defer':'';
$typeText = $isDefer ? 'defer' : '';
return "<script {$typeText} src='{$path}{$tail}'></script>\n";
}
public static function printCSS(string $path){
public static function printCSS(string $path)
{
$upath = \phpUri::parse($path);
$path = $upath->join('');
if(!$upath->scheme){
if(!file_exists($upath->path)){
if (!$upath->scheme) {
if (!file_exists($upath->path)) {
return "<!-- CSS '{$path}' -->\n";
}
$mtime = filemtime($upath->path);
if($upath->query){
$tail = '&'.$mtime;
if ($upath->query) {
$tail = '&' . $mtime;
} else {
$tail = '?' . $mtime;
}
else{
$tail = '?'.$mtime;
}
}
else{
} else {
$tail = '';
}
return "<link rel='stylesheet' type='text/css' href='{$path}{$tail}' />\n";
}
public static function printStaticValues(array $values, bool $pretty=true){
if(!count($values)){
public static function printStaticValues(array $values, bool $pretty = true)
{
if (!count($values)) {
return;
}
$lines = ["<script>"];
foreach($values as $key => $value){
$lines[] = "var {$key} = ".Json::encode($value, Json::EMPTY_ARRAY_IS_DICT | ($pretty?Json::PRETTY:0));
foreach ($values as $key => $value) {
$lines[] = "var {$key} = " . Json::encode($value, Json::EMPTY_ARRAY_IS_DICT | ($pretty ? Json::PRETTY : 0));
}
$lines[] = "</script>\n";
@@ -195,13 +198,14 @@ class WebUtil
return join("\n", $lines);
}
public static function htmlPurify(?string $text): string{
if(!$text){
public static function htmlPurify(?string $text): string
{
if (!$text) {
return '';
}
$config = \HTMLPurifier_HTML5Config::createDefault();
$config->set('Filter.Custom', array (new \HTMLPurifier_Filter_YouTube()));
$config->set('Filter.Custom', array(new \HTMLPurifier_Filter_YouTube()));
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%'); //allow YouTube and Vimeo
$def = $config->getHTMLDefinition();
@@ -210,19 +214,32 @@ class WebUtil
return $purifier->purify($text);
}
public static function drawMenu(string $path): string{
if(!file_exists($path)){
public static function errorBackMsg(string $msg, ?string $target=null): string
{
$jmsg = Json::encode($msg);
if(!$target){
$moveNext = 'history.go(-1);';
}
else{
$moveNext = "location.replace('{$target}');";
}
return "<html><head><style>html,body{background:black;}</style><script>alert({$jmsg});$moveNext</script></head><body></body></html>";
}
public static function drawMenu(string $path): string
{
if (!file_exists($path)) {
return '';
}
$json = Json::decode(file_get_contents($path));
$result = [];
foreach($json as $menuItem){
foreach ($json as $menuItem) {
if (count($menuItem) == 2) {
[$url, $title] = $menuItem;
$targetAttr = '';
}
else{
} else {
[$url, $title, $target] = $menuItem;
$target = htmlspecialchars($target);
$targetAttr = "target='$target' ";