Skip to content
Permalink
Browse files

Huge Update

All right now I lost my ability to write in English but I have already built a large vocabulary in my brain. Let me write a list of the changes of this update:

* Used SQLite3 for database. (Don't worry for SQL injection, I've set many protections.)
* Improved naming of functions and variables. (I learnt more better words for replacements)
* Improved README quality. (The same reason as above update).
* Added a visible installation page.
* Added admin management page. (Unfinished.)

Enjoy this update or download the original version!
  • Loading branch information...
DFFZMXJ committed Jan 17, 2019
1 parent 42e5e29 commit 3ffff0488d71b6dd1b58132e04c2090ecd96fce3
Showing with 2,717 additions and 1,833 deletions.
  1. +36 −23 Readme.md
  2. +68 −159 api.php
  3. +5 −1 auth.php
  4. +100 −0 console.php
  5. +12 −3 index.php
  6. +82 −99 intialize.php
  7. +99 −87 intrduction.html
  8. +21 −16 javascript.js
  9. +1,401 −1,405 markdown.php
  10. +17 −2 nav.php
  11. +3 −3 profile.php
  12. +15 −0 properties.php
  13. +49 −0 setup.html
  14. +53 −0 setup.php
  15. +38 −0 setup.sql
  16. +657 −0 sqlite.php
  17. +17 −2 stylesheet.css
  18. +44 −33 view.php
@@ -1,47 +1,60 @@
How tired it is of updating! So don't modify your own source code easily!

# 5 Minute Forum

5 Minute Forum is a simple forum written with PHP.

## I don't understand English, what to do?
This document is still improving. When I learned more about English, I'll update this document again.

## Help! I don't understand English!

This resource code based a Chinese document : `project/introduction.html`. If you really don't understand English ~~(Or I wrote too many wrongs)~~ , please read this document.

## Why will I program this forum

This resource code based a Chinese document at `profect/intrduction.html`. If you can't read English ~~(Or I wrote too many syntax errors)~~ , please read here.
Here are the reasons of why I program this fourm:

翻译:
* To show you how excellent I am. (用中文说就是装X)
* To help you with the structure of a forum software.
* To help you build a forum.
* To record as a video and publish to Bilibili.
* To pratiece myself.
* To...

> ## 我不造英文,咋办?
> 本源代码包涵一份中文文档`项目目录/intrduction.html`。如果你真读不懂英语 ~~(或者我写的错误太多)~~ ,可以读读这里。
## Migrate from old version

## Why make this forum
Originally I don't want to open this category because no one who I found is using my forum. But after a deep thinking, I decieded to write here.

I don't want to fight with other forum softwares with this forum, this forum is just to teach noobs the structure of the a forum software, or let them modify and use in production easier. Also, this software can tell you my technology level then get the way to learn more.
Please write a script yourself to realize this feature, or get help from me with migration.

## Features

* Store data into JSON files.
* Submit post and reply.
* Press likes for posts and replies.
* Add VIP to users.
* No frameworks based.
* Use SQLite for database. (Used JSON in initial version)
* Post and comment.
* Like and reply to a comment.
* VIP users.
* Native PHP.

## Installtion

1. Download/Clone this repository.
2. Move files to the path of you want to install.
3. Visit `http://name.domain/path/install.php`. (install.php)
4. Completed!
3. Access `http://name.domain/path/setup.php`. (setup.php)
4. Fill basic information and click "Setup" button.
5. WINNER WINNER CHICKEN DINNER!

## I don't recommed you to use
## Don't use in production

This forum is just let me show you my techonology, I don't recommed you to use this software because:
I've told you this forum is to show how excellent I am. There are lots of found bugs at this forum:

* If too many users submitted data at same time, JSON database may occure errors.
* No administration tools based, you can't manage posts with user interface.
* Doesn't support lots users access at same time.
* No administration console, so you must modify database to manage the forum.
* Doesn't support tags and categories, you can't category posts.
* Doesn't support pages, if too many posts and replies existed, browser maybe crash. (No matter how your computer's performance good)
* No XSS protection and evil HTML filter, users will break the forum by changig the script.(e.g. send cookies to another server with AJAX.)
* Doesn't support multi-pages, if too many posts and replies existed, browser maybe crash. (No matter how your computer's performance amazing)
* No XSS protection, users will attack the forum by evil code.(e.g. steal user cookies with AJAX.)

You can improve this software easily, because it's too simple!
You can improve this forum if you can.

## Contact
## Contact Me

To contact me, add my QQ `2477819731` as your contact, or post on [my forum](https://forum.dffzmxj.tk).
To contact me, add my QQ `2477819731` as your contact, or post at [my forum](https://forum.dffzmxj.com).
227 api.php
@@ -1,10 +1,11 @@
<?php
/*APIs of the fourm*/
/*Opened APIs of the fourm.*/
require "intialize.php";
function auto_header($state,$content_type){
/*Set based headers automatically.*/
$status = [
function api_puts($status=0,$message,$data=null,$continue_processing=false){
/*Return formated JSON automatically.*/
$status_list = [
/*Status list*/
0 => "HTTP/1.1 0 Undefined",
100 => "HTTP/1.1 100 Continue",
101 => "HTTP/1.1 101 Switching Protocols",
200 => "HTTP/1.1 200 OK",
@@ -46,189 +47,97 @@ function auto_header($state,$content_type){
504 => "HTTP/1.1 504 Gateway Time-out"
];
/*Set the headers.*/
header($status[$state]);
header("Content-type:".$content_type);
header($status_list[$status]);
header("Content-type: application/json");
echo json_encode([
'status'=>$status,
'message'=>$message,
'data'=>$data
],JSON_PRETTY_PRINT);//Optimize JSON appearence
if(!$continue_processing) exit();//exit==die
return true;
}
$_POST = json_decode(file_get_contents("php://input"),true);
if(empty($_GET['thing'])){
/*Default return*/
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'You must enter enough information!'
],JSON_PRETTY_PRINT));
/**
* I wanted to change the attribute 'thing' to 'operation',
* but I'm lazy to change JavaScript file, sorry.
*/
api_puts(406,'Operation is undefined!');
}else switch(strtolower($_GET['thing'])){
case 'signin':
/*Log in*/
if(empty($_POST['username'])||empty($_POST['password'])){
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'Username and password cannot be empty!'
],JSON_PRETTY_PRINT));
}else{
if(($logged = User::login($_POST['username'],$_POST['password'],true))['logged']){
auto_header(200,"application/json");
die(json_encode([
'status'=>200,
'message'=>$logged['message']
],JSON_PRETTY_PRINT));
}else{
auto_header(401,"application/json");
die(json_encode([
'status'=>401,
'message'=>$logged['message']
],JSON_PRETTY_PRINT));
}
}
if(empty($_POST['username'])||empty($_POST['password']))
api_puts(406,'Username or password are empty!');
else if(($logged = User::login($_POST['username'],$_POST['password'],true))['logged'])
api_puts(200,$logged['message']);
else
api_puts(401,$logged['message']);
break;
case 'signup':
/*Register a new account*/
if(User::logged()){
auto_header(403,"application/json");
die(json_encode([
'status'=>403,
'message'=>'You are already signed in!'
],JSON_PRETTY_PRINT));
}
if(empty($_POST['username'])||empty($_POST['password'])||empty($_POST['gender'])){
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'Username, password and gender cannot be empty!'
],JSON_PRETTY_PRINT));
}else{
if(($registered = User::register($_POST['username'],$_POST['password'],$_POST['gender']))['registered']){
if(User::logged()) api_puts(403,'You\'ve already signed in!');
if(empty($_POST['username'])||empty($_POST['password'])||empty($_POST['gender']))
api_puts(406,'Username, password or gender are empty!');
else if(($registered = User::register($_POST['username'],$_POST['password'],$_POST['gender']))['registered']){
User::login($_POST['username'],$_POST['password'],true);
auto_header(201,"application/json");
die(json_encode([
'status'=>201,
'message'=>$registered['message']
],JSON_PRETTY_PRINT));
}else{
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>$registered['message']
],JSON_PRETTY_PRINT));
}
}
api_puts(201,$registered['message']);
}else
api_puts(406,$registered['message']);
break;
case 'signout':
if(!User::logged()){
auto_header(401,"application/json");
die(json_encode([
'status'=>401,
'message'=>'You are not signed in!'
],JSON_PRETTY_PRINT));
}else{
auto_header(200,"application/json");
die(json_encode([
'status'=>200,
'message'=>User::logout()['message']
],JSON_PRETTY_PRINT));
}
if(!User::logged())
api_puts(401,'You are not signed in!');
else
api_puts(200,User::logout()['message']);
break;
case 'post':
if(!User::logged()){
auto_header(401,"application/json");
die(json_encode([
'status'=>401,
'message'=>'You are not signed in!'
],JSON_PRETTY_PRINT));
}else if(empty($_POST['title'])||empty($_POST['content'])){
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'Title and content cannot be empty!'
],JSON_PRETTY_PRINT));
}else{
if(($created = Post::create($_POST['title'],$_POST['content']))['created']){
auto_header(201,"application/json");
die(json_encode([
'status'=>201,
'message'=>$created['message'],
'post'=>$created['id']
],JSON_PRETTY_PRINT));
}else{
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>$created['message']
],JSON_PRETTY_PRINT));
}
}
if(!User::logged())
api_puts(401,'You\'re not signed in!');
else if(empty($_POST['title'])||empty($_POST['content']))
api_puts(401,'Title or content are empty!');
else if(($created = Post::create($_POST['title'],$_POST['content']))['created'])
api_puts(201,$created['message'],[
'post'=>$created['id']
]);
else
api_puts(406,$created['message']);
break;
case 'reply':
if(!User::logged()){
auto_header(401,"application/json");
die(json_encode([
'status'=>401,
'message'=>'You are not signed in!'
],JSON_PRETTY_PRINT));
}else if(empty($_POST['content'])||empty($_POST['post'])){
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'Content, post-id and replied-to options cannot be empty!'
],JSON_PRETTY_PRINT));
}else if(($replied = Post::reply($_POST["post"],$_POST["content"],$_POST["repliedto"]?$_POST['repliedto']:null))['replied']){
auto_header(201,"application/json");
die(json_encode([
'status'=>201,
'message'=>'Replied!',
if(!User::logged())
api_puts(401,"You're not signed in!");
else if(empty($_POST['content'])||empty($_POST['post']))
api_puts(406,"Contents and Post ID are requried!");
else if(($replied = Post::reply($_POST["post"],$_POST["content"],$_POST["repliedto"]?$_POST['repliedto']:null))['replied'])
api_puts(201,'Replied!',[
'repliedTo'=>$replied['replied_to'],
'floor'=>$replied['reply_floor'],
'content'=>$replied['marked_content'],
'id'=>$_POST['post']
],JSON_PRETTY_PRINT));
}else{
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>$replied['message']
],JSON_PRETTY_PRINT));
}
]);
else
api_puts(406,$replied['message']);
break;
case 'like':
/*Like/Unlike a post/reply.*/
if(!User::logged()){
auto_header(401,"application/json");
die(json_encode([
'status'=>401,
'message'=>'You are not signed in!'
],JSON_PRETTY_PRINT));
}else if(empty($_POST['type'])||empty($_POST['id'])){
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'ID and like-type options cannot be empty!'
],JSON_PRETTY_PRINT));
}else if(($liked = Post::like($_POST['type'],$_POST['id']))){
auto_header(200,"application/json");
die(json_encode([
'status'=>200,
'message'=>$liked['message'],
'liked'=>$liked['nowStatus'],
'fullStr'=>isset($_POST['fullStr'])?$_POST['fullStr']:'{}'
],JSON_PRETTY_PRINT));
}else{
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>$liked['message']
],JSON_PRETTY_PRINT));
}
if(!User::logged())
api_puts(401,'You are not signed in!');
else if(empty($_POST['type'])||empty($_POST['id']))
api_puts(406,'Type and ID are required!');
else if(($liked = Post::like($_POST['type'],$_POST['id'])))
api_puts(200,$liked['message'],[
'liked'=>$liked['currentStatus'],
'fullString'=>isset($_POST['fullStr'])?$_POST['fullStr']:'{}'
]);
else
api_puts(406,$liked['message']);
break;
case 'info-modify':
/*Coming in future: user information edit.*/
api_puts(503,"Operation is not supported!");
break;
default:
/*If user did unsupported action.*/
auto_header(406,"application/json");
die(json_encode([
'status'=>406,
'message'=>'Your operation is unsupported!'
],JSON_PRETTY_PRINT));
api_puts(404,"Operation not found!");
break;
}
@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width" />
<meta name="page-sign-verified" />
<link rel="stylesheet" href="stylesheet.css"/>
<title>Sign In - <?php echo $config["sitename"];?></title>
<title>Sign In - <?php echo Property::$properties["forum"]['name'];?></title>
<style>
#sign-up{
display:none;
@@ -24,6 +24,10 @@
.card-content{
height:auto;
}
body{
height:100vh;
background:linear-gradient(to right bottom, #90FF2A,#20ADCA);
}
</style>
</head>
<body>

1 comment on commit 3ffff04

@DFFZMXJ

This comment has been minimized.

Copy link
Owner Author

commented on 3ffff04 Jan 17, 2019

哎呀呀,忘记在GitHub上删除install.php了。

Please sign in to comment.
You can’t perform that action at this time.