XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
functions.php
Go to the documentation of this file.
1 <?php
18 function install_acceptUser($hash = '')
19 {
20  $GLOBALS['xoopsUser'] = null;
21  $hash_data = @explode("-", $_COOKIE['xo_install_user'], 2);
22  list($uname, $hash_login) = array($hash_data[0], strval( @$hash_data[1] ));
23  if (empty($uname) || empty($hash_login)) {
24  return false;
25  }
26  $memebr_handler =& xoops_gethandler('member');
27  $user = array_pop($memebr_handler->getUsers(new Criteria('uname', $uname)));
28  if ($hash_login != md5($user->getVar('pass') . XOOPS_DB_NAME . XOOPS_DB_PASS . XOOPS_DB_PREFIX)) {
29  return false;
30  }
31  $myts = MyTextsanitizer::getInstance();
32  if (is_object($GLOBALS['xoops']) && method_exists($GLOBALS['xoops'], 'acceptUser')) {
33  $res = $GLOBALS['xoops']->acceptUser($uname, true, $msg);
34  return $res;
35  }
36  $GLOBALS['xoopsUser'] = $user;
37  $_SESSION['xoopsUserId'] = $GLOBALS['xoopsUser']->getVar('uid');
38  $_SESSION['xoopsUserGroups'] = $GLOBALS['xoopsUser']->getGroups();
39  return true;
40 }
41 
43 {
44  // Set mainfile.php readonly
45  @chmod(XOOPS_ROOT_PATH . "/mainfile.php", 0444);
46  // Set Secure file readonly
47  @chmod(XOOPS_VAR_PATH . "/data/secure.php", 0444);
48  // Rename installer folder
49  @rename(XOOPS_ROOT_PATH . "/install", XOOPS_ROOT_PATH . "/" . $installer_modified);
50 }
51 
52 function xoFormField( $name, $value, $label, $help = '' )
53 {
55  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
56  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
57  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
58  echo "<label class='xolabel' for='$name'>$label</label>\n";
59  if ( $help ) {
60  echo '<div class="xoform-help">' . $help . "</div>\n";
61  }
62  if ( $name == "adminname" ) {
63  echo "<input type='text' name='$name' id='$name' value='$value' maxlength='25' />";
64  } else {
65  echo "<input type='text' name='$name' id='$name' value='$value' />";
66  }
67 }
68 
69 function xoPassField($name, $value, $label, $help = '')
70 {
72  $label = $myts->htmlspecialchars( $label, ENT_QUOTES, _INSTALL_CHARSET, false);
73  $name = $myts->htmlspecialchars( $name, ENT_QUOTES, _INSTALL_CHARSET, false);
74  $value = $myts->htmlspecialchars( $value, ENT_QUOTES );
75  echo "<label class='xolabel' for='{$name}'>{$label}</label>\n";
76  if ($help) {
77  echo '<div class="xoform-help">' . $help . "</div>\n";
78  }
79 
80  if ($name == "adminpass") {
81  echo "<input type='password' name='{$name}' id='{$name}' value='{$value}' onkeyup='passwordStrength(this.value)' />";
82  } else {
83  echo "<input type='password' name='{$name}' id='{$name}' value='{$value}' />";
84  }
85 }
86 
87 /*
88  * gets list of name of directories inside a directory
89  */
91 {
92  $dirlist = array();
93  if ($handle = opendir($dirname)) {
94  while ($file = readdir($handle)) {
95  if ($file{0} != '.' && is_dir($dirname . $file)) {
96  $dirlist[] = $file;
97  }
98  }
99  closedir($handle);
100  asort($dirlist);
101  reset($dirlist);
102  }
103  return $dirlist;
104 }
105 
106 function xoDiag($status = -1, $str = '')
107 {
108  if ($status == -1) {
109  $GLOBALS['error'] = true;
110  }
111  $classes = array(-1 => 'error', 0 => 'warning', 1 => 'success');
112  $strings = array(-1 => FAILED, 0 => WARNING, 1 => SUCCESS);
113  if (empty($str)) {
114  $str = $strings[$status];
115  }
116  return '<span class="' . $classes[$status] . '">' . $str . '</span>';
117 }
118 
119 function xoDiagBoolSetting($name, $wanted = false, $severe = false)
120 {
121  $setting = strtolower(ini_get($name));
122  $setting = (empty($setting) || $setting == 'off' || $setting == 'false') ? false : true;
123  if ($setting == $wanted) {
124  return xoDiag(1, $setting ? 'ON' : 'OFF');
125  } else {
126  return xoDiag($severe ? -1 : 0, $setting ? 'ON' : 'OFF');
127  }
128 }
129 
131 {
132  $path = "../" . $path;
133  $error = true;
134  if (!is_dir($path)) {
135  if (file_exists($path)) {
136  @chmod($path, 0666);
137  $error = !is_writeable($path);
138  }
139  } else {
140  @chmod($path, 0777);
141  $error = !is_writeable($path);
142  }
143  return xoDiag($error ? -1 : 1, $error ? 'Not writable' : 'Writable');
144 }
145 
146 function xoPhpVersion()
147 {
148  if (version_compare(phpversion(), '5.2.0', '>=')) {
149  return xoDiag(1, phpversion());
150  } else if (version_compare(phpversion(), '5.1.0', '>=')) {
151  return xoDiag(0, phpversion());
152  } else {
153  return xoDiag(-1, phpversion());
154  }
155 }
156 
157 function genPathCheckHtml($path, $valid)
158 {
159  if ($valid) {
160  switch ($path) {
161  case 'root':
162  $msg = sprintf(XOOPS_FOUND, XOOPS_VERSION);
163  break;
164 
165  case 'lib':
166  case 'data':
167  default:
169  break;
170  }
171  return '<span class="pathmessage"><img src="img/yes.png" alt="Success" />' . $msg . '</span>';
172  } else {
173  switch ($path) {
174  case 'root':
176  break;
177 
178  case 'lib':
179  case 'data':
180  default:
182  break;
183  }
184  return '<span class="pathmessage"><img src="img/no.png" alt="Error" /> ' . $msg . '</span>';
185  }
186 }
187 
188 function getDbCharsets($link)
189 {
190  static $charsets = array();
191  if ($charsets) return $charsets;
192 
193  $charsets["utf8"] = "UTF-8 Unicode";
194  $ut8_available = false;
195  if ($result = mysql_query("SHOW CHARSET", $link)) {
196  while ($row = mysql_fetch_assoc($result)) {
197  $charsets[$row["Charset"]] = $row["Description"];
198  if ($row["Charset"] == "utf8") {
199  $ut8_available = true;
200  }
201  }
202  }
203  if (!$ut8_available) {
204  unset($charsets["utf8"]);
205  }
206 
207  return $charsets;
208 }
209 
210 function getDbCollations($link, $charset)
211 {
212  static $collations = array();
213  if (!empty($collations[$charset])) {
214  return $collations[$charset];
215  }
216 
217  if ($result = mysql_query("SHOW COLLATION WHERE CHARSET = '" . mysql_real_escape_string($charset) . "'", $link)) {
218  while ($row = mysql_fetch_assoc($result)) {
219  $collations[$charset][$row["Collation"]] = $row["Default"] ? 1 : 0;
220  }
221  }
222 
223  return $collations[$charset];
224 }
225 
226 function validateDbCharset($link, &$charset, &$collation)
227 {
228  $error = null;
229 
230  if (empty($charset)) {
231  $collation = "";
232  }
233  if (version_compare(mysql_get_server_info($link), "4.1.0", "lt")) {
234  $charset = $collation = "";
235  }
236  if (empty($charset) && empty($collation)) {
237  return $error;
238  }
239 
240  $charsets = getDbCharsets($link);
241  if (!isset($charsets[$charset])) {
242  $error = sprintf(ERR_INVALID_DBCHARSET, $charset);
243  } else if (!empty($collation)) {
244  $collations = getDbCollations($link, $charset);
245  if (!isset($collations[$collation])) {
246  $error = sprintf(ERR_INVALID_DBCOLLATION, $collation);
247  }
248  }
249 
250  return $error;
251 }
252 
253 function xoFormFieldCollation($name, $value, $label, $help, $link, $charset)
254 {
255  if (version_compare(mysql_get_server_info($link), "4.1.0", "lt")) {
256  return "";
257  }
258  if (empty($charset) || !$collations = getDbCollations($link, $charset)) {
259  return "";
260  }
261 
263  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
264  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
265  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
266 
267  $field = "<label class='xolabel' for='{$name}'>{$label}</label>\n";
268  if ($help) {
269  $field .= '<div class="xoform-help">' . $help . "</div>\n";
270  }
271  $field .= "<select name='{$name}' id='{$name}'\">";
272 
273  $collation_default = "";
274  $options = "";
275  foreach ($collations as $key => $isDefault) {
276  if ($isDefault) {
277  $collation_default = $key;
278  continue;
279  }
280  $options .= "<option value='{$key}'" . (($value == $key) ? " selected='selected'" : "") . ">{$key}</option>";
281  }
282  if ($collation_default) {
283  $field .= "<option value='{$collation_default}'" . ( ($value == $collation_default || empty($value)) ? " 'selected'" : "" ) . ">{$collation_default} (Default)</option>";
284  }
285  $field .= $options;
286  $field .= "</select>";
287 
288  return $field;
289 }
290 
291 function xoFormBlockCollation($name, $value, $label, $help, $link, $charset)
292 {
293  $block = '<div id="' . $name . '_div">';
294  $block .= xoFormFieldCollation($name, $value, $label, $help, $link, $charset);
295  $block .= '</div>';
296 
297  return $block;
298 }
299 
300 
301 function xoFormFieldCharset( $name, $value, $label, $help = '', $link )
302 {
303  if (version_compare(mysql_get_server_info($link), "4.1.0", "lt")) {
304  return "";
305  }
306  if (!$chars = getDbCharsets($link)) {
307  return "";
308  }
309 
310  $charsets = array();
311  if (isset($chars["utf8"])) {
312  $charsets["utf8"] = $chars["utf8"];
313  unset ($chars["utf8"]);
314  }
315  ksort($chars);
316  $charsets = array_merge($charsets, $chars);
317 
319  $label = $myts->htmlspecialchars($label, ENT_QUOTES, _INSTALL_CHARSET, false);
320  $name = $myts->htmlspecialchars($name, ENT_QUOTES, _INSTALL_CHARSET, false);
321  $value = $myts->htmlspecialchars($value, ENT_QUOTES);
322 
323  $field = "<label class='xolabel' for='{$name}'>{$label}</label>\n";
324  if ( $help ) {
325  $field .= '<div class="xoform-help">' . $help . "</div>\n";
326  }
327  $field .= "<select name='{$name}' id='{$name}' onchange=\"setFormFieldCollation('DB_COLLATION_div', this.value)\">";
328  $field .= "<option value=''>None</option>";
329  foreach ($charsets as $key => $desc) {
330  $field .= "<option value='{$key}'" . (($value == $key) ? " selected='selected'" : "") . ">{$key} - {$desc}</option>";
331  }
332  $field .= "</select>";
333 
334  return $field;
335 }
336 
337 
342 function xoPutLicenseKey($system_key, $licensefile, $license_file_dist = 'license.dist.php')
343 {
344  chmod($licensefile, 0777);
345  $fver = fopen($licensefile, 'w');
346  $fver_buf = file($license_file_dist);
347  foreach ($fver_buf as $line => $value) {
348  if (strpos($value, 'XOOPS_LICENSE_KEY') > 0) {
349  $ret = 'define(\'XOOPS_LICENSE_KEY\', \'' . $system_key . "');";
350  } else {
351  $ret = $value;
352  }
353  fwrite($fver, $ret, strlen($ret));
354  }
355  fclose($fver);
356  chmod($licensefile, 0444);
357  return "Written XOOPS " . XOOPS_LICENSE_CODE . " License Key: <strong>{$system_key}</strong>";
358 }
359 
365 {
366  $xoops_serdat = array();
367  srand((((float)('0' . substr(microtime(), strpos(microtime(), ' ') + 1, strlen(microtime()) - strpos(microtime(), ' ') + 1))) * mt_rand(30, 99999)));
368  srand((((float)('0' . substr(microtime(), strpos(microtime(), ' ') + 1, strlen(microtime()) - strpos(microtime(), ' ') + 1))) * mt_rand(30, 99999)));
369  $checksums = array(1 => 'md5', 2 => 'sha1');
370  $type = rand(1, 2);
371  $func = $checksums[$type];
372 
373  error_reporting(0);
374 
375  // Public Key
376  if ($xoops_serdat['version'] = $func(XOOPS_VERSION)) {
377  $xoops_serdat['version'] = substr($xoops_serdat['version'],0, 6);
378  }
379  if ($xoops_serdat['licence'] = $func(XOOPS_LICENSE_CODE)) {
380  $xoops_serdat['licence'] = substr($xoops_serdat['licence'],0, 2);
381  }
382  if ($xoops_serdat['license_text'] = $func(XOOPS_LICENSE_TEXT)) {
383  $xoops_serdat['license_text'] = substr($xoops_serdat['license_text'],0, 2);
384  }
385 
386  if ($xoops_serdat['domain_host'] = $func($_SERVER['HTTP_HOST'])) {
387  $xoops_serdat['domain_host'] = substr($xoops_serdat['domain_host'],0, 2);
388  }
389 
390  // Private Key
391  $xoops_serdat['file'] = $func(__FILE__);
392  $xoops_serdat['basename'] = $func(basename(__FILE__));
393  $xoops_serdat['path'] = $func(dirname(__FILE__));
394 
395  foreach ($_SERVER as $key => $data) {
396  $xoops_serdat[$key] = substr($func(serialize($data)),0, 4);
397  }
398 
399  foreach ($xoops_serdat as $key => $data){
400  $xoops_key .= $data;
401  }
402  while (strlen($xoops_key) > 40) {
403  $lpos = rand(18, strlen($xoops_key));
404  $xoops_key = substr($xoops_key, 0, $lpos).substr($xoops_key, $lpos + 1 , strlen($xoops_key) - ($lpos + 1));
405  }
406 
407  return xoStripeKey($xoops_key);
408 }
409 
414 function xoStripeKey($xoops_key)
415 {
416  $uu = 0;
417  $num = 6;
418  $length = 30;
419  $strip = floor(strlen($xoops_key) / 6);
420  for ($i = 0; $i < strlen($xoops_key); $i++) {
421  if ($i < $length) {
422  $uu++;
423  if ($uu == $strip) {
424  $ret .= substr($xoops_key, $i, 1) . '-';
425  $uu = 0;
426  } else {
427  if (substr($xoops_key, $i, 1) != '-') {
428  $ret .= substr($xoops_key, $i, 1);
429  } else {
430  $uu--;
431  }
432  }
433  }
434  }
435  $ret = str_replace('--', '-', $ret);
436  if (substr($ret, 0, 1) == '-') {
437  $ret = substr($ret, 2, strlen($ret));
438  }
439  if (substr($ret, strlen($ret) - 1, 1) == '-') {
440  $ret = substr($ret, 0, strlen($ret) - 1);
441  }
442  return $ret;
443 }
444 ?>