Skip to content

Commit 9b18f4f

Browse files
committed
Migrate disp_topics and disp_posts
1 parent 5e05277 commit 9b18f4f

File tree

13 files changed

+59
-65
lines changed

13 files changed

+59
-65
lines changed

featherbb/Controller/Forum.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function display($req, $res, $args)
4848
}
4949

5050
// Determine the topic offset (based on $args['page'])
51-
$num_pages = ceil($cur_forum['num_topics'] / User::get()->disp_topics);
51+
$num_pages = ceil($cur_forum['num_topics'] / User::getPref('disp.topics'));
5252

5353
$p = (!isset($args['page']) || $args['page'] <= 1 || $args['page'] > $num_pages) ? 1 : intval($args['page']);
54-
$start_from = User::get()->disp_topics * ($p - 1);
54+
$start_from = User::getPref('disp.topics') * ($p - 1);
5555
$url_forum = Url::url_friendly($cur_forum['forum_name']);
5656

5757
// Generate paging links
@@ -109,10 +109,10 @@ public function moderate($req, $res, $args)
109109
$sort_by = $this->model->sort_forum_by($cur_forum['sort_by']);
110110

111111
// Determine the topic offset (based on $_GET['p'])
112-
$num_pages = ceil($cur_forum['num_topics'] / User::get()->disp_topics);
112+
$num_pages = ceil($cur_forum['num_topics'] / User::getPref('disp.topics'));
113113

114114
$p = (!isset($args['page']) || $args['page'] <= 1 || $args['page'] > $num_pages) ? 1 : intval($args['page']);
115-
$start_from = User::get()->disp_topics * ($p - 1);
115+
$start_from = User::getPref('disp.topics') * ($p - 1);
116116
$url_forum = Url::url_friendly($cur_forum['forum_name']);
117117

118118
View::setPageInfo(array(

featherbb/Controller/Install.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ public function create_db(array $data)
221221
Container::get('perms')->allowGroup(1, array('*'));
222222
// Init preferences
223223
Container::get('prefs')->set(array(
224+
'disp.topics' => 30,
225+
'disp.posts' => 25,
224226
'post.min_interval' => 60,
225227
'search.min_interval' => 30,
226228
'email.min_interval' => 60,
@@ -306,8 +308,8 @@ public function load_default_config(array $data)
306308
// 'o_default_style' => $data['default_style'],
307309
'o_default_user_group' => 4,
308310
'o_topic_review' => 15,
309-
'o_disp_topics_default' => 30,
310-
'o_disp_posts_default' => 25,
311+
// 'o_disp_topics_default' => 30,
312+
// 'o_disp_posts_default' => 25,
311313
'o_indent_num_spaces' => 4,
312314
'o_quote_depth' => 3,
313315
'o_quickpost' => 1,

featherbb/Controller/Topic.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public function display($req, $res, $args)
6262
}
6363

6464
// Determine the post offset (based on $_GET['p'])
65-
$num_pages = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);
65+
$num_pages = ceil(($cur_topic['num_replies'] + 1) / User::getPref('disp.posts'));
6666

6767
$p = (!isset($args['page']) || $args['page'] <= 1 || $args['page'] > $num_pages) ? 1 : intval($args['page']);
68-
$start_from = User::get()->disp_posts * ($p - 1);
68+
$start_from = User::getPref('disp.posts') * ($p - 1);
6969

7070
$url_topic = Url::url_friendly($cur_topic['subject']);
7171
$url_forum = Url::url_friendly($cur_topic['forum_name']);
@@ -217,11 +217,11 @@ public function moderate($req, $res, $args)
217217
$cur_topic = $this->model->get_topic_info($args['fid'], $args['id']);
218218

219219
// Determine the post offset (based on $_GET['p'])
220-
$num_pages = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);
220+
$num_pages = ceil(($cur_topic['num_replies'] + 1) / User::getPref('disp.posts'));
221221

222222
$p = (!isset($args['page']) || $args['page'] <= 1 || $args['page'] > $num_pages) ? 1 : intval($args['page']);
223223

224-
$start_from = User::get()->disp_posts * ($p - 1);
224+
$start_from = User::getPref('disp.posts') * ($p - 1);
225225

226226
// Delete one or more posts
227227
if (Input::post('delete_posts_comply')) {
@@ -258,7 +258,7 @@ public function moderate($req, $res, $args)
258258
$button_status = ($cur_topic['num_replies'] == 0) ? ' disabled="disabled"' : '';
259259

260260
/*if (isset($_GET['action']) && $_GET['action'] == 'all') {
261-
User::get()->disp_posts = $cur_topic['num_replies'] + 1;
261+
User::getPref('disp.posts') = $cur_topic['num_replies'] + 1;
262262
}*/
263263

264264
if (ForumSettings::get('o_censoring') == '1') {

featherbb/Middleware/Auth.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ private function load_default_user()
224224
{
225225
$user = AuthModel::load_user(1);
226226

227-
$user->disp_topics = ForumSettings::get('o_disp_topics_default');
228-
$user->disp_posts = ForumSettings::get('o_disp_posts_default');
229227
$user->is_guest = true;
230228
$user->is_admmod = false;
231229

@@ -257,12 +255,6 @@ public function __invoke($req, $res, $next)
257255

258256
$user->is_guest = false;
259257

260-
if (!$user->disp_topics) {
261-
$user->disp_topics = ForumSettings::get('o_disp_topics_default');
262-
}
263-
if (!$user->disp_posts) {
264-
$user->disp_posts = ForumSettings::get('o_disp_posts_default');
265-
}
266258
if (!file_exists(ForumEnv::get('FEATHER_ROOT').'featherbb/lang/'.$user->language)) {
267259
$user->language = ForumSettings::get('language');
268260
}

featherbb/Model/Admin/Options.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function update_options()
3838
// 'smilies_sig' => Input::post('form_smilies_sig') != '1' ? '0' : '1',
3939
'make_links' => Input::post('form_make_links') != '1' ? '0' : '1',
4040
'topic_review' => (intval(Input::post('form_topic_review')) >= 0) ? intval(Input::post('form_topic_review')) : 0,
41-
'disp_topics_default' => intval(Input::post('form_disp_topics_default')),
42-
'disp_posts_default' => intval(Input::post('form_disp_posts_default')),
41+
// 'disp_topics_default' => intval(Input::post('form_disp_topics_default')),
42+
// 'disp_posts_default' => intval(Input::post('form_disp_posts_default')),
4343
'indent_num_spaces' => (intval(Input::post('form_indent_num_spaces')) >= 0) ? intval(Input::post('form_indent_num_spaces')) : 0,
4444
'quote_depth' => (intval(Input::post('form_quote_depth')) > 0) ? intval(Input::post('form_quote_depth')) : 1,
4545
'quickpost' => Input::post('form_quickpost') != '1' ? '0' : '1',
@@ -87,6 +87,8 @@ public function update_options()
8787
'date_format' => Utils::trim(Input::post('form_date_format')),
8888
'smilies' => Input::post('form_smilies') != '1' ? '0' : '1',
8989
'smilies.sig' => Input::post('form_smilies_sig') != '1' ? '0' : '1',
90+
'disp.topics' => intval(Input::post('form_disp_topics_default')),
91+
'disp.posts' => intval(Input::post('form_disp_posts_default')),
9092
);
9193

9294
$form = Container::get('hooks')->fire('model.admin.options.update_options.form', $form);
@@ -183,16 +185,16 @@ public function update_options()
183185
}
184186

185187
// Make sure the number of displayed topics and posts is between 3 and 75
186-
if ($form['disp_topics_default'] < 3) {
187-
$form['disp_topics_default'] = 3;
188-
} elseif ($form['disp_topics_default'] > 75) {
189-
$form['disp_topics_default'] = 75;
188+
if ($prefs['disp.topics'] < 3) {
189+
$prefs['disp.topics'] = 3;
190+
} elseif ($prefs['disp.topics'] > 75) {
191+
$prefs['disp.topics'] = 75;
190192
}
191193

192-
if ($form['disp_posts_default'] < 3) {
193-
$form['disp_posts_default'] = 3;
194-
} elseif ($form['disp_posts_default'] > 75) {
195-
$form['disp_posts_default'] = 75;
194+
if ($prefs['disp.posts'] < 3) {
195+
$prefs['disp.posts'] = 3;
196+
} elseif ($prefs['disp.posts'] > 75) {
197+
$prefs['disp.posts'] = 75;
196198
}
197199

198200
if ($form['report_method'] < 0 || $form['report_method'] > 2) {

featherbb/Model/Api/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function display($id)
2020
// Remove sensitive fields for regular users
2121
if (!$this->isAdMod) {
2222
Container::get('hooks')->bind('model.profile.get_user_info', function ($user) {
23-
$user = $user->select_delete_many(array('u.email', 'u.registration_ip', 'u.disp_topics', 'u.disp_posts', 'u.email_setting', 'u.notify_with_post', 'u.auto_notify', 'u.show_img', 'u.show_img_sig', 'u.show_avatars', 'u.show_sig', 'u.admin_note', 'u.last_visit'));
23+
$user = $user->select_delete_many(array('u.email', 'u.registration_ip', 'u.email_setting', 'u.notify_with_post', 'u.auto_notify', 'u.show_img', 'u.show_img_sig', 'u.show_avatars', 'u.show_sig', 'u.admin_note', 'u.last_visit'));
2424
return $user;
2525
});
2626
}

featherbb/Model/Forum.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function print_topics($forum_id, $sort_by, $start_from)
139139
->order_by_desc('sticky')
140140
->order_by_expr($sort_by)
141141
->order_by_desc('id')
142-
->limit(User::get()->disp_topics)
142+
->limit(User::getPref('disp.topics'))
143143
->offset($start_from);
144144
$result = Container::get('hooks')->fire('model.forum.print_topics_ids_query', $result);
145145
$result = $result->find_many();
@@ -238,7 +238,7 @@ public function print_topics($forum_id, $sort_by, $start_from)
238238
}
239239
}
240240

241-
$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);
241+
$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / User::getPref('disp.posts'));
242242

243243
if ($num_pages_topic > 1) {
244244
$subject_multipage = '<span class="pagestext">[ '.Url::paginate($num_pages_topic, -1, 'topic/'.$cur_topic['id'].'/'.$url_subject.'/#').' ]</span>';
@@ -276,7 +276,7 @@ public function display_topics_moderate($fid, $sort_by, $start_from)
276276
$result = DB::for_table('topics')->select('id')
277277
->where('forum_id', $fid)
278278
->order_by_expr('sticky DESC, '.$sort_by)
279-
->limit(User::get()->disp_topics)
279+
->limit(User::getPref('disp.topics'))
280280
->offset($start_from);
281281
$result = Container::get('hooks')->fireDB('model.forum.display_topics_list_ids', $result);
282282
$result = $result->find_many();
@@ -348,7 +348,7 @@ public function display_topics_moderate($fid, $sort_by, $start_from)
348348
// Insert the status text before the subject
349349
$cur_topic['subject_disp'] = implode(' ', $status_text).' '.$cur_topic['subject_disp'];
350350

351-
$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);
351+
$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / User::getPref('disp.posts'));
352352

353353
if ($num_pages_topic > 1) {
354354
$subject_multipage = '<span class="pagestext">[ '.Url::paginate($num_pages_topic, -1, 'topic/'.$cur_topic['id'].'/'.$url_topic.'/#').' ]</span>';

featherbb/Model/Install.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ class Install
206206
`url` varchar(100) DEFAULT NULL,
207207
`location` varchar(30) DEFAULT NULL,
208208
`signature` text,
209-
`disp_topics` tinyint(3) unsigned DEFAULT NULL,
210-
`disp_posts` tinyint(3) unsigned DEFAULT NULL,
211209
`email_setting` tinyint(1) NOT NULL DEFAULT '1',
212210
`notify_with_post` tinyint(1) NOT NULL DEFAULT '0',
213211
`auto_notify` tinyint(1) NOT NULL DEFAULT '0',

featherbb/Model/Profile.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -824,37 +824,37 @@ public function update_profile($id, $info, $section)
824824

825825
case 'display':
826826
{
827-
$form = array(
828-
'disp_topics' => intval(Input::post('form_disp_topics')),
829-
'disp_posts' => intval(Input::post('form_disp_posts')),
827+
$prefs = array(
828+
'disp.topics' => intval(Input::post('form_disp_topics')),
829+
'disp.posts' => intval(Input::post('form_disp_posts')),
830830
'show_smilies' => Input::post('form_show_smilies') ? '1' : '0',
831831
'show_img' => Input::post('form_show_img') ? '1' : '0',
832832
'show_img_sig' => Input::post('form_show_img_sig') ? '1' : '0',
833833
'show_avatars' => Input::post('form_show_avatars') ? '1' : '0',
834834
'show_sig' => Input::post('form_show_sig') ? '1' : '0',
835835
);
836836

837-
if ($form['disp_topics'] != '') {
838-
if ($form['disp_topics'] < 3) {
839-
$form['disp_topics'] = 3;
840-
} elseif ($form['disp_topics'] > 75) {
841-
$form['disp_topics'] = 75;
837+
if ($prefs['disp.topics'] != '') {
838+
if ($prefs['disp.topics'] < 3) {
839+
$prefs['disp.topics'] = 3;
840+
} elseif ($prefs['disp.topics'] > 75) {
841+
$prefs['disp.topics'] = 75;
842842
}
843843
}
844844

845-
if ($form['disp_posts'] != '') {
846-
if ($form['disp_posts'] < 3) {
847-
$form['disp_posts'] = 3;
848-
} elseif ($form['disp_posts'] > 75) {
849-
$form['disp_posts'] = 75;
845+
if ($prefs['disp.posts'] != '') {
846+
if ($prefs['disp.posts'] < 3) {
847+
$prefs['disp.posts'] = 3;
848+
} elseif ($prefs['disp.posts'] > 75) {
849+
$prefs['disp.posts'] = 75;
850850
}
851851
}
852852

853853
// Make sure we got a valid style string
854854
if (Input::post('form_style')) {
855855
$styles = \FeatherBB\Core\Lister::getStyles();
856-
$form['style'] = Utils::trim(Input::post('form_style'));
857-
if (!in_array($form['style'], $styles)) {
856+
$prefs['style'] = Utils::trim(Input::post('form_style'));
857+
if (!in_array($prefs['style'], $styles)) {
858858
throw new Error(__('Bad request'), 404);
859859
}
860860
}
@@ -998,7 +998,7 @@ public function update_profile($id, $info, $section)
998998

999999
public function get_user_info($id)
10001000
{
1001-
$user['select'] = array('u.id', 'u.username', 'u.email', 'u.title', 'u.realname', 'u.url', 'u.location', 'u.signature', 'u.disp_topics', 'u.disp_posts', 'u.email_setting', 'u.notify_with_post', 'u.auto_notify', 'u.show_img', 'u.show_img_sig', 'u.show_avatars', 'u.show_sig', 'u.num_posts', 'u.last_post', 'u.registered', 'u.registration_ip', 'u.admin_note', 'u.last_visit', 'g.g_id', 'g.g_user_title', 'g.g_moderator');
1001+
$user['select'] = array('u.id', 'u.username', 'u.email', 'u.title', 'u.realname', 'u.url', 'u.location', 'u.signature', 'u.email_setting', 'u.notify_with_post', 'u.auto_notify', 'u.show_img', 'u.show_img_sig', 'u.show_avatars', 'u.show_sig', 'u.num_posts', 'u.last_post', 'u.registered', 'u.registration_ip', 'u.admin_note', 'u.last_visit', 'g.g_id', 'g.g_user_title', 'g.g_moderator');
10021002

10031003
$user = DB::for_table('users')
10041004
->table_alias('u')

featherbb/Model/Search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public function get_search_results()
594594
}
595595

596596
// Determine the topic or post offset (based on $_GET['p'])
597-
$per_page = ($show_as == 'posts') ? User::get()->disp_posts : User::get()->disp_topics;
597+
$per_page = ($show_as == 'posts') ? User::getPref('disp.posts') : User::getPref('disp.topics');
598598
$num_pages = ceil($num_hits / $per_page);
599599

600600
$p = (!Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $num_pages) ? 1 : intval(Input::query('p'));
@@ -763,7 +763,7 @@ public function display_search_results($search)
763763
// Insert the status text before the subject
764764
$subject = implode(' ', $status_text).' '.$subject;
765765

766-
$num_pages_topic = ceil(($cur_search['num_replies'] + 1) / User::get()->disp_posts);
766+
$num_pages_topic = ceil(($cur_search['num_replies'] + 1) / User::getPref('disp.posts'));
767767

768768
if ($num_pages_topic > 1) {
769769
$subject_multipage = '<span class="pagestext">[ '.Url::paginate($num_pages_topic, -1, 'topic/'.$cur_search['tid'].'/'.$url_topic.'/#').' ]</span>';

0 commit comments

Comments
 (0)