diff --git a/README.md b/README.md index 3b008c4..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,3 +0,0 @@ -# ez-site - -油二黑子站 \ No newline at end of file diff --git a/apis/account.php b/apis/account.php new file mode 100644 index 0000000..9ead56d --- /dev/null +++ b/apis/account.php @@ -0,0 +1,81 @@ +prepare("SELECT username FROM users WHERE username = ?"); + $checkStmt->execute([$username]); + + if ($checkStmt->rowCount() > 0) { + $title = '用户名已存在'; + $right_word = '注册'; + $href_url = '/?page=account'; + include('includes/time.php'); + } else { + $stmt = $pdo->prepare("INSERT INTO users (username, password, contact) VALUES (?, ?, ?)"); + + if ($stmt->execute([$username, $password, $contact])) { + $title = '注册成功'; + $right_word = '登录'; + $href_url = '/?page=account'; + include('includes/time.php'); + } else { + $title = '注册失败'; + $right_word = '注册'; + $href_url = '/?page=account'; + include('includes/time.php'); + } + } + } + } +} + +// 登录 +if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login_username'])) { + $login_username = trim($_POST['login_username']); + $login_password = $_POST['login_password']; + + // 检查登录用户名是否为空 + if (empty($login_username)) { + $title = '用户名不能为空'; + $right_word = '登录'; + $href_url = '/?page=account'; + include('includes/time.php'); + } else { + $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$login_username]); + $user = $stmt->fetch(); + + if ($user && password_verify($login_password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $title = '登录成功'; + $right_word = '首'; + $href_url = '/'; + include('includes/time.php'); + } else { + $title = '用户名或密码错误'; + $right_word = '登录'; + $href_url = '/?page=account'; + include('includes/time.php'); + } + } +} +?> \ No newline at end of file diff --git a/apis/load_comments.php b/apis/load_comments.php new file mode 100644 index 0000000..f686a31 --- /dev/null +++ b/apis/load_comments.php @@ -0,0 +1,12 @@ +prepare("SELECT comments.content, users.username FROM comments JOIN users ON comments.user_id = users.id WHERE love_wall_id = ? ORDER BY comments.created_at DESC"); + $stmt->execute([$love_wall_id]); + while ($row = $stmt->fetch()) { + echo "
{$row['username']}: {$row['content']}
"; + } +} +?> diff --git a/apis/load_love_wall.php b/apis/load_love_wall.php new file mode 100644 index 0000000..212357e --- /dev/null +++ b/apis/load_love_wall.php @@ -0,0 +1,8 @@ +query("SELECT love_wall.content, users.username FROM love_wall JOIN users ON love_wall.user_id = users.id ORDER BY love_wall.created_at DESC"); +while ($row = $stmt->fetch()) { + echo "
{$row['username']}: {$row['content']}
"; +} +?> diff --git a/apis/onesay.php b/apis/onesay.php new file mode 100644 index 0000000..7c98189 --- /dev/null +++ b/apis/onesay.php @@ -0,0 +1,34 @@ + "秦涛", + "天涯何处无芳草,何必要在身边找,本来数量就不多,质量还不咋地" => "秦涛", + "弱小和无知,不是生存的障碍,傲慢才是" => "《三体》", + "你的无畏来源于无知" => "《三体》", + "要想逃避现实,最好的方式就是深深介入现实之中" => "《三体》", + "我爱你,与你有何相干?毁灭你,又与你有何相干?" => "《三体》", + "宇宙很大,生活更大,也许以后还有缘相见" => "《三体》", + "大多数人到死都没有向尘世之外瞥一眼" => "《三体》", + "碑是那么小,与其说是为了纪念,更像是为了忘却" => "《三体》", + "人们习惯将凡事分出黑与白,但很遗憾,现实全是灰色的" => "《三体》", + "没有不散的宴席,一切都有个尽头" => "《三体》", + "编程本身虽然是一种智力活动,但是中国的现实却更像一种体力劳动" => "《未来世界的幸存者》", + "我们只是让某些局部变得更有秩序,把混乱转移到另一些领域。" => "《未来世界的幸存者》", + "苦难就是苦难,苦难不会带来成功" => "《活着》", + "我的职业建议是,任何工作要么让你学习(learn),要么让你赚钱(earn)。如果既学不到新东西,又赚不到钱,你就应该走了" => "Garry Tan", + "编程既不是短跑,也不是马拉松,而是日记。在日复一日的累积当中,完成你的事业" => "《四十年编程感想》" +]; + +$randomKey = array_rand($quotes); +$quote = $randomKey; +$author = $quotes[$randomKey]; + +// 创建一个数组来存储名言和作者信息 +$response = [ + 'quote' => $quote, + 'author' => $author +]; + +// 将数组转换为 JSON 格式并输出 +echo json_encode($response); \ No newline at end of file diff --git a/apis/submit_comment.php b/apis/submit_comment.php new file mode 100644 index 0000000..081315a --- /dev/null +++ b/apis/submit_comment.php @@ -0,0 +1,17 @@ +prepare("INSERT INTO comments (user_id, content, love_wall_id) VALUES (?, ?, ?)"); + $stmt->execute([$user_id, $content, $love_wall_id]); + } elseif (isset($_POST['article_id'])) { + $article_id = intval($_POST['article_id']); + $stmt = $pdo->prepare("INSERT INTO comments (user_id, content, article_id) VALUES (?, ?, ?)"); + $stmt->execute([$user_id, $content, $article_id]); + } +} +?> \ No newline at end of file diff --git a/apis/submit_love.php b/apis/submit_love.php new file mode 100644 index 0000000..03bb1c7 --- /dev/null +++ b/apis/submit_love.php @@ -0,0 +1,19 @@ +prepare("INSERT INTO love_wall (user_id, content) VALUES (?, ?)"); + + // 执行SQL语句 + if ($stmt->execute([$user_id, $content])) { + echo "发表成功!"; + } else { + echo "发表失败!"; + } +} +?> diff --git a/assets/css/account.min.css b/assets/css/account.min.css new file mode 100644 index 0000000..44bbddd --- /dev/null +++ b/assets/css/account.min.css @@ -0,0 +1,213 @@ +:root { + /* COLORS */ + --white: #e9e9e9; + --gray: #333; + --blue: #0367a6; + --lightblue: #008997; + + /* RADII */ + --button-radius: 0.7rem; + + /* SIZES */ + --max-width: 758px; + --max-height: 420px; + + font-size: 16px; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, + Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; +} + +body { + align-items: center; + background-color: var(--white); + background: url("https://api.mmeiblog.cn/?api=pic&et=pc&time=true&source=true"); + background-attachment: fixed; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + display: grid; + height: 100vh; + place-items: center; +} + +.form__title { + font-weight: 300; + margin: 0; + margin-bottom: 1.25rem; +} + +.link { + color: var(--gray); + font-size: 0.9rem; + margin: 1.5rem 0; + text-decoration: none; +} + +.container { + background-color: var(--white); + border-radius: var(--button-radius); + box-shadow: 0 0.9rem 1.7rem rgba(0, 0, 0, 0.25), + 0 0.7rem 0.7rem rgba(0, 0, 0, 0.22); + height: var(--max-height); + max-width: var(--max-width); + overflow: hidden; + position: relative; + width: 100%; +} + +.container__form { + height: 100%; + position: absolute; + top: 0; + transition: all 0.6s ease-in-out; +} + +.container--signin { + left: 0; + width: 50%; + z-index: 2; +} + +.container.right-panel-active .container--signin { + transform: translateX(100%); +} + +.container--signup { + left: 0; + opacity: 0; + width: 50%; + z-index: 1; +} + +.container.right-panel-active .container--signup { + animation: show 0.6s; + opacity: 1; + transform: translateX(100%); + z-index: 5; +} + +.container__overlay { + height: 100%; + left: 50%; + overflow: hidden; + position: absolute; + top: 0; + transition: transform 0.6s ease-in-out; + width: 50%; + z-index: 100; +} + +.container.right-panel-active .container__overlay { + transform: translateX(-100%); +} + +.overlay { + background-color: var(--lightblue); + background: url("https://api.mmeiblog.cn/?api=pic&et=pc&time=true&source=true"); + background-attachment: fixed; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + height: 100%; + left: -100%; + position: relative; + transform: translateX(0); + transition: transform 0.6s ease-in-out; + width: 200%; +} + +.container.right-panel-active .overlay { + transform: translateX(50%); +} + +.overlay__panel { + align-items: center; + display: flex; + flex-direction: column; + height: 100%; + justify-content: center; + position: absolute; + text-align: center; + top: 0; + transform: translateX(0); + transition: transform 0.6s ease-in-out; + width: 50%; +} + +.overlay--left { + transform: translateX(-20%); +} + +.container.right-panel-active .overlay--left { + transform: translateX(0); +} + +.overlay--right { + right: 0; + transform: translateX(0); +} + +.container.right-panel-active .overlay--right { + transform: translateX(20%); +} + +.btn { + background-color: var(--blue); + background-image: linear-gradient(90deg, var(--blue) 0%, var(--lightblue) 74%); + border-radius: 20px; + border: 1px solid var(--blue); + color: var(--white); + cursor: pointer; + font-size: 0.8rem; + font-weight: bold; + letter-spacing: 0.1rem; + padding: 0.9rem 4rem; + text-transform: uppercase; + transition: transform 80ms ease-in; +} + +.form>.btn { + margin-top: 1.5rem; +} + +.btn:active { + transform: scale(0.95); +} + +.btn:focus { + outline: none; +} + +.form { + background-color: var(--white); + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + padding: 0 3rem; + height: 100%; + text-align: center; +} + +.input { + background-color: #fff; + border: none; + padding: 0.9rem 0.9rem; + margin: 0.5rem 0; + width: 100%; +} + +@keyframes show { + + 0%, + 49.99% { + opacity: 0; + z-index: 1; + } + + 50%, + 100% { + opacity: 1; + z-index: 5; + } +} diff --git a/assets/css/all.min.css b/assets/css/all.min.css new file mode 100644 index 0000000..70ded5a --- /dev/null +++ b/assets/css/all.min.css @@ -0,0 +1,201 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background: url('/assets/img/bg.webp') no-repeat center center fixed; + background-size: cover; + color: #333; +} + +nav { + background-color: #66ccff; + color: white; + padding: 15px; + position: sticky; + top: 0; + z-index: 1000; + display: flex; + justify-content: space-between; + align-items: center; +} + +nav .logo { + color: #fff; + text-decoration: none; + font-size: 24px; +} + +nav ul { + list-style-type: none; + padding: 0; + display: flex; +} + +nav ul li { + margin-right: 20px; +} + +nav ul li:last-child { + margin-right: 0; +} + +nav a { + color: white; + text-decoration: none; + transition: color 0.3s; +} + +nav a:hover { + color: #ffcc00; +} + +.icons { + display: flex; + flex-wrap: wrap; + justify-content: center; + margin: 20px 0; +} + +.icon { + width: 200px; + margin: 10px; + text-align: center; + background-color: rgba(255, 255, 255, 0.8); + border-radius: 10px; + padding: 20px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + transition: transform 0.3s; +} + +.icon a { + color: #007BFF; + text-decoration: none; + transition: color 0.3s; +} + +.icon a:hover { + color: #ffcc00; +} + +.icon p { + margin-top: 10px; + color: #777; +} + +.icon:hover { + transform: scale(1.05); +} + +.articles { + display: flex; + justify-content: space-between; + margin: 20px; +} + +.left-column, .right-column { + width: 48%; + padding: 20px; + background-color: rgba(255, 255, 255, 0.9); + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +.left-column > a, .right-column > a { + display: inline-block; + margin-bottom: 10px; + text-decoration: none; + color: #007BFF; + transition: color 0.3s; +} + +.left-column > a:hover, .right-column > a:hover { + color: #ffcc00; +} + +.left-column small, .right-column small { + display: block; + margin-top: 10px; + color: #777; +} + + +h2 { + text-align: center; + color: #333; +} + +h3 { + color: #007BFF; +} + +textarea { + width: 100%; + height: 100px; + border-radius: 5px; + border: 1px solid #ccc; + padding: 10px; + margin-bottom: 10px; +} + +input[type="text"], input[type="password"] { + width: 100%; + padding: 10px; + margin-bottom: 10px; + border-radius: 5px; + border: 1px solid #ccc; +} + +button { + background-color: #007BFF; + color: white; + border: none; + padding: 10px 15px; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s; +} + +button:hover { + background-color: #0056b3; +} + +small { + display: block; + margin-top: 10px; + color: #777; +} + +.comment-section { + margin-top: 20px; + padding: 10px; + border-top: 1px solid #ddd; +} + +.page-footer { + background-color: #fff; + color: #66ccff; + text-align: center; + padding: 1em 0; + position: relative; +} + +.footer-content { + display: flex; + justify-content: space-between; + align-items: center; + max-width: 1200px; + margin: 0 auto; +} + +.copyright { + margin: 0; +} + +.commit-id { + margin: 0; +} + +.commit-id span { + color: #aaa; +} + diff --git a/assets/css/article.min.css b/assets/css/article.min.css new file mode 100644 index 0000000..c44a360 --- /dev/null +++ b/assets/css/article.min.css @@ -0,0 +1,168 @@ +body { + font-family: 'Arial', sans-serif; + line-height: 1.6; + color: #333; + background-color: #f4f4f4; + margin: 0; + padding: 0; +} + +.container { + width: 80%; + max-width: 1200px; + margin: 0 auto; + padding: 20px; + background: #fff; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} +nav { + background-color: #66ccff; + color: white; + padding: 15px; + position: sticky; + top: 0; + z-index: 1000; + display: flex; + justify-content: space-between; + align-items: center; +} + +nav ul { + list-style-type: none; + padding: 0; + display: flex; +} + +nav ul li { + margin-right: 20px; +} + +nav ul li:last-child { + margin-right: 0; +} + +nav a { + color: white; + text-decoration: none; + transition: color 0.3s; +} + +nav .logo { + color: #fff; + text-decoration: none; + font-size: 24px; +} + +nav a:hover { + color: #ffcc00; +} + +h2 { + text-align: center; + color: #333; +} + +small { + color: #666; +} + +hr { + border: 0; + height: 1px; + background: #ddd; + margin: 20px 0; +} + +.comment { + border-bottom: 1px solid #e0e0e0; + padding: 15px; + margin-bottom: 15px; + background-color: #fff; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); + transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out; +} + +.comment:hover { + transform: translateY(-5px); + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); +} + +.comment strong { + color: #333; + display: block; + font-size: 1.1em; + margin-bottom: 5px; +} + +.comment p { + color: #666; + font-size: 1em; +} + +.comment:last-child { + margin-bottom: 0; + border-bottom: none; +} + +/* 回复功能 还没写*/ +.comment .sub-comment { + margin-left: 20px; + border-top: 1px solid #e0e0e0; + padding-top: 10px; +} + +#comments h2 { + margin-top: 20px; + margin-bottom: 10px; + border-bottom: 1px solid #ddd; + padding-bottom: 5px; + font-size: 1.5em; +} + +form textarea { + width: 100%; + height: 100px; + padding: 10px; + box-sizing: border-box; + margin-bottom: 10px; +} + +form button { + padding: 10px 20px; + background: #333; + color: #fff; + border: none; + cursor: pointer; +} + +form button:hover { + background: #555; +} + +.page-footer { + background-color: #333; + color: #fff; + text-align: center; + padding: 1em 0; + position: relative; +} + +.footer-content { + display: flex; + justify-content: space-between; + align-items: center; + max-width: 1200px; + margin: 0 auto; +} + +.copyright { + margin: 0; +} + +.commit-id { + margin: 0; +} + +.commit-id span { + color: #aaa; +} \ No newline at end of file diff --git a/assets/css/love.min.css b/assets/css/love.min.css new file mode 100644 index 0000000..224eba8 --- /dev/null +++ b/assets/css/love.min.css @@ -0,0 +1,188 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background: url('/assets/img/bg.webp') no-repeat center center fixed; + background-size: cover; + color: #333; +} + +nav { + background-color: #66ccff; + color: white; + padding: 15px; + position: sticky; + top: 0; + z-index: 1000; + display: flex; + justify-content: space-between; + align-items: center; +} + +nav .logo { + color: #fff; + text-decoration: none; + font-size: 24px; +} + +nav ul { + list-style-type: none; + padding: 0; + display: flex; +} + +nav ul li { + margin-right: 20px; +} + +nav ul li:last-child { + margin-right: 0; +} + +nav a { + color: white; + text-decoration: none; + transition: color 0.3s; +} + +nav a:hover { + color: #ffcc00; +} + +.container { + max-width: 1200px; + margin: 0 auto; + padding: 20px; +} + +.container h1 { + text-align: center; + margin-bottom: 20px; + color: #66ccff; +} + +#loveForm { + margin-bottom: 20px; + background-color: rgba(255, 255, 255, 0.9); + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + padding: 20px; +} + +#loveForm textarea { + width: 100%; + height: 100px; + border-radius: 5px; + border: 1px solid #ccc; + padding: 10px; + margin-bottom: 10px; + resize: vertical; +} + +#loveForm button[type="submit"] { + background-color: #007BFF; + color: white; + border: none; + padding: 10px 15px; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s; +} + +#loveForm button[type="submit"]:hover { + background-color: #0056b3; +} + +#loveWall { + margin-top: 20px; + background-color: rgba(255, 255, 255, 0.9); + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + padding: 20px; +} + +.love-message { + display: flex; + align-items: center; + padding: 10px; + border-bottom: 1px solid #ddd; + margin-bottom: 10px; +} + +.love-message strong { + margin-right: 10px; +} + +.comment-section { + margin-top: 20px; + padding: 10px; + border-top: 1px solid #ddd; +} + +.comment { + display: flex; + align-items: center; + padding: 10px; + border-bottom: 1px solid #ddd; + margin-bottom: 10px; +} + +.comment strong { + margin-right: 10px; +} + +.commentForm { + margin-top: 10px; +} + +.commentForm textarea { + width: 100%; + min-height: 50px; + border-radius: 5px; + border: 1px solid #ccc; + padding: 10px; + margin-bottom: 10px; + resize: vertical; +} + +.commentForm button[type="submit"] { + background-color: #007BFF; + color: white; + border: none; + padding: 10px 15px; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s; +} + +.commentForm button[type="submit"]:hover { + background-color: #0056b3; +} + +.page-footer { + background-color: #fff; + color: #66ccff; + text-align: center; + padding: 1em 0; + position: relative; +} + +.footer-content { + display: flex; + justify-content: space-between; + align-items: center; + max-width: 1200px; + margin: 0 auto; +} + +.copyright { + margin: 0; +} + +.commit-id { + margin: 0; +} + +.commit-id span { + color: #aaa; +} \ No newline at end of file diff --git a/assets/img/bg.webp b/assets/img/bg.webp new file mode 100644 index 0000000..dba27f2 Binary files /dev/null and b/assets/img/bg.webp differ diff --git a/assets/img/logo.png b/assets/img/logo.png new file mode 100644 index 0000000..95691d3 Binary files /dev/null and b/assets/img/logo.png differ diff --git a/config.php b/config.php new file mode 100644 index 0000000..a92b503 --- /dev/null +++ b/config.php @@ -0,0 +1,27 @@ +"油二黑子站", + "account"=>"登录/注册 - 油二黑子站", + "admin"=>"管理界面 - 油二黑子站", + "love"=>"表白墙 - 油二黑子站" +); + +// 文章路由 +$article_type = Array( + "news"=>"新闻动态", + "activity"=>"活动一览" +); + +// iconfont图标库的地址 +$icon_font = '//at.alicdn.com/t/c/font_4536557_e64emmx4sxm.css'; + +// git commit id 要自己写 +$git_commits = "18ebd2d112"; + +// umami统计的地址(其他的什么也行,可以不填) +$umami= ''; +?> \ No newline at end of file diff --git a/core/Parsedown.php b/core/Parsedown.php new file mode 100644 index 0000000..cdf39e6 --- /dev/null +++ b/core/Parsedown.php @@ -0,0 +1,1694 @@ +DefinitionData = array(); + + # standardize line breaks + $text = str_replace(array("\r\n", "\r"), "\n", $text); + + # remove surrounding line breaks + $text = trim($text, "\n"); + + # split text into lines + $lines = explode("\n", $text); + + # iterate through lines to identify blocks + $markup = $this->lines($lines); + + # trim line breaks + $markup = trim($markup, "\n"); + + return $markup; + } + + # + # Setters + # + + function setBreaksEnabled($breaksEnabled) + { + $this->breaksEnabled = $breaksEnabled; + + return $this; + } + + protected $breaksEnabled; + + function setMarkupEscaped($markupEscaped) + { + $this->markupEscaped = $markupEscaped; + + return $this; + } + + protected $markupEscaped; + + function setUrlsLinked($urlsLinked) + { + $this->urlsLinked = $urlsLinked; + + return $this; + } + + protected $urlsLinked = true; + + function setSafeMode($safeMode) + { + $this->safeMode = (bool) $safeMode; + + return $this; + } + + protected $safeMode; + + protected $safeLinksWhitelist = array( + 'http://', + 'https://', + 'ftp://', + 'ftps://', + 'mailto:', + 'data:image/png;base64,', + 'data:image/gif;base64,', + 'data:image/jpeg;base64,', + 'irc:', + 'ircs:', + 'git:', + 'ssh:', + 'news:', + 'steam:', + ); + + # + # Lines + # + + protected $BlockTypes = array( + '#' => array('Header'), + '*' => array('Rule', 'List'), + '+' => array('List'), + '-' => array('SetextHeader', 'Table', 'Rule', 'List'), + '0' => array('List'), + '1' => array('List'), + '2' => array('List'), + '3' => array('List'), + '4' => array('List'), + '5' => array('List'), + '6' => array('List'), + '7' => array('List'), + '8' => array('List'), + '9' => array('List'), + ':' => array('Table'), + '<' => array('Comment', 'Markup'), + '=' => array('SetextHeader'), + '>' => array('Quote'), + '[' => array('Reference'), + '_' => array('Rule'), + '`' => array('FencedCode'), + '|' => array('Table'), + '~' => array('FencedCode'), + ); + + # ~ + + protected $unmarkedBlockTypes = array( + 'Code', + ); + + # + # Blocks + # + + protected function lines(array $lines) + { + $CurrentBlock = null; + + foreach ($lines as $line) + { + if (chop($line) === '') + { + if (isset($CurrentBlock)) + { + $CurrentBlock['interrupted'] = true; + } + + continue; + } + + if (strpos($line, "\t") !== false) + { + $parts = explode("\t", $line); + + $line = $parts[0]; + + unset($parts[0]); + + foreach ($parts as $part) + { + $shortage = 4 - mb_strlen($line, 'utf-8') % 4; + + $line .= str_repeat(' ', $shortage); + $line .= $part; + } + } + + $indent = 0; + + while (isset($line[$indent]) and $line[$indent] === ' ') + { + $indent ++; + } + + $text = $indent > 0 ? substr($line, $indent) : $line; + + # ~ + + $Line = array('body' => $line, 'indent' => $indent, 'text' => $text); + + # ~ + + if (isset($CurrentBlock['continuable'])) + { + $Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock); + + if (isset($Block)) + { + $CurrentBlock = $Block; + + continue; + } + else + { + if ($this->isBlockCompletable($CurrentBlock['type'])) + { + $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); + } + } + } + + # ~ + + $marker = $text[0]; + + # ~ + + $blockTypes = $this->unmarkedBlockTypes; + + if (isset($this->BlockTypes[$marker])) + { + foreach ($this->BlockTypes[$marker] as $blockType) + { + $blockTypes []= $blockType; + } + } + + # + # ~ + + foreach ($blockTypes as $blockType) + { + $Block = $this->{'block'.$blockType}($Line, $CurrentBlock); + + if (isset($Block)) + { + $Block['type'] = $blockType; + + if ( ! isset($Block['identified'])) + { + $Blocks []= $CurrentBlock; + + $Block['identified'] = true; + } + + if ($this->isBlockContinuable($blockType)) + { + $Block['continuable'] = true; + } + + $CurrentBlock = $Block; + + continue 2; + } + } + + # ~ + + if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) + { + $CurrentBlock['element']['text'] .= "\n".$text; + } + else + { + $Blocks []= $CurrentBlock; + + $CurrentBlock = $this->paragraph($Line); + + $CurrentBlock['identified'] = true; + } + } + + # ~ + + if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type'])) + { + $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); + } + + # ~ + + $Blocks []= $CurrentBlock; + + unset($Blocks[0]); + + # ~ + + $markup = ''; + + foreach ($Blocks as $Block) + { + if (isset($Block['hidden'])) + { + continue; + } + + $markup .= "\n"; + $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']); + } + + $markup .= "\n"; + + # ~ + + return $markup; + } + + protected function isBlockContinuable($Type) + { + return method_exists($this, 'block'.$Type.'Continue'); + } + + protected function isBlockCompletable($Type) + { + return method_exists($this, 'block'.$Type.'Complete'); + } + + # + # Code + + protected function blockCode($Line, $Block = null) + { + if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) + { + return; + } + + if ($Line['indent'] >= 4) + { + $text = substr($Line['body'], 4); + + $Block = array( + 'element' => array( + 'name' => 'pre', + 'handler' => 'element', + 'text' => array( + 'name' => 'code', + 'text' => $text, + ), + ), + ); + + return $Block; + } + } + + protected function blockCodeContinue($Line, $Block) + { + if ($Line['indent'] >= 4) + { + if (isset($Block['interrupted'])) + { + $Block['element']['text']['text'] .= "\n"; + + unset($Block['interrupted']); + } + + $Block['element']['text']['text'] .= "\n"; + + $text = substr($Line['body'], 4); + + $Block['element']['text']['text'] .= $text; + + return $Block; + } + } + + protected function blockCodeComplete($Block) + { + $text = $Block['element']['text']['text']; + + $Block['element']['text']['text'] = $text; + + return $Block; + } + + # + # Comment + + protected function blockComment($Line) + { + if ($this->markupEscaped or $this->safeMode) + { + return; + } + + if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!') + { + $Block = array( + 'markup' => $Line['body'], + ); + + if (preg_match('/-->$/', $Line['text'])) + { + $Block['closed'] = true; + } + + return $Block; + } + } + + protected function blockCommentContinue($Line, array $Block) + { + if (isset($Block['closed'])) + { + return; + } + + $Block['markup'] .= "\n" . $Line['body']; + + if (preg_match('/-->$/', $Line['text'])) + { + $Block['closed'] = true; + } + + return $Block; + } + + # + # Fenced Code + + protected function blockFencedCode($Line) + { + if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches)) + { + $Element = array( + 'name' => 'code', + 'text' => '', + ); + + if (isset($matches[1])) + { + /** + * https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes + * Every HTML element may have a class attribute specified. + * The attribute, if specified, must have a value that is a set + * of space-separated tokens representing the various classes + * that the element belongs to. + * [...] + * The space characters, for the purposes of this specification, + * are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), + * U+000A LINE FEED (LF), U+000C FORM FEED (FF), and + * U+000D CARRIAGE RETURN (CR). + */ + $language = substr($matches[1], 0, strcspn($matches[1], " \t\n\f\r")); + + $class = 'language-'.$language; + + $Element['attributes'] = array( + 'class' => $class, + ); + } + + $Block = array( + 'char' => $Line['text'][0], + 'element' => array( + 'name' => 'pre', + 'handler' => 'element', + 'text' => $Element, + ), + ); + + return $Block; + } + } + + protected function blockFencedCodeContinue($Line, $Block) + { + if (isset($Block['complete'])) + { + return; + } + + if (isset($Block['interrupted'])) + { + $Block['element']['text']['text'] .= "\n"; + + unset($Block['interrupted']); + } + + if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text'])) + { + $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1); + + $Block['complete'] = true; + + return $Block; + } + + $Block['element']['text']['text'] .= "\n".$Line['body']; + + return $Block; + } + + protected function blockFencedCodeComplete($Block) + { + $text = $Block['element']['text']['text']; + + $Block['element']['text']['text'] = $text; + + return $Block; + } + + # + # Header + + protected function blockHeader($Line) + { + if (isset($Line['text'][1])) + { + $level = 1; + + while (isset($Line['text'][$level]) and $Line['text'][$level] === '#') + { + $level ++; + } + + if ($level > 6) + { + return; + } + + $text = trim($Line['text'], '# '); + + $Block = array( + 'element' => array( + 'name' => 'h' . min(6, $level), + 'text' => $text, + 'handler' => 'line', + ), + ); + + return $Block; + } + } + + # + # List + + protected function blockList($Line) + { + list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); + + if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) + { + $Block = array( + 'indent' => $Line['indent'], + 'pattern' => $pattern, + 'element' => array( + 'name' => $name, + 'handler' => 'elements', + ), + ); + + if($name === 'ol') + { + $listStart = stristr($matches[0], '.', true); + + if($listStart !== '1') + { + $Block['element']['attributes'] = array('start' => $listStart); + } + } + + $Block['li'] = array( + 'name' => 'li', + 'handler' => 'li', + 'text' => array( + $matches[2], + ), + ); + + $Block['element']['text'] []= & $Block['li']; + + return $Block; + } + } + + protected function blockListContinue($Line, array $Block) + { + if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches)) + { + if (isset($Block['interrupted'])) + { + $Block['li']['text'] []= ''; + + $Block['loose'] = true; + + unset($Block['interrupted']); + } + + unset($Block['li']); + + $text = isset($matches[1]) ? $matches[1] : ''; + + $Block['li'] = array( + 'name' => 'li', + 'handler' => 'li', + 'text' => array( + $text, + ), + ); + + $Block['element']['text'] []= & $Block['li']; + + return $Block; + } + + if ($Line['text'][0] === '[' and $this->blockReference($Line)) + { + return $Block; + } + + if ( ! isset($Block['interrupted'])) + { + $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); + + $Block['li']['text'] []= $text; + + return $Block; + } + + if ($Line['indent'] > 0) + { + $Block['li']['text'] []= ''; + + $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); + + $Block['li']['text'] []= $text; + + unset($Block['interrupted']); + + return $Block; + } + } + + protected function blockListComplete(array $Block) + { + if (isset($Block['loose'])) + { + foreach ($Block['element']['text'] as &$li) + { + if (end($li['text']) !== '') + { + $li['text'] []= ''; + } + } + } + + return $Block; + } + + # + # Quote + + protected function blockQuote($Line) + { + if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) + { + $Block = array( + 'element' => array( + 'name' => 'blockquote', + 'handler' => 'lines', + 'text' => (array) $matches[1], + ), + ); + + return $Block; + } + } + + protected function blockQuoteContinue($Line, array $Block) + { + if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) + { + if (isset($Block['interrupted'])) + { + $Block['element']['text'] []= ''; + + unset($Block['interrupted']); + } + + $Block['element']['text'] []= $matches[1]; + + return $Block; + } + + if ( ! isset($Block['interrupted'])) + { + $Block['element']['text'] []= $Line['text']; + + return $Block; + } + } + + # + # Rule + + protected function blockRule($Line) + { + if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text'])) + { + $Block = array( + 'element' => array( + 'name' => 'hr' + ), + ); + + return $Block; + } + } + + # + # Setext + + protected function blockSetextHeader($Line, array $Block = null) + { + if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) + { + return; + } + + if (chop($Line['text'], $Line['text'][0]) === '') + { + $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; + + return $Block; + } + } + + # + # Markup + + protected function blockMarkup($Line) + { + if ($this->markupEscaped or $this->safeMode) + { + return; + } + + if (preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) + { + $element = strtolower($matches[1]); + + if (in_array($element, $this->textLevelElements)) + { + return; + } + + $Block = array( + 'name' => $matches[1], + 'depth' => 0, + 'markup' => $Line['text'], + ); + + $length = strlen($matches[0]); + + $remainder = substr($Line['text'], $length); + + if (trim($remainder) === '') + { + if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) + { + $Block['closed'] = true; + + $Block['void'] = true; + } + } + else + { + if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) + { + return; + } + + if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder)) + { + $Block['closed'] = true; + } + } + + return $Block; + } + } + + protected function blockMarkupContinue($Line, array $Block) + { + if (isset($Block['closed'])) + { + return; + } + + if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open + { + $Block['depth'] ++; + } + + if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close + { + if ($Block['depth'] > 0) + { + $Block['depth'] --; + } + else + { + $Block['closed'] = true; + } + } + + if (isset($Block['interrupted'])) + { + $Block['markup'] .= "\n"; + + unset($Block['interrupted']); + } + + $Block['markup'] .= "\n".$Line['body']; + + return $Block; + } + + # + # Reference + + protected function blockReference($Line) + { + if (preg_match('/^\[(.+?)\]:[ ]*?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches)) + { + $id = strtolower($matches[1]); + + $Data = array( + 'url' => $matches[2], + 'title' => null, + ); + + if (isset($matches[3])) + { + $Data['title'] = $matches[3]; + } + + $this->DefinitionData['Reference'][$id] = $Data; + + $Block = array( + 'hidden' => true, + ); + + return $Block; + } + } + + # + # Table + + protected function blockTable($Line, array $Block = null) + { + if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) + { + return; + } + + if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '') + { + $alignments = array(); + + $divider = $Line['text']; + + $divider = trim($divider); + $divider = trim($divider, '|'); + + $dividerCells = explode('|', $divider); + + foreach ($dividerCells as $dividerCell) + { + $dividerCell = trim($dividerCell); + + if ($dividerCell === '') + { + continue; + } + + $alignment = null; + + if ($dividerCell[0] === ':') + { + $alignment = 'left'; + } + + if (substr($dividerCell, - 1) === ':') + { + $alignment = $alignment === 'left' ? 'center' : 'right'; + } + + $alignments []= $alignment; + } + + # ~ + + $HeaderElements = array(); + + $header = $Block['element']['text']; + + $header = trim($header); + $header = trim($header, '|'); + + $headerCells = explode('|', $header); + + foreach ($headerCells as $index => $headerCell) + { + $headerCell = trim($headerCell); + + $HeaderElement = array( + 'name' => 'th', + 'text' => $headerCell, + 'handler' => 'line', + ); + + if (isset($alignments[$index])) + { + $alignment = $alignments[$index]; + + $HeaderElement['attributes'] = array( + 'style' => 'text-align: '.$alignment.';', + ); + } + + $HeaderElements []= $HeaderElement; + } + + # ~ + + $Block = array( + 'alignments' => $alignments, + 'identified' => true, + 'element' => array( + 'name' => 'table', + 'handler' => 'elements', + ), + ); + + $Block['element']['text'] []= array( + 'name' => 'thead', + 'handler' => 'elements', + ); + + $Block['element']['text'] []= array( + 'name' => 'tbody', + 'handler' => 'elements', + 'text' => array(), + ); + + $Block['element']['text'][0]['text'] []= array( + 'name' => 'tr', + 'handler' => 'elements', + 'text' => $HeaderElements, + ); + + return $Block; + } + } + + protected function blockTableContinue($Line, array $Block) + { + if (isset($Block['interrupted'])) + { + return; + } + + if ($Line['text'][0] === '|' or strpos($Line['text'], '|')) + { + $Elements = array(); + + $row = $Line['text']; + + $row = trim($row); + $row = trim($row, '|'); + + preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches); + + foreach ($matches[0] as $index => $cell) + { + $cell = trim($cell); + + $Element = array( + 'name' => 'td', + 'handler' => 'line', + 'text' => $cell, + ); + + if (isset($Block['alignments'][$index])) + { + $Element['attributes'] = array( + 'style' => 'text-align: '.$Block['alignments'][$index].';', + ); + } + + $Elements []= $Element; + } + + $Element = array( + 'name' => 'tr', + 'handler' => 'elements', + 'text' => $Elements, + ); + + $Block['element']['text'][1]['text'] []= $Element; + + return $Block; + } + } + + # + # ~ + # + + protected function paragraph($Line) + { + $Block = array( + 'element' => array( + 'name' => 'p', + 'text' => $Line['text'], + 'handler' => 'line', + ), + ); + + return $Block; + } + + # + # Inline Elements + # + + protected $InlineTypes = array( + '"' => array('SpecialCharacter'), + '!' => array('Image'), + '&' => array('SpecialCharacter'), + '*' => array('Emphasis'), + ':' => array('Url'), + '<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'), + '>' => array('SpecialCharacter'), + '[' => array('Link'), + '_' => array('Emphasis'), + '`' => array('Code'), + '~' => array('Strikethrough'), + '\\' => array('EscapeSequence'), + ); + + # ~ + + protected $inlineMarkerList = '!"*_&[:<>`~\\'; + + # + # ~ + # + + public function line($text, $nonNestables=array()) + { + $markup = ''; + + # $excerpt is based on the first occurrence of a marker + + while ($excerpt = strpbrk($text, $this->inlineMarkerList)) + { + $marker = $excerpt[0]; + + $markerPosition = strpos($text, $marker); + + $Excerpt = array('text' => $excerpt, 'context' => $text); + + foreach ($this->InlineTypes[$marker] as $inlineType) + { + # check to see if the current inline type is nestable in the current context + + if ( ! empty($nonNestables) and in_array($inlineType, $nonNestables)) + { + continue; + } + + $Inline = $this->{'inline'.$inlineType}($Excerpt); + + if ( ! isset($Inline)) + { + continue; + } + + # makes sure that the inline belongs to "our" marker + + if (isset($Inline['position']) and $Inline['position'] > $markerPosition) + { + continue; + } + + # sets a default inline position + + if ( ! isset($Inline['position'])) + { + $Inline['position'] = $markerPosition; + } + + # cause the new element to 'inherit' our non nestables + + foreach ($nonNestables as $non_nestable) + { + $Inline['element']['nonNestables'][] = $non_nestable; + } + + # the text that comes before the inline + $unmarkedText = substr($text, 0, $Inline['position']); + + # compile the unmarked text + $markup .= $this->unmarkedText($unmarkedText); + + # compile the inline + $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); + + # remove the examined text + $text = substr($text, $Inline['position'] + $Inline['extent']); + + continue 2; + } + + # the marker does not belong to an inline + + $unmarkedText = substr($text, 0, $markerPosition + 1); + + $markup .= $this->unmarkedText($unmarkedText); + + $text = substr($text, $markerPosition + 1); + } + + $markup .= $this->unmarkedText($text); + + return $markup; + } + + # + # ~ + # + + protected function inlineCode($Excerpt) + { + $marker = $Excerpt['text'][0]; + + if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(? strlen($matches[0]), + 'element' => array( + 'name' => 'code', + 'text' => $text, + ), + ); + } + } + + protected function inlineEmailTag($Excerpt) + { + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches)) + { + $url = $matches[1]; + + if ( ! isset($matches[2])) + { + $url = 'mailto:' . $url; + } + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'a', + 'text' => $matches[1], + 'attributes' => array( + 'href' => $url, + ), + ), + ); + } + } + + protected function inlineEmphasis($Excerpt) + { + if ( ! isset($Excerpt['text'][1])) + { + return; + } + + $marker = $Excerpt['text'][0]; + + if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) + { + $emphasis = 'strong'; + } + elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) + { + $emphasis = 'em'; + } + else + { + return; + } + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => $emphasis, + 'handler' => 'line', + 'text' => $matches[1], + ), + ); + } + + protected function inlineEscapeSequence($Excerpt) + { + if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) + { + return array( + 'markup' => $Excerpt['text'][1], + 'extent' => 2, + ); + } + } + + protected function inlineImage($Excerpt) + { + if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') + { + return; + } + + $Excerpt['text']= substr($Excerpt['text'], 1); + + $Link = $this->inlineLink($Excerpt); + + if ($Link === null) + { + return; + } + + $Inline = array( + 'extent' => $Link['extent'] + 1, + 'element' => array( + 'name' => 'img', + 'attributes' => array( + 'src' => $Link['element']['attributes']['href'], + 'alt' => $Link['element']['text'], + ), + ), + ); + + $Inline['element']['attributes'] += $Link['element']['attributes']; + + unset($Inline['element']['attributes']['href']); + + return $Inline; + } + + protected function inlineLink($Excerpt) + { + $Element = array( + 'name' => 'a', + 'handler' => 'line', + 'nonNestables' => array('Url', 'Link'), + 'text' => null, + 'attributes' => array( + 'href' => null, + 'title' => null, + ), + ); + + $extent = 0; + + $remainder = $Excerpt['text']; + + if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) + { + $Element['text'] = $matches[1]; + + $extent += strlen($matches[0]); + + $remainder = substr($remainder, $extent); + } + else + { + return; + } + + if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) + { + $Element['attributes']['href'] = $matches[1]; + + if (isset($matches[2])) + { + $Element['attributes']['title'] = substr($matches[2], 1, - 1); + } + + $extent += strlen($matches[0]); + } + else + { + if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) + { + $definition = strlen($matches[1]) ? $matches[1] : $Element['text']; + $definition = strtolower($definition); + + $extent += strlen($matches[0]); + } + else + { + $definition = strtolower($Element['text']); + } + + if ( ! isset($this->DefinitionData['Reference'][$definition])) + { + return; + } + + $Definition = $this->DefinitionData['Reference'][$definition]; + + $Element['attributes']['href'] = $Definition['url']; + $Element['attributes']['title'] = $Definition['title']; + } + + return array( + 'extent' => $extent, + 'element' => $Element, + ); + } + + protected function inlineMarkup($Excerpt) + { + if ($this->markupEscaped or $this->safeMode or strpos($Excerpt['text'], '>') === false) + { + return; + } + + if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w[\w-]*[ ]*>/s', $Excerpt['text'], $matches)) + { + return array( + 'markup' => $matches[0], + 'extent' => strlen($matches[0]), + ); + } + + if ($Excerpt['text'][1] === '!' and preg_match('/^/s', $Excerpt['text'], $matches)) + { + return array( + 'markup' => $matches[0], + 'extent' => strlen($matches[0]), + ); + } + + if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w[\w-]*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches)) + { + return array( + 'markup' => $matches[0], + 'extent' => strlen($matches[0]), + ); + } + } + + protected function inlineSpecialCharacter($Excerpt) + { + if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text'])) + { + return array( + 'markup' => '&', + 'extent' => 1, + ); + } + + $SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot'); + + if (isset($SpecialCharacter[$Excerpt['text'][0]])) + { + return array( + 'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';', + 'extent' => 1, + ); + } + } + + protected function inlineStrikethrough($Excerpt) + { + if ( ! isset($Excerpt['text'][1])) + { + return; + } + + if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) + { + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'del', + 'text' => $matches[1], + 'handler' => 'line', + ), + ); + } + } + + protected function inlineUrl($Excerpt) + { + if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') + { + return; + } + + if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) + { + $url = $matches[0][0]; + + $Inline = array( + 'extent' => strlen($matches[0][0]), + 'position' => $matches[0][1], + 'element' => array( + 'name' => 'a', + 'text' => $url, + 'attributes' => array( + 'href' => $url, + ), + ), + ); + + return $Inline; + } + } + + protected function inlineUrlTag($Excerpt) + { + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) + { + $url = $matches[1]; + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'a', + 'text' => $url, + 'attributes' => array( + 'href' => $url, + ), + ), + ); + } + } + + # ~ + + protected function unmarkedText($text) + { + if ($this->breaksEnabled) + { + $text = preg_replace('/[ ]*\n/', "
\n", $text); + } + else + { + $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "
\n", $text); + $text = str_replace(" \n", "\n", $text); + } + + return $text; + } + + # + # Handlers + # + + protected function element(array $Element) + { + if ($this->safeMode) + { + $Element = $this->sanitiseElement($Element); + } + + $markup = '<'.$Element['name']; + + if (isset($Element['attributes'])) + { + foreach ($Element['attributes'] as $name => $value) + { + if ($value === null) + { + continue; + } + + $markup .= ' '.$name.'="'.self::escape($value).'"'; + } + } + + if (isset($Element['text'])) + { + $markup .= '>'; + + if (!isset($Element['nonNestables'])) + { + $Element['nonNestables'] = array(); + } + + if (isset($Element['handler'])) + { + $markup .= $this->{$Element['handler']}($Element['text'], $Element['nonNestables']); + } + else + { + $markup .= self::escape($Element['text'], true); + } + + $markup .= ''; + } + else + { + $markup .= ' />'; + } + + return $markup; + } + + protected function elements(array $Elements) + { + $markup = ''; + + foreach ($Elements as $Element) + { + $markup .= "\n" . $this->element($Element); + } + + $markup .= "\n"; + + return $markup; + } + + # ~ + + protected function li($lines) + { + $markup = $this->lines($lines); + + $trimmedMarkup = trim($markup); + + if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '

') + { + $markup = $trimmedMarkup; + $markup = substr($markup, 3); + + $position = strpos($markup, "

"); + + $markup = substr_replace($markup, '', $position, 4); + } + + return $markup; + } + + # + # Deprecated Methods + # + + function parse($text) + { + $markup = $this->text($text); + + return $markup; + } + + protected function sanitiseElement(array $Element) + { + static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; + static $safeUrlNameToAtt = array( + 'a' => 'href', + 'img' => 'src', + ); + + if (isset($safeUrlNameToAtt[$Element['name']])) + { + $Element = $this->filterUnsafeUrlInAttribute($Element, $safeUrlNameToAtt[$Element['name']]); + } + + if ( ! empty($Element['attributes'])) + { + foreach ($Element['attributes'] as $att => $val) + { + # filter out badly parsed attribute + if ( ! preg_match($goodAttribute, $att)) + { + unset($Element['attributes'][$att]); + } + # dump onevent attribute + elseif (self::striAtStart($att, 'on')) + { + unset($Element['attributes'][$att]); + } + } + } + + return $Element; + } + + protected function filterUnsafeUrlInAttribute(array $Element, $attribute) + { + foreach ($this->safeLinksWhitelist as $scheme) + { + if (self::striAtStart($Element['attributes'][$attribute], $scheme)) + { + return $Element; + } + } + + $Element['attributes'][$attribute] = str_replace(':', '%3A', $Element['attributes'][$attribute]); + + return $Element; + } + + # + # Static Methods + # + + protected static function escape($text, $allowQuotes = false) + { + return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8'); + } + + protected static function striAtStart($string, $needle) + { + $len = strlen($needle); + + if ($len > strlen($string)) + { + return false; + } + else + { + return strtolower(substr($string, 0, $len)) === strtolower($needle); + } + } + + static function instance($name = 'default') + { + if (isset(self::$instances[$name])) + { + return self::$instances[$name]; + } + + $instance = new static(); + + self::$instances[$name] = $instance; + + return $instance; + } + + private static $instances = array(); + + # + # Fields + # + + protected $DefinitionData; + + # + # Read-Only + + protected $specialCharacters = array( + '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', + ); + + protected $StrongRegex = array( + '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s', + '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us', + ); + + protected $EmRegex = array( + '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', + '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', + ); + + protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?'; + + protected $voidElements = array( + 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', + ); + + protected $textLevelElements = array( + 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', + 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', + 'i', 'rp', 'del', 'code', 'strike', 'marquee', + 'q', 'rt', 'ins', 'font', 'strong', + 's', 'tt', 'kbd', 'mark', + 'u', 'xm', 'sub', 'nobr', + 'sup', 'ruby', + 'var', 'span', + 'wbr', 'time', + ); +} diff --git a/core/db.php b/core/db.php new file mode 100644 index 0000000..9397d17 --- /dev/null +++ b/core/db.php @@ -0,0 +1,13 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + echo "Connection failed: " . $e->getMessage(); +} +?> diff --git a/core/safe/waf.php b/core/safe/waf.php new file mode 100644 index 0000000..df3fda7 --- /dev/null +++ b/core/safe/waf.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/ez_site.sql b/ez_site.sql new file mode 100644 index 0000000..3812b19 --- /dev/null +++ b/ez_site.sql @@ -0,0 +1,163 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.1 +-- https://www.phpmyadmin.net/ +-- +-- 主机: 114.5.1.4 +-- 生成日期: 2024-10-19 06:27:45 +-- 服务器版本: 8.4.2 +-- PHP 版本: 8.2.23 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- 数据库: `ez_site` +-- + +-- -------------------------------------------------------- + +-- +-- 表的结构 `articles` +-- + +CREATE TABLE `articles` ( + `id` int NOT NULL, + `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `type` enum('activity','news') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- + +-- 表的结构 `comments` +-- + +CREATE TABLE `comments` ( + `id` int NOT NULL, + `user_id` int DEFAULT NULL, + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `love_wall_id` int DEFAULT NULL, + `article_id` int DEFAULT NULL, + `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- + +-- 表的结构 `love_wall` +-- + +CREATE TABLE `love_wall` ( + `id` int NOT NULL, + `user_id` int DEFAULT NULL, + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- + +-- 表的结构 `users` +-- + +CREATE TABLE `users` ( + `id` int NOT NULL, + `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `email` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL, + `group` enum('admin','user') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'user', + `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `contact` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, + `phone_number` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- + +-- 转储表的索引 +-- + +-- +-- 表的索引 `articles` +-- +ALTER TABLE `articles` + ADD PRIMARY KEY (`id`); + +-- +-- 表的索引 `comments` +-- +ALTER TABLE `comments` + ADD PRIMARY KEY (`id`), + ADD KEY `user_id` (`user_id`), + ADD KEY `love_wall_id` (`love_wall_id`), + ADD KEY `article_id` (`article_id`); + +-- +-- 表的索引 `love_wall` +-- +ALTER TABLE `love_wall` + ADD PRIMARY KEY (`id`), + ADD KEY `user_id` (`user_id`); + +-- +-- 表的索引 `users` +-- +ALTER TABLE `users` + ADD PRIMARY KEY (`id`), + ADD UNIQUE KEY `username` (`username`); + +-- +-- 在导出的表使用AUTO_INCREMENT +-- + +-- +-- 使用表AUTO_INCREMENT `articles` +-- +ALTER TABLE `articles` + MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; + +-- +-- 使用表AUTO_INCREMENT `comments` +-- +ALTER TABLE `comments` + MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21; + +-- +-- 使用表AUTO_INCREMENT `love_wall` +-- +ALTER TABLE `love_wall` + MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23; + +-- +-- 使用表AUTO_INCREMENT `users` +-- +ALTER TABLE `users` + MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=82; + +-- +-- 限制导出的表 +-- + +-- +-- 限制表 `comments` +-- +ALTER TABLE `comments` + ADD CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`), + ADD CONSTRAINT `comments_ibfk_2` FOREIGN KEY (`love_wall_id`) REFERENCES `love_wall` (`id`), + ADD CONSTRAINT `comments_ibfk_3` FOREIGN KEY (`article_id`) REFERENCES `articles` (`id`); + +-- +-- 限制表 `love_wall` +-- +ALTER TABLE `love_wall` + ADD CONSTRAINT `love_wall_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`); +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..95691d3 Binary files /dev/null and b/favicon.ico differ diff --git a/import.sql b/import.sql new file mode 100644 index 0000000..4d47ab5 --- /dev/null +++ b/import.sql @@ -0,0 +1,39 @@ +CREATE TABLE users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + `email` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL, + `group` ENUM('admin', 'user') DEFAULT 'user', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + contact VARCHAR(255) NULL + `phone_number` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL +); + +CREATE TABLE love_wall ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT, + content TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id) +); + +CREATE TABLE articles ( + id INT AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(255) NOT NULL, + content TEXT NOT NULL, + `type` ENUM('activity', 'news') NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE comments ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT, + content TEXT NOT NULL, + love_wall_id INT DEFAULT NULL, + article_id INT DEFAULT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id), + FOREIGN KEY (love_wall_id) REFERENCES love_wall(id), + FOREIGN KEY (article_id) REFERENCES articles(id) +); + diff --git a/includes/account.php b/includes/account.php new file mode 100644 index 0000000..708d740 --- /dev/null +++ b/includes/account.php @@ -0,0 +1,67 @@ + + + +
+ +
+
+

登录

+ + +

+ 忘记密码? +
+
+ + +
+
+ +

注册

+ + + + +
+
+ + +
+
+
+

已经有帐号了?

+ +
+
+ +
+
+
+
+ + + + \ No newline at end of file diff --git a/includes/admin.php b/includes/admin.php new file mode 100644 index 0000000..8057eee --- /dev/null +++ b/includes/admin.php @@ -0,0 +1,46 @@ + + +

后台管理 - 发布文章

+ + 登录后访问此页面。

"; + exit; + } + + $stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); + $stmt->execute([$_SESSION['user_id']]); + $user = $stmt->fetch(); + + if ($user['group'] !== 'admin') { + echo "

您没有权限访问此页面。

"; + exit; + } + + // 发布文章逻辑 + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $title = $_POST['title']; + $content = $_POST['content']; + $type = $_POST['type']; // 获取文章类型 + + $stmt = $pdo->prepare("INSERT INTO articles (title, content, type, created_at) VALUES (?, ?, ?, NOW())"); + if ($stmt->execute([$title, $content, $type])) { + echo "

文章发布成功!

"; + } else { + echo "

文章发布失败!

"; + } + } + ?> + +
+ + + + +
+ + \ No newline at end of file diff --git a/includes/article.php b/includes/article.php new file mode 100644 index 0000000..d3b272a --- /dev/null +++ b/includes/article.php @@ -0,0 +1,108 @@ +prepare("SELECT * FROM articles WHERE id = ?"); +$stmt->execute([$article_id]); +$article = $stmt->fetch(); +?> + + + + + + + + + + + + + + "> + + + + + + + + <?php echo "{$article['title']} - 油田二中黑子站"; ?> + + + + + + + + +
+ {$article['title']}"; + echo "
发布于: {$article['created_at']}
"; + echo "
分类: {$article_type[$article['type']]}
"; + echo "

{$article['content']}

"; + ?> + +

评论区

+
+ prepare("SELECT comments.content, users.username FROM comments JOIN users ON comments.user_id = users.id WHERE article_id = ? ORDER BY comments.created_at DESC"); + $commentStmt->execute([$article_id]); + while ($comment = $commentStmt->fetch()) { + echo "
{$comment['username']}: {$comment['content']}
"; + } + ?> +
+ + +
+ + +
+ +

登录后发表评论。

+ +
+ + + + + \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..cb9f121 --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..0a31668 --- /dev/null +++ b/includes/header.php @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + <?php echo $page_title[$page] ?> + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/includes/home.php b/includes/home.php new file mode 100644 index 0000000..bf3dc0e --- /dev/null +++ b/includes/home.php @@ -0,0 +1,61 @@ +
+
+ + 距离下一次大休还有

' . $days . '

'; + } else { + $remainingDays = $firstPeriodDays - $currentPeriod; + $remainingTime = $remainingDays * (60 * 60 * 24) + $extraHours * (60 * 60); + $days = floor($remainingTime / (60 * 60 * 24)); + echo '

距离开学还有

1

'; + } + } + + $startDate = '2024-10-06 16:25:00'; // 开始计时的日期 + $firstPeriodDays = 12; // 第一阶段的天数 + $secondPeriodDays = 2; // 第二阶段的天数 + $extraHours = 0; // 额外的小时数 + $countdownText = startCountdown($startDate, $firstPeriodDays, $secondPeriodDays, $extraHours); + ?> +
+
+

今天油二

+ 没有爆炸 +
+ +
+
+
+

活动一览

+ query("SELECT * FROM articles WHERE type = 'activity' ORDER BY created_at DESC"); + while ($row = $stmt->fetch()) { + echo "

{$row['title']}

"; + echo "

{$row['content']}

"; + echo "发布于: {$row['created_at']}
"; + } + ?> +
+
+

新闻动态

+ query("SELECT * FROM articles WHERE type = 'news' ORDER BY created_at DESC"); + while ($row = $stmt->fetch()) { + echo "

{$row['title']}

"; + echo "

{$row['content']}

"; + echo "发布于: {$row['created_at']}
"; + } + ?> +
+
\ No newline at end of file diff --git a/includes/love.php b/includes/love.php new file mode 100644 index 0000000..79abce7 --- /dev/null +++ b/includes/love.php @@ -0,0 +1,83 @@ +
+

表白墙

+ + +
+
+ +
+ +
+ +

登录后发表内容。

+ + +

表白内容

+
+ prepare("SELECT love_wall.id, love_wall.content, users.username FROM love_wall JOIN users ON love_wall.user_id = users.id ORDER BY love_wall.created_at DESC"); + $stmt->execute(); + while ($row = $stmt->fetch()) { + echo "
" . htmlspecialchars($row['username']) . ": " . htmlspecialchars($row['content']) . "
"; + echo "
"; + + // 加载评论 + $commentStmt = $pdo->prepare("SELECT comments.content, users.username FROM comments JOIN users ON comments.user_id = users.id WHERE love_wall_id = ? ORDER BY comments.created_at DESC"); + $commentStmt->execute([$row['id']]); + while ($comment = $commentStmt->fetch()) { + echo "
" . htmlspecialchars($comment['username']) . ": " . htmlspecialchars($comment['content']) . "
"; + } + echo "
"; + + if (isset($_SESSION['user_id'])) { + echo "
"; + echo ""; + echo ""; + echo "
"; + } + + echo "
"; + } + ?> +
+
+ + + + \ No newline at end of file diff --git a/includes/time.php b/includes/time.php new file mode 100644 index 0000000..dadb8e9 --- /dev/null +++ b/includes/time.php @@ -0,0 +1,31 @@ + + + + + + 2 Seconds Countdown Redirect + + + +

!,将在 2 秒后跳转至

+ + + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..fa7048e --- /dev/null +++ b/index.php @@ -0,0 +1,33 @@ + diff --git a/rewrite.conf b/rewrite.conf new file mode 100644 index 0000000..c4aac7c --- /dev/null +++ b/rewrite.conf @@ -0,0 +1,5 @@ +rewrite ^/article/([^.]+)\.html$ /?page=article&id=$1 last; +rewrite ^/love\.html$ /?page=love last; +rewrite ^/account\.html$ /?page=account last; +rewrite ^/home\.html$ /?page=home last; +rewrite ^/admin\.html$ /?page=admin last; \ No newline at end of file