This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
108 changed files
with
17,181 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php get_header();?> | ||
<div id="header_info"> | ||
<nav class="header-nav reveal"> | ||
<a style="text-decoration:none;" href="https://www.ouorz.com" class="header-logo" title="TonyHe">404 :)</a> | ||
<p class="lead" style="margin-top: 0px;display:block">抱歉,你请求的页面不存在</p> | ||
<a href="https://www.ouorz.com" style="padding: 4px 18px 6px 19px;border: 2px solid rgb(0, 123, 255);border-radius: 4px;font-weight: 600;line-height: 80px;text-decoration:none">返回主页</a> | ||
</nav> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
use Lazer\Classes\Database as Lazer; | ||
|
||
class ArtalkServer { | ||
use lib\Action; | ||
use lib\Table; | ||
use lib\Http; | ||
use lib\Permission; | ||
use lib\Util; | ||
|
||
private $conf; | ||
|
||
public function __construct($conf) | ||
{ | ||
$this->conf = $conf; | ||
|
||
$this->allowOriginControl(); | ||
$this->initTables(); | ||
|
||
$actionName = $_GET['action'] ?? $_POST['action'] ?? null; | ||
$methodName = "action{$actionName}"; | ||
if (method_exists($this, $methodName)) { | ||
$result = $this->{$methodName}(); | ||
} else { | ||
$result = $this->error('这是哪?我要干什么?现在几点?蛤?什么鬼!?(╯‵□′)╯︵┴─┴'); | ||
} | ||
|
||
echo json_encode($result, JSON_UNESCAPED_UNICODE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
return [ | ||
'allow_origin' => [ | ||
'https://www.ouorz.com' | ||
], | ||
'admin_users' => [ | ||
['nick' => 'TonyHe', 'email' => '[email protected]', 'password' => ''] | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "qwqcode/artalk-server-php", | ||
"type": "project", | ||
"license": "GPL-2.0", | ||
"authors": [ | ||
{ | ||
"name": "qwqcode", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"PHP": ">=7.0", | ||
"ext-json": "*", | ||
"greg0/lazer-database": "^1.1" | ||
}, | ||
"scripts": { | ||
"dev": "php -S localhost:23366 -t public" | ||
}, | ||
"config": { | ||
"process-timeout": 0 | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"lib\\": "lib" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
namespace lib; | ||
|
||
trait Action | ||
{ | ||
public function actionAdminCheck() | ||
{ | ||
$nick = trim($_POST['nick'] ?? ''); | ||
$email = trim($_POST['email'] ?? ''); | ||
$password = trim($_POST['password'] ?? ''); | ||
if (empty($nick)) return $this->error('昵称 不能为空'); | ||
if (empty($email)) return $this->error('邮箱 不能为空'); | ||
if (empty($password)) return $this->error('密码 不能为空'); | ||
|
||
if (!$this->isAdmin($nick, $email)) { | ||
return $this->error('无需管理员权限'); | ||
} | ||
if ($this->checkAdminPassword($nick, $email, $password)) { | ||
return $this->success('密码正确'); | ||
} else { | ||
return $this->error('密码错误'); | ||
} | ||
} | ||
|
||
public function actionCommentAdd() | ||
{ | ||
$content = trim($_POST['content'] ?? ''); | ||
$nick = trim($_POST['nick'] ?? ''); | ||
$email = trim($_POST['email'] ?? ''); | ||
$link = trim($_POST['link'] ?? ''); | ||
$rid = intval(trim($_POST['rid'] ?? 0)); | ||
$pageKey = trim($_POST['page_key'] ?? ''); | ||
$ua = $_SERVER['HTTP_USER_AGENT'] ?? ''; | ||
$password = trim($_POST['password'] ?? ''); | ||
|
||
if (empty($pageKey)) return $this->error('pageKey 不能为空'); | ||
if (empty($nick)) return $this->error('昵称不能为空'); | ||
if (empty($email)) return $this->error('邮箱不能为空'); | ||
if (empty($content)) return $this->error('内容不能为空'); | ||
|
||
if ($this->isAdmin($nick, $email) && !$this->checkAdminPassword($nick, $email, $password)) { | ||
return $this->error('需要管理员身份', ['need_password' => true]); | ||
} | ||
if (!empty($link) && !$this->urlValidator($link)) { | ||
return $this->error('链接不是 URL'); | ||
} | ||
|
||
$commentData = [ | ||
'content' => $content, | ||
'nick' => $nick, | ||
'email' => $email, | ||
'link' => $link, | ||
'page_key' => $pageKey, | ||
'rid' => $rid, | ||
'ua' => $ua, | ||
'date' => date("Y-m-d H:i:s"), | ||
'ip' => $this->getUserIP() | ||
]; | ||
$comment = self::getCommentsTable(); | ||
$comment->set($commentData); | ||
$comment->save(); | ||
|
||
$commentData['id'] = $comment->lastId(); | ||
return $this->success('评论成功', ['comment' => $this->beautifyCommentData($commentData)]); | ||
} | ||
|
||
public function actionCommentGet() | ||
{ | ||
$pageKey = trim($_POST['page_key'] ?? ''); | ||
if (empty($pageKey)) { | ||
return $this->error('page_key 不能为空'); | ||
} | ||
|
||
$commentsRaw = self::getCommentsTable() | ||
->where('page_key', '=', $pageKey) | ||
->orderBy('date', 'DESC') | ||
->findAll() | ||
->asArray(); | ||
|
||
$comments = []; | ||
foreach ($commentsRaw as $item) { | ||
$comments[] = $this->beautifyCommentData($item); | ||
} | ||
|
||
return $this->success('获取成功', ['comments' => $comments]); | ||
} | ||
|
||
private function beautifyCommentData($rawComment) | ||
{ | ||
$comment = []; | ||
$showField = ['id', 'content', 'nick', 'link', 'page_key', 'rid', 'ua', 'date']; | ||
foreach ($rawComment as $key => $value) { | ||
if (in_array($key, $showField)) { | ||
$comment[$key] = $value; | ||
} | ||
} | ||
|
||
$comment['email_encrypted'] = md5(strtolower(trim($rawComment['email']))); | ||
$comment['badge'] = null; | ||
if ($this->isAdmin($rawComment['nick'] ?? null, $rawComment['email'] ?? null)) { | ||
$comment['badge'] = '管理员'; | ||
} | ||
return $comment; | ||
} | ||
|
||
public function actionCommentReplyGet() | ||
{ | ||
$nick = trim($_POST['nick'] ?? ''); | ||
$email = trim($_POST['email'] ?? ''); | ||
if (empty($nick)) return $this->error('昵称 不能为空'); | ||
if (empty($email)) return $this->error('邮箱 不能为空'); | ||
|
||
$replyRaw = self::getCommentsTable(); | ||
|
||
if (!$this->isAdmin($nick, $email)) { | ||
$myComments = self::getCommentsTable() | ||
->where('nick', '=', $nick) | ||
->andWhere('email', '=', $email) | ||
->orderBy('date', 'DESC') | ||
->findAll() | ||
->asArray(); | ||
|
||
$idList = []; | ||
foreach ($myComments as $item) { | ||
$idList[] = $item['id']; | ||
} | ||
|
||
$replyRaw = $replyRaw->where('rid', 'IN', $idList); | ||
} | ||
|
||
$replyRaw = $replyRaw | ||
->orderBy('date', 'DESC') | ||
->findAll() | ||
->asArray(); | ||
|
||
$reply = []; | ||
foreach ($replyRaw as $item) { | ||
$reply[] = $this->beautifyCommentData($item); | ||
} | ||
|
||
return $this->success('获取成功', ['reply_comments' => $reply]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace lib; | ||
|
||
trait Http | ||
{ | ||
private function success($msg = null, $data = null) | ||
{ | ||
return [ | ||
'success' => true, | ||
'msg' => $msg, | ||
'data' => $data | ||
]; | ||
} | ||
|
||
private function error($msg = null, $data = null) | ||
{ | ||
return [ | ||
'success' => false, | ||
'msg' => $msg, | ||
'data' => $data | ||
]; | ||
} | ||
} |
Oops, something went wrong.