Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
17-2-2019
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttonyhe committed Feb 17, 2019
1 parent 50210be commit ac90ebb
Show file tree
Hide file tree
Showing 108 changed files with 17,181 additions and 271 deletions.
8 changes: 8 additions & 0 deletions 404.php
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>
30 changes: 0 additions & 30 deletions README.md

This file was deleted.

30 changes: 30 additions & 0 deletions com/ArtalkServer.php
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);
}
}
9 changes: 9 additions & 0 deletions com/Config.php
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' => '']
],
];
27 changes: 27 additions & 0 deletions com/composer.json
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"
}
}
}
73 changes: 73 additions & 0 deletions com/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions com/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
143 changes: 143 additions & 0 deletions com/lib/Action.php
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]);
}
}
23 changes: 23 additions & 0 deletions com/lib/Http.php
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
];
}
}
Loading

0 comments on commit ac90ebb

Please sign in to comment.