-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCache.php
More file actions
211 lines (183 loc) · 7.28 KB
/
Copy pathCache.php
File metadata and controls
211 lines (183 loc) · 7.28 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Model;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Interfaces\ForumEnv;
class Cache
{
public static function getConfig()
{
$result = DB::table('config')
->findArray();
$config = [];
foreach ($result as $item) {
$config[$item['conf_name']] = $item['conf_value'];
}
return $config;
}
public static function getPreferences()
{
$result = DB::table('preferences')
->where('default', 1)
->findArray();
$preferences = [];
foreach ($result as $item) {
$preferences[$item['preference_name']] = $item['preference_value'];
}
return $preferences;
}
public static function getBans()
{
return DB::table('bans')
->findArray();
}
public static function getCensoring($selectCensoring = 'search_for')
{
$result = DB::table('censoring')
->selectMany($selectCensoring)
->findArray();
$output = [];
foreach ($result as $item) {
$output[] = ($selectCensoring == 'search_for') ? '%(?<=[^\p{L}\p{N}])('.str_replace('\*', '[\p{L}\p{N}]*?', preg_quote($item['search_for'], '%')).')(?=[^\p{L}\p{N}])%iu' : $item['replace_with'];
}
return $output;
}
public static function getUsersInfo()
{
$stats = [];
$selectGetUsersInfo = ['id', 'username'];
$stats['total_users'] = DB::table('users')
->whereNotEqual('group_id', ForumEnv::get('FEATHER_UNVERIFIED'))
->whereNotEqual('id', 1)
->count();
$stats['last_user'] = DB::table('users')->selectMany($selectGetUsersInfo)
->whereNotEqual('group_id', ForumEnv::get('FEATHER_UNVERIFIED'))
->orderByDesc('registered')
->limit(1)
->findArray()[0];
return $stats;
}
public static function getAdminIds()
{
return DB::table('users')
->select('id')
->where('group_id', ForumEnv::get('FEATHER_ADMIN'))
->findArray();
}
public static function quickjump()
{
$readPerms = DB::table('permissions')
->select('group', 'g_id')
->whereAnyIs([
['permission_name' => 'board.read'],
['permission_name' => '*']
])
->where('allow', 1)
->findArray();
$output = [];
foreach ($readPerms as $item) {
$selectQuickjump = ['cid' => 'c.id', 'c.cat_name', 'fid' => 'f.id', 'f.forum_name', 'f.redirect_url'];
$whereQuickjump = [
['fp.read_forum' => 'IS NULL'],
['fp.read_forum' => '1']
];
$orderByQuickjump = ['c.disp_position', 'c.id', 'f.disp_position'];
$result = DB::table('categories')
->tableAlias('c')
->selectMany($selectQuickjump)
->innerJoin('forums', ['c.id', '=', 'f.cat_id'], 'f')
->leftOuterJoin('forum_perms', 'fp.forum_id=f.id AND fp.group_id='.$item['g_id'], 'fp')
->whereAnyIs($whereQuickjump)
->whereNull('f.redirect_url')
->orderByMany($orderByQuickjump)
->findMany();
$forumData = [];
foreach ($result as $forum) {
if (!isset($forumData[$forum['cid']])) {
$forumData[$forum['cid']] = ['cat_name' => $forum['cat_name'],
'cat_position' => $forum['cat_position'],
'cat_forums' => []];
}
$forumData[$forum['cid']]['cat_forums'][] = ['forum_id' => $forum['fid'],
'forum_name' => $forum['forum_name'],
'position' => $forum['forum_position']];
}
$output[(int) $item['g_id']] = $forumData;
}
return $output;
}
public static function getStopwords($langPath = null)
{
if (!$langPath) {
$langPath = ForumEnv::get('FEATHER_ROOT').'featherbb/lang';
}
$files = new \DirectoryIterator($langPath);
$stopwords = [];
foreach ($files as $file) {
if (!$file->isDot() && $file->getBasename() != '.DS_Store' && $file->isDir() && file_exists($file->getPathName().'/stopwords.txt')) {
$stopwords = array_merge($stopwords, file($file->getPathName().'/stopwords.txt'));
}
}
return array_map('trim', $stopwords);
}
public static function getPermissions()
{
// Initial empty array
$result = [];
// First, get default group permissions
$groupsPerms = DB::table('permissions')->whereNull('user')->orderByDesc('group')->findArray();
foreach ($groupsPerms as $perm) {
if ((bool) $perm['allow']) {
$result[$perm['group']][0][$perm['permission_name']] = true;
}
}
// Then get optional user permissions to override their group defaults
// TODO: Add a page in profile Administration section to display custom permissions
$usersPerms = DB::table('permissions')
->tableAlias('p')
->selectMany('p.permission_name', 'p.allow', 'p.deny', 'p.user', 'u.group_id')
->innerJoin('users', ['u.id', '=', 'p.user'], 'u')
->whereNotNull('p.user')
->findArray();
foreach ($usersPerms as $perm) {
$result[$perm['group_id']][$perm['user']][$perm['permission_name']] = (bool) $perm['allow'] || !(bool) $perm['deny'];
}
return $result;
}
public static function getGroupPreferences()
{
$groupsPreferences = [];
$groups = DB::table('groups')->select('g_id')->findArray();
foreach ($groups as $group) {
$result = DB::table('preferences')
->tableAlias('p')
->whereAnyIs([
['p.group' => $group['g_id']],
['p.default' => 1],
])
->orderByDesc('p.default')
->findArray();
$groupsPreferences[$group['g_id']] = [];
foreach ($result as $pref) {
$groupsPreferences[$group['g_id']][(string) $pref['preference_name']] = $pref['preference_value'];
}
}
return (array) $groupsPreferences;
}
public static function getSmilies()
{
$result = [];
$smilies = DB::table('smilies')
->selectMany('text', 'image')
->findArray();
foreach ($smilies as $smiley) {
$result[$smiley['text']] = $smiley['image'];
}
return $result;
}
}