Skip to content

Commit

Permalink
Merge pull request #28 from 49372s/main
Browse files Browse the repository at this point in the history
LaTeX
  • Loading branch information
49372s authored Jul 14, 2024
2 parents 16119a0 + a4355b7 commit 1b9b12d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/articles/post/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
APIResponse(false,"Undefined error");
}

//$html = Markdown::defaultTransform($body);
//html = Markdown::defaultTransform($body);
$html = $body;
if(!file_exists($_SERVER['DOCUMENT_ROOT']."/content/data/")){
mkdir($_SERVER['DOCUMENT_ROOT']."/content/data/");
}
$fhd = fopen($_SERVER['DOCUMENT_ROOT']."/content/data/blog_$uuid.html","w");
fwrite($fhd,$html);
fwrite($fhd,$body);
fclose($fhd);

if($mode === true || $mode === "1" || $mode === "true"){
Expand Down
4 changes: 4 additions & 0 deletions article/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title><?=$title?> | <?=$CMS_CONFIG["SITE_NAME"]?></title>
<link
rel="stylesheet"
href="https://unpkg.com/katex@0.12.0/dist/katex.min.css"
/>
<!-- ここから指示あるまでは削除しても構わない -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<!-- ここまで -->
Expand Down
24 changes: 19 additions & 5 deletions includes/modules/plugin/MASTER.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,23 @@ public static function getPluginStatus($id){
foreach($res as $val){
if($val[0] == $id){
$flug = true;
if($val[2] == 1){
if($val[4] == 1){
return true;
}else{
return false;
}
}
}
if($flug == false){
$sql = "INSERT into plugins(id, name, status) values(:i,:n,:s)";
$sql = "INSERT into plugins(id, name, detail, config, status, author) values(:i, :n, :d, :c, :s, :a)";
$pre = $pdo->prepare($sql);
$arr = array(
":i" => $id,
":n" => master::getPluginsInfo($id)["name"],
":s" => 0
":d" => master::getPluginsInfo($id)["detail"],
":c" => master::getPluginsInfo($id)["config"],
":s" => intval(master::getPluginsInfo($id)["status"]),
":a" => master::getPluginsInfo($id)["author"]
);
$pre->execute($arr);
return false;
Expand All @@ -117,23 +120,34 @@ public static function getPluginStatus($id){
public static function getPluginsInfo($id){
$max_try = 3;
for ($try=0; $try < $max_try; $try++) {
$f = file_get_contents($_SERVER["DOCUMENT_ROOT"]."/includes/modules/plugin/plugins.cache");
if(file_exists($_SERVER["DOCUMENT_ROOT"]."/includes/modules/plugin/plugins.cache")){
$f = file_get_contents($_SERVER["DOCUMENT_ROOT"]."/includes/modules/plugin/plugins.cache");
}else{
$f = "[]";
}
if($f == "null" || $f == null){
$f = "[]";
unlink($_SERVER["DOCUMENT_ROOT"]."/includes/modules/plugin/plugins.cache");

}
$pluginsFile = json_decode($f,true);
foreach($pluginsFile as $val){
if($val["id"] == $id){
return $val;
break;
}
}
sleep(1);
}
return [];
}
public static function outputPluginsList(){
$f = file_get_contents($_SERVER["DOCUMENT_ROOT"]."/includes/modules/plugin/plugins.cache");
$pluginsFile = json_decode($f,true);
$list = $pluginsFile;
$html = "";
foreach($list as $val){
$html = $html . "<tr><td style=\"word-break: keep-all;\">".$val['name']."</td><td style=\"word-break: break-all;\">".$val["detail"]."</td><td style=\"word-break: keep-all;\">".$val["author"]."</td><td style=\"word-break: keep-all;\">".$val["config"]."</td><td style=\"word-break: keep-all;\">".master::getToggle($val['id'],$val["status"])."</td></tr>\n";
$html = $html . "<tr><td style=\"word-break: keep-all;\">".$val['name']."</td><td style=\"word-break: break-all;\">".$val["detail"]."</td><td style=\"word-break: keep-all;\">".$val["author"]."</td><td style=\"word-break: keep-all;\">".$val["config"]."</td><td style=\"word-break: keep-all;\">".master::getToggle($val['id'],master::getPluginStatus($val['id']))."</td></tr>\n";
}
return $html;
}
Expand Down
38 changes: 37 additions & 1 deletion includes/plugins/_articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function readArticles($id){
foreach($res as $val){
if($val[0]==$id){
$html = file_get_contents($_SERVER['DOCUMENT_ROOT']."/content/data/blog_$id.html");
return Markdown::defaultTransform($html);
return Markdown::defaultTransform(latex($html));
}
}
}
Expand All @@ -38,4 +38,40 @@ function latestArticles($int = 5){
}
return $html;
}

function latex($body){
//LaTexを利用する(beta)
$bcLatex = array();
//LaTex構文の位置指定文字を指定する
$latex_start = '$sl$';
$latex_final = '$el$';
//latex構文位置が複数あることを考慮し、分割する(終了位置分割)
$latex_final_position = explode($latex_final, $body);
foreach($latex_final_position as $column){
array_push($bcLatex,explode($latex_start, $column));
}

//print_r($bcLatex);
$body = "";
foreach($bcLatex as $row){
if(count($row)===1){
$body = $body . $row[0];
continue;
}
$ch = curl_init();
$row[1] = str_replace(PHP_EOL,"",$row[1]);
curl_setopt($ch, CURLOPT_URL, "https://api.tkngh.jp/latex2html");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("latexString"=>$row[1])));
$headers = [
'Content-Type: application/json',
'Accept-Charset: UTF-8',
];
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$converted = curl_exec($ch);
$body = $body . $row[0] . json_decode($converted,true)["html"];
}
return $body;
}
?>
4 changes: 2 additions & 2 deletions includes/plugins/_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ function AdminAuthenticate($user,$pass){
$res = $pdo->query("SELECT * from user");
foreach($res as $val){
if($val[1] == $user && $val[4]==getSHA($pass) && $val[6]==3){
setcookie("token",md5(date("Ym").$val[0].$val[4]),time() + 60 * 60 * 24 * 30, "/", null, true);
setcookie("token",md5(date("Ym").$val[0].$val[4]),time() + 60 * 60 * 24 * 30, "/", null);
http_response_code(200);
header('Location: /dashboard');
header('Location: /dashboard/');
exit();
}
}
Expand Down
2 changes: 1 addition & 1 deletion save-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
exit();
}

include('./includes/plugins/uuid.php');
include('./includes/plugins/_uuid.php');
$sql = "INSERT into user(uid,handle,nickname,mail,pwd,mi,permit) value(:u,:h,:n,:m,:p,:mi,:pe)";
$pre = $pdo->prepare($sql);
$arr = array(
Expand Down

0 comments on commit 1b9b12d

Please sign in to comment.