1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875:
<?php
require_once(dirname(dirname(__FILE__)) . '/global-definitions.php');
$const_webpath = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
$_zp_setup_serverpath = str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME']));
preg_match('~(.*)/(' . ZENFOLDER . ')~', $const_webpath, $matches);
if (empty($matches)) {
$const_webpath = '';
} else {
$const_webpath = $matches[1];
$_zp_setup_serverpath = substr($_zp_setup_serverpath, 0, strrpos($_zp_setup_serverpath, '/' . ZENFOLDER));
}
define('SETUPLOG', $_zp_setup_serverpath . '/' . DATA_FOLDER . '/setup.log');
if (!defined('SERVERPATH'))
define('SERVERPATH', $_zp_setup_serverpath);
require_once(dirname(dirname(__FILE__)) . '/functions-config.php');
class setup {
static function getResidentZPFiles($folder, $lcFilesystem = false) {
global $_zp_resident_files;
$dir = opendir($folder);
while (($file = readdir($dir)) !== false) {
$file = str_replace('\\', '/', $file);
if ($file != '.' && $file != '..') {
if (is_dir($folder . '/' . $file)) {
if ($file != 'session') {
setup::getResidentZPFiles($folder . '/' . $file, $lcFilesystem);
$entry = $folder . '/' . $file;
if ($lcFilesystem)
$entry = strtolower($entry);
$_zp_resident_files[] = $entry;
}
} else {
$entry = $folder . '/' . $file;
if ($lcFilesystem)
$entry = strtolower($entry);
$_zp_resident_files[] = $entry;
}
}
}
closedir($dir);
}
static function primeMark($text) {
global $_zp_setup_primeid;
?>
<script type="text/javascript">
$("#prime<?php echo $_zp_setup_primeid; ?>").remove();
</script>
<div id="prime<?php echo ++$_zp_setup_primeid; ?>" class="error"><?php printf(gettext('Testing %s.'), $text); ?></div>
<?php
}
static function checkMark($check, $text, $text2, $msg, $stopAutorun = true) {
global $_zp_setup_warn, $_zp_setup_moreid, $_zp_setup_primeid, $_zp_setup_autorun;
$classes = array(
'fail' => gettext('Fail: '),
'warn' => gettext('Warn: '),
'pass' => gettext('Pass: '));
?>
<script type="text/javascript">
$("#prime<?php echo $_zp_setup_primeid; ?>").remove();
</script>
<?php
$anyway = 0;
$dsp = '';
if ($check > 0) {
$check = 1;
}
switch ($check) {
case 0:
$cls = "fail";
break;
case -1:
case -3:
$cls = "warn";
$_zp_setup_warn = true;
if ($stopAutorun && $_zp_setup_autorun) {
$_zp_setup_autorun = false;
$anyway = 2;
$check = -1;
} else {
$anyway = 1;
}
break;
case 1:
case -2:
$cls = "pass";
break;
}
if ($check <= 0) {
?>
<li class="<?php echo $cls; ?>"><?php
if (empty($text2)) {
echo $text;
$dsp .= trim($text);
} else {
echo $text2;
$dsp .= trim($text2);
}
if (!empty($msg)) {
switch ($check) {
case 0:
?>
<div class="error">
<h1><?php echo gettext('Error!'); ?></h1>
<p><?php echo $msg; ?></p>
</div>
<?php
break;
case -1:
$anyway = 1;
?>
<div class="warning">
<h1><?php echo gettext('Warning!'); ?></h1>
<p><?php echo $msg; ?></p>
</div>
<?php
break;
default:
$_zp_setup_moreid++;
?>
<?php
if ($check == -3) {
?>
<div class="warning" id="more<?php echo $_zp_setup_moreid; ?>">
<h1><?php echo gettext('Warning!'); ?></h1>
<?php
} else {
?>
<div class="notice" id="more<?php echo $_zp_setup_moreid; ?>">
<h1><?php echo gettext('Notice!'); ?></h1>
<?php
}
?>
<p><?php echo $msg; ?></p>
</div>
<?php
break;
}
$dsp .= ' ' . $msg;
}
?>
</li>
<?php
} else {
$anyway = 1;
$dsp = $text;
}
if ($anyway == 2) {
$stopped = '(' . gettext('Autorun aborted') . ') ';
} else {
$stopped = '';
}
setup::log($classes[$cls] . $stopped . $dsp, $anyway);
return $check;
}
static function folderCheck($which, $path, $class, $subfolders, $recurse, $chmod, $updatechmod) {
global $_zp_setup_serverpath, $_zp_setup_permission_names;
$path = str_replace('\\', '/', $path);
if (!is_dir($path) && $class == 'std') {
mkdir_recursive($path, $chmod);
}
switch ($class) {
case 'std':
$append = trim(str_replace($_zp_setup_serverpath, '', $path), '/');
if (($append != $which)) {
$f = " (<em>$append</em>)";
} else {
$f = '';
}
if (!is_null($subfolders)) {
$subfolderfailed = '';
foreach ($subfolders as $subfolder) {
if (!mkdir_recursive($path . $subfolder, $chmod)) {
$subfolderfailed .= ', <code>' . $subfolder . '</code>';
}
}
if (!empty($subfolderfailed)) {
return setup::checkMark(-1, '', sprintf(gettext('<em>%1$s</em> folder%2$s [subfolder creation failure]'), $which, $f), sprintf(gettext('Setup could not create the following subfolders:<br />%s'), substr($subfolderfailed, 2)));
}
}
if (setup::isWin()) {
$perms = fileperms($path) & 0700;
$check = $chmod & 0700;
} else {
$perms = fileperms($path) & 0777;
$check = $chmod;
}
if (setup::userAuthorized() && $updatechmod) {
@chmod($path, $chmod);
clearstatcache();
$perms = fileperms($path) & 0777;
if (!setup::checkPermissions($perms, $chmod)) {
if (array_key_exists($perms & 0666 | 4, $_zp_setup_permission_names)) {
$perms_class = $_zp_setup_permission_names[$perms & 0666 | 4];
} else {
$perms_class = gettext('unknown');
}
if (array_key_exists($chmod & 0666 | 4, $_zp_setup_permission_names)) {
$chmod_class = $_zp_setup_permission_names[$chmod & 0666 | 4];
} else {
$chmod_class = gettext('unknown');
}
return setup::checkMark(-1, '', sprintf(gettext('<em>%1$s</em> folder%2$s [permissions failure]'), $which, $f), sprintf(gettext('Setup could not change the file permissions from <em>%1$s</em> (<code>0%2$o</code>) to <em>%3$s</em> (<code>0%4$o</code>). You will have to set the permissions manually. See the <a href="http://www.zenphoto.org/news/troubleshooting-zenphoto#29">Troubleshooting guide</a> for details on Zenphoto permissions requirements.'), $perms_class, $perms, $chmod_class, $chmod));
} else {
if ($recurse) {
?>
<script type="text/javascript">
$.ajax({
type: 'POST',
cache: false,
url: '<?php echo WEBPATH . '/' . ZENFOLDER; ?>/setup/setup_permissions_changer.php',
data: 'folder=<?php echo $path; ?>&key=<?php echo sha1(filemtime(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE) . file_get_contents(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE)); ?>'
});
</script>
<?php
}
}
}
break;
case 'in_webpath':
$webpath = $_SERVER['SCRIPT_NAME'];
if (empty($webpath)) {
$serverroot = $_zp_setup_serverpath;
} else {
$i = strpos($webpath, '/' . ZENFOLDER);
$webpath = substr($webpath, 0, $i);
$serverroot = substr($_zp_setup_serverpath, 0, strpos($_zp_setup_serverpath, $webpath));
}
$append = substr($path, strlen($serverroot) + 1);
$f = " (<em>$append</em>)";
break;
case 'external':
$append = $path;
$f = " (<em>$append</em>)";
break;
}
if (!is_dir($path)) {
$msg = " " . sprintf(gettext('You must create the folder <em>%1$s</em><br /><code>mkdir(%2$s, 0777)</code>.'), $append, substr($path, 0, -1));
if ($class != 'std') {
return setup::checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> does not exist]'), $which, $append), $msg);
} else {
return setup::checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> does not exist and <strong>setup</strong> could not create it]'), $which, $append), $msg);
}
} else if (!is_writable($path)) {
$msg = sprintf(gettext('Change the permissions on the <code>%1$s</code> folder to be writable by the server (<code>chmod 777 %2$s</code>)'), $which, $append);
return setup::checkMark(false, '', sprintf(gettext('<em>%1$s</em> folder [<em>%2$s</em> is not writeable and <strong>setup</strong> could not make it so]'), $which, $append), $msg);
} else {
return setup::checkMark(true, sprintf(gettext('<em>%1$s</em> folder%2$s'), $which, $f), '', '');
}
}
static function versionCheck($required, $desired, $found) {
$nr = explode(".", $required . '.0.0.0');
$vr = $nr[0] * 10000 + $nr[1] * 100 + $nr[2];
$nf = explode(".", $found . '.0.0.0');
$vf = $nf[0] * 10000 + $nf[1] * 100 + $nf[2];
$nd = explode(".", $desired . '.0.0.0');
$vd = $nd[0] * 10000 + $nd[1] * 100 + $nd[2];
if ($vf < $vr)
return 0;
if ($vf < $vd)
return -1;
return 1;
}
static function glob($pattern, $flags = 0) {
$split = explode('/', $pattern);
$match = array_pop($split);
$path_return = $path = implode('/', $split);
if (empty($path)) {
$path = '.';
} else {
$path_return = $path_return . '/';
}
if (($dir = opendir($path)) !== false) {
$glob = array();
while (($file = readdir($dir)) !== false) {
if (setup::fnmatch($match, $file)) {
if ((is_dir("$path/$file")) || (!($flags & GLOB_ONLYDIR))) {
if ($flags & GLOB_MARK)
$file .= '/';
$glob[] = $path_return . $file;
}
}
}
closedir($dir);
if (!($flags & GLOB_NOSORT))
sort($glob);
return $glob;
} else {
return array();
}
}
static function fnmatch($pattern, $string) {
if (!function_exists('fnmatch')) {
return @preg_match('/^' . strtr(addcslashes($pattern, '\\.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string);
} else {
return fnmatch($pattern, $string);
}
}
static function charsetSelector($select) {
global $_zp_UTF8;
$selector = '<select id="FILESYSTEM_CHARSET" name="FILESYSTEM_CHARSET" >';
$selector .= '<option value ="unknown">' . gettext('Unknown') . '</option>';
$totalsets = $_zp_UTF8->charsets;
ksort($totalsets);
foreach ($totalsets as $key => $char) {
$selector .= ' <option value="' . $key . '"';
if ($key == $select) {
$selector .= ' selected="selected"';
}
$selector .= '>' . $key . '</option>';
}
$selector .= '</select>';
$selector .= '<span class="buttons" style="float: right"><button type="submit" alt="' . gettext('change the definition') . '"><strong>' . gettext('apply') . '</strong></button></span>';
return $selector;
}
static function permissionsSelector($permission_names, $select) {
$select = $select | 4;
global $_zp_UTF8;
$selector = '<select id="chmod_permissions" name="chmod_permissions" >';
$c = 0;
foreach ($permission_names as $key => $permission) {
$selector .= ' <option value="' . $c . '"' . ($select == $key ? ' selected="selected"' : '') . '>' . sprintf(gettext('%1$s (0%2$o)'), $permission_names[$key], $key) . '</option>';
$c++;
}
$selector .= '</select>';
$selector .= '<span class="buttons" style="float: right;"><button type="submit" alt="' . gettext('change the definition') . '"><strong>' . gettext('apply') . '</strong></button></span><br class="clearall" />';
return $selector;
}
static function log($message, $anyway = false, $reset = false) {
global $_zp_setup_debug, $_zp_mutex, $_zp_setup_chmod;
if ($_zp_setup_debug || $anyway) {
if (is_object($_zp_mutex))
$_zp_mutex->lock();
if (!file_exists(dirname(SETUPLOG))) {
mkdir_recursive(dirname(SETUPLOG), $_zp_setup_chmod | 0311);
}
if ($reset) {
$mode = 'w';
} else {
$mode = 'a';
}
$f = fopen(SETUPLOG, $mode);
if ($f) {
fwrite($f, strip_tags($message) . "\n");
fclose($f);
clearstatcache();
}
if (is_object($_zp_mutex))
$_zp_mutex->unlock();
}
}
static function languageSelector() {
global $_zp_setup_xsrftoken;
$languages = generateLanguageList();
if (isset($_REQUEST['locale'])) {
$locale = sanitize($_REQUEST['locale']);
if (getOption('locale') != $locale || getOption('unsupported_' . $locale)) {
?>
<div class="errorbox">
<h2>
<?php printf(gettext('<em>%s</em> is not available.'), html_encode($languages[$locale])); ?>
<?php printf(gettext('The locale %s is not supported on your server.'), html_encode($locale)); ?>
<br />
<?php echo gettext('See the <a href="http://www.zenphoto.org/news/troubleshooting-zenphoto#24">troubleshooting guide</a> on zenphoto.org for details.'); ?>
</h2>
</div>
<?php
}
}
?>
<ul class="sflags">
<?php
$_languages = generateLanguageList();
ksort($_languages, SORT_LOCALE_STRING);
$currentValue = getOption('locale');
foreach ($_languages as $text => $lang) {
if (setup::locale($lang)) {
?>
<li<?php if ($lang == $currentValue) echo ' class="currentLanguage"'; ?>>
<?php
if ($lang != $currentValue) {
?>
<a href="javascript:launchScript('',['locale=<?php echo $lang; ?>']);" >
<?php
}
if (file_exists(SERVERPATH . '/' . ZENFOLDER . '/locale/' . $lang . '/flag.png')) {
$flag = WEBPATH . '/' . ZENFOLDER . '/locale/' . $lang . '/flag.png';
} else {
$flag = WEBPATH . '/' . ZENFOLDER . '/locale/missing_flag.png';
}
?>
<img src="<?php echo $flag; ?>" alt="<?php echo $text; ?>" title="<?php echo $text; ?>" />
<?php
if ($lang != $currentValue) {
?>
</a>
<?php
}
?>
</li>
<?php
}
}
?>
</ul>
<?php
}
static function XSRFDefender() {
global $_zp_setup_xsrftoken;
if (!isset($_REQUEST['xsrfToken']) || $_zp_setup_xsrftoken != $_REQUEST['xsrfToken']) {
?>
<p class="errorbox" >
<?php echo gettext('An attempt at cross site reference forgery has been blocked.') ?>
</p>
<?php
exit();
}
}
static function sanitize($input_string, $sanitize_level = 3) {
if (is_array($input_string)) {
foreach ($input_string as $output_key => $output_value) {
$output_string[$output_key] = setup::sanitize_string($output_value, $sanitize_level);
}
unset($output_key, $output_value);
} else {
$output_string = setup::sanitize_string($input_string, $sanitize_level);
}
return $output_string;
}
static function sanitize_string($input_string, $sanitize_level) {
if ($sanitize_level === 0) {
$input_string = str_replace(chr(0), " ", $input_string);
} else {
$input_string = strip_tags($input_string);
}
return $input_string;
}
static function isWin() {
return (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
}
static function isMac() {
return strtoupper(PHP_OS) == 'DARWIN';
}
static function checkPermissions($actual, $expected) {
if (setup::isWin()) {
return ($actual & 0700) == ($expected & 0700);
} else {
return ($actual & 0770) == ($expected & 0770);
}
}
static function folderPermissions($folder) {
$files = array();
if (($dir = opendir($folder)) !== false) {
while (($file = readdir($dir)) !== false) {
if ($file != '.' && $file != '..') {
$files[] = $file;
}
}
closedir($dir);
}
foreach ($files as $file) {
$path = $folder . '/' . $file;
if (is_dir($path)) {
@chmod($path, FOLDER_MOD);
clearstatcache();
if (setup::checkPermissions(fileperms($path) & 0777, FOLDER_MOD)) {
if (!setup::folderPermissions($path)) {
return false;
}
} else {
return false;
}
} else {
@chmod($path, FILE_MOD);
clearstatcache();
if (!setup::checkPermissions(fileperms($path) & 0777, FILE_MOD)) {
return false;
}
}
}
return true;
}
static function siteClosed($ht) {
if (empty($ht)) {
return false;
} else {
preg_match('|[# ][ ]*RewriteRule(.*)plugins/site_upgrade/closed|', $ht, $matches);
return !(empty($matches)) && strpos($matches[0], '#') === false;
}
}
static function closeSite($nht) {
preg_match_all('|[# ][ ]*RewriteRule(.*)plugins/site_upgrade/closed|', $nht, $matches);
foreach ($matches[0] as $match) {
$nht = str_replace($match, ' ' . substr($match, 1), $nht);
}
return $nht;
}
static function acknowledge($value) {
global $_zp_setup_xsrftoken, $_zp_conf_vars;
$link = WEBPATH . '/' . ZENFOLDER . '/setup/index.php?security_ack=' . ((isset($_zp_conf_vars['security_ack']) ? $_zp_conf_vars['security_ack'] : NULL) | $value) . '&xsrfToken=' . $_zp_setup_xsrftoken;
return sprintf(gettext('Click <a href="%s">here</a> to acknowledge that you wish to ignore this issue. It will then become a warning.'), $link);
}
static function configMod() {
$mod = 0600;
$str = '';
while (empty($str)) {
@chmod(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, $mod);
$str = @file_get_contents(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE);
if ($mod == 0666) {
break;
}
$mod = $mod | $mod >> 3;
}
return $str;
}
static function printFooter() {
?>
<br class="clearall" />
</div><!-- content -->
</div><!-- main -->
<div id="footer">
<a href="http://www.zenphoto.org" title="<?php echo gettext('ZenphotoCMS - The simpler media website CMS'); ?>">zen<strong>photo</strong></a>
| <a href="http://www.zenphoto.org/support" title=" <?php echo gettext('Forum'); ?>"><?php echo gettext('Forum'); ?></a>
| <a href="https://github.com/zenphoto/zenphoto/issues" title="Bugtracker">Bugtracker </a> | <a href="http://www.zenphoto.org/news/category/changelog" title="<?php echo gettext('View Change log'); ?>"><?php echo gettext('View Change log'); ?></a>
</div>
</body>
</html>
<?php
}
static function userAuthorized() {
if (function_exists('zp_loggedin')) {
return zp_loggedin(ADMIN_RIGHTS);
} else {
return true;
}
}
static function updateConfigfile($zp_cfg) {
global $_zp_setup_xsrftoken;
$mod1 = fileperms(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE) & 0777;
$mod2 = fileperms(SERVERPATH . '/' . DATA_FOLDER) & 0777;
@chmod(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, 0777);
if (is_writeable(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE)) {
rename(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, $backkup = SERVERPATH . '/' . DATA_FOLDER . '/' . str_replace(strrchr(CONFIGFILE, "."), '', CONFIGFILE) . '.bak.php');
chmod($backkup, $mod1);
if ($handle = fopen(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, 'w')) {
if (fwrite($handle, $zp_cfg)) {
setup::Log(gettext("Updated configuration file"));
$base = true;
}
}
fclose($handle);
clearstatcache();
}
@chmod(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, $mod2);
$str = setup::configMod();
$_zp_setup_xsrftoken = sha1(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE . $str . session_id());
}
static function checkUnique($table, $unique) {
global $_zp_setup_autorun;
$sql = 'SHOW KEYS FROM ' . $table;
$result = query_full_array($sql);
foreach ($result as $key) {
if (!$key['Non_unique']) {
unset($unique[$key['Column_name']]);
}
}
if (!empty($unique)) {
$_zp_setup_autorun = false;
?>
<p class="notebox">
<?php
printf(gettext('<strong>Warning:</strong> the <code>%s</code> table appears not to have a proper <em>UNIQUE</em> key. There are probably duplicate entries in the table which can cause unpredictable behavior. This can normally be corrected by creating a Zenphoto backup, dropping the table, running setup to restore the table, and then restoring from the backup. Note, however, that the duplicate entries will be lost.'), trim($table, '`'));
?>
</p>
<?php
} else {
echo '<img src="' . FULLWEBPATH . '/' . ZENFOLDER . '/images/pass.png" alt="">';
}
}
static function mkdir_r($pathname, $mode) {
if (!is_dir(dirname($pathname))) {
setup::mkdir_r(dirname($pathname), $mode);
}
return is_dir($pathname) || @mkdir($pathname, $mode);
}
static function locale($locale) {
global $_zp_RTL_css;
$en1 = LOCAL_CHARSET;
$en2 = str_replace('ISO-', 'ISO', $en1);
$simple = str_replace('_', '-', $locale);
$simple = explode('-', $simple);
$try[$locale . '.UTF8'] = $locale . '.UTF8';
$try[$locale . '.UTF-8'] = $locale . '.UTF-8';
$try[$locale . '.@euro'] = $locale . '.@euro';
$try[$locale . '.' . $en2] = $locale . '.' . $en2;
$try[$locale . '.' . $en1] = $locale . '.' . $en1;
$try[$locale] = $locale;
$try[$simple[0]] = $simple[0];
$try['NULL'] = NULL;
$rslt = setlocale(LC_ALL, $try);
$_zp_RTL_css = in_array(substr($rslt, 0, 2), array('fa', 'ar', 'he', 'hi', 'ur'));
return $rslt;
}
static function defaultOptionsRequest($name, $type = 'plugin') {
global $_zp_conf_vars;
$curloptions = array();
switch ($type) {
case 'modrewrite':
$uri = FULLWEBPATH . '/' . $_zp_conf_vars['special_pages']['page']['rewrite'] . '/setup_set-mod_rewrite?z=setup';
$curloptions = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 2000,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POSTREDIR => 3
);
break;
case 'plugin':
$uri = FULLWEBPATH . '/' . ZENFOLDER . '/setup/setup_pluginOptions.php?plugin=' . $name;
break;
case 'theme':
$uri = FULLWEBPATH . '/' . ZENFOLDER . '/setup/setup_themeOptions.php?theme=' . $name;
break;
}
if (function_exists('curl_init')) {
$uri .= '&returnmode';
$success = curlRequest($uri, $curloptions);
if ($success) {
$image = FULLWEBPATH . '/' . ZENFOLDER . '/images/pass.png';
} else {
$image = FULLWEBPATH . '/' . ZENFOLDER . '/images/fail.png';
}
if ($success) {
?>
<span>
<img src="<?php echo $image; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" height="16px" width="16px" />
</span>
<?php
} else {
?>
<p class="error">
<img src="<?php echo $image; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" height="16px" width="16px" /> <?php echo $name; ?>
</p>
<?php
}
} else {
?>
<span>
<img src="<?php echo $uri; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" height="16px" width="16px" />
</span>
<?php
}
}
static function checkServerSoftware() {
$serversoftware = setup::getServerSoftware();
if(in_array($serversoftware, array('apache', 'nginx'))) {
return true;
} else {
return false;
}
}
static function getServerSoftware() {
if(stristr($_SERVER['SERVER_SOFTWARE'], "apache")) {
return 'apache';
} else if(stristr($_SERVER['SERVER_SOFTWARE'], "nginx")) {
return 'nginx';
} else {
return $_SERVER['SERVER_SOFTWARE'];
}
}
static function getFileList($array) {
$list = '';
if ($array) {
$list .= '<ul class="setup_filelist">';
foreach ($array as $entry) {
$list .= '<li><code>' . $entry . '</code></li>';
}
$list .= '</ul>';
}
return $list;
}
static function secureServer() {
if (isset($_SERVER['HTTPS'])) {
if ('on' == strtolower($_SERVER['HTTPS'])) {
return true;
}
if ('1' == $_SERVER['HTTPS']) {
return true;
}
} elseif (isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] )) {
return true;
} elseif (isset($_SERVER['HTTP_FORWARDED']) && preg_match("/^(.+[,;])?\s*proto=https\s*([,;].*)$/", strtolower($_SERVER['HTTP_FORWARDED']))) {
return true;
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']))) {
return true;
}
return false;
}
}