Skip to content

Commit c707ce6

Browse files
committed
Fix install, begin smilies cache
1 parent 1b0c4de commit c707ce6

File tree

5 files changed

+182
-50
lines changed

5 files changed

+182
-50
lines changed

featherbb/Controller/Install.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct()
3535
$this->availableLangs = Lister::getLangs();
3636
Container::set('user', null);
3737
View::setStyle('FeatherBB');
38+
Lang::construct();
3839
}
3940

4041
public function run()
@@ -52,7 +53,7 @@ public function run()
5253
$csrf = new \FeatherBB\Middleware\Csrf();
5354
$csrf->generateNewToken(Container::get('request'));
5455

55-
Lang::load('install', 'featherbb', $this->installLang);
56+
Lang::load('install', 'FeatherBB', false, $this->installLang);
5657

5758
// Second form has been submitted to start install
5859
if (Request::isPost() && !Input::post('choose_lang')) {
@@ -191,7 +192,7 @@ public function createDb(array $data)
191192
// Init DB
192193
Core::initDb($data);
193194
// Load appropriate language
194-
Lang::load('install', 'featherbb', $data['language']);
195+
Lang::load('install', 'featherbb', false, $data['language']);
195196

196197
// Create tables
197198
foreach ($this->model->getDatabaseScheme() as $table => $sql) {
@@ -267,6 +268,8 @@ public function createDb(array $data)
267268
$this->model->addMockForum($this->model->loadMockForumData($data));
268269
// Store config in DB
269270
$this->model->saveConfig($this->loadDefaultConfig($data));
271+
// Add smilies
272+
$this->model->addSmilies($this->model->loadSmilies());
270273

271274
// Handle .htaccess
272275
if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules())) {

featherbb/Core/Interfaces/Lang.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,34 @@ public static function construct($domain = 'FeatherBB')
1717
self::$translator->register();
1818
}
1919

20-
public static function load($file, $domain = 'FeatherBB', $path = false)
21-
{
22-
// Set default path to forum core translations
23-
$path = $path ? $path : ForumEnv::get('FEATHER_ROOT').'featherbb/lang';
24-
// Set default language to current user
20+
public static function load($file, $domain = 'FeatherBB', $path = false, $language = false)
21+
{
22+
// Set default path to forum core translations
23+
$path = $path ? $path : ForumEnv::get('FEATHER_ROOT').'featherbb/lang';
24+
// Set default language to current user
25+
if (!$language) {
2526
$language = (!User::get(null)) ? 'English' : User::getPref('language');
27+
}
2628

27-
/**
28-
* Try to locate translation file with the following priority order :
29-
* - As provided in function arguments
30-
* - User language
31-
* - Forum default
32-
* - English (which sould always be available)
33-
*/
34-
if (is_readable($path.'/'.$language.'/'.$file.'.mo')) {
35-
$file = $path.'/'.$language.'/'.$file.'.mo';
36-
} elseif (is_readable($path.'/'.ForumSettings::get('language').'/'.$file.'.mo')) {
37-
$file = $path.'/'.ForumSettings::get('language').'/'.$file.'.mo';
38-
} elseif (is_readable($path.'/English/'.$file.'.mo')) {
39-
$file = $path.'/English/'.$file.'.mo';
40-
} else {
41-
return false;
42-
}
43-
44-
self::$translator->loadTranslations(
45-
Translations::fromMoFile($file)->setDomain($domain)
46-
);
29+
/**
30+
* Try to locate translation file with the following priority order :
31+
* - As provided in function arguments
32+
* - User language
33+
* - Forum default
34+
* - English (which should always be available)
35+
*/
36+
if (is_readable($path.'/'.$language.'/'.$file.'.mo')) {
37+
$file = $path.'/'.$language.'/'.$file.'.mo';
38+
} elseif (is_readable($path.'/'.ForumSettings::get('language').'/'.$file.'.mo')) {
39+
$file = $path.'/'.ForumSettings::get('language').'/'.$file.'.mo';
40+
} elseif (is_readable($path.'/English/'.$file.'.mo')) {
41+
$file = $path.'/English/'.$file.'.mo';
42+
} else {
43+
return false;
4744
}
45+
46+
self::$translator->loadTranslations(
47+
Translations::fromMoFile($file)->setDomain($domain)
48+
);
49+
}
4850
}

featherbb/Middleware/Core.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
class Core
2929
{
30-
protected $forum_env;
31-
protected $forum_settings;
30+
protected $forumEnv;
31+
protected $forumSettings;
3232
protected $headers = [
3333
'Cache-Control' => 'no-cache, no-store, must-revalidate',
3434
'Pragma' => 'no-cache',
@@ -42,23 +42,23 @@ public function __construct($data)
4242
'cache_dir' => 'cache/',
4343
'debug' => false], $data);
4444
// Define some core variables
45-
$this->forum_env['FEATHER_ROOT'] = realpath(dirname(__FILE__).'/../../').'/';
46-
$this->forum_env['FORUM_CACHE_DIR'] = is_writable($this->forum_env['FEATHER_ROOT'].$data['cache_dir']) ? realpath($this->forum_env['FEATHER_ROOT'].$data['cache_dir']).'/' : null;
47-
$this->forum_env['FORUM_CONFIG_FILE'] = $this->forum_env['FEATHER_ROOT'].$data['config_file'];
48-
$this->forum_env['FEATHER_DEBUG'] = $this->forum_env['FEATHER_SHOW_QUERIES'] = ($data['debug'] == 'all' || filter_var($data['debug'], FILTER_VALIDATE_BOOLEAN) == true);
49-
$this->forum_env['FEATHER_SHOW_INFO'] = ($data['debug'] == 'info' || $data['debug'] == 'all');
45+
$this->forumEnv['FEATHER_ROOT'] = realpath(dirname(__FILE__).'/../../').'/';
46+
$this->forumEnv['FORUM_CACHE_DIR'] = is_writable($this->forumEnv['FEATHER_ROOT'].$data['cache_dir']) ? realpath($this->forumEnv['FEATHER_ROOT'].$data['cache_dir']).'/' : null;
47+
$this->forumEnv['FORUM_CONFIG_FILE'] = $this->forumEnv['FEATHER_ROOT'].$data['config_file'];
48+
$this->forumEnv['FEATHER_DEBUG'] = $this->forumEnv['FEATHER_SHOW_QUERIES'] = ($data['debug'] == 'all' || filter_var($data['debug'], FILTER_VALIDATE_BOOLEAN) == true);
49+
$this->forumEnv['FEATHER_SHOW_INFO'] = ($data['debug'] == 'info' || $data['debug'] == 'all');
5050

5151
// Populate forum_env
52-
$this->forum_env = array_merge(self::load_default_forum_env(), $this->forum_env);
52+
$this->forumEnv = array_merge(self::loadDefaultForumEnv(), $this->forumEnv);
5353

5454
// Load files
55-
require $this->forum_env['FEATHER_ROOT'].'featherbb/Helpers/utf8/utf8.php';
55+
require $this->forumEnv['FEATHER_ROOT'].'featherbb/Helpers/utf8/utf8.php';
5656

5757
// Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
5858
setlocale(LC_CTYPE, 'C');
5959
}
6060

61-
public static function load_default_forum_env()
61+
public static function loadDefaultForumEnv()
6262
{
6363
return [
6464
'FEATHER_ROOT' => '',
@@ -84,7 +84,7 @@ public static function load_default_forum_env()
8484
];
8585
}
8686

87-
public static function load_default_forum_settings()
87+
public static function loadDefaultForumSettings()
8888
{
8989
return [
9090
// Database
@@ -145,28 +145,28 @@ public static function loadPlugins()
145145

146146
// Headers
147147

148-
protected function set_headers($res)
148+
protected function setHeaders($res)
149149
{
150150
foreach ($this->headers as $label => $value) {
151151
$res = $res->withHeader($label, $value);
152152
}
153-
$res = $res->withHeader('X-Powered-By', $this->forum_env['FORUM_NAME']);
153+
$res = $res->withHeader('X-Powered-By', $this->forumEnv['FORUM_NAME']);
154154

155155
return $res;
156156
}
157157

158158
public function __invoke($req, $res, $next)
159159
{
160160
// Set headers
161-
$res = $this->set_headers($res);
161+
$res = $this->setHeaders($res);
162162

163163
// Block prefetch requests
164164
if ((isset($_SERVER['HTTP_X_MOZ'])) && ($_SERVER['HTTP_X_MOZ'] == 'prefetch')) {
165165
$res = $res->withStatus(403);
166166
return $next($req, $res);
167167
}
168168
// Populate Slim object with forum_env vars
169-
Container::set('forum_env', $this->forum_env);
169+
Container::set('forum_env', $this->forumEnv);
170170
// Load FeatherBB utils class
171171
Container::set('utils', function ($container) {
172172
return new Utils();
@@ -179,7 +179,7 @@ public function __invoke($req, $res, $next)
179179
});
180180
// Load FeatherBB cache
181181
Container::set('cache', function ($container) {
182-
$path = $this->forum_env['FORUM_CACHE_DIR'];
182+
$path = $this->forumEnv['FORUM_CACHE_DIR'];
183183
return new \FeatherBB\Core\Cache(['name' => 'feather',
184184
'path' => $path,
185185
'extension' => '.cache']);
@@ -208,7 +208,6 @@ public function __invoke($req, $res, $next)
208208
Container::set('email', function ($container) {
209209
return new Email();
210210
});
211-
212211
Container::set('parser', function ($container) {
213212
return new Parser();
214213
});
@@ -233,8 +232,8 @@ public function __invoke($req, $res, $next)
233232

234233
// Load config from disk
235234
include ForumEnv::get('FORUM_CONFIG_FILE');
236-
if (isset($featherbb_config) && is_array($featherbb_config)) {
237-
$this->forum_settings = array_merge(self::load_default_forum_settings(), $featherbb_config);
235+
if (isset($featherbbConfig) && is_array($featherbbConfig)) {
236+
$this->forumSettings = array_merge(self::loadDefaultForumSettings(), $featherbbConfig);
238237
} else {
239238
$res = $res->withStatus(500); // Send forbidden header
240239
$body = $res->getBody();
@@ -243,7 +242,7 @@ public function __invoke($req, $res, $next)
243242
}
244243

245244
// Init DB and configure Slim
246-
self::initDb($this->forum_settings, ForumEnv::get('FEATHER_SHOW_INFO'));
245+
self::initDb($this->forumSettings, ForumEnv::get('FEATHER_SHOW_INFO'));
247246
Config::set('displayErrorDetails', ForumEnv::get('FEATHER_DEBUG'));
248247

249248
// Ensure cached forum data exist
@@ -259,8 +258,8 @@ public function __invoke($req, $res, $next)
259258
}
260259

261260
// Finalize forum_settings array
262-
$this->forum_settings = array_merge(Container::get('cache')->retrieve('config'), $this->forum_settings);
263-
Container::set('forum_settings', $this->forum_settings);
261+
$this->forumSettings = array_merge(Container::get('cache')->retrieve('config'), $this->forumSettings);
262+
Container::set('forum_settings', $this->forumSettings);
264263

265264
Lang::construct();
266265

featherbb/Model/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static function getPermissions()
153153
}
154154
}
155155

156-
// Then get optionnal user permissions to override their group defaults
156+
// Then get optional user permissions to override their group defaults
157157
// TODO: Add a page in profile Administration section to display custom permissions
158158
$usersPerms = DB::table('permissions')
159159
->tableAlias('p')

featherbb/Model/Install.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ class Install
166166
PRIMARY KEY (`word`),
167167
KEY `search_words_id_idx` (`id`)
168168
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
169+
'smilies' => "CREATE TABLE IF NOT EXISTS %t% (
170+
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
171+
`image` varchar(40) NOT NULL DEFAULT '',
172+
`text` varchar(20) NOT NULL DEFAULT '',
173+
`disp_position` tinyint(2) UNSIGNED NOT NULL DEFAULT '0',
174+
PRIMARY KEY (`id`)
175+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
169176
'topic_subscriptions' => "CREATE TABLE IF NOT EXISTS %t% (
170177
`user_id` int(10) unsigned NOT NULL DEFAULT '0',
171178
`topic_id` int(10) unsigned NOT NULL DEFAULT '0',
@@ -249,6 +256,13 @@ public function saveConfig(array $data)
249256
}
250257
}
251258

259+
public function addSmilies(array $smilies)
260+
{
261+
foreach ($smilies as $smiley) {
262+
$this->addData('smilies', $smiley);
263+
}
264+
}
265+
252266
public function getDatabaseScheme()
253267
{
254268
return $this->databaseScheme;
@@ -341,4 +355,118 @@ public static function loadMockForumData(array $data)
341355
'posted' => $now,
342356
'topic_id' => 1]];
343357
}
358+
359+
public static function loadSmilies()
360+
{
361+
return $smilies = [
362+
[
363+
'id' => 1,
364+
'image' => 'smile.png',
365+
'text' => ':)',
366+
'disp_position' => 0
367+
],
368+
[
369+
'id' => 2,
370+
'image' => 'smile.png',
371+
'text' => '=)',
372+
'disp_position' => 1
373+
],
374+
[
375+
'id' => 3,
376+
'image' => 'neutral.png',
377+
'text' => ':|',
378+
'disp_position' => 2
379+
],
380+
[
381+
'id' => 4,
382+
'image' => 'neutral.png',
383+
'text' => '=|',
384+
'disp_position' => 3
385+
],
386+
[
387+
'id' => 5,
388+
'image' => 'sad.png',
389+
'text' => ':(',
390+
'disp_position' => 4
391+
],
392+
[
393+
'id' => 6,
394+
'image' => 'sad.png',
395+
'text' => '=(',
396+
'disp_position' => 5
397+
],
398+
[
399+
'id' => 7,
400+
'image' => 'big_smile.png',
401+
'text' => '=D',
402+
'disp_position' => 6
403+
],
404+
[
405+
'id' => 8,
406+
'image' => 'big_smile.png',
407+
'text' => ':D',
408+
'disp_position' => 7
409+
],
410+
[
411+
'id' => 9,
412+
'image' => 'yikes.png',
413+
'text' => ':o',
414+
'disp_position' => 8
415+
],
416+
[
417+
'id' => 10,
418+
'image' => 'yikes.png',
419+
'text' => ':O',
420+
'disp_position' => 9
421+
],
422+
[
423+
'id' => 11,
424+
'image' => 'wink.png',
425+
'text' => ';)',
426+
'disp_position' => 10
427+
],
428+
[
429+
'id' => 12,
430+
'image' => 'hmm.png',
431+
'text' => ':/',
432+
'disp_position' => 11
433+
],
434+
[
435+
'id' => 13,
436+
'image' => 'tongue.png',
437+
'text' => ':P',
438+
'disp_position' => 12
439+
],
440+
[
441+
'id' => 14,
442+
'image' => 'tongue.png',
443+
'text' => ':p',
444+
'disp_position' => 13
445+
],
446+
[
447+
'id' => 15,
448+
'image' => 'lol.png',
449+
'text' => ':lol:',
450+
'disp_position' => 14
451+
],
452+
[
453+
'id' => 16,
454+
'image' => 'mad.png',
455+
'text' => ':mad:',
456+
'disp_position' => 15
457+
],
458+
[
459+
'id' => 17,
460+
'image' => 'roll.png',
461+
'text' => ':rolleyes:',
462+
'disp_position' => 16
463+
],
464+
[
465+
'id' => 18,
466+
'image' => 'cool.png',
467+
'text' => ':cool:',
468+
'disp_position' => 17
469+
],
470+
];
471+
}
344472
}

0 commit comments

Comments
 (0)