38 $this->sanitizer = TextSanitizer::getInstance();
43 $this->dbhost =
'localhost';
47 mt_srand( (
double) microtime() * 1_000_000 );
49 $this->prefix = substr( md5( random_int( 1, 6 ) ), 0, 6 );
50 }
while ( ! preg_match(
'/^[a-z]/', $this->prefix ) );
52 $this->salt = substr( md5( random_int(0, mt_getrandmax()) ), 5, 8 );
54 $this->db_pconnect = 0;
56 $this->root_path = str_replace(
'\\',
'/', getcwd() );
57 $this->root_path = str_replace(
'/install',
'', $this->root_path );
59 $filepath = ( ! empty( $_SERVER[
'REQUEST_URI'] ) )
60 ? dirname( $_SERVER[
'REQUEST_URI'] )
61 : dirname( $_SERVER[
'SCRIPT_NAME'] );
64 $filepath = str_replace( [
'\\',
'/install' ], [
'/',
'' ], $filepath );
65 if (
'/' === substr( $filepath, 0, 1 ) ) {
66 $filepath = substr( $filepath, 1 );
68 if (
'/' === substr( $filepath, - 1 ) ) {
69 $filepath = substr( $filepath, 0, - 1 );
71 $protocol = ( ! empty( $_SERVER[
'HTTPS'] ) && (
'on' === $_SERVER[
'HTTPS'] ) ) ?
'https://' :
'http://';
72 $this->xoops_url = ( ! empty( $filepath ) ) ? $protocol . $_SERVER[
'HTTP_HOST'] .
'/' . $filepath : $protocol . $_SERVER[
'HTTP_HOST'];
75 $path = $this->root_path;
76 while ( strlen( $path ) > 4 ) {
77 if ( is_dir( $path .
'/xoops_trust_path' ) ) {
78 $this->trust_path = $path .
'/xoops_trust_path';
81 if ( is_dir( $path .
'/trust_path' ) ) {
82 $this->trust_path = $path .
'/trust_path';
85 $path = dirname( $path );
90 public function readPost() {
91 if ( isset( $_POST[
'database'] ) ) {
92 $this->
database = $this->sanitizer->stripSlashesGPC( $_POST[
'database'] );
94 if ( isset( $_POST[
'dbhost'] ) ) {
95 $this->dbhost = $this->sanitizer->stripSlashesGPC( $_POST[
'dbhost'] );
97 if ( isset( $_POST[
'dbuname'] ) ) {
98 $this->dbuname = $this->sanitizer->stripSlashesGPC( $_POST[
'dbuname'] );
100 if ( isset( $_POST[
'dbpass'] ) ) {
101 $this->dbpass = $this->sanitizer->stripSlashesGPC( $_POST[
'dbpass'] );
103 if ( isset( $_POST[
'dbname'] ) ) {
104 $this->dbname = $this->sanitizer->stripSlashesGPC( $_POST[
'dbname'] );
106 if ( isset( $_POST[
'prefix'] ) ) {
107 $this->prefix = $this->sanitizer->stripSlashesGPC( $_POST[
'prefix'] );
109 if ( isset( $_POST[
'db_pconnect'] ) ) {
110 $this->db_pconnect = (int) $_POST[
'db_pconnect'] > 0 ? 1 : 0;
112 if ( isset( $_POST[
'root_path'] ) ) {
113 $this->root_path = $this->sanitizer->stripSlashesGPC( $_POST[
'root_path'] );
115 if ( isset( $_POST[
'trust_path'] ) ) {
116 $this->trust_path = $this->sanitizer->stripSlashesGPC( $_POST[
'trust_path'] );
118 if ( isset( $_POST[
'xoops_url'] ) ) {
119 $this->xoops_url = $this->sanitizer->stripSlashesGPC( $_POST[
'xoops_url'] );
121 if ( isset( $_POST[
'salt'] ) ) {
122 $this->salt = $this->sanitizer->stripSlashesGPC( $_POST[
'salt'] );
126 public function readConstant() {
127 if ( defined(
'XOOPS_DB_TYPE' ) ) {
128 $this->database = XOOPS_DB_TYPE;
130 if ( defined(
'XOOPS_DB_HOST' ) ) {
131 $this->dbhost = XOOPS_DB_HOST;
133 if ( defined(
'XOOPS_DB_USER' ) ) {
134 $this->dbuname = XOOPS_DB_USER;
136 if ( defined(
'XOOPS_DB_PASS' ) ) {
137 $this->dbpass = XOOPS_DB_PASS;
139 if ( defined(
'XOOPS_DB_NAME' ) ) {
140 $this->dbname = XOOPS_DB_NAME;
142 if ( defined(
'XOOPS_DB_PREFIX' ) ) {
143 $this->prefix = XOOPS_DB_PREFIX;
145 if ( defined(
'XOOPS_DB_PCONNECT' ) ) {
146 $this->db_pconnect = XOOPS_DB_PCONNECT > 0 ? 1 : 0;
148 if ( defined(
'XOOPS_ROOT_PATH' ) ) {
149 $this->root_path = XOOPS_ROOT_PATH;
151 if ( defined(
'XOOPS_TRUST_PATH' ) ) {
152 $this->trust_path = XOOPS_TRUST_PATH;
154 if ( defined(
'XOOPS_URL' ) ) {
155 $this->xoops_url = XOOPS_URL;
157 if ( defined(
'XOOPS_SALT' ) ) {
158 $this->salt = XOOPS_SALT;
162 public function checkData() {
166 if ( empty( $this->dbhost ) ) {
167 $error[] = sprintf( _INSTALL_L57, _INSTALL_L27 );
169 if ( empty( $this->dbname ) ) {
170 $error[] = sprintf( _INSTALL_L57, _INSTALL_L29 );
172 if ( empty( $this->prefix ) ) {
173 $error[] = sprintf( _INSTALL_L57, _INSTALL_L30 );
175 if ( empty( $this->salt ) ) {
176 $error[] = sprintf( _INSTALL_L57, _INSTALL_LANG_XOOPS_SALT );
178 if ( empty( $this->root_path ) ) {
179 $error[] = sprintf( _INSTALL_L57, _INSTALL_L55 );
181 if ( empty( $this->trust_path ) ) {
182 $error[] = sprintf( _INSTALL_L57, _INSTALL_L55 );
184 if ( empty( $this->xoops_url ) ) {
185 $error[] = sprintf( _INSTALL_L57, _INSTALL_L56 );
188 if ( ! empty( $error ) ) {
189 $ret .=
'<div class="confirmError">';
190 foreach ( $error as $err ) {
199 public function editform() {
200 $ret =
'<h4>' . _INSTALL_L51 .
'</h4>
201 <p><small>' . _INSTALL_L66 .
'</small>
203 <select size="1" name="database" id="database">';
204 $dblist = $this->getDBList();
205 foreach ( $dblist as $val ) {
206 $ret .=
'<option value="' . $val .
'"';
207 if ( $val === $this->database ) {
208 $ret .=
' selected="selected"';
210 $ret .=
'>' . $val .
'</option>';
212 $ret .=
'</select></p>';
213 $ret .= $this->editform_sub( _INSTALL_L27, _INSTALL_L67,
'dbhost', $this->sanitizer->htmlSpecialChars( $this->dbhost ) );
214 $ret .= $this->editform_sub( _INSTALL_L28, _INSTALL_L65,
'dbuname', $this->sanitizer->htmlSpecialChars( $this->dbuname ) );
215 $ret .= $this->editform_sub( _INSTALL_L52, _INSTALL_L68,
'dbpass', $this->sanitizer->htmlSpecialChars( $this->dbpass ) );
216 $ret .= $this->editform_sub( _INSTALL_L29, _INSTALL_L64,
'dbname', $this->sanitizer->htmlSpecialChars( $this->dbname ) );
217 $ret .= $this->editform_sub( _INSTALL_L30, _INSTALL_L63,
'prefix', $this->sanitizer->htmlSpecialChars( $this->prefix ) );
218 $ret .= $this->editform_sub( _INSTALL_LANG_XOOPS_SALT, _INSTALL_LANG_XOOPS_SALT_DESC,
'salt', $this->sanitizer->htmlSpecialChars( $this->salt ) );
220 $ret .=
'<h4>' . _INSTALL_L54 .
'</h4>
221 <p><span style="font-size:85%;">' . _INSTALL_L69 .
'</span></p>
222 <p><input type="radio" name="db_pconnect" value="1"' . ( 1 === $this->db_pconnect ?
' checked="checked"' :
'' ) .
'>' . _INSTALL_L23 .
'
223 <input type="radio" name="db_pconnect" value="0"' . ( 1 !== $this->db_pconnect ?
' checked="checked"' :
'' ) .
'>' . _INSTALL_L24 .
'
226 $ret .= $this->editform_sub( _INSTALL_L55, _INSTALL_L59,
'root_path', $this->sanitizer->htmlSpecialChars( $this->root_path ) );
227 $ret .= $this->editform_sub( _INSTALL_L75, _INSTALL_L76,
'trust_path', $this->sanitizer->htmlSpecialChars( $this->trust_path ) );
228 $ret .= $this->editform_sub( _INSTALL_L56, _INSTALL_L58,
'xoops_url', $this->sanitizer->htmlSpecialChars( $this->xoops_url ) );
233 public function editform_sub( $title, $desc, $name, $value ) {
234 return '<h4>' . $title .
'</h4>
235 <p><span style="font-size:85%;">' . $desc .
'</span><br>
236 <input type="text" name="' . $name .
'" id="' . $name .
'" size="30" maxlength="100" value="' . htmlspecialchars( $value, ENT_QUOTES | ENT_HTML5 ) .
'">
240 public function confirmForm() {
241 $yesno = empty( $this->db_pconnect ) ? _INSTALL_L24 : _INSTALL_L23;
242 $ret =
'<h3>' . _INSTALL_L51 .
'</h3>
243 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->database ) .
'</p>
244 <h4>' . _INSTALL_L27 .
'</h4>
245 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbhost ) .
'</p>
246 <h4>' . _INSTALL_L28 .
'</h4>
247 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbuname ) .
'</p>
248 <h4>' . _INSTALL_L52 .
'</h4>
249 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbpass ) .
'</p>
250 <h4>' . _INSTALL_L29 .
'</h4>
251 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbname ) .
'</p>
252 <h4>' . _INSTALL_L30 .
'</h4>
253 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->prefix ) .
'</p>
254 <h4>' . _INSTALL_LANG_XOOPS_SALT .
'</h4>
255 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->salt ) .
'</p>
256 <h4>' . _INSTALL_L54 .
'</h4>
257 <p class="data">' . $yesno .
'</p>
258 <h4>' . _INSTALL_L55 .
'</h4>
259 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->root_path ) .
'</p>
260 <h4>' . _INSTALL_L75 .
'</h4>
261 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->trust_path ) .
'</p>
262 <h4>' . _INSTALL_L56 .
'</h4>
263 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->xoops_url ) .
'</p>
265 <input type="hidden" name="database" value="' . $this->sanitizer->htmlSpecialChars( $this->database ) .
'">
266 <input type="hidden" name="dbhost" value="' . $this->sanitizer->htmlSpecialChars( $this->dbhost ) .
'">
267 <input type="hidden" name="dbuname" value="' . $this->sanitizer->htmlSpecialChars( $this->dbuname ) .
'">
268 <input type="hidden" name="dbpass" value="' . $this->sanitizer->htmlSpecialChars( $this->dbpass ) .
'">
269 <input type="hidden" name="dbname" value="' . $this->sanitizer->htmlSpecialChars( $this->dbname ) .
'">
270 <input type="hidden" name="prefix" value="' . $this->sanitizer->htmlSpecialChars( $this->prefix ) .
'">
271 <input type="hidden" name="salt" value="' . $this->sanitizer->htmlSpecialChars( $this->salt ) .
'">
272 <input type="hidden" name="db_pconnect" value="' . (int) $this->db_pconnect .
'">
273 <input type="hidden" name="root_path" value="' . $this->sanitizer->htmlSpecialChars( $this->root_path ) .
'">
274 <input type="hidden" name="trust_path" value="' . $this->sanitizer->htmlSpecialChars( $this->trust_path ) .
'">
275 <input type="hidden" name="xoops_url" value="' . $this->sanitizer->htmlSpecialChars( $this->xoops_url ) .
'">
281 public function getDBList() {
289 return [ extension_loaded(
'mysql' ) ?
'mysql' :
'mysqli' ];
290 $dirname =
'../class/database/';
292 if (is_dir($dirname) && $handle = opendir($dirname)) {
293 while (
false !== ($file = readdir($handle))) {
294 if ( !preg_match(
"/^[.]{1,2}$/",$file) ) {
295 if (strtolower($file) !=
'cvs' && is_dir($dirname.$file) ) {
296 $dirlist[$file] = strtolower($file);