XOOPS  2.6.0
page_configsave.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
27 require_once __DIR__ . '/include/common.inc.php';
28 
29 /* @var $wizard XoopsInstallWizard */
30 $wizard = $_SESSION['wizard'];
31 
32 $settings = $_SESSION['settings'];
33 
34 if (empty($settings['ROOT_PATH'])) {
35  $wizard->redirectToPage('pathsettings');
36  exit();
37 } elseif (empty($settings['DB_PARAMETERS'])) {
38  $wizard->redirectToPage('dbdriver');
39  exit();
40 }
41 $error = '';
42 
43 $rewrite = array(
44  'GROUP_ADMIN' => 1, 'GROUP_USERS' => 2, 'GROUP_ANONYMOUS' => 3
45 );
46 $rewrite = array_merge($rewrite, $settings);
47 
48 if (!@copy($settings['ROOT_PATH'] . '/mainfile.dist.php', $settings['ROOT_PATH'] . '/mainfile.php')) {
50 } else {
51  clearstatcache();
52 
53  if (!$file = fopen($settings['ROOT_PATH'] . '/mainfile.php', "r")) {
55  } else {
56  $content = fread($file, filesize($settings['ROOT_PATH'] . '/mainfile.php'));
57  fclose($file);
58 
59  foreach ($rewrite as $key => $val) {
60  if ($key == 'authorized') {
61  continue;
62  }
63  if (is_int($val) && preg_match("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([0-9]+)\s*\)/", $content)) {
64  $content = preg_replace("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([0-9]+)\s*\)/", "define('XOOPS_{$key}', {$val})", $content);
65  } else {
66  if (preg_match("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", $content)) {
67  $val = str_replace('$', '\$', addslashes($val));
68  $content = preg_replace("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", "define('XOOPS_{$key}', '{$val}')", $content);
69  } else {
70  //$this->error = true;
71  //$this->report .= _NGIMG.sprintf( ERR_WRITING_CONSTANT, "<strong>$val</strong>")."<br />\n";
72  }
73  }
74  }
75  if (!$file = fopen($settings['ROOT_PATH'] . '/mainfile.php', "w")) {
77  } else {
78  if (fwrite($file, $content) == -1) {
80  }
81  fclose($file);
82  }
83  }
84 }
85 
86 if (!@copy($rewrite['VAR_PATH'] . '/data/secure.dist.php', $rewrite['VAR_PATH'] . '/data/secure.php')) {
87  $error = ERR_COPY_SECURE . $rewrite['VAR_PATH'] . '/data/secure.dist.php';
88 } else {
89  clearstatcache();
90 
91  if (!$file = fopen($rewrite['VAR_PATH'] . '/data/secure.php', "r")) {
93  } else {
94  $content = fread($file, filesize($rewrite['VAR_PATH'] . '/data/secure.php'));
95  fclose($file);
96 
97  foreach ($rewrite as $key => $val) {
98  if ($key == 'authorized') {
99  continue;
100  }
101  if (is_int($val) && preg_match("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([0-9]+)\s*\)/", $content)) {
102  $content = preg_replace("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([0-9]+)\s*\)/", "define('XOOPS_{$key}', {$val})", $content);
103  } else {
104  if (preg_match("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", $content)) {
105  $val = str_replace('$', '\$', addslashes($val));
106  $content = preg_replace("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", "define('XOOPS_{$key}', \"{$val}\")", $content);
107  }
108  }
109  }
110  if (!$file = fopen($rewrite['VAR_PATH'] . '/data/secure.php', "w")) {
112  } else {
113  if (fwrite($file, $content) == -1) {
115  }
116  fclose($file);
117  }
118  }
119 }
120 
121 // update composer.json with our paths
122 $composer_path = $settings['PATH'] . '/composer.json';
123 $composer = json_decode(file_get_contents($composer_path));
124 $xoops_modules_path = $settings['ROOT_PATH'] . '/modules/';
125 if (isset($composer->extra) && is_object($composer->extra)) {
126  $composer->extra->xoops_modules_path = $xoops_modules_path;
127 } else {
128  $composer->extra['xoops_modules_path'] = $xoops_modules_path;
129 }
130 $composerOut = \Xoops\Core\JsonFormatter::format(json_encode($composer), true, true);
131 file_put_contents($composer_path, $composerOut);
132 //$jsonEncodeOpts = 0;
133 //if (defined('JSON_PRETTY_PRINT') && defined('JSON_UNESCAPED_SLASHES')) {
134 // $jsonEncodeOpts = $jsonEncodeOpts | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;
135 //}
136 //file_put_contents($composer_path, json_encode($composer, $jsonEncodeOpts));
137 
138 $settings['authorized'] = false;
139 if (empty($error)) {
140  $_SESSION['UserLogin'] = true;
141  $settings['authorized'] = true;
142  $wizard->cleanCache($rewrite['VAR_PATH']);
143  ob_start();
144  ?>
145 
146 <div class="caption"><?php echo SAVED_MAINFILE; ?></div>
147 <div class='x2-note confirmMsg'><?php echo SAVED_MAINFILE_MSG; ?></div>
148 <ul class='diags'>
149 
150  <?php
151  foreach ($settings as $k => $v) {
152  if ($k == 'authorized') {
153  continue;
154  }
155  echo "<li><strong>XOOPS_{$k}</strong> " . IS_VALOR . " {$v}</li>";
156 }
157  ?>
158 </ul>
159  <?php
160  $content = ob_get_contents();
161  ob_end_clean();
162 } else {
163  $content = '<div class="errorMsg">' . $error . '</div>';
164 }
165 
166 $_SESSION['pageHasHelp'] = false;
167 $_SESSION['pageHasForm'] = false;
168 $_SESSION['content'] = $content;
169 $_SESSION['settings'] = $settings;
170 include XOOPS_INSTALL_PATH . '/include/install_tpl.php';
const SAVED_MAINFILE_MSG
Definition: install.php:140
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
const ERR_COPY_MAINFILE
Definition: install.php:157
const ERR_WRITE_SECURE
Definition: install.php:163
$rewrite
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$settings
$xoops_modules_path
exit
Definition: browse.php:104
const ERR_READ_SECURE
Definition: install.php:162
const XOOPS_INSTALL_PATH
Definition: common.inc.php:33
$composer_path
$_SESSION['pageHasHelp']
$composerOut
const ERR_READ_MAINFILE
Definition: install.php:159
const SAVED_MAINFILE
Definition: install.php:139
const ERR_WRITE_MAINFILE
Definition: install.php:158
const ERR_COPY_SECURE
Definition: install.php:161
const IS_VALOR
Definition: install.php:209