|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Article; |
|
6
|
|
|
use App\Models\ArticleCategory; |
|
7
|
|
|
use Illuminate\Http\Response; |
|
8
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class ArticleController. |
|
12
|
|
|
*/ |
|
13
|
|
|
class ArticleController extends BaseController |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Render a specific view of Article set. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $countryId |
|
19
|
|
|
* @param string $articleCategory |
|
20
|
|
|
* |
|
21
|
|
|
* @return Response |
|
22
|
|
|
*/ |
|
23
|
|
|
public function many(string $countryId, string $articleCategory): Response |
|
24
|
|
|
{ |
|
25
|
|
|
$category = ArticleCategory::find(strstr(($articleCategory = |
|
26
|
|
|
str_replace('.html', '', $articleCategory)), '_', true)); |
|
27
|
|
|
|
|
28
|
|
|
$categoryPage = strstr(strrev($articleCategory), '_', true); |
|
29
|
|
|
|
|
30
|
|
|
return $articleCategory == 'front' ? $this->front() : $this->category($countryId, $category, $categoryPage, |
|
31
|
|
|
$categoryPage == 1 ? 0 : (10 * ($categoryPage - 1))); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Render the Front Page of the Articles Page. |
|
36
|
|
|
* |
|
37
|
|
|
* @return Response |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function front(): Response |
|
40
|
|
|
{ |
|
41
|
|
|
return response(view('habbo-web-news.articles-front', ['set' => Article::orderBy('id', 'DESC')->limit(10)->get()])); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Render a specific Category Articles Page. |
|
46
|
|
|
* |
|
47
|
|
|
* @TODO: Proper Way to use Country ID |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $countryId |
|
50
|
|
|
* @param ArticleCategory $category |
|
51
|
|
|
* @param int $categoryPage |
|
52
|
|
|
* @param int $start |
|
53
|
|
|
* |
|
54
|
|
|
* @return Response |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function category(string $countryId, ArticleCategory $category, int $categoryPage, int $start): Response |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
$articles = Article::where('id', '>=', $start)->limit(10)->orderBy('id', 'DESC')->get()->filter(function ($item) use ($category) { |
|
59
|
|
|
return $category->name == 'all' || in_array($category, $item->categories); |
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
return response(view('habbo-web-news.articles-category', [ |
|
63
|
|
|
'category' => $category, 'page' => $categoryPage, 'categories' => ArticleCategory::all(), 'articles' => $articles, |
|
64
|
|
|
])); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Render a specific view of a specific Article. |
|
69
|
|
|
* |
|
70
|
|
|
* @TODO: Proper Way to use Country ID |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $countryId |
|
73
|
|
|
* @param string $articleName |
|
74
|
|
|
* |
|
75
|
|
|
* @return Response |
|
76
|
|
|
*/ |
|
77
|
|
|
public function one(string $countryId, string $articleName): Response |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
if (($article = Article::find(strstr($articleName, '_', true))) == null) { |
|
80
|
|
|
return response()->json(null, 404); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$related = ($latest = Article::all())->filter(function ($item) use ($article) { |
|
84
|
|
|
return in_array($article->categories[0], $item->categories); |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
return response(view('habbo-web-news.articles-view', |
|
88
|
|
|
['article' => $article, 'latest' => $latest->slice(0, 5), 'related' => $related->slice(0, 5)] |
|
89
|
|
|
)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get All Habbo Articles as XML/RSS. |
|
94
|
|
|
* |
|
95
|
|
|
* @return Response |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getRss() |
|
98
|
|
|
{ |
|
99
|
|
|
return response(view('habbo-web-pages.habbo-rss', ['articles' => Article::limit(20)->get()]))->header('Content-Type', 'text/xml'); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.