XOOPS  2.6.0
functions.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 
29 function install_acceptUser($hash = '')
30 {
32  $xoops->user = null;
33  $hash_data = @explode("-", $_COOKIE['xo_install_user'], 2);
34  list($uname, $hash_login) = array($hash_data[0], strval(@$hash_data[1]));
35  if (empty($uname) || empty($hash_login)) {
36  return false;
37  }
38  $member_handler = $xoops->getHandlerMember();
39  /* @var $user XoopsUser */
40  $users = $member_handler->getUsers(new Criteria('uname', $uname));
41  $user = array_pop($users);
42  if ($hash_login != md5($user->getVar('pass') . XOOPS_DB_NAME . XOOPS_DB_PASS . XOOPS_DB_PREFIX)) {
43  return false;
44  }
45  $xoops->user = $user;
46  $xoops->userIsAdmin = true;
47  $_SESSION['xoopsUserId'] = $xoops->user->getVar('uid');
48  $_SESSION['xoopsUserGroups'] = $xoops->user->getGroups();
49  return true;
50 }
51 
57 {
58  // Set mainfile.php readonly
59  @chmod(XOOPS_ROOT_PATH . "/mainfile.php", 0444);
60  // Set Secure file readonly
61  @chmod(XOOPS_VAR_PATH . "/data/secure.php", 0444);
62  // Rename installer folder
63  @rename(XOOPS_ROOT_PATH . "/install", XOOPS_ROOT_PATH . "/" . $installer_modified);
64 }
65 
76 function xoFormField($name, $value, $label, $help = '')
77 {
79  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
80  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
81  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
82  echo "<label class='xolabel' for='$name'>$label</label>\n";
83  if ($help) {
84  echo '<div class="xoform-help">' . $help . "</div>\n";
85  }
86  if ($name == "adminname") {
87  echo "<input type='text' name='$name' id='$name' value='$value' maxlength='25' />";
88  } else {
89  echo "<input type='text' name='$name' id='$name' value='$value' />";
90  }
91 }
92 
103 function xoPassField($name, $value, $label, $help = '')
104 {
106  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
107  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
108  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
109  echo "<label class='xolabel' for='{$name}'>{$label}</label>\n";
110  if ($help) {
111  echo '<div class="xoform-help">' . $help . "</div>\n";
112  }
113 
114  if ($name == "adminpass") {
115  echo "<input type='password' name='{$name}' id='{$name}' value='{$value}' onkeyup='passwordStrength(this.value)' />";
116  } else {
117  echo "<input type='password' name='{$name}' id='{$name}' value='{$value}' />";
118  }
119 }
120 
131 function xoBoolField($name, $value, $label, $help = '')
132 {
134  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
135  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
136  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
137  echo "<label class='xolabel' for='$name'>$label</label>\n";
138  if ($help) {
139  echo '<div class="xoform-help">' . $help . "</div>\n";
140  }
141  $checked = $value ? 'checked' : '';
142  echo "<input type=\"checkbox\" name=\"{$name}\" value=\"1\" {$checked} />"
143  . ENABLE . "<br />";
144 }
145 
146 /*
147  * gets list of name of directories inside a directory
148  *
149  * @param string $dirname
150  * @return array
151  */
153 {
154  $dirlist = array();
155  if ($handle = opendir($dirname)) {
156  while ($file = readdir($handle)) {
157  if ($file{0} != '.' && is_dir($dirname . $file)) {
158  $dirlist[] = $file;
159  }
160  }
161  closedir($handle);
162  asort($dirlist);
163  reset($dirlist);
164  }
165  return $dirlist;
166 }
167 
173 function xoDiag($status = -1, $str = '')
174 {
175  if ($status == -1) {
176  $_SESSION['error'] = true;
177  }
178  $classes = array(-1 => 'error', 0 => 'warning', 1 => 'success');
179  $strings = array(-1 => FAILED, 0 => WARNING, 1 => SUCCESS);
180  if (empty($str)) {
181  $str = $strings[$status];
182  }
183  return '<span class="' . $classes[$status] . '">' . $str . '</span>';
184 }
185 
192 function xoDiagBoolSetting($name, $wanted = false, $severe = false)
193 {
194  $setting = strtolower(ini_get($name));
195  $setting = (empty($setting) || $setting == 'off' || $setting == 'false') ? false : true;
196  if ($setting == $wanted) {
197  return xoDiag(1, $setting ? 'ON' : 'OFF');
198  } else {
199  return xoDiag($severe ? -1 : 0, $setting ? 'ON' : 'OFF');
200  }
201 }
202 
208 {
209  $path = "../" . $path;
210  $error = true;
211  if (!is_dir($path)) {
212  if (file_exists($path)) {
213  @chmod($path, 0666);
214  $error = !is_writeable($path);
215  }
216  } else {
217  @chmod($path, 0777);
218  $error = !is_writeable($path);
219  }
220  return xoDiag($error ? -1 : 1, $error ? 'Not writable' : 'Writable');
221 }
222 
226 function xoPhpVersion()
227 {
228  if (version_compare(phpversion(), '5.4.0', '>=')) {
229  return xoDiag(1, phpversion());
230  } else {
231  return xoDiag(-1, phpversion());
232  }
233 }
234 
240 function genPathCheckHtml($path, $valid)
241 {
242  if ($valid) {
243  switch ($path) {
244  case 'root':
245  $msg = sprintf(XOOPS_FOUND, XOOPS_VERSION);
246  break;
247 
248  case 'lib':
249  case 'data':
250  default:
252  break;
253  }
254  return '<span class="pathmessage"><img src="img/yes.png" alt="Success" />' . $msg . '</span>';
255  } else {
256  switch ($path) {
257  case 'root':
259  break;
260 
261  case 'lib':
262  case 'data':
263  default:
265  break;
266  }
267  return '<span class="pathmessage"><img src="img/no.png" alt="Error" /> ' . $msg . '</span>';
268  }
269 }
270 
276 {
277  static $charsets = array();
278  if ($charsets) {
279  return $charsets;
280  }
281 
282  $charsets["utf8"] = "UTF-8 Unicode";
283  $ut8_available = false;
284  if ($result = mysql_query("SHOW CHARSET", $link)) {
285  while ($row = mysql_fetch_assoc($result)) {
286  $charsets[$row["Charset"]] = $row["Description"];
287  if ($row["Charset"] == "utf8") {
288  $ut8_available = true;
289  }
290  }
291  }
292  if (!$ut8_available) {
293  unset($charsets["utf8"]);
294  }
295 
296  return $charsets;
297 }
298 
304 function getDbCollations($link, $charset)
305 {
306  static $collations = array();
307  if (!empty($collations[$charset])) {
308  return $collations[$charset];
309  }
310 
311  if ($result = mysql_query("SHOW COLLATION WHERE CHARSET = '" . mysql_real_escape_string($charset) . "'", $link)) {
312  while ($row = mysql_fetch_assoc($result)) {
313  $collations[$charset][$row["Collation"]] = $row["Default"] ? 1 : 0;
314  }
315  }
316 
317  return $collations[$charset];
318 }
319 
326 function validateDbCharset($link, &$charset, &$collation)
327 {
328  $error = null;
329 
330  if (empty($charset)) {
331  $collation = "";
332  }
333  if (version_compare(mysql_get_server_info($link), "4.1.0", "lt")) {
334  $charset = $collation = "";
335  }
336  if (empty($charset) && empty($collation)) {
337  return $error;
338  }
339 
340  $charsets = getDbCharsets($link);
341  if (!isset($charsets[$charset])) {
342  $error = sprintf(ERR_INVALID_DBCHARSET, $charset);
343  } else {
344  if (!empty($collation)) {
345  $collations = getDbCollations($link, $charset);
346  if (!isset($collations[$collation])) {
347  $error = sprintf(ERR_INVALID_DBCOLLATION, $collation);
348  }
349  }
350  }
351 
352  return $error;
353 }
354 
364 function xoFormFieldCollation($name, $value, $label, $help, $link, $charset)
365 {
366  if (version_compare(mysql_get_server_info($link), "4.1.0", "lt")) {
367  return "";
368  }
369  if (empty($charset) || !$collations = getDbCollations($link, $charset)) {
370  return "";
371  }
372 
374  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
375  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
376  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
377 
378  $field = "<label class='xolabel' for='{$name}'>{$label}</label>\n";
379  if ($help) {
380  $field .= '<div class="xoform-help">' . $help . "</div>\n";
381  }
382  $field .= "<select name='{$name}' id='{$name}'\">";
383 
384  $collation_default = "";
385  $options = "";
386  foreach ($collations as $key => $isDefault) {
387  if ($isDefault) {
388  $collation_default = $key;
389  continue;
390  }
391  $options .= "<option value='{$key}'" . (($value == $key) ? " selected='selected'" : "") . ">{$key}</option>";
392  }
393  if ($collation_default) {
394  $field .= "<option value='{$collation_default}'" . (($value == $collation_default || empty($value))
395  ? " 'selected'" : "") . ">{$collation_default} (Default)</option>";
396  }
397  $field .= $options;
398  $field .= "</select>";
399 
400  return $field;
401 }
402 
412 function xoFormBlockCollation($name, $value, $label, $help, $link, $charset)
413 {
414  $block = '<div id="' . $name . '_div">';
415  $block .= xoFormFieldCollation($name, $value, $label, $help, $link, $charset);
416  $block .= '</div>';
417 
418  return $block;
419 }
420 
429 function xoFormFieldCharset($name, $value, $label, $help, $link)
430 {
431  if (version_compare(mysql_get_server_info($link), "4.1.0", "lt")) {
432  return "";
433  }
434  if (!$chars = getDbCharsets($link)) {
435  return "";
436  }
437 
438  $charsets = array();
439  if (isset($chars["utf8"])) {
440  $charsets["utf8"] = $chars["utf8"];
441  unset ($chars["utf8"]);
442  }
443  ksort($chars);
444  $charsets = array_merge($charsets, $chars);
445 
447  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
448  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
449  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
450 
451  $field = "<label class='xolabel' for='{$name}'>{$label}</label>\n";
452  if ($help) {
453  $field .= '<div class="xoform-help">' . $help . "</div>\n";
454  }
455  $field .= "<select name='{$name}' id='{$name}' onchange=\"setFormFieldCollation('DB_COLLATION_div', this.value)\">";
456  $field .= "<option value=''>None</option>";
457  foreach ($charsets as $key => $desc) {
458  $field .= "<option value='{$key}'" . (($value == $key) ? " selected='selected'"
459  : "") . ">{$key} - {$desc}</option>";
460  }
461  $field .= "</select>";
462 
463  return $field;
464 }
465 
473 {
474  $wizard = $_SESSION['wizard'];
475  $settings = $_SESSION['settings'];
476 
477  // get list of parameters the selected driver accepts
478  $driver_info = $wizard->configs['db_types'][$settings['DB_DRIVER']];
479  $driver_params=explode(',', $driver_info['params']);
480 
481  $connectionParams = array(
482  'driver' => $settings['DB_DRIVER'],
483  'charset' => 'utf8',
484  );
485 
486  foreach ($driver_params as $param) {
487  if (!empty($settings[$wizard->configs['db_param_names'][$param]])) {
488  $connectionParams[$param] = $settings[$wizard->configs['db_param_names'][$param]];
489  }
490  }
491 
492  return $connectionParams;
493 }
494 
503 {
504  //New database connector
505  $config = new \Doctrine\DBAL\Configuration();
506  $connectionParams = getDbConnectionParams();
507 
508  try {
509  $instance = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
510  } catch (Exception $e) {
511  $error = $e->getMessage();
512  return false;
513  }
514  if (!$instance) {
516  return false;
517  } else {
518  try {
519  $instance->connect();
520  } catch (Exception $e) {
521  $error = $e->getMessage();
522  return false;
523  }
524  }
525  return $instance;
526 }
$path
Definition: execute.php:31
$_SESSION['RF']["verify"]
Definition: dialog.php:4
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
xoFormFieldCharset($name, $value, $label, $help, $link)
Definition: functions.php:429
const ERR_NO_XOOPS_FOUND
Definition: install.php:147
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
const ERR_INVALID_DBCHARSET
Definition: install.php:165
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$settings
$installer_modified
Definition: finish.php:7
if(array_key_exists('DB_PARAMETERS', $settings)) $driver_info
$options['editor']
$result
Definition: pda.php:33
const SUCCESS
Definition: install.php:38
$user
Definition: checklogin.php:47
xoPassField($name, $value, $label, $help= '')
Definition: functions.php:103
$link
Definition: userinfo.php:84
const ERR_COULD_NOT_ACCESS
Definition: install.php:146
const _INSTALL_CHARSET
Definition: install.php:170
genPathCheckHtml($path, $valid)
Definition: functions.php:240
const XOOPS_DB_NAME
Definition: secure.dist.php:42
const XOOPS_FOUND
Definition: install.php:132
xoDiagIfWritable($path)
Definition: functions.php:207
$wizard
Definition: common.inc.php:66
const XOOPS_DB_PASS
Definition: secure.dist.php:38
$xoops
Definition: admin.php:25
$status
xoPhpVersion()
Definition: functions.php:226
getDirList($dirname)
Definition: functions.php:152
const ERR_INVALID_DBCOLLATION
Definition: install.php:166
xoDiagBoolSetting($name, $wanted=false, $severe=false)
Definition: functions.php:192
xoFormField($name, $value, $label, $help= '')
Definition: functions.php:76
const XOOPS_VERSION
Definition: version.php:23
install_finalize($installer_modified)
Definition: functions.php:56
xoFormFieldCollation($name, $value, $label, $help, $link, $charset)
Definition: functions.php:364
const XOOPS_DB_PREFIX
Definition: secure.dist.php:26
const FAILED
Definition: install.php:40
const ENABLE
Definition: install.php:41
const XOOPS_PATH_FOUND
Definition: install.php:137
install_acceptUser($hash= '')
Definition: functions.php:29
const WARNING
Definition: install.php:39
return $config
$uname
Definition: checklogin.php:37
getDbConnection(&$error)
Definition: functions.php:502
xoDiag($status=-1, $str= '')
Definition: functions.php:173
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
xoBoolField($name, $value, $label, $help= '')
Definition: functions.php:131
const ERR_NO_DBCONNECTION
Definition: install.php:153
$dirname
Definition: backend.php:38
$driver_params
xoFormBlockCollation($name, $value, $label, $help, $link, $charset)
Definition: functions.php:412
getDbConnectionParams()
Definition: functions.php:472
getDbCollations($link, $charset)
Definition: functions.php:304
$myts
Definition: edituser.php:38
getDbCharsets($link)
Definition: functions.php:275
validateDbCharset($link, &$charset, &$collation)
Definition: functions.php:326