XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
mainfilemanager.php
1<?php
13
15
16 public $path = '../mainfile.php';
17 public $distfile = '../mainfile.dist.php';
18 public $rewrite = [];
19
20 public $report = [];
21 public $error = false;
22
23 public function setRewrite( $def, $val ) {
24 $this->rewrite[ $def ] = $val;
25 }
26
27 public function copyDistFile() {
28 if ( ! copy( $this->distfile, $this->path ) ) {
29 $this->report[] = _NGIMG . sprintf( _INSTALL_L126, '<b>' . $this->path . '</b>' );
30 $this->error = true;
31
32 return false;
33 }
34 $this->report[] = _OKIMG . sprintf( _INSTALL_L125, '<b>' . $this->path . '</b>', '<b>' . $this->distfile . '</b>' );
35
36 return true;
37 }
38
39 public function doRewrite() {
40 if ( ! $file = fopen( $this->path, 'r' ) ) {
41 $this->error = true;
42
43 return false;
44 }
45 clearstatcache();
46 $content = fread( $file, filesize( $this->path ) );
47 fclose( $file );
48
49 foreach ( $this->rewrite as $key => $val ) {
50 if ( is_int( $val ) &&
51 preg_match( "/(define\‍()([\"'])(" . $key . ")\\2,\s*([0-9]+)\s*\‍)/", $content ) ) {
52 $content = preg_replace( "/(define\‍()([\"'])(" . $key . ")\\2,\s*([0-9]+)\s*\‍)/", "define('" . $key . "', " . $val . ')', $content );
53 $this->report[] = _OKIMG . sprintf( _INSTALL_L121, "<b>$key</b>", $val );
54 } elseif ( preg_match( "/(define\‍()([\"'])(" . $key . ")\\2,\s*([\"'])(.*?)\\4\s*\‍)/", $content ) ) {
55 if ( 'XOOPS_DB_TYPE' === $key && 'mysql' === $val ) {
56 $content = preg_replace( "/(define\‍()([\"'])(" . $key . ")\\2,\s*([\"'])(.*?)\\4\s*\‍)/", "extension_loaded('mysql')? define('XOOPS_DB_TYPE', 'mysql') : define('XOOPS_DB_TYPE', 'mysqli')", $content );
57 $this->report[] = _OKIMG . sprintf( _INSTALL_L121, '<b>' . $key . '</b>', $val );
58 } else {
59 $content = preg_replace( "/(define\‍()([\"'])(" . $key . ")\\2,\s*([\"'])(.*?)\\4\s*\‍)/", "define('" . $key . "', '" . $this->sanitize( $val ) . "')", $content );
60 $this->report[] = _OKIMG . sprintf( _INSTALL_L121, '<b>' . $key . '</b>', $val );
61 }
62 } else {
63 $this->error = true;
64 $this->report[] = _NGIMG . sprintf( _INSTALL_L122, '<b>' . $val . '</b>' );
65 }
66 }
67
68 if ( ! $file = fopen( $this->path, 'wb' ) ) {
69 $this->error = true;
70
71 return false;
72 }
73
74 if ( fwrite( $file, $content ) === - 1 ) {
75 fclose( $file );
76 $this->error = true;
77
78 return false;
79 }
80
81 fclose( $file );
82
83 return true;
84 }
85
86 public function report() {
87 return $this->report;
88 }
89
90 public function error() {
91 return $this->error;
92 }
93
94 public function sanitize( $val ) {
95 $val = addslashes( $val );
96
97 return str_replace( '$', '\$', $val );
98 }
99}