最初コミット

このコミットが含まれているのは:
守矢諏訪子 2022-03-27 01:55:57 +09:00
コミット e80c591e3f
13個のファイルの変更379行の追加0行の削除

1
.gitignore vendored ノーマルファイル
ファイルの表示

@ -0,0 +1 @@
config.php

4
README.md ノーマルファイル
ファイルの表示

@ -0,0 +1,4 @@
# LoliPHP
## 0.1
フレームワークじゃなくて、小さいエンジンだけです。♡

10
config.sample.php ノーマルファイル
ファイルの表示

@ -0,0 +1,10 @@
<?php
// アプリ
define('APP_NAME', 'LoliPHP');
// データベース
define('DB_HOST', 'localhost');
define('DB_USER', '');
define('DB_PASS', '');
define('DB_NAME', '');
?>

103
helper.php ノーマルファイル
ファイルの表示

@ -0,0 +1,103 @@
<?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 () {}
// セッション
// ハッシュ
?>

164
helper/db.php ノーマルファイル
ファイルの表示

@ -0,0 +1,164 @@
<?php
/* 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;
}
// 順のチェック。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;
}
?>

27
public/index.php ノーマルファイル
ファイルの表示

@ -0,0 +1,27 @@
<?php
require_once('../src/config.php');
require_once('../helper.php');
$path = $_SERVER['REQUEST_URI'] == '/' ? '/home' : $_SERVER['REQUEST_URI'];
if (!file_exists('../src'.$path.'/index.php')) $path = '/404';
require_once('../src'.$path.'/index.php');
?>
<!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">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<meta name="title" content="<?php echo $sitename.': '.$title; ?>" />
<meta name="description" content="<?php echo $sitedesc; ?>" />
<meta property="og:title" content="<?php echo $sitename; ?>" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="ja_JP" />
<meta property="og:site_name" content="<?php echo $sitename.': '.$title; ?>" />
<meta property="og:url" content="<?php echo $siteurl; ?>" />
<meta property="og:image" content="./static/<?php echo $thumbnail; ?>" />
<title><?php echo $sitename.': '.$title; ?></title>
<link rel="stylesheet" type="text/css" href="./static/style.css" />
</head>
<body>
<?php include_once($childview); ?>
</body>
</html>

41
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;
}

4
src/404/index.php ノーマルファイル
ファイルの表示

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

13
src/about/index.php ノーマルファイル
ファイルの表示

@ -0,0 +1,13 @@
<?php
$title = 'helperテスト';
$childview = '../ui/about/index.php';
// まだテストしませんでしたので、コメアウトしました。Not yet tested, so it is comentout.
// $data = [
// 'select' => ['id', 'name'],
// 'where' => ['id', 1]
// ];
// $dbres = lolidb('example', $data, 'one');
// dd($dbres);
dd($title);
?>

6
src/home/index.php ノーマルファイル
ファイルの表示

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

2
ui/404/index.php ノーマルファイル
ファイルの表示

@ -0,0 +1,2 @@
<h1>404</h1>
<p>ページを見つけられませんでした…</p>

1
ui/about/index.php ノーマルファイル
ファイルの表示

@ -0,0 +1 @@

3
ui/home/index.php ノーマルファイル
ファイルの表示

@ -0,0 +1,3 @@
<section>
例のページ
</section>