1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Upgrade Smarty 3 Migration |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
* |
12
|
|
|
* @copyright (c) 2000-2023 XOOPS Project (www.xoops.org) |
13
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14
|
|
|
* @package upgrader |
15
|
|
|
* @since 2.3.0 |
16
|
|
|
* @author Skalpa Keo <[email protected]> |
17
|
|
|
* @author Taiwen Jiang <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
/* @var XoopsUser $xoopsUser */ |
20
|
|
|
|
21
|
|
|
use Xoops\Upgrade\ScannerOutput; |
22
|
|
|
use Xoops\Upgrade\ScannerProcess; |
23
|
|
|
use Xoops\Upgrade\ScannerWalker; |
24
|
|
|
use Xoops\Upgrade\Smarty3ScannerOutput; |
25
|
|
|
use Xoops\Upgrade\Smarty3TemplateChecks; |
26
|
|
|
use Xoops\Upgrade\Smarty3TemplateRepair; |
27
|
|
|
use Xoops\Upgrade\Smarty3RepairOutput; |
28
|
|
|
|
29
|
|
|
function fatalPhpErrorHandler($e = null) |
30
|
|
|
{ |
31
|
|
|
$messageFormat = '<br><div>Fatal %s %s file: %s : %d </div>'; |
32
|
|
|
$exceptionClass = '\Exception'; |
33
|
|
|
$throwableClass = '\Throwable'; |
34
|
|
|
if ($e === null) { |
35
|
|
|
$lastError = error_get_last(); |
36
|
|
|
if ($lastError['type'] === E_ERROR) { |
37
|
|
|
// fatal error |
38
|
|
|
printf($messageFormat, 'Error', $lastError['message'], $lastError['file'], $lastError['line']); |
39
|
|
|
} |
40
|
|
|
} elseif ($e instanceof $exceptionClass || $e instanceof $throwableClass) { |
41
|
|
|
/** @var \Exception $e */ |
42
|
|
|
printf($messageFormat, get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
register_shutdown_function('fatalPhpErrorHandler'); |
46
|
|
|
set_exception_handler('fatalPhpErrorHandler'); |
47
|
|
|
|
48
|
|
|
/* |
49
|
|
|
* Before xoops 2.5.8 the table 'sess_ip' was of type varchar (15). This is a problem for IPv6 |
50
|
|
|
* addresses because it is longer. The upgrade process would change the column to VARCHAR(45) |
51
|
|
|
* but it requires login, which is failing. If the user has an IPv6 address, it is converted to |
52
|
|
|
* short IP during the upgrade. At the end of the upgrade IPV6 works |
53
|
|
|
* |
54
|
|
|
* Here we save the current IP address if needed |
55
|
|
|
*/ |
56
|
|
|
$ip = $_SERVER['REMOTE_ADDR']; |
57
|
|
|
if (strlen($_SERVER['REMOTE_ADDR']) > 15) { |
58
|
|
|
//new IP for upgrade |
59
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
include_once __DIR__ . '/checkmainfile.php'; |
63
|
|
|
defined('XOOPS_ROOT_PATH') or die('Bad installation: please add this folder to the XOOPS install you want to upgrade'); |
64
|
|
|
|
65
|
|
|
$endscan = Xmf\Request::getString('endscan', 'no'); |
66
|
|
|
if ($endscan === 'yes') { |
67
|
|
|
$_SESSION['preflight'] = 'complete'; |
68
|
|
|
header("Location: ./index.php"); |
69
|
|
|
exit; |
70
|
|
|
} |
71
|
|
|
$_SESSION['preflight'] = 'active'; // so that manually loading preflight.php forces to active |
72
|
|
|
|
73
|
|
|
$reporting = 0; |
74
|
|
|
if (isset($_GET['debug'])) { |
75
|
|
|
$reporting = -1; |
76
|
|
|
} |
77
|
|
|
error_reporting($reporting); |
78
|
|
|
$xoopsLogger->activated = true; |
79
|
|
|
$xoopsLogger->enableRendering(); |
80
|
|
|
xoops_loadLanguage('logger'); |
81
|
|
|
set_exception_handler('fatalPhpErrorHandler'); // should have been changed by now, reset to ours |
82
|
|
|
|
83
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/ScannerOutput.php'; |
84
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/ScannerProcess.php'; |
85
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/ScannerWalker.php'; |
86
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/Smarty3ScannerOutput.php'; |
87
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/Smarty3TemplateChecks.php'; |
88
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/Smarty3TemplateRepair.php'; |
89
|
|
|
require __DIR__ . '/class/Xoops/Upgrade/Smarty3RepairOutput.php'; |
90
|
|
|
|
91
|
|
|
require __DIR__ . '/class/abstract.php'; |
92
|
|
|
require __DIR__ . '/class/patchstatus.php'; |
93
|
|
|
require __DIR__ . '/class/control.php'; |
94
|
|
|
|
95
|
|
|
$GLOBALS['error'] = false; |
96
|
|
|
$GLOBALS['upgradeControl'] = new UpgradeControl(); |
97
|
|
|
|
98
|
|
|
$upgradeControl->determineLanguage(); |
99
|
|
|
|
100
|
|
|
if (file_exists(__DIR__ . "../language/{$upgradeControl->upgradeLanguage}/user.php")) { |
101
|
|
|
include_once __DIR__ . "../language/{$upgradeControl->upgradeLanguage}/user.php"; |
102
|
|
|
} else { |
103
|
|
|
include_once __DIR__ . "../language/english/user.php"; |
104
|
|
|
} |
105
|
|
|
if (file_exists(__DIR__ . "/language/{$upgradeControl->upgradeLanguage}/smarty3.php")) { |
106
|
|
|
include_once __DIR__ . "/language/{$upgradeControl->upgradeLanguage}/smarty3.php"; |
107
|
|
|
} else { |
108
|
|
|
include_once __DIR__ . "/language/english/smarty3.php"; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* User options form for preflight |
113
|
|
|
* template_dir a directory relative to XOOPS_ROOT_PATH, i.e. /themes/ or /themes/xbootstrap/ |
114
|
|
|
* template_ext a file extension to scan for. Typical values are tpl or html |
115
|
|
|
* runfix if checked, attempt to fix any issues found. Note not all possible issues can be automatically fixed |
116
|
|
|
* |
117
|
|
|
* @return string options form |
118
|
|
|
*/ |
119
|
|
|
function tplScannerForm($parameters=null) |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
$action = XOOPS_URL . '/upgrade/preflight.php'; |
122
|
|
|
|
123
|
|
|
$form = '<h2>' . _XOOPS_SMARTY3_RESCAN_OPTIONS . '</h2>'; |
124
|
|
|
$form .= '<form action="' . $action . '" method="post" class="form-horizontal">'; |
125
|
|
|
|
126
|
|
|
$form .= '<div class="form-group">'; |
127
|
|
|
$form .= '<input name="template_dir" class="form-control" type="text" placeholder="/themes/">'; |
128
|
|
|
$form .= '<label for="template_dir">' . _XOOPS_SMARTY3_TEMPLATE_DIR . '</label>'; |
129
|
|
|
$form .= '</div>'; |
130
|
|
|
|
131
|
|
|
$form .= '<div class="form-group">'; |
132
|
|
|
$form .= '<input name="template_ext" class="form-control" type="text" placeholder="tpl">'; |
133
|
|
|
$form .= '<label for="template_ext">' . _XOOPS_SMARTY3_TEMPLATE_EXT . '</label>'; |
134
|
|
|
$form .= '</div>'; |
135
|
|
|
|
136
|
|
|
$form .= '<div class="form-group row">'; |
137
|
|
|
$form .= '<div class="form-check">'; |
138
|
|
|
$form .= '<legend class="col-form-label">' . _XOOPS_SMARTY3_FIX_BUTTON . '</legend>'; |
139
|
|
|
$form .= '<input class="form-check-input" type="checkbox" name="runfix" >'; |
140
|
|
|
$form .= '<label class="form-check-label" for="runfix">' . _YES . '</label>'; |
141
|
|
|
$form .= '</div>'; |
142
|
|
|
$form .= '</div>'; |
143
|
|
|
|
144
|
|
|
$form .= '<div class="form-group">'; |
145
|
|
|
$form .= '<button class="btn btn-lg btn-success" type="submit">' . _XOOPS_SMARTY3_SCANNER_RUN; |
146
|
|
|
$form .= ' <span class="fa fa-caret-right"></span></button>'; |
147
|
|
|
$form .= '</div>'; |
148
|
|
|
|
149
|
|
|
$form .= '</form>'; |
150
|
|
|
|
151
|
|
|
$form .= '<form action="' . $action . '" method="post" class="form-horizontal">'; |
152
|
|
|
$form .= '<div class="form-group">'; |
153
|
|
|
$form .= '<button class="btn btn-lg btn-danger" type="submit">' . _XOOPS_SMARTY3_SCANNER_END; |
154
|
|
|
$form .= ' <span class="fa fa-caret-right"></span></button>'; |
155
|
|
|
$form .= '<input type="hidden" name="endscan" value="yes">'; |
156
|
|
|
$form .= '</div>'; |
157
|
|
|
|
158
|
|
|
$form .= '</form>'; |
159
|
|
|
|
160
|
|
|
return $form; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
ob_start(); |
164
|
|
|
|
165
|
|
|
global $xoopsUser; |
166
|
|
|
if (!$xoopsUser || !$xoopsUser->isAdmin()) { |
|
|
|
|
167
|
|
|
include_once __DIR__ . '/login.php'; |
168
|
|
|
} else { |
169
|
|
|
$template_dir = Xmf\Request::getString('template_dir', ''); |
170
|
|
|
$template_ext = Xmf\Request::getString('template_ext', ''); |
171
|
|
|
$runfix = Xmf\Request::getString('runfix', 'off'); |
172
|
|
|
Xmf\Debug::dump($_POST, $runfix, $template_dir, $template_ext); |
173
|
|
|
if (empty($op)) { |
174
|
|
|
$upgradeControl->loadLanguage('welcome'); |
175
|
|
|
echo _XOOPS_SMARTY3_SCANNER_OFFER; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if ($runfix==='on') { |
179
|
|
|
$output = new Smarty3RepairOutput(); |
180
|
|
|
$process = new Smarty3TemplateRepair($output); |
181
|
|
|
} else { |
182
|
|
|
$output = new Smarty3ScannerOutput(); |
183
|
|
|
$process = new Smarty3TemplateChecks($output); |
184
|
|
|
} |
185
|
|
|
$scanner = new ScannerWalker($process, $output); |
186
|
|
|
if('' === $template_dir) { |
187
|
|
|
$scanner->addDirectory(XOOPS_ROOT_PATH . '/themes/'); |
188
|
|
|
$scanner->addDirectory(XOOPS_ROOT_PATH . '/modules/'); |
189
|
|
|
} else { |
190
|
|
|
$scanner->addDirectory(XOOPS_ROOT_PATH . $template_dir); |
191
|
|
|
} |
192
|
|
|
if('' === $template_ext) { |
193
|
|
|
$scanner->addExtension('tpl'); |
194
|
|
|
$scanner->addExtension('html'); |
195
|
|
|
} else { |
196
|
|
|
$scanner->addExtension($template_ext); |
197
|
|
|
} |
198
|
|
|
$scanner->runScan(); |
199
|
|
|
|
200
|
|
|
echo $output->outputFetch(); |
201
|
|
|
|
202
|
|
|
echo tplScannerForm(); |
203
|
|
|
} |
204
|
|
|
$content = ob_get_contents(); |
205
|
|
|
ob_end_clean(); |
206
|
|
|
|
207
|
|
|
//echo $content; |
208
|
|
|
|
209
|
|
|
include_once __DIR__ . '/upgrade_tpl.php'; |
210
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.