Skip to content

Commit 0e7d21b

Browse files
committed
Add Prefs interface
1 parent 139441b commit 0e7d21b

File tree

11 files changed

+85
-21
lines changed

11 files changed

+85
-21
lines changed

featherbb/Controller/Install.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use FeatherBB\Core\Interfaces\Input;
1717
use FeatherBB\Core\Interfaces\Lang;
1818
use FeatherBB\Core\Interfaces\Perms;
19+
use FeatherBB\Core\Interfaces\Prefs;
1920
use FeatherBB\Core\Interfaces\Request;
2021
use FeatherBB\Core\Interfaces\Router;
2122
use FeatherBB\Core\Interfaces\View;
@@ -232,7 +233,7 @@ public function createDb(array $data)
232233
Perms::allowGroup(1, ['*']);
233234
Cache::store('permissions', \FeatherBB\Model\Cache::getPermissions());
234235
// Init preferences
235-
Container::get('prefs')->set([
236+
Prefs::set([
236237
'disp.topics' => 30,
237238
'disp.posts' => 25,
238239
'post.min_interval' => 60,
@@ -257,13 +258,13 @@ public function createDb(array $data)
257258
'notify_with_post' => 0,
258259
'auto_notify' => 0,
259260
]);
260-
Container::get('prefs')->setGroup(2, [
261+
Prefs::setGroup(2, [
261262
'post.min_interval' => 0,
262263
'search.min_interval' => 0,
263264
'email.min_interval' => 0,
264265
'report.min_interval' => 0
265266
]);
266-
Container::get('prefs')->setGroup(1, [
267+
Prefs::setGroup(1, [
267268
'post.min_interval' => 0,
268269
'search.min_interval' => 0,
269270
'email.min_interval' => 0,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
namespace FeatherBB\Core\Interfaces;
3+
4+
5+
class Prefs extends SlimSugar
6+
{
7+
public static function setUser($user = null, $prefs, $gid = null)
8+
{
9+
return static::$slim->getContainer()['prefs']->setUser($user, $prefs, $gid);
10+
}
11+
12+
public static function setGroup($gid = null, $prefs)
13+
{
14+
return static::$slim->getContainer()['prefs']->setGroup($gid, $prefs);
15+
}
16+
17+
public static function set(array $prefs) // Default
18+
{
19+
return static::$slim->getContainer()['prefs']->set($prefs);
20+
}
21+
22+
public static function delUser($user = null, $prefs = null)
23+
{
24+
return static::$slim->getContainer()['prefs']->delUser($user, $prefs);
25+
}
26+
27+
public static function delGroup($gid = null, $prefs = null)
28+
{
29+
return static::$slim->getContainer()['prefs']->delGroup($gid, $prefs);
30+
}
31+
32+
public static function del($prefs = null) // Default
33+
{
34+
return static::$slim->getContainer()['prefs']->del($prefs);
35+
}
36+
37+
public static function get($user = null, $pref = null)
38+
{
39+
return static::$slim->getContainer()['prefs']->get($user, $pref);
40+
}
41+
42+
public static function loadPrefs($user = null)
43+
{
44+
return static::$slim->getContainer()['prefs']->loadPrefs($user);
45+
}
46+
47+
protected function getInfosFromUser($user = null)
48+
{
49+
return static::$slim->getContainer()['prefs']->getInfosFromUser($user);
50+
}
51+
52+
public static function getGroupPreferences($groupId = null, $preference = null)
53+
{
54+
return static::$slim->getContainer()['prefs']->getGroupPreferences($groupId, $preference);
55+
}
56+
}

featherbb/Core/Interfaces/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function getBasic($user = null)
4848
public static function getPref($pref = null, $user = null)
4949
{
5050
$user = self::getBasic($user);
51-
return Container::get('prefs')->get($user, $pref);
51+
return Prefs::get($user, $pref);
5252
}
5353

5454
/**

featherbb/Middleware/Auth.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use FeatherBB\Core\Interfaces\ForumSettings;
2222
use FeatherBB\Core\Interfaces\Lang;
2323
use FeatherBB\Core\Interfaces\Perms;
24+
use FeatherBB\Core\Interfaces\Prefs;
2425
use FeatherBB\Core\Interfaces\User;
2526
use FeatherBB\Core\Track;
2627
use FeatherBB\Core\Utils;
@@ -262,17 +263,17 @@ public function __invoke($req, $res, $next)
262263

263264
// Load permissions and preferences for logged user
264265
Perms::getUserPermissions($user);
265-
$user->prefs = Container::get('prefs')->loadPrefs($user);
266+
$user->prefs = Prefs::loadPrefs($user);
266267

267268
$expires = ($jwt->exp > Container::get('now') + ForumSettings::get('o_timeout_visit')) ? Container::get('now') + 1209600 : Container::get('now') + ForumSettings::get('o_timeout_visit');
268269

269270
$user->is_guest = false;
270271

271272
if (!is_dir(ForumEnv::get('FEATHER_ROOT').'featherbb/lang/'.$user->prefs['language'])) {
272-
Container::get('prefs')->setUser($user, ['language' => ForumSettings::get('language')]);
273+
Prefs::setUser($user, ['language' => ForumSettings::get('language')]);
273274
}
274275
if (!file_exists(ForumEnv::get('FEATHER_ROOT').'style/themes/'.$user->prefs['style'].'/style.css')) {
275-
Container::get('prefs')->setUser($user, ['style' => ForumSettings::get('style')]);
276+
Prefs::setUser($user, ['style' => ForumSettings::get('style')]);
276277
}
277278

278279
// Add user to DIC
@@ -312,7 +313,7 @@ public function __invoke($req, $res, $next)
312313

313314
// Load permissions and preferences for guest user
314315
Perms::getUserPermissions($user);
315-
$user->prefs = Container::get('prefs')->loadPrefs($user);
316+
$user->prefs = Prefs::loadPrefs($user);
316317

317318
// Add $user as guest to DIC
318319
Container::set('user', $user);

featherbb/Model/Admin/Groups.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FeatherBB\Core\Interfaces\Hooks;
1818
use FeatherBB\Core\Interfaces\Input;
1919
use FeatherBB\Core\Interfaces\Perms;
20+
use FeatherBB\Core\Interfaces\Prefs;
2021
use FeatherBB\Core\Interfaces\Router;
2122
use FeatherBB\Core\Utils;
2223
use FeatherBB\Model\Cache;
@@ -58,7 +59,7 @@ public function infoAdd($groups, $id)
5859
}
5960

6061
$group['info'] = $groups[$id];
61-
$group['prefs'] = Container::get('prefs')->getGroupPreferences($id);
62+
$group['prefs'] = Prefs::getGroupPreferences($id);
6263
$group['perms'] = Perms::getGroupPermissions($id);
6364

6465
$group = Hooks::fire('model.admin.groups.info_add_group', $group);
@@ -219,7 +220,7 @@ public function addEdit($groups)
219220
$newGroupId = Hooks::fire('model.admin.groups.add_edit_group.new_group_id', (int) $add->id());
220221

221222
// Set new group preferences
222-
Container::get('prefs')->setGroup($newGroupId, $groupPreferences);
223+
Prefs::setGroup($newGroupId, $groupPreferences);
223224

224225
// Now lets copy the forum specific permissions from the group which this group is based on
225226
$selectForumPerms = ['forum_id', 'read_forum', 'post_replies', 'post_topics'];
@@ -254,7 +255,7 @@ public function addEdit($groups)
254255
->save();
255256

256257
// Update group preferences
257-
Container::get('prefs')->setGroup(Input::post('group_id'), $groupPreferences);
258+
Prefs::setGroup(Input::post('group_id'), $groupPreferences);
258259

259260
// Promote all users who would be promoted to this group on their next post
260261
if ($promoteNextGroup) {

featherbb/Model/Admin/Options.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use FeatherBB\Core\Interfaces\ForumSettings;
1717
use FeatherBB\Core\Interfaces\Hooks;
1818
use FeatherBB\Core\Interfaces\Input;
19+
use FeatherBB\Core\Interfaces\Prefs;
1920
use FeatherBB\Core\Interfaces\Router;
2021
use FeatherBB\Core\Utils;
2122
use FeatherBB\Model\Cache;
@@ -228,7 +229,7 @@ public function update()
228229
}
229230
}
230231

231-
Container::get('prefs')->set($prefs);
232+
Prefs::set($prefs);
232233

233234
// Regenerate the config cache
234235
$config = array_merge(Cache::getConfig(), Cache::getPreferences());

featherbb/Model/Api/Topic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
use FeatherBB\Core\Interfaces\ForumSettings;
1717
use FeatherBB\Core\Interfaces\Hooks;
1818
use FeatherBB\Core\Interfaces\Input;
19+
use FeatherBB\Core\Interfaces\Prefs;
1920
use FeatherBB\Core\Interfaces\Router;
2021
use FeatherBB\Core\Interfaces\User;
21-
use FeatherBB\Core\Interfaces\User;
2222
use FeatherBB\Core\Track;
2323
use FeatherBB\Core\Url;
2424
use FeatherBB\Core\Utils;
@@ -110,7 +110,7 @@ public function checkPermissions($curPosting, $tid, $fid)
110110
public function checkErrorsBeforePost($fid, $errors)
111111
{
112112
// Flood protection
113-
if (Input::post('preview') != '' && $this->user->last_post != '' && (time() - $this->user->last_post) < Container::get('prefs')->get($this->user, 'post.min_interval')) {
113+
if (Input::post('preview') != '' && $this->user->last_post != '' && (time() - $this->user->last_post) < Prefs::get($this->user, 'post.min_interval')) {
114114
$errors[] = sprintf(__('Flood start'), User::getPref('post.min_interval', $this->user), User::getPref('post.min_interval', $this->user) - (time() - $this->user->last_post));
115115
}
116116

featherbb/Model/Post.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use FeatherBB\Core\Interfaces\ForumSettings;
1717
use FeatherBB\Core\Interfaces\Hooks;
1818
use FeatherBB\Core\Interfaces\Input;
19+
use FeatherBB\Core\Interfaces\Prefs;
1920
use FeatherBB\Core\Interfaces\Request;
2021
use FeatherBB\Core\Interfaces\Router;
2122
use FeatherBB\Core\Interfaces\User;
@@ -813,7 +814,7 @@ public static function sendNotificationsReply($tid, $curPosting, $newPid, $post)
813814

814815
// Loop through subscribed users and send emails
815816
foreach ($result as $curSubscriber) {
816-
$curSubscriber['prefs'] = Container::get('prefs')->loadPrefs($curSubscriber);
817+
$curSubscriber['prefs'] = Prefs::loadPrefs($curSubscriber);
817818
// Is the subscription email for User::getPref('language', $curSubscriber['id']) cached or not?
818819
if (!isset($notificationEmails[$curSubscriber['prefs']['language']])) {
819820
if (file_exists(ForumEnv::get('FEATHER_ROOT').'featherbb/lang/'.$curSubscriber['prefs']['language'].'/mail_templates/new_reply.tpl')) {
@@ -1023,7 +1024,7 @@ public function sendNotificationsNewTopic($post, $curPosting, $newTid)
10231024

10241025
// Loop through subscribed users and send emails
10251026
foreach ($result as $curSubscriber) {
1026-
$curSubscriber['prefs'] = Container::get('prefs')->loadPrefs($curSubscriber);
1027+
$curSubscriber['prefs'] = Prefs::loadPrefs($curSubscriber);
10271028
// Is the subscription email for User::getPref('language', $curSubscriber['id']) cached or not?
10281029
if (!isset($notificationEmails[$curSubscriber['prefs']['language']])) {
10291030
if (file_exists(ForumEnv::get('FEATHER_ROOT').'featherbb/lang/'.$curSubscriber['prefs']['language'].'/mail_templates/new_topic.tpl')) {

featherbb/Model/Profile.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use FeatherBB\Core\Interfaces\Input;
2020
use FeatherBB\Core\Interfaces\Lang;
2121
use FeatherBB\Core\Interfaces\Perms;
22+
use FeatherBB\Core\Interfaces\Prefs;
2223
use FeatherBB\Core\Interfaces\Request;
2324
use FeatherBB\Core\Interfaces\Router;
2425
use FeatherBB\Core\Interfaces\User;
@@ -904,7 +905,7 @@ public function updateProfile($id, $info, $section)
904905

905906
// Update user prefs
906907
if (!empty($prefs)) {
907-
Container::get('prefs')->setUser($id, $prefs);
908+
Prefs::setUser($id, $prefs);
908909
}
909910

910911
// If we changed the username we have to update some stuff
@@ -1007,7 +1008,7 @@ public function getUserInfo($id)
10071008
throw new Error(__('Bad request'), 404);
10081009
}
10091010

1010-
$user['prefs'] = ($id == User::get()->id) ? User::get()->prefs : Container::get('prefs')->loadPrefs($user);
1011+
$user['prefs'] = ($id == User::get()->id) ? User::get()->prefs : Prefs::loadPrefs($user);
10111012

10121013
return $user;
10131014
}

featherbb/Model/Register.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FeatherBB\Core\Interfaces\ForumSettings;
1818
use FeatherBB\Core\Interfaces\Hooks;
1919
use FeatherBB\Core\Interfaces\Input;
20+
use FeatherBB\Core\Interfaces\Prefs;
2021
use FeatherBB\Core\Interfaces\Router;
2122
use FeatherBB\Core\Interfaces\User;
2223
use FeatherBB\Core\Random;
@@ -159,9 +160,9 @@ public function insertUser($user)
159160
$newUid = DB::getDb()->lastInsertId(ForumSettings::get('db_prefix').'users');
160161

161162
if (ForumSettings::get('o_regs_verify') == '1') {
162-
Container::get('prefs')->setUser($newUid, ['language' => $user['language']], ForumEnv::get('FEATHER_UNVERIFIED'));
163+
Prefs::setUser($newUid, ['language' => $user['language']], ForumEnv::get('FEATHER_UNVERIFIED'));
163164
} else {
164-
Container::get('prefs')->setUser($newUid, ['language' => $user['language']]);
165+
Prefs::setUser($newUid, ['language' => $user['language']]);
165166
}
166167

167168
// If the mailing list isn't empty, we may need to send out some alerts

0 commit comments

Comments
 (0)