diff --git a/config.sample.php b/config.sample.php index 2e2e6e5..938975d 100644 --- a/config.sample.php +++ b/config.sample.php @@ -1,10 +1,10 @@ diff --git a/helper.php b/helper.php index 0d9cda7..bf9eee7 100644 --- a/helper.php +++ b/helper.php @@ -1,103 +1,12 @@ -'; - var_dump($val); - echo ''; - die(); -} - -// データベースエンジン -// Database engine -require_once('helper/db.php'); - -// リクエスト -// Request -function request (string $name): array { - if (isset($_POST[$name])) { - return ['post' => htmlspecialchars($name)]; - } - else if (isset($_GET[$name])) { - return ['get' => htmlspecialchars($name)]; - } - else if (isset($_REQUEST[$name])) { - return ['request' => htmlspecialchars($name)]; - } - - return ['error' => '']; -} - -function request_all (): array { - $res = []; - if (!empty($_POST)) { - $res['post'] = []; - foreach ($_POST as $k => $v) $res['post'][$k] = htmlspecialchars($v); - } - if (!empty($_GET)) { - $res['get'] = []; - foreach ($_GET as $k => $v) $res['get'][$k] = htmlspecialchars($v); - } - if (!empty($_REQUEST)) { - $res['request'] = []; - foreach ($_REQUEST as $k => $v) $res['request'][$k] = htmlspecialchars($v); - } - - return $res; -} - -// ファイルアップロード -function loliupload () {} - -// CURL -function lolicurl () {} - -// クッキー -function getcookie (string $name): array { return htmlspecialchars($_COOKIE[$name]); } - -function getrawcookie (string $name): array { return $_COOKIE[$name]; } - -// メール -function lolimail () {} - -// セッション - -// ハッシュ - + diff --git a/helper/cookie.php b/helper/cookie.php new file mode 100644 index 0000000..81dbb17 --- /dev/null +++ b/helper/cookie.php @@ -0,0 +1,9 @@ + diff --git a/helper/curl.php b/helper/curl.php new file mode 100644 index 0000000..63a8f65 --- /dev/null +++ b/helper/curl.php @@ -0,0 +1,3 @@ + diff --git a/helper/db.php b/helper/db.php index 877f9f7..76b1223 100644 --- a/helper/db.php +++ b/helper/db.php @@ -1,164 +1,164 @@ ['var1', 'var2'...] - * insert|update|where => ['key1' => 'value1', 'key2' => 'value2'...] - * order => ['var', 'asc'|'desc'] - * limit => int - * */ -function lolidb (string $table, array $val, string $mode='select'): array|bool { - // モードは違う場合、やめる。If the mode is wrong, stop. - 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\"."); - return false; - } + require_once('../config.php'); - // 順のチェック。Check order. - if (isset($val['order'])) { - // selectかoneじゃない場合。If not select or one. - if ($mode !== 'select' || $mode !== 'one') { - dd("「order」は「select」又は「one」のみで使えます。\n\"order\" can only be used with \"select\" or \"one\"."); + /* val + * + * select => ['var1', 'var2'...] + * insert|update|where => ['key1' => 'value1', 'key2' => 'value2'...] + * order => ['var', 'asc'|'desc'] + * limit => int + * */ + function lolidb (string $table, array $val, string $mode='select'): array|bool { + // モードは違う場合、やめる。If the mode is wrong, stop. + 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\"."); return false; } - // 複数の場合。If multiple. - if (count($val['order'] > 1)) { - dd("複数「order」は未対応です。\nMultiple \"order\" is not yet supported."); - return false; + // 順のチェック。Check order. + if (isset($val['order'])) { + // selectかoneじゃない場合。If not select or one. + if ($mode !== 'select' || $mode !== 'one') { + dd("「order」は「select」又は「one」のみで使えます。\n\"order\" can only be used with \"select\" or \"one\"."); + return false; + } + + // 複数の場合。If multiple. + if (count($val['order'] > 1)) { + dd("複数「order」は未対応です。\nMultiple \"order\" is not yet supported."); + return false; + } + + // ascかdescかどうか。Whether it's asc or desc. + foreach ($val['order'] as $k => $v) { + if ($v !== 'asc' && $v !== 'desc') { + dd("「order」は「asc」又は「desc」です。\n\"order\" should be \"asc\" or \"desc\"."); + return false; + } + } } - // ascかdescかどうか。Whether it's asc or desc. - foreach ($val['order'] as $k => $v) { - if ($v !== 'asc' && $v !== 'desc') { - dd("「order」は「asc」又は「desc」です。\n\"order\" should be \"asc\" or \"desc\"."); + // 限界のチェック。Check limit. + if (($mode === 'select' || $mode === 'one') && isset($val['limit'])) { + // oneの場合。If 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\"."); + return false; + } + + // selectじゃない場合。If not select. + else if ($mode !== 'select') { + dd("「insert」、「update」及び「delete」で、「limit」を使えません。\n\"limit\" cannot be used with \"insert\", \"update\", and \"delete\"."); return false; } } - } - // 限界のチェック。Check limit. - if (($mode === 'select' || $mode === 'one') && isset($val['limit'])) { - // oneの場合。If 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\"."); + // insertの場合。In case of insert. + if ($mode === 'insert' && !isset($val['insert'])) { + dd("「insert」モードの場合、「insert」値は必須です。\nIn case of \"insert\" mode, \"insert\" value is necessary."); return false; } - // selectじゃない場合。If not select. - else if ($mode !== 'select') { - dd("「insert」、「update」及び「delete」で、「limit」を使えません。\n\"limit\" cannot be used with \"insert\", \"update\", and \"delete\"."); + // updateの場合。In case of update. + if ($mode === 'update' && !isset($val['update'])) { + dd("「update」モードの場合、「update」値は必須です。\nIn case of \"update\" mode, \"update\" value is necessary."); return false; } - } - // insertの場合。In case of insert. - if ($mode === 'insert' && !isset($val['insert'])) { - dd("「insert」モードの場合、「insert」値は必須です。\nIn case of \"insert\" mode, \"insert\" value is necessary."); - return false; - } + // MySQLiの創作。Creation of MySQLi. + $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_TABLE); + $result = null; - // updateの場合。In case of update. - if ($mode === 'update' && !isset($val['update'])) { - dd("「update」モードの場合、「update」値は必須です。\nIn case of \"update\" mode, \"update\" value is necessary."); - return false; - } - - // MySQLiの創作。Creation of MySQLi. - $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_TABLE); - $result = null; - - if ($mode == 'select' || $mode == 'one') { - // select値がなければ、全部を選択する。If there is no select value, select everything. - if (!isset($val['select'])) $val['select'] = ['*']; - $query = 'SELECT '.$val['select'].' FROM '.$table; - - if (isset($val['where'])) { - $query .= ' WHERE '; - foreach ($val['where'] as $k => $v) { - $query .= $k.' = '.$v; - if ($k !== array_key_last($val['where'])) $query .= ' AND '; + if ($mode == 'select' || $mode == 'one') { + // select値がなければ、全部を選択する。If there is no select value, select everything. + if (!isset($val['select'])) { + $val['select'] = ['*']; } - } - if (isset($val['order'])) { - $query .= ' ORDER BY '; - foreach ($val['order'] as $k => $v) { - $query .= $k; - $query .= ' '.strtoupper($v); + $query = 'SELECT '.$val['select'].' FROM '.$table; + + if (isset($val['where'])) { + $query .= ' WHERE '; + foreach ($val['where'] as $k => $v) { + $query .= $k.' = '.$v; + if ($k !== array_key_last($val['where'])) $query .= ' AND '; + } } - } - if ($mode == 'one') $query .= ' LIMIT 1'; + if (isset($val['order'])) { + $query .= ' ORDER BY '; + foreach ($val['order'] as $k => $v) { + $query .= $k; + $query .= ' '.strtoupper($v); + } + } + + if ($mode == 'one') { + $query .= ' LIMIT 1'; + } + else { + if (isset($val['limit'])) { + $query .= ' LIMIT '.(int)$val['limit']; + } + } + + $result = mysqli_query($mysqli, $query.';'); + $row = mysqli_fetch_assoc($result); + } else { - if (isset($val['limit'])) $query .= ' LIMIT '.(int)$val['limit']; - } - - $result = mysqli_query($mysqli, $query.';'); - $row = mysqli_fetch_assoc($result); - } - else { - if ($mode == 'insert') { - $query .= 'INSERT INTO '.$table.' ('; - foreach ($val['insert'] as $k => $v) { - $query .= $k; - if ($k !== array_key_last($val['insert'])) $query .= ', '; + if ($mode == 'insert') { + $query .= 'INSERT INTO '.$table.' ('; + foreach ($val['insert'] as $k => $v) { + $query .= $k; + if ($k !== array_key_last($val['insert'])) { + $query .= ', '; + } + } + $query .= ') VALUES ('; + foreach ($val['insert'] as $k => $v) { + $query .= $v; + if ($k !== array_key_last($val['insert'])) { + $query .= ', '; + } + } + $query .= ')'; } - $query .= ') VALUES ('; - foreach ($val['insert'] as $k => $v) { - $query .= $v; - if ($k !== array_key_last($val['insert'])) $query .= ', '; - } - $query .= ')'; - } - else if ($mode == 'update') { - $query .= 'UPDATE '.$table.' SET '; - foreach ($val['update'] as $k => $v) { - $query .= $k.' = '.$v; - if ($k !== array_key_last($val['update'])) $query .= ', '; - } - - if (isset($val['where'])) { - $query .= ' WHERE '; - foreach ($val['where'] as $k => $v) { + else if ($mode == 'update') { + $query .= 'UPDATE '.$table.' SET '; + foreach ($val['update'] as $k => $v) { $query .= $k.' = '.$v; - if ($k !== array_key_last($val['where'])) $query .= ' AND '; + if ($k !== array_key_last($val['update'])) { + $query .= ', '; + } + } + + if (isset($val['where'])) { + $query .= ' WHERE '; + foreach ($val['where'] as $k => $v) { + $query .= $k.' = '.$v; + if ($k !== array_key_last($val['where'])) { + $query .= ' AND '; + } + } } } - } - else if ($mode == 'delete') { - $query .= 'DELETE FROM '.$table; + else if ($mode == 'delete') { + $query .= 'DELETE FROM '.$table; - if (isset($val['where'])) { - $query .= ' WHERE '; - foreach ($val['where'] as $k => $v) { - $query .= $k.' = '.$v; - if ($k !== array_key_last($val['where'])) $query .= ' AND '; + if (isset($val['where'])) { + $query .= ' WHERE '; + foreach ($val['where'] as $k => $v) { + $query .= $k.' = '.$v; + if ($k !== array_key_last($val['where'])) { + $query .= ' AND '; + } + } } } + + $stmt = mysqli_prepare($mysqli, $query.';'); } - $stmt = mysqli_prepare($mysqli, $query.';'); + return $row; } - - return $row; -} - -function lolilog (string $val, string $mode='info'): bool { - if (!$file = fopen('./lolilog', 'a+')) { - dd('lolilogファイルを開けられません。'); - return false; - } - - $time = time(); - - $logtext = '['.date('Y-m-d H:i:s T', $time).' ('.$time.') - '.mb_strtoupper($mode)."]\n".$val."\n\n"; - - if (fwrite($file, $logtext) === false) { - dd('lolilogファイルに書き出しに失敗しました。'); - return false; - } - - fclose($file); - return true; -} ?> diff --git a/helper/debug.php b/helper/debug.php new file mode 100644 index 0000000..c235f9e --- /dev/null +++ b/helper/debug.php @@ -0,0 +1,26 @@ +'; + var_dump($val); + echo ''; + die(); + } + + function lolilog (string $val, string $mode='info'): bool { + if (!$file = fopen('./lolilog', 'a+')) { + dd('lolilogファイルを開けられません。'); + return false; + } + + $time = time(); + $logtext = '['.date('Y-m-d H:i:s T', $time).' ('.$time.') - '.mb_strtoupper($mode)."]\n".$val."\n\n"; + + if (fwrite($file, $logtext) === false) { + dd('lolilogファイルに書き出しに失敗しました。'); + return false; + } + + fclose($file); + return true; + } +?> diff --git a/helper/hash.php b/helper/hash.php new file mode 100644 index 0000000..acb6c35 --- /dev/null +++ b/helper/hash.php @@ -0,0 +1,2 @@ + diff --git a/helper/mail.php b/helper/mail.php new file mode 100644 index 0000000..0b215eb --- /dev/null +++ b/helper/mail.php @@ -0,0 +1,3 @@ + diff --git a/helper/php8compat.php b/helper/php8compat.php new file mode 100644 index 0000000..938c0e1 --- /dev/null +++ b/helper/php8compat.php @@ -0,0 +1,34 @@ + diff --git a/helper/request.php b/helper/request.php new file mode 100644 index 0000000..8385293 --- /dev/null +++ b/helper/request.php @@ -0,0 +1,33 @@ + htmlspecialchars($name)]; + } + else if (isset($_GET[$name])) { + return ['get' => htmlspecialchars($name)]; + } + else if (isset($_REQUEST[$name])) { + return ['request' => htmlspecialchars($name)]; + } + + return ['error' => '']; +} + +function request_all (): array { + $res = []; + if (!empty($_POST)) { + $res['post'] = []; + foreach ($_POST as $k => $v) $res['post'][$k] = htmlspecialchars($v); + } + if (!empty($_GET)) { + $res['get'] = []; + foreach ($_GET as $k => $v) $res['get'][$k] = htmlspecialchars($v); + } + if (!empty($_REQUEST)) { + $res['request'] = []; + foreach ($_REQUEST as $k => $v) $res['request'][$k] = htmlspecialchars($v); + } + + return $res; +} +?> diff --git a/helper/session.php b/helper/session.php new file mode 100644 index 0000000..acb6c35 --- /dev/null +++ b/helper/session.php @@ -0,0 +1,2 @@ + diff --git a/helper/upload.php b/helper/upload.php new file mode 100644 index 0000000..e333e2d --- /dev/null +++ b/helper/upload.php @@ -0,0 +1,3 @@ +