commit e80c591e3fc9f7e3be2eb1bed488268fa9c68f0a Author: テクニカル諏訪子 Date: Sun Mar 27 01:55:57 2022 +0900 最初コミット diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f4773f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a52818 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# LoliPHP +## 0.1 + +フレームワークじゃなくて、小さいエンジンだけです。♡ diff --git a/config.sample.php b/config.sample.php new file mode 100644 index 0000000..2e2e6e5 --- /dev/null +++ b/config.sample.php @@ -0,0 +1,10 @@ + diff --git a/helper.php b/helper.php new file mode 100644 index 0000000..0d9cda7 --- /dev/null +++ b/helper.php @@ -0,0 +1,103 @@ +'; + 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/db.php b/helper/db.php new file mode 100644 index 0000000..877f9f7 --- /dev/null +++ b/helper/db.php @@ -0,0 +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; + } + + // 順のチェック。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; + } + } + } + + // 限界のチェック。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; + } + } + + // 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; + } + + // 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 (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 ($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 .= ')'; + } + 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) { + $query .= $k.' = '.$v; + if ($k !== array_key_last($val['where'])) $query .= ' AND '; + } + } + } + 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 '; + } + } + } + + $stmt = mysqli_prepare($mysqli, $query.';'); + } + + 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/public/index.php b/public/index.php new file mode 100644 index 0000000..4ff5a2a --- /dev/null +++ b/public/index.php @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + <?php echo $sitename.': '.$title; ?> + + + + + + diff --git a/public/static/style.css b/public/static/style.css new file mode 100644 index 0000000..acd09e9 --- /dev/null +++ b/public/static/style.css @@ -0,0 +1,41 @@ +body { + --mainColor: #ea81e8; + --mainColorLighter: #d68ad5; + --mainColorLightest: #fdd1fc; + --mainHoverColor: #fc54f9; + --mainBackgroundColor: #301a30; + --mainForegroundColor: #fcfcfc; + --secondaryColor: #421a46; + --submenuBackgroundColor: #5e3c62; + --channelBackgroundColor: #5e3c62; + --actionButtonColor: #ea81e8; + --supportButtonBackgroundColor: #971195; + --supportButtonColor: var(--actionButtonColor); + --supportButtonHeartColor: #ec1818; + --submenuColor: #272727; + --inputColor: #272727; + --inputPlaceholderColor: rgba(195,195,195,0.878431); + --menuAndHeaderBackgroundColor: #272727; + --menuForegroundColor: rgba(195,195,195,0.878431); + --menuBackgroundColor: #272727; + --whiteColor: #ffffff; + --dangerBackgroundColor: #d9534f; + font-family: "Open Sans",sans-serif; + --greyForegroundColor: #585858; + --greyBackgroundColor: #e5e5e5; + --inputForegroundColor: #000; + --inputBackgroundColor: #fff; + --textareaForegroundColor: #000; + --textareaBackgroundColor: #fff; + --markdownTextareaBackgroundColor: #efefef; + --activatedActionButtonColor: #000; + --horizontalMarginContent: 30px; + --videosHorizontalMarginContent: 6vw; + --mainColWidth: calc(100vw - 240px); + font-weight: 400; + color: var(--mainForegroundColor); + background-color: var(--mainBackgroundColor); + font-size: 14px; + overflow-y: scroll; + text-align: start; +} diff --git a/src/404/index.php b/src/404/index.php new file mode 100644 index 0000000..42aa00c --- /dev/null +++ b/src/404/index.php @@ -0,0 +1,4 @@ + diff --git a/src/about/index.php b/src/about/index.php new file mode 100644 index 0000000..9f85989 --- /dev/null +++ b/src/about/index.php @@ -0,0 +1,13 @@ + ['id', 'name'], + // 'where' => ['id', 1] + // ]; + // $dbres = lolidb('example', $data, 'one'); + // dd($dbres); + dd($title); +?> diff --git a/src/home/index.php b/src/home/index.php new file mode 100644 index 0000000..0d3d73b --- /dev/null +++ b/src/home/index.php @@ -0,0 +1,6 @@ + diff --git a/ui/404/index.php b/ui/404/index.php new file mode 100644 index 0000000..133ce4b --- /dev/null +++ b/ui/404/index.php @@ -0,0 +1,2 @@ +

404

+

ページを見つけられませんでした…

diff --git a/ui/about/index.php b/ui/about/index.php new file mode 100644 index 0000000..af55a3b --- /dev/null +++ b/ui/about/index.php @@ -0,0 +1 @@ +空 diff --git a/ui/home/index.php b/ui/home/index.php new file mode 100644 index 0000000..273ee79 --- /dev/null +++ b/ui/home/index.php @@ -0,0 +1,3 @@ +
+ 例のページ +