Skip to content
This repository was archived by the owner on Jun 25, 2022. It is now read-only.

Commit b3a0d14

Browse files
authored
Merge pull request #7 from elyday/0.2
0.2.0
2 parents e20bb58 + 68bc8c4 commit b3a0d14

28 files changed

+1350
-276
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ DB_PASSWORD=secret
1515

1616
CACHE_DRIVER=file
1717
QUEUE_DRIVER=sync
18+
19+
CAPTCHA_SECRET=captcha
20+
21+
AUTH0_API_AUDIENCE=
22+
AUTH0_DOMAIN=

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# PHP Comment Server
2+
[![Build Status](https://travis-ci.org/elyday/comment-server.svg)](https://travis-ci.org/elyday/comment-server)
3+
[![Total Downloads](https://poser.pugx.org/elyday/comment-server/downloads)](https://packagist.org/packages/elyday/comment-server)
4+
[![License](https://poser.pugx.org/elyday/comment-server/license.svg)](https://packagist.org/packages/elyday/comment-server)
5+
[![Latest Stable Version](https://poser.pugx.org/elyday/comment-server/v/stable.svg)](https://packagist.org/packages/elyday/comment-server)
6+
[![Latest Unstable Version](https://poser.pugx.org/elyday/comment-server/v/unstable.svg)](https://packagist.org/packages/elyday/comment-server)
7+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/elyday/comment-server/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/elyday/comment-server/?branch=master)
8+
[![Code Coverage](https://scrutinizer-ci.com/g/elyday/comment-server/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/elyday/comment-server/?branch=master)
9+
10+
This comment server was written using the [PHP Microframework Lumen](https://lumen.laravel.com/) and is used to store, moderate and read comments.
11+
12+
## Configuration
13+
1. To use the Comment Server you must first copy the file `.env.example` and rename it to `.env`.
14+
2. Then you have to specify a key for the app under `APP_KEY` (best with the head over the keyboard).
15+
3. Now you have to enter your database configuration in the `DB_` section. This includes address, user name and password.
16+
4. With `CAPTCHA_SECRET` you now have to define a captcha. This must be answered or sent as soon as someone wants to write a comment.
17+
5. wip...

_ide_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* A helper file for Laravel 5, to provide autocomplete information to your IDE
4-
* Generated for Laravel Lumen (5.6.3) (Laravel Components 5.6.*) on 2018-04-10 13:41:42.
4+
* Generated for Laravel Lumen (5.6.3) (Laravel Components 5.6.*) on 2018-04-20 08:37:22.
55
*
66
* This file should not be included in your code, only analyzed by your IDE!
77
*

app/Blog.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88
/**
99
* Class Blog
1010
*
11-
* @property int $id
11+
* @package App
12+
* @property string $hash
1213
* @property string $name
1314
* @property string $description
1415
* @property string $url
1516
* @property \Carbon\Carbon|null $created_at
1617
* @property \Carbon\Carbon|null $updated_at
1718
* @method static Builder|Blog whereCreatedAt($value)
1819
* @method static Builder|Blog whereDescription($value)
19-
* @method static Builder|Blog whereId($value)
20+
* @method static Builder|Blog whereHash($value)
2021
* @method static Builder|Blog whereName($value)
2122
* @method static Builder|Blog whereUpdatedAt($value)
2223
* @method static Builder|Blog whereUrl($value)
23-
* @method static Builder|Blog whereHash($value)
2424
* @mixin \Eloquent
25-
* @property string $hash
2625
*/
2726
class Blog extends Model
2827
{
2928
protected $table = "blog";
29+
protected $primaryKey = "hash";
30+
protected $keyType = "varchar";
3031

3132
protected $fillable = [
32-
'name', 'description', 'url'
33+
'hash',
34+
'name',
35+
'description',
36+
'url'
3337
];
3438

35-
protected $hidden = [
36-
'hash'
37-
];
39+
protected $hidden = [];
3840
}

app/BlogArticle.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
* Class BlogArticle
1010
*
1111
* @package App
12-
* @property int $id
13-
* @property int $blogId
12+
* @property string $hash
13+
* @property string $blogHash
1414
* @property string $title
1515
* @property string $author
1616
* @property string $url
1717
* @property \Carbon\Carbon|null $created_at
1818
* @property \Carbon\Carbon|null $updated_at
1919
* @method static Builder|BlogArticle whereAuthor($value)
20-
* @method static Builder|BlogArticle whereBlogId($value)
20+
* @method static Builder|BlogArticle whereBlogHash($value)
2121
* @method static Builder|BlogArticle whereCreatedAt($value)
22-
* @method static Builder|BlogArticle whereId($value)
22+
* @method static Builder|BlogArticle whereHash($value)
2323
* @method static Builder|BlogArticle whereTitle($value)
2424
* @method static Builder|BlogArticle whereUpdatedAt($value)
2525
* @method static Builder|BlogArticle whereUrl($value)
@@ -28,9 +28,15 @@
2828
class BlogArticle extends Model
2929
{
3030
protected $table = "blog_article";
31+
protected $primaryKey = 'hash';
32+
protected $keyType = "varchar";
3133

3234
protected $fillable = [
33-
'blogId', 'title', 'author', 'url'
35+
'hash',
36+
'blogHash',
37+
'title',
38+
'author',
39+
'url'
3440
];
3541

3642
protected $hidden = [];

app/Comments.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
/**
9+
* Class Comments
10+
*
11+
* @package App
12+
* @property string $hash
13+
* @property string $articleHash
14+
* @property string $authorName
15+
* @property string|null $authorMail
16+
* @property string|null $title
17+
* @property string $content
18+
* @property \Carbon\Carbon|null $created_at
19+
* @property \Carbon\Carbon|null $updated_at
20+
* @method static Builder|Comments whereArticleHash($value)
21+
* @method static Builder|Comments whereAuthorMail($value)
22+
* @method static Builder|Comments whereAuthorName($value)
23+
* @method static Builder|Comments whereContent($value)
24+
* @method static Builder|Comments whereCreatedAt($value)
25+
* @method static Builder|Comments whereHash($value)
26+
* @method static Builder|Comments whereTitle($value)
27+
* @method static Builder|Comments whereUpdatedAt($value)
28+
* @mixin \Eloquent
29+
*/
30+
class Comments extends Model
31+
{
32+
protected $table = "comments";
33+
34+
protected $fillable = [
35+
'hash',
36+
'articleHash',
37+
'authorName',
38+
'authorMail',
39+
'title',
40+
'content'
41+
];
42+
43+
protected $hidden = [];
44+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\BlogArticle;
6+
use App\Comments;
7+
use App\Helper\FormatHelper;
8+
use Illuminate\Http\Request;
9+
10+
/**
11+
* Class ArticleController
12+
* @package App\Http\Controllers
13+
*/
14+
class ArticleController extends Controller
15+
{
16+
public function getArticlesByBlog($blogHash)
17+
{
18+
$blogArticle = new BlogArticle();
19+
$articleResult = $blogArticle->where("blogHash", $blogHash)->orderBy("created_at")->get();
20+
21+
return FormatHelper::formatData($articleResult);
22+
}
23+
24+
public function addArticle(Request $request)
25+
{
26+
$article = new BlogArticle();
27+
28+
$blogHash = $request->input("blogHash");
29+
$title = $request->input("title");
30+
$author = $request->input("author");
31+
$url = $request->input("url");
32+
33+
$articleHash = md5(time());
34+
$dataArray = array(
35+
"hash" => $articleHash,
36+
"blogHash" => $blogHash,
37+
"title" => $title,
38+
"author" => $author,
39+
"url" => $url
40+
);
41+
$article->create($dataArray);
42+
return $dataArray;
43+
}
44+
45+
public function editArticle(Request $request)
46+
{
47+
$article = new BlogArticle();
48+
49+
$articleHash = $request->input("blogHash");
50+
$title = $request->input("title");
51+
$author = $request->input("author");
52+
$url = $request->input("url");
53+
54+
$dataArray = array();
55+
56+
if ($title != null) {
57+
$dataArray["title"] = $title;
58+
}
59+
60+
if ($author != null) {
61+
$dataArray["author"] = $author;
62+
}
63+
64+
if ($url != null) {
65+
$dataArray["url"] = $url;
66+
}
67+
68+
$article->where("hash", $articleHash)->update($dataArray);
69+
70+
return $dataArray;
71+
}
72+
73+
public function deleteArticle($articleHash)
74+
{
75+
$comment = new Comments();
76+
77+
$article = new BlogArticle();
78+
$articleResult = $article->where("hash", $articleHash)->first();
79+
if ($articleResult != null) {
80+
$comment->where("articleHash", $articleHash)->delete();
81+
$articleResult->delete();
82+
return FormatHelper::formatData(array(), true);
83+
} else {
84+
return FormatHelper::formatData(array("errorCode" => "article-not-found"), false, 404);
85+
}
86+
}
87+
}

app/Http/Controllers/BlogController.php

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Blog;
66
use App\BlogArticle;
77
use App\Helper\FormatHelper;
8+
use Illuminate\Http\Request;
89

910
/**
1011
* Class BlogController
@@ -17,25 +18,86 @@ public function index()
1718
return FormatHelper::formatData(Blog::all());
1819
}
1920

20-
public function getBlog($blogHash)
21+
public function getBlogByHash($blogHash)
2122
{
2223
$blog = new Blog();
23-
$return = $blog->where("hash", $blogHash)->first();
24-
return $return != null ? FormatHelper::formatData($return) : FormatHelper::formatData(array(), FALSE);
24+
$blogResult = $blog->where("hash", $blogHash)->first();
25+
26+
if ($blogResult != null) {
27+
return FormatHelper::formatData($blogResult);
28+
} else {
29+
return FormatHelper::formatData(array("errorCode" => "blog-not-found"), false, 404);
30+
}
2531
}
2632

27-
public function getBlogWithArticles($blogHash)
33+
public function getArticle($articleHash)
34+
{
35+
$article = new BlogArticle();
36+
$articleResult = $article->where("hash", $articleHash)->first();
37+
38+
if ($articleResult != null) {
39+
return FormatHelper::formatData($articleResult);
40+
} else {
41+
return FormatHelper::formatData(array("errorCode" => "article-not-found"), false, 404);
42+
}
43+
}
44+
45+
public function addBlog(Request $request)
2846
{
2947
$blog = new Blog();
30-
$blogResult = $blog->where("hash", $blogHash)->first();
3148

32-
if ($blogResult != null) {
33-
$blogArticle = new BlogArticle();
34-
$blogResult["articles"] = $blogArticle->where("blogId", $blogResult["id"])->get();
49+
$name = $request->input("name");
50+
$description = $request->input("description");
51+
$url = $request->input("url");
3552

36-
return $blogResult != null ? FormatHelper::formatData($blogResult) : FormatHelper::formatData(array(), FALSE);
53+
$blogHash = md5(time());
54+
$dataArray = array(
55+
"hash" => $blogHash,
56+
"name" => $name,
57+
"description" => $description,
58+
"url" => $url
59+
);
60+
$blog->create($dataArray);
61+
return $dataArray;
62+
}
63+
64+
public function editBlog(Request $request)
65+
{
66+
$blog = new Blog();
67+
68+
$blogHash = $request->input("hash");
69+
$name = $request->input("name");
70+
$description = $request->input("description");
71+
$url = $request->input("url");
72+
73+
$dataArray = array();
74+
75+
if ($name != null) {
76+
$dataArray["name"] = $name;
77+
}
78+
79+
if ($description != null) {
80+
$dataArray["description"] = $description;
81+
}
82+
83+
if ($url != null) {
84+
$dataArray["url"] = $url;
85+
}
86+
87+
$blog->where("hash", $blogHash)->update($dataArray);
88+
89+
return $dataArray;
90+
}
91+
92+
public function deleteBlog($blogHash)
93+
{
94+
$blog = new Blog();
95+
$blogResult = $blog->where("hash", $blogHash)->first();
96+
if ($blogResult != null) {
97+
$blogResult->delete();
98+
return FormatHelper::formatData(array(), true);
3799
} else {
38-
return FormatHelper::formatData(array(), false);
100+
return FormatHelper::formatData(array("errorCode" => "blog-not-found"), false, 404);
39101
}
40102
}
41103
}

0 commit comments

Comments
 (0)