クリーンアップ
このコミットが含まれているのは:
コミット
c3b251434c
111
helper.php
111
helper.php
|
@ -1,103 +1,12 @@
|
|||
<?php
|
||||
require_once('config.php');
|
||||
|
||||
// PHP8を実行していない場合
|
||||
if (!function_exists('str_starts_with')) {
|
||||
function str_starts_with (string $haystack, string $needle): bool {
|
||||
return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('str_ends_with')) {
|
||||
function str_ends_with (string $haystack, string $needle): bool {
|
||||
$needle_len = strlen($needle);
|
||||
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('str_contains')) {
|
||||
function str_contains (string $haystack, string $needle): bool {
|
||||
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('array_key_first')) {
|
||||
function array_key_first (array $array): int|string|null {
|
||||
if (!is_array($array) || empty($array)) return NULL;
|
||||
return array_keys($array)[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('array_key_last')) {
|
||||
function array_key_last (array $array): int|string|null {
|
||||
if (!is_array($array) || empty($array)) return NULL;
|
||||
return array_keys($array)[count($array)-1];
|
||||
}
|
||||
}
|
||||
|
||||
// デバッガー
|
||||
// Debugger
|
||||
function dd ($val) {
|
||||
echo '<pre>';
|
||||
var_dump($val);
|
||||
echo '</pre>';
|
||||
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 () {}
|
||||
|
||||
// セッション
|
||||
|
||||
// ハッシュ
|
||||
|
||||
require_once('./helper/php8compat.php'); // PHP8を実行していない場合・If not running PHP8
|
||||
require_once('./helper/debug.php'); // デバッガー・Debugger
|
||||
require_once('./helper/db.php'); // データベースエンジン・Database engine
|
||||
require_once('./helper/request.php'); // リクエスト・Request
|
||||
require_once('./helper/upload.php'); // ファイルアップロード・File upload
|
||||
require_once('./helper/curl.php'); // CURL
|
||||
require_once('./helper/cookie.php'); // クッキー・Cookie
|
||||
require_once('./helper/mail.php'); // メール・Mail
|
||||
require_once('./helper/session.php'); // セッション・Session
|
||||
require_once('./helper/hash.php'); // ハッシュ・Hash
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
function getcookie (string $name): array {
|
||||
return htmlspecialchars($_COOKIE[$name]);
|
||||
}
|
||||
|
||||
function getrawcookie (string $name): array {
|
||||
return $_COOKIE[$name];
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
function lolicurl () {}
|
||||
?>
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
require_once('../config.php');
|
||||
|
||||
/* val
|
||||
*
|
||||
* select => ['var1', 'var2'...]
|
||||
|
@ -69,7 +71,10 @@ function lolidb (string $table, array $val, string $mode='select'): array|bool {
|
|||
|
||||
if ($mode == 'select' || $mode == 'one') {
|
||||
// select値がなければ、全部を選択する。If there is no select value, select everything.
|
||||
if (!isset($val['select'])) $val['select'] = ['*'];
|
||||
if (!isset($val['select'])) {
|
||||
$val['select'] = ['*'];
|
||||
}
|
||||
|
||||
$query = 'SELECT '.$val['select'].' FROM '.$table;
|
||||
|
||||
if (isset($val['where'])) {
|
||||
|
@ -88,9 +93,13 @@ function lolidb (string $table, array $val, string $mode='select'): array|bool {
|
|||
}
|
||||
}
|
||||
|
||||
if ($mode == 'one') $query .= ' LIMIT 1';
|
||||
if ($mode == 'one') {
|
||||
$query .= ' LIMIT 1';
|
||||
}
|
||||
else {
|
||||
if (isset($val['limit'])) $query .= ' LIMIT '.(int)$val['limit'];
|
||||
if (isset($val['limit'])) {
|
||||
$query .= ' LIMIT '.(int)$val['limit'];
|
||||
}
|
||||
}
|
||||
|
||||
$result = mysqli_query($mysqli, $query.';');
|
||||
|
@ -101,12 +110,16 @@ function lolidb (string $table, array $val, string $mode='select'): array|bool {
|
|||
$query .= 'INSERT INTO '.$table.' (';
|
||||
foreach ($val['insert'] as $k => $v) {
|
||||
$query .= $k;
|
||||
if ($k !== array_key_last($val['insert'])) $query .= ', ';
|
||||
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 .= ', ';
|
||||
if ($k !== array_key_last($val['insert'])) {
|
||||
$query .= ', ';
|
||||
}
|
||||
}
|
||||
$query .= ')';
|
||||
}
|
||||
|
@ -114,14 +127,18 @@ function lolidb (string $table, array $val, string $mode='select'): array|bool {
|
|||
$query .= 'UPDATE '.$table.' SET ';
|
||||
foreach ($val['update'] as $k => $v) {
|
||||
$query .= $k.' = '.$v;
|
||||
if ($k !== array_key_last($val['update'])) $query .= ', ';
|
||||
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 ';
|
||||
if ($k !== array_key_last($val['where'])) {
|
||||
$query .= ' AND ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +149,9 @@ function lolidb (string $table, array $val, string $mode='select'): array|bool {
|
|||
$query .= ' WHERE ';
|
||||
foreach ($val['where'] as $k => $v) {
|
||||
$query .= $k.' = '.$v;
|
||||
if ($k !== array_key_last($val['where'])) $query .= ' AND ';
|
||||
if ($k !== array_key_last($val['where'])) {
|
||||
$query .= ' AND ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,23 +161,4 @@ function lolidb (string $table, array $val, string $mode='select'): array|bool {
|
|||
|
||||
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;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
function dd ($val) {
|
||||
echo '<pre>';
|
||||
var_dump($val);
|
||||
echo '</pre>';
|
||||
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;
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
?>
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
function lolimail () {}
|
||||
?>
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
if (!function_exists('str_starts_with')) {
|
||||
function str_starts_with (string $haystack, string $needle): bool {
|
||||
return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('str_ends_with')) {
|
||||
function str_ends_with (string $haystack, string $needle): bool {
|
||||
$needle_len = strlen($needle);
|
||||
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('str_contains')) {
|
||||
function str_contains (string $haystack, string $needle): bool {
|
||||
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('array_key_first')) {
|
||||
function array_key_first (array $array): int|string|null {
|
||||
if (!is_array($array) || empty($array)) return NULL;
|
||||
return array_keys($array)[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('array_key_last')) {
|
||||
function array_key_last (array $array): int|string|null {
|
||||
if (!is_array($array) || empty($array)) return NULL;
|
||||
return array_keys($array)[count($array)-1];
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
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;
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
?>
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
function loliupload () {}
|
||||
?>
|
読み込み中…
新しいイシューから参照