1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24:
25: function installHtmlSpecialCharacters($value)
26: {
27: return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
28: }
29:
30: 31: 32: 33:
34: function install_acceptUser($hash = '')
35: {
36: $xoops = Xoops::getInstance();
37: $xoops->user = null;
38: $hash_data = @explode("-", $_COOKIE['xo_install_user'], 2);
39: list($uname, $hash_login) = array($hash_data[0], (string)(@$hash_data[1]));
40: if (empty($uname) || empty($hash_login)) {
41: return false;
42: }
43: $member_handler = $xoops->getHandlerMember();
44:
45: $users = $member_handler->getUsers(new Criteria('uname', $uname));
46: $user = array_pop($users);
47: if ($hash_login != md5($user->getVar('pass') . XOOPS_DB_NAME . XOOPS_DB_PASS . XOOPS_DB_PREFIX)) {
48: return false;
49: }
50: $xoops->user = $user;
51: $xoops->userIsAdmin = true;
52: $_SESSION['xoopsUserId'] = $xoops->user->getVar('uid');
53: $_SESSION['xoopsUserGroups'] = $xoops->user->getGroups();
54: return true;
55: }
56:
57: 58: 59: 60:
61: function install_finalize($installer_modified)
62: {
63:
64: @chmod(XOOPS_ROOT_PATH . "/mainfile.php", 0444);
65:
66: @chmod(XOOPS_VAR_PATH . "/data/secure.php", 0444);
67:
68: @rename(XOOPS_ROOT_PATH . "/install", XOOPS_ROOT_PATH . "/" . $installer_modified);
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78: 79: 80:
81: function xoFormField($name, $value, $label, $help = '')
82: {
83: $label = installHtmlSpecialCharacters($label);
84: $name = installHtmlSpecialCharacters($name);
85: $value = installHtmlSpecialCharacters($value);
86: echo "<label class='xolabel' for='$name'>$label</label>\n";
87: if ($help) {
88: echo '<div class="xoform-help">' . $help . "</div>\n";
89: }
90: if ($name === "adminname") {
91: echo "<input type='text' name='$name' id='$name' value='$value' maxlength='25' />";
92: } else {
93: echo "<input type='text' name='$name' id='$name' value='$value' />";
94: }
95: }
96:
97: 98: 99: 100: 101: 102: 103: 104: 105: 106:
107: function xoPassField($name, $value, $label, $help = '')
108: {
109: $label = installHtmlSpecialCharacters($label);
110: $name = installHtmlSpecialCharacters($name);
111: $value = installHtmlSpecialCharacters($value);
112: echo "<label class='xolabel' for='{$name}'>{$label}</label>\n";
113: if ($help) {
114: echo '<div class="xoform-help">' . $help . "</div>\n";
115: }
116:
117: if ($name === "adminpass") {
118: echo "<input type='password' name='{$name}' id='{$name}' value='{$value}' onkeyup='passwordStrength(this.value)' />";
119: } else {
120: echo "<input type='password' name='{$name}' id='{$name}' value='{$value}' />";
121: }
122: }
123:
124: 125: 126: 127: 128: 129: 130: 131: 132: 133:
134: function xoBoolField($name, $value, $label, $help = '')
135: {
136: $label = installHtmlSpecialCharacters($label);
137: $name = installHtmlSpecialCharacters($name);
138: $value = installHtmlSpecialCharacters($value);
139: echo "<label class='xolabel' for='$name'>$label</label>\n";
140: if ($help) {
141: echo '<div class="xoform-help">' . $help . "</div>\n";
142: }
143: $checked = $value ? 'checked' : '';
144: echo "<input type=\"checkbox\" name=\"{$name}\" value=\"1\" {$checked} />"
145: . ENABLE . "<br />";
146: }
147:
148: 149: 150: 151: 152: 153:
154: function getDirList($dirname)
155: {
156: $dirlist = array();
157: if ($handle = opendir($dirname)) {
158: while ($file = readdir($handle)) {
159: if ($file{0} !== '.' && is_dir($dirname . $file)) {
160: $dirlist[] = $file;
161: }
162: }
163: closedir($handle);
164: asort($dirlist);
165: reset($dirlist);
166: }
167: return $dirlist;
168: }
169:
170: 171: 172: 173: 174:
175: function xoDiag($status = -1, $str = '')
176: {
177: if ($status == -1) {
178: $_SESSION['error'] = true;
179: }
180: $classes = array(-1 => 'error', 0 => 'warning', 1 => 'success');
181: $strings = array(-1 => FAILED, 0 => WARNING, 1 => SUCCESS);
182: if (empty($str)) {
183: $str = $strings[$status];
184: }
185: return '<span class="' . $classes[$status] . '">' . $str . '</span>';
186: }
187:
188: 189: 190: 191: 192: 193:
194: function xoDiagBoolSetting($name, $wanted = false, $severe = false)
195: {
196: $setting = strtolower(ini_get($name));
197: $setting = (empty($setting) || $setting === 'off' || $setting === 'false') ? false : true;
198: if ($setting == $wanted) {
199: return xoDiag(1, $setting ? 'ON' : 'OFF');
200: } else {
201: return xoDiag($severe ? -1 : 0, $setting ? 'ON' : 'OFF');
202: }
203: }
204:
205: 206: 207: 208:
209: function xoDiagIfWritable($path)
210: {
211: $path = "../" . $path;
212: $error = true;
213: if (!is_dir($path)) {
214: if (file_exists($path)) {
215: @chmod($path, 0666);
216: $error = !is_writeable($path);
217: }
218: } else {
219: @chmod($path, 0777);
220: $error = !is_writeable($path);
221: }
222: return xoDiag($error ? -1 : 1, $error ? 'Not writable' : 'Writable');
223: }
224:
225: 226: 227:
228: function xoPhpVersion()
229: {
230: if (version_compare(phpversion(), '5.4.0', '>=')) {
231: return xoDiag(1, phpversion());
232: } else {
233: return xoDiag(-1, phpversion());
234: }
235: }
236:
237: 238: 239: 240: 241:
242: function genPathCheckHtml($path, $valid)
243: {
244: if ($valid) {
245: switch ($path) {
246: case 'root':
247: $msg = sprintf(XOOPS_FOUND, XOOPS_VERSION);
248: break;
249:
250: case 'lib':
251: case 'data':
252: default:
253: $msg = XOOPS_PATH_FOUND;
254: break;
255: }
256: return '<span class="pathmessage"><img src="img/yes.png" alt="Success" />' . $msg . '</span>';
257: } else {
258: switch ($path) {
259: case 'root':
260: $msg = ERR_NO_XOOPS_FOUND;
261: break;
262:
263: case 'lib':
264: case 'data':
265: default:
266: $msg = ERR_COULD_NOT_ACCESS;
267: break;
268: }
269: return '<span class="pathmessage"><img src="img/no.png" alt="Error" /> ' . $msg . '</span>';
270: }
271: }
272:
273: 274: 275: 276: 277: 278:
279: function getDbConnectionParams()
280: {
281: $wizard = $_SESSION['wizard'];
282: $settings = $_SESSION['settings'];
283:
284:
285: $driver_info = $wizard->configs['db_types'][$settings['DB_DRIVER']];
286: $driver_params=explode(',', $driver_info['params']);
287:
288: $connectionParams = array(
289: 'driver' => $settings['DB_DRIVER'],
290: 'charset' => 'utf8',
291: );
292:
293:
294: if (false !== strstr($settings['DB_DRIVER'],'mysql')) {
295: $connectionParams['charset'] = 'utf8mb4';
296: $connectionParams['collate'] = 'utf8mb4_unicode_ci';
297: }
298:
299: foreach ($driver_params as $param) {
300: if (!empty($settings[$wizard->configs['db_param_names'][$param]])) {
301: $connectionParams[$param] = $settings[$wizard->configs['db_param_names'][$param]];
302: }
303: }
304:
305: return $connectionParams;
306: }
307:
308: 309: 310: 311: 312: 313: 314:
315: function getDbConnection(&$error)
316: {
317:
318: $config = new \Doctrine\DBAL\Configuration();
319: $connectionParams = getDbConnectionParams();
320:
321: try {
322: $instance = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
323: } catch (Exception $e) {
324: $error = $e->getMessage();
325: return false;
326: }
327: if (!$instance) {
328: $error = ERR_NO_DBCONNECTION;
329: return false;
330: } else {
331: try {
332: $instance->connect();
333: } catch (Exception $e) {
334: $error = $e->getMessage();
335: return false;
336: }
337: }
338: return $instance;
339: }
340: