-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathForums.php
More file actions
89 lines (73 loc) · 2.25 KB
/
Forums.php
File metadata and controls
89 lines (73 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace App\Libraries;
use App\Models\MyBBModel;
/**
* Provides View Cell functionality
* for displaying recent posts from the forums.
*/
class Forums
{
/**
* @var MyBBModel
*/
protected $mybb;
protected $forumUrl;
/**
* Number of items to display by default.
*
* @var int
*/
protected $limit = 5;
public function __construct()
{
$this->mybb = new MyBBModel();
$this->forumUrl = config('MyBB')->forumURL;
}
/**
* Process the latest posts from the forum
*
* @param array $params
*
* @return string
*/
public function posts($params = [])
{
$limit = $params['limit'] ?? $this->limit;
// get the forum posts
if (! $items = cache('bb_posts')) {
$items = $this->mybb->getRecentPosts($limit);
$ttl = 60 * 60 * 4; // time to live s/b 4 hours
cache()->save('bb_posts', $items, $ttl);
}
if (! empty($items) && is_array($items)) {
// massage the date formats
foreach ($items as &$item) {
$item['lastpost'] = date('Y.m.d', $item['lastpost']);
$item['mybb_forum_url'] = $this->forumUrl;
$item['subject'] = strip_tags($item['subject']); // fix #79
}
return view('forum/_posts', ['posts' => $items]);
}
return view('forum/_drats');
}
public function news($params = [])
{
$limit = $params['limit'] ?? $this->limit;
// get the forum posts
if (! $items = cache('bb_news')) {
$items = $this->mybb->getRecentNews($limit);
$ttl = 60 * 60 * 4; // time to live s/b 4 hours
cache()->save('bb_news', $items, $ttl);
}
if (! empty($items) && is_array($items)) {
// massage the date formats
foreach ($items as &$item) {
$item['lastpost'] = date('Y.m.d', $item['lastpost']);
$item['mybb_forum_url'] = $this->forumUrl;
$item['subject'] = strip_tags($item['subject']); // fix #79
}
return view('forum/_posts', ['posts' => $items]);
}
return view('forum/_drats');
}
}