-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
552 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,130 @@ | ||
<?php | ||
|
||
define('ACCESS', true); | ||
|
||
require '.init.php'; | ||
|
||
$data = [ | ||
'status' => false, | ||
'message' => 'error' | ||
]; | ||
|
||
if (!isset($_POST['requestApi'])) { | ||
goto end_request; | ||
} | ||
|
||
if ($dir == null || $name == null || !is_file(processDirectory($dir . '/' . $name))) { | ||
$data['message'] = 'Đường dẫn không tồn tại'; | ||
goto end_request; | ||
} | ||
|
||
|
||
if (!isFormatText($name) && !isFormatUnknown($name)) { | ||
$data['message'] = 'Tập tin này không phải dạng văn bản'; | ||
goto end_request; | ||
} | ||
|
||
if (isset($_POST['format_php'])) { | ||
$configFile = __DIR__ . '/.php-cs-fixer.dist.php'; | ||
$tempFile = __DIR__ . '/tmp/fixer.txt'; | ||
//$cacheFile = __DIR__ . '/tmp/.php-cs-fixer.cache'; | ||
|
||
$content = isset($_POST['content']) ? $_POST['content'] : ''; | ||
$data = array( | ||
'format' => '', | ||
'error' => 'Không thành công! Yêu cầu chạy "composer install"!' | ||
); | ||
|
||
if (!empty($content)) { | ||
file_put_contents($tempFile, $content); | ||
|
||
@chmod('vendor/bin/php-cs-fixer', 0775); | ||
$result = exec("vendor/bin/php-cs-fixer fix {$tempFile} --config {$configFile}"); | ||
|
||
if ($result) { | ||
$data['format'] = file_get_contents($tempFile); | ||
$data['error'] = ''; | ||
|
||
@unlink($tempFile); | ||
//@unlink($cacheFile); | ||
} | ||
} | ||
|
||
goto end_request; | ||
} | ||
|
||
|
||
// luu file | ||
$dir = processDirectory($dir); | ||
$path = $dir . '/' . $name; | ||
|
||
if (!isset($_POST['content'])) { | ||
$data['message'] = 'Chưa nhập nội dung'; | ||
goto end_request; | ||
} | ||
|
||
$content = $_POST['content']; | ||
$currentOwner = fileowner($path); | ||
|
||
if (file_put_contents($path, $content) !== false) { | ||
// fix owner | ||
@chown($path, $currentOwner); | ||
|
||
$data['status'] = true; | ||
$data['message'] = 'Lưu lại thành công'; | ||
|
||
$checkPHP = isset($_POST['check']) ? (bool) $_POST['check'] : false; | ||
|
||
if ($checkPHP) { | ||
$error_syntax = 'Lưu thành công! Không thể kiểm tra lỗi'; | ||
$isExecute = isFunctionExecEnable(); | ||
|
||
if ($isExecute) { | ||
@exec(getPathPHP() . ' -c -f -l ' . $path, $output, $value); | ||
|
||
if ($value == -1) { | ||
} elseif ($value == 255 || count($output) == 3) { | ||
$error_syntax = 'Lưu thành công! Có lỗi!'; | ||
|
||
$data['error'] = $output[1]; | ||
} else { | ||
$error_syntax = 'Lưu thành công! Không có lỗi'; | ||
} | ||
} | ||
|
||
$data['message'] = $error_syntax; | ||
} | ||
} else { | ||
$data['message'] = 'Lưu lại thất bại'; | ||
} | ||
|
||
// response | ||
end_request: | ||
@ob_end_clean(); | ||
header('Content-Type: application/json; charset=utf-8'); | ||
echo json_encode($data); | ||
<?php | ||
|
||
define('ACCESS', true); | ||
|
||
require '.init.php'; | ||
|
||
$data = [ | ||
'status' => false, | ||
'message' => 'error' | ||
]; | ||
|
||
if (!isset($_POST['requestApi'])) { | ||
goto end_request; | ||
} | ||
|
||
if ($dir == null || $name == null || !is_file(processDirectory($dir . '/' . $name))) { | ||
$data['message'] = 'Đường dẫn không tồn tại'; | ||
goto end_request; | ||
} | ||
|
||
if (!isFormatText($name) && !isFormatUnknown($name)) { | ||
$data['message'] = 'Tập tin này không phải dạng văn bản'; | ||
goto end_request; | ||
} | ||
|
||
// thông tin file | ||
$dir = processDirectory($dir); | ||
$path = $dir . '/' . $name; | ||
|
||
$content = isset($_POST['content']) ? $_POST['content'] : ''; | ||
|
||
if (isset($_POST['format'])) { | ||
$formatType = trim($_POST['format']); | ||
|
||
switch ($formatType) { | ||
case 'php': | ||
$configFile = __DIR__ . '/.php-cs-fixer.dist.php'; | ||
$tempFile = __DIR__ . '/tmp/fixer.txt'; | ||
$data = [ | ||
'format' => '', | ||
'error' => 'Không thành công! Yêu cầu chạy "composer install"!' | ||
]; | ||
|
||
if (!empty($content)) { | ||
file_put_contents($tempFile, $content); | ||
|
||
@chmod('vendor/bin/php-cs-fixer', 0775); | ||
$result = exec("vendor/bin/php-cs-fixer fix {$tempFile} --config {$configFile}"); | ||
|
||
if ($result) { | ||
$data['format'] = file_get_contents($tempFile); | ||
$data['error'] = ''; | ||
|
||
@unlink($tempFile); | ||
} | ||
} | ||
break; | ||
|
||
case 'js': | ||
case 'html': | ||
case 'ts': | ||
case 'css': | ||
case 'scss': | ||
case 'json': | ||
case 'yaml': | ||
$opt = [ | ||
'--print-width=1000000', | ||
'--quote-props=preserve' | ||
]; | ||
$res = runCommand('source ~/.bashrc; prettier ' . implode(' ', $opt) . ' ' . $path); | ||
$data['format'] = $res['out']; | ||
$data['error'] = ''; | ||
|
||
break; | ||
|
||
default: | ||
$data['format'] = $content; | ||
$data['error'] = ''; | ||
} | ||
|
||
goto end_request; | ||
} | ||
|
||
|
||
// luu file | ||
if (!isset($_POST['content'])) { | ||
$data['message'] = 'Chưa nhập nội dung'; | ||
goto end_request; | ||
} | ||
|
||
$content = $_POST['content']; | ||
$currentOwner = fileowner($path); | ||
|
||
if (file_put_contents($path, $content) !== false) { | ||
// fix owner | ||
@chown($path, $currentOwner); | ||
|
||
$data['status'] = true; | ||
$data['message'] = 'Lưu lại thành công'; | ||
|
||
$checkPHP = isset($_POST['check']) ? (bool) $_POST['check'] : false; | ||
|
||
if ($checkPHP) { | ||
$error_syntax = 'Lưu thành công! Không thể kiểm tra lỗi'; | ||
$isExecute = isFunctionExecEnable(); | ||
|
||
if ($isExecute) { | ||
@exec(getPathPHP() . ' -c -f -l ' . $path, $output, $value); | ||
|
||
if ($value == -1) { | ||
} elseif ($value == 255 || count($output) == 3) { | ||
$error_syntax = 'Lưu thành công! Có lỗi!'; | ||
|
||
$data['error'] = $output[1]; | ||
} else { | ||
$error_syntax = 'Lưu thành công! Không có lỗi'; | ||
} | ||
} | ||
|
||
$data['message'] = $error_syntax; | ||
} | ||
} else { | ||
$data['message'] = 'Lưu lại thất bại'; | ||
} | ||
|
||
// response | ||
end_request: | ||
@ob_end_clean(); | ||
header('Content-Type: application/json; charset=utf-8'); | ||
echo json_encode($data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
function onCheckItem() | ||
{ | ||
for (let i = 0; i < document.form.elements.length; ++i) { | ||
if (document.form.elements[i].type === 'checkbox') { | ||
document.form.elements[i].checked = document.form.all.checked === true; | ||
} | ||
} | ||
} | ||
function onCheckItem() { | ||
for (let i = 0; i < document.form.elements.length; ++i) { | ||
if (document.form.elements[i].type === "checkbox") { | ||
document.form.elements[i].checked = document.form.all.checked === true; | ||
} | ||
} | ||
} |
Oops, something went wrong.