Skip to content

Commit dff53f6

Browse files
committed
Early SMF initialization and Ajax Login.
Moved the SMF initialization from template class to the skin class. This allows us to use SMF's globals early. This is needed for setting SMF's headers. Also added the missing `reqOverlayDiv` function for ajax login. smfCurve2TemplateCustom template is already correcly set up to use it. Ajax login works now. Also removed the now obsolete fixes from popup functions, since correctly loading SMF's globals fixes them. This also fixes: * Incorrect viewport setting. (copied from the curve2 theme) * Missing theme color. Signed-off-by: Mustafa Can Elmacı <[email protected]>
1 parent 9374bc6 commit dff53f6

File tree

4 files changed

+238
-166
lines changed

4 files changed

+238
-166
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');

includes/smfCurve2TemplateCustom.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ public function smfUserMenu()
7171
return;
7272
}
7373

74-
$out = $this->getSkin()->getOutput();
75-
$out->addJsConfigVars('ajax_notification_text', $txt['ajax_in_progress']);
76-
7774
// If the user is logged in, display some things that might be useful.
7875
if ($context['user']['is_logged']) {
7976
// Firstly, the user's menu

0 commit comments

Comments
 (0)