Skip to content

Commit f88093b

Browse files
committed
Early SMF initialization
Moved the SMF initialization from template class to the skin class. This allows us to use SMF's globals early. An example usage is added (Adds forum's favicon to the wiki). This also fixes: * Incorrect viewport setting. (copied from the curve theme) * Missing theme color. Signed-off-by: Mustafa Can Elmacı <[email protected]>
1 parent 9374bc6 commit f88093b

File tree

3 files changed

+238
-163
lines changed

3 files changed

+238
-163
lines changed

includes/smfCurve2Skin.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,34 @@ class smfCurve2Skin extends SkinTemplate
4848
*/
4949
public function initPage(OutputPage $out)
5050
{
51+
$this->smfSetup();
5152
parent::initPage($out);
5253

54+
global $boardurl, $context;
55+
5356
// We want it responsive
54-
$out->addMeta(
55-
'viewport',
56-
'width=device-width, initial-scale=1.0, user-scalable=yes, minimum-scale=0.25, maximum-scale=5.0'
57-
);
57+
$out->addMeta('viewport', 'width=device-width, initial-scale=1');
58+
59+
// What is your Lollipop's color?
60+
$out->addMeta('theme-color', '#557EA0');
61+
62+
// Default JS variables for SMF
63+
if (defined('SMF') && !empty($context['javascript_vars']) && is_array($context['javascript_vars'])) {
64+
$script = "<script>";
65+
66+
foreach ($context['javascript_vars'] as $key => $value) {
67+
if (!is_string($key) || is_numeric($key))
68+
continue;
69+
70+
if (!is_string($value) && !is_numeric($value))
71+
$value = null;
72+
73+
$script .= "\n\tvar {$key} = " . ($value ?? 'null') . ";";
74+
}
75+
76+
$script .= "\n</script>";
77+
$out->addHeadItem('smfcurve2-inline-vars', $script);
78+
}
5879

5980
// CSS & Less Files
6081
$out->addModuleStyles([
@@ -70,4 +91,28 @@ public function initPage(OutputPage $out)
7091
'skins.smfcurve2.js'
7192
]);
7293
}
94+
95+
/**
96+
* Set up the SMF environment.
97+
*/
98+
private function smfSetup()
99+
{
100+
// SMF's massive globals.
101+
global $maintenance, $msubject, $mmessage, $mbname, $language;
102+
global $boardurl, $boarddir, $sourcedir, $webmaster_email, $cookiename, $db_character_set;
103+
global $db_type, $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error, $db_show_debug;
104+
global $db_connection, $db_port, $modSettings, $context, $sc, $user_info, $topic, $board, $txt;
105+
global $smcFunc, $ssi_db_user, $scripturl, $ssi_db_passwd, $db_passwd, $cache_enable, $cachedir;
106+
global $auth_secret, $cache_accelerator, $cache_memcached;
107+
108+
// Add to your LocalSettings: $wgsmfRoot = '';
109+
// If you have the ForumSSoProvider installed you could do: $wgsmfRoot = $wgFSPPath;
110+
$ssi = $this->getConfig()->get('smfRoot');
111+
112+
if (!empty($ssi) && is_string($ssi) && file_exists($ssi . '/SSI.php')) {
113+
include $ssi . '/Settings.php';
114+
115+
require_once $ssi . '/SSI.php';
116+
}
117+
}
73118
}

includes/smfCurve2Template.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,6 @@ private function setupCustomization()
102102
{
103103
global $wgRequest;
104104

105-
// SMF's massive globals.
106-
global $maintenance, $msubject, $mmessage, $mbname, $language;
107-
global $boardurl, $boarddir, $sourcedir, $webmaster_email, $cookiename, $db_character_set;
108-
global $db_type, $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error, $db_show_debug;
109-
global $db_connection, $db_port, $modSettings, $context, $sc, $user_info, $topic, $board, $txt;
110-
global $smcFunc, $ssi_db_user, $scripturl, $ssi_db_passwd, $db_passwd, $cache_enable, $cachedir;
111-
global $auth_secret, $cache_accelerator, $cache_memcached;
112-
113-
// Add to your LocalSettings: $wgsmfRoot = '';
114-
// If you have the ForumSSoProvider installed you could do: $wgsmfRoot = $wgFSPPath;
115-
$ssi = $this->getConfig()->get('smfRoot');
116-
117-
if (!empty($ssi) && is_string($ssi) && file_exists($ssi . '/SSI.php')) {
118-
include $ssi . '/Settings.php';
119-
120-
require_once $ssi . '/SSI.php';
121-
}
122-
123105
// Add to your LocalSettings: $wgshowSMFmenu = true;
124106
if (is_bool($this->getConfig()->get('showSMFmenu'))) {
125107
$this->showSMFmenu = $this->getConfig()->get('showSMFmenu');

0 commit comments

Comments
 (0)