16 public $path =
'../mainfile.php';
17 public $distfile =
'../mainfile.dist.php';
21 public $error =
false;
23 public function setRewrite( $def, $val ) {
24 $this->rewrite[ $def ] = $val;
27 public function copyDistFile() {
28 if ( ! copy( $this->distfile, $this->path ) ) {
29 $this->report[] = _NGIMG . sprintf( _INSTALL_L126,
'<b>' . $this->path .
'</b>' );
34 $this->report[] = _OKIMG . sprintf( _INSTALL_L125,
'<b>' . $this->path .
'</b>',
'<b>' . $this->distfile .
'</b>' );
39 public function doRewrite() {
40 if ( ! $file = fopen( $this->path,
'r' ) ) {
46 $content = fread( $file, filesize( $this->path ) );
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 );
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 );
64 $this->report[] = _NGIMG . sprintf( _INSTALL_L122,
'<b>' . $val .
'</b>' );
68 if ( ! $file = fopen( $this->path,
'wb' ) ) {
74 if ( fwrite( $file, $content ) === - 1 ) {
86 public function report() {
90 public function error() {
94 public function sanitize( $val ) {
95 $val = addslashes( $val );
97 return str_replace(
'$',
'\$', $val );