Skip to content

Commit 26a08f4

Browse files
committed
Begin to load default forum preferences
for : - show smilies - language - style - time format - date format
1 parent eb66d8f commit 26a08f4

File tree

18 files changed

+76
-70
lines changed

18 files changed

+76
-70
lines changed

featherbb/Controller/Install.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,12 @@ public function create_db(array $data)
225225
'search.min_interval' => 30,
226226
'email.min_interval' => 60,
227227
'report.min_interval' => 60,
228-
'core.timezone' => 0,
229-
'core.time_format' => 'H:i:s',
230-
'core.date_format' => 'Y-m-d',
231-
'core.lang' => $data['default_lang'],
232-
'core.style' => $data['default_style'],
233-
'smilies.post.show' => 1,
234-
'smilies.signature.show' => 1,
228+
'timezone' => 0,
229+
'time_format' => 'H:i:s',
230+
'date_format' => 'Y-m-d',
231+
'language' => $data['default_lang'],
232+
'style' => $data['default_style'],
233+
'smilies' => 1,
235234
));
236235
Container::get('prefs')->setGroup(2, array(
237236
'post.min_interval' => 0,
@@ -291,19 +290,19 @@ public function load_default_config(array $data)
291290
'o_board_title' => $data['title'],
292291
'o_board_desc' => $data['description'],
293292
'o_default_timezone' => 0,
294-
'o_time_format' => 'H:i:s',
295-
'o_date_format' => 'Y-m-d',
293+
// 'o_time_format' => 'H:i:s',
294+
// 'o_date_format' => 'Y-m-d',
296295
'o_timeout_visit' => 1800,
297296
'o_timeout_online' => 300,
298297
'o_show_version' => 0,
299298
'o_show_user_info' => 1,
300299
'o_show_post_count' => 1,
301300
'o_signatures' => 1,
302-
'o_smilies' => 1,
301+
// 'o_smilies' => 1,
303302
'o_smilies_sig' => 1,
304303
'o_make_links' => 1,
305-
'o_default_lang' => $data['default_lang'],
306-
'o_default_style' => $data['default_style'],
304+
// 'o_default_lang' => $data['default_lang'],
305+
// 'o_default_style' => $data['default_style'],
307306
'o_default_user_group' => 4,
308307
'o_topic_review' => 15,
309308
'o_disp_topics_default' => 30,

featherbb/Core/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ public function parse_bbcode(&$text, $hide_smilies = 0)
7777
// Set $smile_on flag depending on global flags and whether or not this is a signature.
7878
if ($this->pd['in_signature'])
7979
{
80-
$smile_on = (ForumSettings::get('o_smilies_sig') && User::get()['show_smilies'] && !$hide_smilies) ? 1 : 0;
80+
$smile_on = (ForumSettings::get('o_smilies_sig') && User::getPref('smilies') && !$hide_smilies) ? 1 : 0;
8181
}
8282
else
8383
{
84-
$smile_on = (ForumSettings::get('o_smilies') && User::get()['show_smilies'] && !$hide_smilies) ? 1 : 0;
84+
$smile_on = (ForumSettings::get('smilies') && User::getPref('smilies') && !$hide_smilies) ? 1 : 0;
8585
}
8686
// Split text into hidden and non-hidden chunks. Process the non-hidden content chunks.
8787
$parts = explode("\1", $text); // Hidden chunks pre-marked like so: "\1\2<code.../code>\1"

featherbb/Core/Utils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public static function format_time($timestamp, $date_only = false, $date_format
7070
$now = time();
7171

7272
if (is_null($date_format)) {
73-
$date_format = Container::get('forum_date_formats')[User::get()->date_format];
73+
$date_format = Container::get('forum_date_formats')[User::getPref('date_format')];
7474
}
7575

7676
if (is_null($time_format)) {
77-
$time_format = Container::get('forum_time_formats')[User::get()->time_format];
77+
$time_format = Container::get('forum_time_formats')[User::getPref('time_format')];
7878
}
7979

8080
$date = gmdate($date_format, $timestamp);

featherbb/Core/gettext/l10n.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ function translate($mofile, $domain = 'featherbb', $language = false, $path = fa
3333
*/
3434
if (is_readable($path.'/'.$language.'/'.$mofile.'.mo')) {
3535
$mofile = $path.'/'.$language.'/'.$mofile.'.mo';
36-
} elseif (is_readable($path.'/'.ForumSettings::get('o_default_lang').'/'.$mofile.'.mo')) {
37-
$mofile = $path.'/'.ForumSettings::get('o_default_lang').'/'.$mofile.'.mo';
36+
} elseif (is_readable($path.'/'.ForumSettings::get('language').'/'.$mofile.'.mo')) {
37+
$mofile = $path.'/'.ForumSettings::get('language').'/'.$mofile.'.mo';
3838
} elseif (is_readable($path.'/English/'.$mofile.'.mo')) {
3939
$mofile = $path.'/English/'.$mofile.'.mo';
4040
} else {

featherbb/Middleware/Auth.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ private function load_default_user()
228228
$user->disp_posts = ForumSettings::get('o_disp_posts_default');
229229
$user->timezone = ForumSettings::get('o_default_timezone');
230230
$user->dst = ForumSettings::get('o_default_dst');
231-
$user->language = ForumSettings::get('o_default_lang');
232-
$user->style = ForumSettings::get('o_default_style');
231+
$user->language = ForumSettings::get('language');
232+
$user->style = ForumSettings::get('style');
233233
$user->is_guest = true;
234234
$user->is_admmod = false;
235235

@@ -268,10 +268,10 @@ public function __invoke($req, $res, $next)
268268
$user->disp_posts = ForumSettings::get('o_disp_posts_default');
269269
}
270270
if (!file_exists(ForumEnv::get('FEATHER_ROOT').'featherbb/lang/'.$user->language)) {
271-
$user->language = ForumSettings::get('o_default_lang');
271+
$user->language = ForumSettings::get('language');
272272
}
273273
if (!file_exists(ForumEnv::get('FEATHER_ROOT').'style/themes/'.$user->style.'/style.css')) {
274-
$user->style = ForumSettings::get('o_default_style');
274+
$user->style = ForumSettings::get('style');
275275
}
276276

277277
// Add user to DIC

featherbb/Middleware/Core.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ public function __invoke($req, $res, $next)
245245
self::loadPlugins();
246246

247247
// Define time formats and add them to the container
248-
Container::set('forum_time_formats', array(ForumSettings::get('o_time_format'), 'H:i:s', 'H:i', 'g:i:s a', 'g:i a'));
249-
Container::set('forum_date_formats', array(ForumSettings::get('o_date_format'), 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y'));
248+
Container::set('forum_time_formats', array(ForumSettings::get('time_format'), 'H:i:s', 'H:i', 'g:i:s a', 'g:i a'));
249+
Container::set('forum_date_formats', array(ForumSettings::get('date_format'), 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y'));
250250

251251
// Call FeatherBBAuth middleware
252252
return $next($req, $res);

featherbb/Model/Admin/Options.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public function update_options()
2525
'base_url' => Utils::trim(Input::post('form_base_url')),
2626
'default_timezone' => floatval(Input::post('form_default_timezone')),
2727
'default_dst' => Input::post('form_default_dst') != '1' ? '0' : '1',
28-
'default_lang' => Utils::trim(Input::post('form_default_lang')),
29-
'default_style' => Utils::trim(Input::post('form_default_style')),
30-
'time_format' => Utils::trim(Input::post('form_time_format')),
31-
'date_format' => Utils::trim(Input::post('form_date_format')),
28+
// 'default_lang' => Utils::trim(Input::post('form_default_lang')),
29+
// 'default_style' => Utils::trim(Input::post('form_default_style')),
30+
// 'time_format' => Utils::trim(Input::post('form_time_format')),
31+
// 'date_format' => Utils::trim(Input::post('form_date_format')),
3232
'timeout_visit' => (intval(Input::post('form_timeout_visit')) > 0) ? intval(Input::post('form_timeout_visit')) : 1,
3333
'timeout_online' => (intval(Input::post('form_timeout_online')) > 0) ? intval(Input::post('form_timeout_online')) : 1,
3434
'show_version' => Input::post('form_show_version') != '1' ? '0' : '1',
3535
'show_user_info' => Input::post('form_show_user_info') != '1' ? '0' : '1',
3636
'show_post_count' => Input::post('form_show_post_count') != '1' ? '0' : '1',
37-
'smilies' => Input::post('form_smilies') != '1' ? '0' : '1',
37+
// 'smilies' => Input::post('form_smilies') != '1' ? '0' : '1',
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,
@@ -78,7 +78,17 @@ public function update_options()
7878
'maintenance_message' => Utils::trim(Input::post('form_maintenance_message')),
7979
);
8080

81+
$prefs = array(
82+
'language' => Utils::trim(Input::post('form_default_lang')),
83+
'style' => Utils::trim(Input::post('form_default_style')),
84+
'time_format' => Utils::trim(Input::post('form_time_format')),
85+
'date_format' => Utils::trim(Input::post('form_date_format')),
86+
'smilies' => Input::post('form_smilies') != '1' ? '0' : '1',
87+
88+
);
89+
8190
$form = Container::get('hooks')->fire('model.admin.options.update_options.form', $form);
91+
$prefs = Container::get('hooks')->fire('model.admin.options.update_options.prefs', $prefs);
8292

8393
if ($form['board_title'] == '') {
8494
throw new Error(__('Must enter title message'), 400);
@@ -99,21 +109,21 @@ public function update_options()
99109
}
100110

101111
$languages = \FeatherBB\Core\Lister::getLangs();
102-
if (!in_array($form['default_lang'], $languages)) {
112+
if (!in_array($prefs['language'], $languages)) {
103113
throw new Error(__('Bad request'), 404);
104114
}
105115

106116
$styles = \FeatherBB\Core\Lister::getStyles();
107-
if (!in_array($form['default_style'], $styles)) {
117+
if (!in_array($prefs['style'], $styles)) {
108118
throw new Error(__('Bad request'), 404);
109119
}
110120

111-
if ($form['time_format'] == '') {
112-
$form['time_format'] = 'H:i:s';
121+
if ($prefs['time_format'] == '') {
122+
$prefs['time_format'] = 'H:i:s';
113123
}
114124

115-
if ($form['date_format'] == '') {
116-
$form['date_format'] = 'Y-m-d';
125+
if ($prefs['date_format'] == '') {
126+
$prefs['date_format'] = 'Y-m-d';
117127
}
118128

119129
if (!Container::get('email')->is_valid_email($form['admin_email'])) {
@@ -208,8 +218,10 @@ public function update_options()
208218
}
209219
}
210220

221+
Container::get('prefs')->set($prefs);
222+
211223
// Regenerate the config cache
212-
Container::get('cache')->store('config', Cache::get_config());
224+
Container::get('cache')->store('config', array_merge(Cache::get_config(), Cache::get_preferences()));
213225

214226
return Router::redirect(Router::pathFor('adminOptions'), __('Options updated redirect'));
215227
}
@@ -222,7 +234,7 @@ public function get_styles()
222234
$output = '';
223235

224236
foreach ($styles as $temp) {
225-
if (ForumSettings::get('o_default_style') == $temp) {
237+
if (ForumSettings::get('style') == $temp) {
226238
$output .= "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
227239
} else {
228240
$output .= "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
@@ -241,7 +253,7 @@ public function get_langs()
241253
$output = '';
242254

243255
foreach ($langs as $temp) {
244-
if (ForumSettings::get('o_default_lang') == $temp) {
256+
if (ForumSettings::get('language') == $temp) {
245257
$output .= "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
246258
} else {
247259
$output .= "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";

featherbb/Model/Install.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ class Install
128128
KEY `posts_multi_idx` (`poster_id`,`topic_id`)
129129
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
130130
'preferences' => "CREATE TABLE IF NOT EXISTS %t% (
131-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
132-
`preference_name` tinytext,
131+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
132+
`preference_name` varchar(200) NOT NULL,
133133
`preference_value` tinytext,
134-
`user` int(11) DEFAULT NULL,
135-
`group` int(11) DEFAULT NULL,
134+
`user` int(10) unsigned DEFAULT NULL,
135+
`group` int(10) unsigned DEFAULT NULL,
136136
`default` tinyint(1) DEFAULT NULL,
137137
PRIMARY KEY (`id`)
138138
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;",
@@ -211,17 +211,12 @@ class Install
211211
`email_setting` tinyint(1) NOT NULL DEFAULT '1',
212212
`notify_with_post` tinyint(1) NOT NULL DEFAULT '0',
213213
`auto_notify` tinyint(1) NOT NULL DEFAULT '0',
214-
`show_smilies` tinyint(1) NOT NULL DEFAULT '1',
215214
`show_img` tinyint(1) NOT NULL DEFAULT '1',
216215
`show_img_sig` tinyint(1) NOT NULL DEFAULT '1',
217216
`show_avatars` tinyint(1) NOT NULL DEFAULT '1',
218217
`show_sig` tinyint(1) NOT NULL DEFAULT '1',
219218
`timezone` float NOT NULL DEFAULT '0',
220219
`dst` tinyint(1) NOT NULL DEFAULT '0',
221-
`time_format` tinyint(1) NOT NULL DEFAULT '0',
222-
`date_format` tinyint(1) NOT NULL DEFAULT '0',
223-
`language` varchar(25) NOT NULL DEFAULT 'English',
224-
`style` varchar(25) NOT NULL DEFAULT 'FeatherBB',
225220
`num_posts` int(10) unsigned NOT NULL DEFAULT '0',
226221
`last_post` int(10) unsigned DEFAULT NULL,
227222
`last_search` int(10) unsigned DEFAULT NULL,

featherbb/Model/Post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ public function get_checkboxes($fid, $is_admmod, $is_subscribed)
12711271
}
12721272

12731273
if (!User::get()->is_guest) {
1274-
if (ForumSettings::get('o_smilies') == '1') {
1274+
if (ForumSettings::get('smilies') == '1') {
12751275
$checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'"'.(Input::post('hide_smilies') ? ' checked="checked"' : '').' />'.__('Hide smilies').'<br /></label>';
12761276
}
12771277

@@ -1293,7 +1293,7 @@ public function get_checkboxes($fid, $is_admmod, $is_subscribed)
12931293

12941294
$checkboxes[] = '<label><input type="checkbox" name="subscribe" value="1" tabindex="'.($cur_index++).'"'.($subscr_checked ? ' checked="checked"' : '').' />'.($is_subscribed ? __('Stay subscribed') : __('Subscribe')).'<br /></label>';
12951295
}
1296-
} elseif (ForumSettings::get('o_smilies') == '1') {
1296+
} elseif (ForumSettings::get('smilies') == '1') {
12971297
$checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'"'.(Input::post('hide_smilies') ? ' checked="checked"' : '').' />'.__('Hide smilies').'<br /></label>';
12981298
}
12991299

@@ -1316,7 +1316,7 @@ public function get_edit_checkboxes($can_edit_subject, $is_admmod, $cur_post, $c
13161316
}
13171317
}
13181318

1319-
if (ForumSettings::get('o_smilies') == '1') {
1319+
if (ForumSettings::get('smilies') == '1') {
13201320
if (Input::post('hide_smilies') || $cur_post['hide_smilies'] == '1') {
13211321
$checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" checked="checked" tabindex="'.($cur_index++).'" />'.__('Hide smilies').'<br /></label>';
13221322
} else {

featherbb/Model/Profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ public function update_profile($id, $info, $section)
994994

995995
public function get_user_info($id)
996996
{
997-
$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_smilies', 'u.show_img', 'u.show_img_sig', 'u.show_avatars', 'u.show_sig', 'u.timezone', 'u.dst', 'u.language', 'u.style', 'u.num_posts', 'u.last_post', 'u.registered', 'u.registration_ip', 'u.admin_note', 'u.date_format', 'u.time_format', 'u.last_visit', 'g.g_id', 'g.g_user_title', 'g.g_moderator');
997+
$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_smilies', 'u.show_img', 'u.show_img_sig', 'u.show_avatars', 'u.show_sig', 'u.timezone', 'u.dst', 'u.language', 'u.style', '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');
998998

999999
$user = DB::for_table('users')
10001000
->table_alias('u')

0 commit comments

Comments
 (0)