このコミットが含まれているのは:
守矢諏訪子 2022-10-25 18:09:58 +09:00
コミット 9c2a5ad8cd
22個のファイルの変更225行の追加212行の削除

ファイルの表示

@ -1,19 +1,21 @@
<?php <?php
// アプリ // アプリ
define('APP_NAME', 'LoliPHP'); define("APP_NAME", "LoliPHP");
define("HTML_VER", "XHTML"); // XHTML、HTML5
define("CAN_MOBILE", false);
// データベース // データベース
define('DB_CONN', 'mysql'); define("DB_CONN", "mysql");
define('DB_HOST', 'localhost'); define("DB_HOST", "localhost");
define('DB_PORT', 3306); define("DB_PORT", 3306);
define('DB_USER', ''); define("DB_USER", "");
define('DB_PASS', ''); define("DB_PASS", "");
define('DB_NAME', ''); define("DB_NAME", "");
// CURL // CURL
define('API_URI', ''); define("API_URI", "");
define('API_AUTH', null); define("API_AUTH", null);
// ハッシュ // ハッシュ
define('PASSWD_PEPPER', ''); // オススメpwgen -ycnB1 40 define("PASSWD_PEPPER", ""); // オススメpwgen -ycnB1 40
?> ?>

ファイルの表示

@ -1,13 +1,13 @@
<?php <?php
require_once('helper/cookie.php'); // クッキー・Cookie require_once("helper/cookie.php"); // クッキー・Cookie
require_once('helper/curl.php'); // CURL require_once("helper/curl.php"); // CURL
require_once('helper/db.php'); // データベースエンジン・Database engine require_once("helper/db.php"); // データベースエンジン・Database engine
require_once('helper/debug.php'); // デバッガー・Debugger require_once("helper/debug.php"); // デバッガー・Debugger
require_once('helper/hash.php'); // ハッシュ・Hash require_once("helper/hash.php"); // ハッシュ・Hash
require_once('helper/mail.php'); // メール・Mail require_once("helper/mail.php"); // メール・Mail
require_once('helper/php8compat.php'); // PHP8を実行していない場合・If not running PHP8 require_once("helper/php8compat.php"); // PHP8を実行していない場合・If not running PHP8
require_once('helper/request.php'); // リクエスト・Request require_once("helper/request.php"); // リクエスト・Request
require_once('helper/session.php'); // セッション・Session require_once("helper/session.php"); // セッション・Session
require_once('helper/upload.php'); // ファイルアップロード・File upload require_once("helper/upload.php"); // ファイルアップロード・File upload
require_once('helper/uuid.php'); // UUIDv4 require_once("helper/uuid.php"); // UUIDv4
?> ?>

ファイルの表示

@ -1,8 +1,7 @@
<?php <?php
function getcookie (string $name): string { function getcookie (string $name): string {
return htmlspecialchars($_COOKIE[$name]); return isset($_COOKIE[$name]) ? htmlspecialchars($_COOKIE[$name]) : "";
} }
function getrawcookie (string $name): string { function getrawcookie (string $name): string {
return $_COOKIE[$name]; return $_COOKIE[$name];
} }

ファイルの表示

@ -1,20 +1,20 @@
<?php <?php
require_once('../config.php'); require_once("../config.php");
function lolicurl ($url, $param='', $method='get', $contenttype='json') { function lolicurl ($url, $param="", $method="get", $contenttype="json") {
set_time_limit(0); set_time_limit(0);
$header = ['Content-Type: application/'.$contenttype, 'Host: '.str_replace('https://', '', API_URI)]; $header = ["Content-Type: application/".$contenttype, "Host: ".str_replace("https://", "", API_URI)];
if (!is_null(API_AUTH)) { if (!is_null(API_AUTH)) {
$header[] = 'Authorization: Bearer '.API_AUTH; $header[] = "Authorization: Bearer ".API_AUTH;
} }
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_URI.$url); curl_setopt($ch, CURLOPT_URL, API_URI.$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if ($method == 'post') { if ($method == "post") {
curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POST, 1);
if ($param != '') curl_setopt($ch, CURLOPT_POSTFIELDS, $param); if ($param != "") curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
} }
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

ファイルの表示

@ -1,37 +1,37 @@
<?php <?php
require_once('../config.php'); require_once("../config.php");
/* val /* val
* *
* select => ['var1', 'var2'...] * select => ["var1", "var2"...]
* insert|update|where => ['key1' => 'value1', 'key2' => 'value2'...] * insert|update|where => ["key1" => "value1", "key2" => "value2"...]
* order => ['var', 'asc'|'desc'] * order => ["var", "asc"|"desc"]
* limit => int * limit => int
* */ * */
function lolidb (string $table, array $val, string $mode='select'): array|bool { function lolidb (string $table, array $val, string $mode="select"): array|bool {
// モードは違う場合、やめる。If the mode is wrong, stop. // モードは違う場合、やめる。If the mode is wrong, stop.
if ($mode != 'select' && $mode != 'one' && $mode != 'insert' && $mode != 'update' && $mode != 'delete') { if ($mode != "select" && $mode != "one" && $mode != "insert" && $mode != "update" && $mode != "delete") {
dd("モードは「select」、「one」、「insert」、「update」、「delete」です。\nMode should be \"select\", \"one\", \"insert\", \"update\", or \"delete\"."); dd("モードは「select」、「one」、「insert」、「update」、「delete」です。\nMode should be \"select\", \"one\", \"insert\", \"update\", or \"delete\".");
return false; return false;
} }
// 順のチェック。Check order. // 順のチェック。Check order.
if (isset($val['order'])) { if (isset($val["order"])) {
// selectかoneじゃない場合。If not select or one. // selectかoneじゃない場合。If not select or one.
if ($mode !== 'select' || $mode !== 'one') { if ($mode !== "select" || $mode !== "one") {
dd("「order」は「select」又は「one」のみで使えます。\n\"order\" can only be used with \"select\" or \"one\"."); dd("「order」は「select」又は「one」のみで使えます。\n\"order\" can only be used with \"select\" or \"one\".");
return false; return false;
} }
// 複数の場合。If multiple. // 複数の場合。If multiple.
if (count($val['order'] > 1)) { if (count($val["order"] > 1)) {
dd("複数「order」は未対応です。\nMultiple \"order\" is not yet supported."); dd("複数「order」は未対応です。\nMultiple \"order\" is not yet supported.");
return false; return false;
} }
// ascかdescかどうか。Whether it's asc or desc. // ascかdescかどうか。Whether it"s asc or desc.
foreach ($val['order'] as $k => $v) { foreach ($val["order"] as $k => $v) {
if ($v !== 'asc' && $v !== 'desc') { if ($v !== "asc" && $v !== "desc") {
dd("「order」は「asc」又は「desc」です。\n\"order\" should be \"asc\" or \"desc\"."); dd("「order」は「asc」又は「desc」です。\n\"order\" should be \"asc\" or \"desc\".");
return false; return false;
} }
@ -39,28 +39,28 @@
} }
// 限界のチェック。Check limit. // 限界のチェック。Check limit.
if (($mode === 'select' || $mode === 'one') && isset($val['limit'])) { if (($mode === "select" || $mode === "one") && isset($val["limit"])) {
// oneの場合。If one. // oneの場合。If one.
if ($mode === 'one') { if ($mode === "one") {
dd("「one」の場合、「limit」はいつでも「1」です。「limit」は1以上は必要の場合、「select」を使って下さい。\nIn case of \"one\", \"limit\" is always \"1\". If \"limit\" needs to be more than \"1\", please use \"select\"."); dd("「one」の場合、「limit」はいつでも「1」です。「limit」は1以上は必要の場合、「select」を使って下さい。\nIn case of \"one\", \"limit\" is always \"1\". If \"limit\" needs to be more than \"1\", please use \"select\".");
return false; return false;
} }
// selectじゃない場合。If not select. // selectじゃない場合。If not select.
else if ($mode !== 'select') { else if ($mode !== "select") {
dd("「insert」、「update」及び「delete」で、「limit」を使えません。\n\"limit\" cannot be used with \"insert\", \"update\", and \"delete\"."); dd("「insert」、「update」及び「delete」で、「limit」を使えません。\n\"limit\" cannot be used with \"insert\", \"update\", and \"delete\".");
return false; return false;
} }
} }
// insertの場合。In case of insert. // insertの場合。In case of insert.
if ($mode === 'insert' && !isset($val['insert'])) { if ($mode === "insert" && !isset($val["insert"])) {
dd("「insert」モードの場合、「insert」値は必須です。\nIn case of \"insert\" mode, \"insert\" value is necessary."); dd("「insert」モードの場合、「insert」値は必須です。\nIn case of \"insert\" mode, \"insert\" value is necessary.");
return false; return false;
} }
// updateの場合。In case of update. // updateの場合。In case of update.
if ($mode === 'update' && !isset($val['update'])) { if ($mode === "update" && !isset($val["update"])) {
dd("「update」モードの場合、「update」値は必須です。\nIn case of \"update\" mode, \"update\" value is necessary."); dd("「update」モードの場合、「update」値は必須です。\nIn case of \"update\" mode, \"update\" value is necessary.");
return false; return false;
} }
@ -69,94 +69,94 @@
$mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_TABLE); $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_TABLE);
$result = null; $result = null;
if ($mode == 'select' || $mode == 'one') { if ($mode == "select" || $mode == "one") {
// select値がなければ、全部を選択する。If there is no select value, select everything. // select値がなければ、全部を選択する。If there is no select value, select everything.
if (!isset($val['select'])) { if (!isset($val["select"])) {
$val['select'] = ['*']; $val["select"] = ["*"];
} }
$query = 'SELECT '.$val['select'].' FROM '.$table; $query = "SELECT ".$val["select"]." FROM ".$table;
if (isset($val['where'])) { if (isset($val["where"])) {
$query .= ' WHERE '; $query .= " WHERE ";
foreach ($val['where'] as $k => $v) { foreach ($val["where"] as $k => $v) {
$query .= $k.' = '.$v; $query .= $k." = ".$v;
if ($k !== array_key_last($val['where'])) $query .= ' AND '; if ($k !== array_key_last($val["where"])) $query .= " AND ";
} }
} }
if (isset($val['order'])) { if (isset($val["order"])) {
$query .= ' ORDER BY '; $query .= " ORDER BY ";
foreach ($val['order'] as $k => $v) { foreach ($val["order"] as $k => $v) {
$query .= $k; $query .= $k;
$query .= ' '.strtoupper($v); $query .= " ".strtoupper($v);
} }
} }
if ($mode == 'one') { if ($mode == "one") {
$query .= ' LIMIT 1'; $query .= " LIMIT 1";
} }
else { else {
if (isset($val['limit'])) { if (isset($val["limit"])) {
$query .= ' LIMIT '.(int)$val['limit']; $query .= " LIMIT ".(int)$val["limit"];
} }
} }
$result = mysqli_query($mysqli, $query.';'); $result = mysqli_query($mysqli, $query.";");
$row = mysqli_fetch_assoc($result); $row = mysqli_fetch_assoc($result);
} }
else { else {
if ($mode == 'insert') { if ($mode == "insert") {
$query .= 'INSERT INTO '.$table.' ('; $query .= "INSERT INTO ".$table." (";
foreach ($val['insert'] as $k => $v) { foreach ($val["insert"] as $k => $v) {
$query .= $k; $query .= $k;
if ($k !== array_key_last($val['insert'])) { if ($k !== array_key_last($val["insert"])) {
$query .= ', '; $query .= ", ";
} }
} }
$query .= ') VALUES ('; $query .= ") VALUES (";
foreach ($val['insert'] as $k => $v) { foreach ($val["insert"] as $k => $v) {
$query .= $v; $query .= $v;
if ($k !== array_key_last($val['insert'])) { if ($k !== array_key_last($val["insert"])) {
$query .= ', '; $query .= ", ";
} }
} }
$query .= ')'; $query .= ")";
} }
else if ($mode == 'update') { else if ($mode == "update") {
$query .= 'UPDATE '.$table.' SET '; $query .= "UPDATE ".$table." SET ";
foreach ($val['update'] as $k => $v) { foreach ($val["update"] as $k => $v) {
$query .= $k.' = '.$v; $query .= $k." = ".$v;
if ($k !== array_key_last($val['update'])) { if ($k !== array_key_last($val["update"])) {
$query .= ', '; $query .= ", ";
} }
} }
if (isset($val['where'])) { if (isset($val["where"])) {
$query .= ' WHERE '; $query .= " WHERE ";
foreach ($val['where'] as $k => $v) { foreach ($val["where"] as $k => $v) {
$query .= $k.' = '.$v; $query .= $k." = ".$v;
if ($k !== array_key_last($val['where'])) { if ($k !== array_key_last($val["where"])) {
$query .= ' AND '; $query .= " AND ";
} }
} }
} }
} }
else if ($mode == 'delete') { else if ($mode == "delete") {
$query .= 'DELETE FROM '.$table; $query .= "DELETE FROM ".$table;
if (isset($val['where'])) { if (isset($val["where"])) {
$query .= ' WHERE '; $query .= " WHERE ";
foreach ($val['where'] as $k => $v) { foreach ($val["where"] as $k => $v) {
$query .= $k.' = '.$v; $query .= $k." = ".$v;
if ($k !== array_key_last($val['where'])) { if ($k !== array_key_last($val["where"])) {
$query .= ' AND '; $query .= " AND ";
} }
} }
} }
} }
$stmt = mysqli_prepare($mysqli, $query.';'); $stmt = mysqli_prepare($mysqli, $query.";");
} }
return $row; return $row;

ファイルの表示

@ -1,22 +1,23 @@
<?php <?php
function dd ($val) { function dd ($val) {
echo '<pre>'; echo "<style> body { background: #232629; color: #fcfcfc; } </style>";
echo "<pre>";
var_dump($val); var_dump($val);
echo '</pre>'; echo "</pre>";
die(); die();
} }
function lolilog (string $val, string $mode='info'): bool { function lolilog (string $val, string $mode="info"): bool {
if (!$file = fopen('./lolilog', 'a+')) { if (!$file = fopen("./lolilog", "a+")) {
dd('lolilogファイルを開けられません。'); dd("lolilogファイルを開けられません。");
return false; return false;
} }
$time = time(); $time = time();
$logtext = '['.date('Y-m-d H:i:s T', $time).' ('.$time.') - '.mb_strtoupper($mode)."]\n".$val."\n\n"; $logtext = "[".date("Y-m-d H:i:s T", $time)." (".$time.") - ".mb_strtoupper($mode)."]\n".$val."\n\n";
if (fwrite($file, $logtext) === false) { if (fwrite($file, $logtext) === false) {
dd('lolilogファイルに書き出しに失敗しました。'); dd("lolilogファイルに書き出しに失敗しました。");
return false; return false;
} }

ファイルの表示

@ -1,5 +1,5 @@
<?php <?php
require_once('../config.php'); require_once("../config.php");
function tokengen (int $bytes=24): string { function tokengen (int $bytes=24): string {
return bin2hex(random_bytes($bytes)); return bin2hex(random_bytes($bytes));
@ -12,18 +12,18 @@
do { do {
$cost++; $cost++;
$start = microtime(true); $start = microtime(true);
password_hash('kero', PASSWORD_ARGON2ID, ['cost' => $cost]); password_hash("kero", PASSWORD_ARGON2ID, ["cost" => $cost]);
$end = microtime(true); $end = microtime(true);
} while (($end - $start) < $millisec); } while (($end - $start) < $millisec);
$addpepper = hash_hmac('sha256', $password, PASSWD_PEPPER); $addpepper = hash_hmac("sha256", $password, PASSWD_PEPPER);
$addmd5 = md5($addpepper); $addmd5 = md5($addpepper);
return password_hash($addmd5, PASSWORD_ARGON2ID, ['cost' => $cost]); return password_hash($addmd5, PASSWORD_ARGON2ID, ["cost" => $cost]);
} }
function verifypasswd (string $raw, string $crypt): bool { function verifypasswd (string $raw, string $crypt): bool {
$addpepper = hash_hmac('sha256', $raw, PASSWD_PEPPER); $addpepper = hash_hmac("sha256", $raw, PASSWD_PEPPER);
$addmd5 = md5($addpepper); $addmd5 = md5($addpepper);
return password_verify($addmd5, $crypt); return password_verify($addmd5, $crypt);

ファイルの表示

@ -1,31 +1,31 @@
<?php <?php
if (!function_exists('str_starts_with')) { if (!function_exists("str_starts_with")) {
function str_starts_with (string $haystack, string $needle): bool { function str_starts_with (string $haystack, string $needle): bool {
return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0; return (string)$needle !== "" && strncmp($haystack, $needle, strlen($needle)) === 0;
} }
} }
if (!function_exists('str_ends_with')) { if (!function_exists("str_ends_with")) {
function str_ends_with (string $haystack, string $needle): bool { function str_ends_with (string $haystack, string $needle): bool {
$needle_len = strlen($needle); $needle_len = strlen($needle);
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len)); return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
} }
} }
if (!function_exists('str_contains')) { if (!function_exists("str_contains")) {
function str_contains (string $haystack, string $needle): bool { function str_contains (string $haystack, string $needle): bool {
return $needle !== '' && mb_strpos($haystack, $needle) !== false; return $needle !== "" && mb_strpos($haystack, $needle) !== false;
} }
} }
if (!function_exists('array_key_first')) { if (!function_exists("array_key_first")) {
function array_key_first (array $array): int|string|null { function array_key_first (array $array): int|string|null {
if (!is_array($array) || empty($array)) return NULL; if (!is_array($array) || empty($array)) return NULL;
return array_keys($array)[0]; return array_keys($array)[0];
} }
} }
if (!function_exists('array_key_last')) { if (!function_exists("array_key_last")) {
function array_key_last (array $array): int|string|null { function array_key_last (array $array): int|string|null {
if (!is_array($array) || empty($array)) return NULL; if (!is_array($array) || empty($array)) return NULL;
return array_keys($array)[count($array)-1]; return array_keys($array)[count($array)-1];

ファイルの表示

@ -1,31 +1,31 @@
<?php <?php
function request (string $name): array { function request (string $name): array {
if (isset($_POST[$name])) { if (isset($_POST[$name])) {
return ['post' => htmlspecialchars($name)]; return ["post" => htmlspecialchars($name)];
} }
else if (isset($_GET[$name])) { else if (isset($_GET[$name])) {
return ['get' => htmlspecialchars($name)]; return ["get" => htmlspecialchars($name)];
} }
else if (isset($_REQUEST[$name])) { else if (isset($_REQUEST[$name])) {
return ['request' => htmlspecialchars($name)]; return ["request" => htmlspecialchars($name)];
} }
return ['error' => '']; return ["error" => ""];
} }
function request_all (): array { function request_all (): array {
$res = []; $res = [];
if (!empty($_POST)) { if (!empty($_POST)) {
$res['post'] = []; $res["post"] = [];
foreach ($_POST as $k => $v) $res['post'][$k] = htmlspecialchars($v); foreach ($_POST as $k => $v) $res["post"][$k] = htmlspecialchars($v);
} }
if (!empty($_GET)) { if (!empty($_GET)) {
$res['get'] = []; $res["get"] = [];
foreach ($_GET as $k => $v) $res['get'][$k] = htmlspecialchars($v); foreach ($_GET as $k => $v) $res["get"][$k] = htmlspecialchars($v);
} }
if (!empty($_REQUEST)) { if (!empty($_REQUEST)) {
$res['request'] = []; $res["request"] = [];
foreach ($_REQUEST as $k => $v) $res['request'][$k] = htmlspecialchars($v); foreach ($_REQUEST as $k => $v) $res["request"][$k] = htmlspecialchars($v);
} }
return $res; return $res;

ファイルの表示

@ -1,55 +1,55 @@
<?php <?php
require_once('uuid.php'); require_once("uuid.php");
function fileextension (string $fname): string { function fileextension (string $fname): string {
$ext = strrpos($fname, '.'); $ext = strrpos($fname, ".");
return $ext === false ? '' : substr($fname, $ext + 1); return $ext === false ? "" : substr($fname, $ext + 1);
} }
// ISOはfalseだったら、kB、MB、GB、TBになります。 // ISOはfalseだったら、kB、MB、GB、TBになります。
// trueの場合、KiB、MiB、GiB、TiBです。 // trueの場合、KiB、MiB、GiB、TiBです。
function humanreadablesize (int $byte, bool $iso=true): string { function humanreadablesize (int $byte, bool $iso=true): string {
$bit = $iso ? 1024 : 1000; $bit = $iso ? 1024 : 1000;
$res = 'B'; $res = "B";
$size = $byte; $size = $byte;
if ($byte >= ($bit * $bit * $bit * $bit * $bit)) { if ($byte >= ($bit * $bit * $bit * $bit * $bit)) {
//dd(5); //dd(5);
$size = $byte / ($bit * $bit * $bit * $bit * $bit); $size = $byte / ($bit * $bit * $bit * $bit * $bit);
$res = $iso ? 'TiB' : 'TB'; $res = $iso ? "TiB" : "TB";
} }
else if ($byte >= ($bit * $bit * $bit * $bit)) { else if ($byte >= ($bit * $bit * $bit * $bit)) {
//dd(4); //dd(4);
$size = $byte / ($bit * $bit * $bit * $bit); $size = $byte / ($bit * $bit * $bit * $bit);
$res = $iso ? 'TiB' : 'TB'; $res = $iso ? "TiB" : "TB";
} }
else if ($byte >= ($bit * $bit * $bit)) { else if ($byte >= ($bit * $bit * $bit)) {
//dd(3); //dd(3);
$size = $byte / ($bit * $bit * $bit); $size = $byte / ($bit * $bit * $bit);
$res = $iso ? 'GiB' : 'GB'; $res = $iso ? "GiB" : "GB";
} }
else if ($byte >= ($bit * $bit)) { else if ($byte >= ($bit * $bit)) {
//dd(2); //dd(2);
$size = $byte / ($bit * $bit); $size = $byte / ($bit * $bit);
$res = $iso ? 'MiB' : 'MB'; $res = $iso ? "MiB" : "MB";
} }
else if ($byte >= $bit) { else if ($byte >= $bit) {
//dd(1); //dd(1);
$size = $byte / $bit; $size = $byte / $bit;
$res = $iso ? 'KiB' : 'kB'; $res = $iso ? "KiB" : "kB";
} }
//dd($size); //dd($size);
return number_format($size, 2).' '.$res; return number_format($size, 2)." ".$res;
} }
function getmimetype (string $fname): string|null { function getmimetype (string $fname): string|null {
$i = 0; $i = 0;
foreach ($_FILES as $v) { foreach ($_FILES as $v) {
if ($fname == $v['name'][$i]) { if ($fname == $v["name"][$i]) {
return $v['type'][$i]; return $v["type"][$i];
} }
$i++; $i++;
@ -63,20 +63,20 @@
$i = 0; $i = 0;
foreach ($_FILES as $file) { foreach ($_FILES as $file) {
if ($file['error'][$i] != 0) { if ($file["error"][$i] != 0) {
$err = ''; $err = "";
switch ($file['error'][$i]) { switch ($file["error"][$i]) {
case 1: $err = 'php.iniでの「upload_max_filesize」値が超えています。ファイルサイズ'.humanreadablesize($file['size'][$i]); break; case 1: $err = "php.iniでの「upload_max_filesize」値が超えています。ファイルサイズ".humanreadablesize($file["size"][$i]); break;
case 2: $err = 'HTMLフォームの「MAX_FILE_SIZE」値が超えています。ファイルサイズ'.humanreadablesize($file['size'][$i]); break; case 2: $err = "HTMLフォームの「MAX_FILE_SIZE」値が超えています。ファイルサイズ".humanreadablesize($file["size"][$i]); break;
case 3: $err = 'ファイルの部分の失敗です。'; break; case 3: $err = "ファイルの部分の失敗です。"; break;
case 4: $err = 'ファイルをアップロード出来ません。'; break; case 4: $err = "ファイルをアップロード出来ません。"; break;
case 5: $err = '不明'; break; case 5: $err = "不明"; break;
case 6: $err = '仮フォルダがありません。'; break; case 6: $err = "仮フォルダがありません。"; break;
case 7: $err = 'uploadフォルダに書き込めません。'; break; case 7: $err = "uploadフォルダに書き込めません。"; break;
case 8: $err = '拡張子がありません。'; break; case 8: $err = "拡張子がありません。"; break;
} }
$res[$file['name'][$i]] = $err; $res[$file["name"][$i]] = $err;
} }
$i++; $i++;
@ -86,18 +86,18 @@
} }
function loliupload (array $files): bool { function loliupload (array $files): bool {
$dir = __DIR__.'/../public/static/upload/'; $dir = __DIR__."/../public/static/upload/";
$fname = ''; $fname = "";
if (!file_exists($dir)) { if (!file_exists($dir)) {
mkdir($dir, 0777); mkdir($dir, 0777);
} }
do { do {
$fname = uuid().'.'.fileextension($files['name'][0]); $fname = uuid().".".fileextension($files["name"][0]);
} while (file_exists($dir.$fname)); } while (file_exists($dir.$fname));
if (move_uploaded_file($files['tmp_name'][0], $dir.$fname)) { if (move_uploaded_file($files["tmp_name"][0], $dir.$fname)) {
return true; return true;
} }

ファイルの表示

@ -1,7 +1,7 @@
<?php <?php
function uuid () { function uuid () {
return sprintf( return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 32bitlow mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 32bitlow
mt_rand(0, 0xffff), // 16bitmid mt_rand(0, 0xffff), // 16bitmid
mt_rand(0, 0x0fff) | 0x4000, // 16bithigh mt_rand(0, 0x0fff) | 0x4000, // 16bithigh

ファイルの表示

@ -1,25 +1,36 @@
<?php <?php
require_once('../src/config.php'); if (session_status() == 1) session_start();
require_once('../helper.php'); require_once("../src/config.php");
$path = $_SERVER['REQUEST_URI'] == '/' ? '/home' : $_SERVER['REQUEST_URI']; require_once("../helper.php");
if (!file_exists('../src'.$path.'/index.php')) $path = '/404'; $path = $_SERVER["REQUEST_URI"] == "/" ? "/home" : $_SERVER["REQUEST_URI"];
$path = explode("?", $path)[0];
if (!file_exists("../src".$path."/index.php")) $path = "/404";
require_once('../src'.$path.'/index.php'); require_once("../src".$path."/index.php");
?> ?>
<?php if (HTML_VER == "HTML5") { ?>
<!DOCTYPE html>
<html lang="ja">
<?php } else { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd" lang="ja" xml:lang="ja"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd" lang="ja" xml:lang="ja">
<?php } ?>
<head> <head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" /> <meta content="text/html; charset=utf-8" http-equiv="content-type" />
<meta name="title" content="<?php echo $sitename.': '.$title; ?>" /> <meta name="title" content="<?= $sitename.": ".$title ?>" />
<meta name="description" content="<?php echo $sitedesc; ?>" /> <meta name="description" content="<?= $sitedesc ?>" />
<meta property="og:title" content="<?php echo $sitename; ?>" /> <?php if (CAN_MOBILE) { ?><meta name="viewport" content="width=device-width, initial-scale=1.0" /><?php }?>
<?php if (HTML_VER == "HTML5") { ?>
<meta property="og:title" content="<?= $sitename ?>" />
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />
<meta property="og:locale" content="ja_JP" /> <meta property="og:locale" content="ja_JP" />
<meta property="og:site_name" content="<?php echo $sitename.': '.$title; ?>" /> <meta property="og:site_name" content="<?= $sitename.": ".$title ?>" />
<meta property="og:url" content="<?php echo $siteurl; ?>" /> <meta property="og:url" content="<?= $siteurl ?>" />
<meta property="og:image" content="./static/<?php echo $thumbnail; ?>" /> <meta property="og:image" content="./static/<?= $thumbnail ?>" />
<title><?php echo $sitename.': '.$title; ?></title> <?php } ?>
<title><?= $sitename.": ".$title ?></title>
<link rel="stylesheet" type="text/css" href="./static/style.css" /> <link rel="stylesheet" type="text/css" href="./static/style.css" />
<?php if (isset($css)) { ?><link rel="stylesheet" type="text/css" href="./static/<?= $css ?>.css" /> <?php } ?>
</head> </head>
<body> <body>
<?php include_once($childview); ?> <?php include_once($childview); ?>

ファイルの表示

@ -1,4 +1,4 @@
<?php <?php
$title = 'エラー'; $title = "エラー";
$childview = '../ui/404/index.php'; $childview = "../ui/404/index.php";
?> ?>

ファイルの表示

@ -1,6 +1,6 @@
<?php <?php
$title = 'helperテスト'; $title = "helperテスト";
$childview = '../ui/about/index.php'; $childview = "../ui/about/index.php";
dd($title); dd($title);
?> ?>

ファイルの表示

@ -1,7 +1,7 @@
<?php <?php
$sitename = 'アプリ'; $sitename = "アプリ";
$sitedesc = 'PHP用エンジンです。'; $sitedesc = "PHP用エンジンです。";
$siteurl = 'http://127.0.0.1:8000'; // cd ~/dev/phpengine/public && php -S 127.0.0.1:8000 $siteurl = "http://127.0.0.1:8000"; // cd ~/dev/phpengine/public && php -S 127.0.0.1:8000
$thumbnail = 'applogo.png'; $thumbnail = "applogo.png";
include('../public/index.php'); include("../public/index.php");
?> ?>

ファイルの表示

@ -1,15 +1,15 @@
<?php <?php
if (isset($_POST['lolicon_cookie'])) { if (isset($_POST["lolicon_cookie"])) {
// 2時間後消えられます。 // 2時間後消えられます。
setcookie('lolicon_cookie', $_POST['lolicon_cookie'], ['expires' => time()+60*60*2, 'path' => '/cookie', 'httponly' => true]); setcookie("lolicon_cookie", $_POST["lolicon_cookie"], ["expires" => time()+60*60*2, "path" => "/cookie", "httponly" => true]);
//setrawcookie('lolicon_cookie', $_POST['lolicon_cookie'], ['expires' => time()+60*60*2, 'path' => '/cookie', 'httponly' => true]); //setrawcookie("lolicon_cookie", $_POST["lolicon_cookie"], ["expires" => time()+60*60*2, "path" => "/cookie", "httponly" => true]);
header('Location: /cookie', 301); header("Location: /cookie", 301);
} }
$title = 'クッキー'; // 必須・Requirement $title = "クッキー"; // 必須・Requirement
$sitedesc = 'クッキーの例え'; // config.phpの文字の交換・Change character of config.php $sitedesc = "クッキーの例え"; // config.phpの文字の交換・Change character of config.php
$siteurl .= '/cookie'; // config.phpの文字に追加・Add to character of config.php $siteurl .= "/cookie"; // config.phpの文字に追加・Add to character of config.php
$childview = '../ui/cookie/index.php'; // 必須・Requirement $childview = "../ui/cookie/index.php"; // 必須・Requirement
$mycookie = getcookie('lolicon_cookie'); $mycookie = getcookie("lolicon_cookie");
//$mycookie = getrawcookie('lolicon_cookie'); //$mycookie = getrawcookie("lolicon_cookie");
?> ?>

ファイルの表示

@ -1,9 +1,9 @@
<?php <?php
$title = 'CURL'; $title = "CURL";
$siteurl .= '/curl'; $siteurl .= "/curl";
$childview = '../ui/curl/index.php'; $childview = "../ui/curl/index.php";
// テストするには、config.phpでの「API_AUTH」値を「https://social.076.ne.jp」、又は違うPleromaインスタンスのホスト名に設定して下さい。 // テストするには、config.phpでの「API_AUTH」値を「https://social.076.ne.jp」、又は違うPleromaインスタンスのホスト名に設定して下さい。
// To test, please set "API_AUTH" in config.php to "https://social.076.ne.jp", or a different Pleroma instance host name. // To test, please set "API_AUTH" in config.php to "https://social.076.ne.jp", or a different Pleroma instance host name.
$result = lolicurl('/api/pleroma/frontend_configurations'); $result = lolicurl("/api/pleroma/frontend_configurations");
?> ?>

ファイルの表示

@ -1,9 +1,9 @@
<?php <?php
$title = 'パスワード創作'; $title = "パスワード創作";
$siteurl .= '/hash'; $siteurl .= "/hash";
$childview = '../ui/hash/index.php'; $childview = "../ui/hash/index.php";
if (isset($_POST['password'])) { if (isset($_POST["password"])) {
$setpasswd = setpasswd($_POST['password']); $setpasswd = setpasswd($_POST["password"]);
} }
?> ?>

ファイルの表示

@ -1,6 +1,6 @@
<?php <?php
$title = 'ホームページ'; // 必須・Requirement $title = "ホームページ"; // 必須・Requirement
$sitedesc = 'ホームページのみの説明。'; // config.phpの文字の交換・Change character of config.php $sitedesc = "ホームページのみの説明。"; // config.phpの文字の交換・Change character of config.php
$siteurl .= '/home'; // config.phpの文字に追加・Add to character of config.php $siteurl .= "/home"; // config.phpの文字に追加・Add to character of config.php
$childview = '../ui/home/index.php'; // 必須・Requirement $childview = "../ui/home/index.php"; // 必須・Requirement
?> ?>

ファイルの表示

@ -1,16 +1,16 @@
<?php <?php
$title = 'アップロード'; $title = "アップロード";
$sitedesc = 'アップロードです。'; $sitedesc = "アップロードです。";
$siteurl .= '/upload'; $siteurl .= "/upload";
$childview = '../ui/upload/index.php'; $childview = "../ui/upload/index.php";
if (isset($_FILES['file'])) { if (isset($_FILES["file"])) {
//dd($_FILES['file']); //dd($_FILES["file"]);
//dd(fileextension($_FILES['file']['name'][0])); //dd(fileextension($_FILES["file"]["name"][0]));
//dd(humanreadablesize($_FILES['file']['size'][0])); //dd(humanreadablesize($_FILES["file"]["size"][0]));
//dd(getmimetype('egaokero.png')); // 存在する //dd(getmimetype("egaokero.png")); // 存在する
//dd(getmimetype('klsdhnjkfjlsdjhnvgf.png')); // 存在しない //dd(getmimetype("klsdhnjkfjlsdjhnvgf.png")); // 存在しない
//dd(verifyupload()); //dd(verifyupload());
dd(loliupload($_FILES['file'])); dd(loliupload($_FILES["file"]));
} }
?> ?>

ファイルの表示

@ -6,8 +6,8 @@ Please enter "mysecurepassword".<br />
</form> </form>
<?php <?php
if (isset($_POST['password'])) { if (isset($_POST["password"])) {
echo '創作したパスワード(plaintext→sha256+pepper→md5→Argon2id) '.$setpasswd.'<br />'; echo "創作したパスワード(plaintext→sha256+pepper→md5→Argon2id) ".$setpasswd."<br />";
echo 'ポスワードは「mysecurepassword」ですか?'.(verifypasswd('mysecurepassword', $setpasswd) ? 'はい' : 'いいえ'); echo "ポスワードは「mysecurepassword」ですか?".(verifypasswd("mysecurepassword", $setpasswd) ? "はい" : "いいえ");
} }
?> ?>

ファイルの表示

@ -2,7 +2,7 @@
<h1>例の一覧</h1> <h1>例の一覧</h1>
<ul> <ul>
<?php <?php
$scan = array_diff(scandir('../ui'), ['..', '.']); $scan = array_diff(scandir("../ui"), ["..", "."]);
foreach ($scan as $s) { foreach ($scan as $s) {
?> ?>