1: <?php
2: 3: 4: 5:
6:
7: 8: 9: 10:
11: function reconfigureAction($mandatory) {
12: list($diff, $needs) = checkSignature($mandatory);
13: $diffkeys = array_keys($diff);
14: if ($mandatory || in_array('ZENPHOTO', $diffkeys) || in_array('FOLDER', $diffkeys)) {
15: if (isset($_GET['rss'])) {
16: if (file_exists(SERVERPATH . '/' . DATA_FOLDER . '/rss-closed.xml')) {
17: $xml = file_get_contents(SERVERPATH . '/' . DATA_FOLDER . '/rss-closed.xml');
18: $xml = preg_replace('~<pubDate>(.*)</pubDate>~', '<pubDate>' . date("r", time()) . '</pubDate>', $xml);
19: echo $xml;
20: }
21: exit();
22: }
23: if (empty($needs)) {
24: $dir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
25: $p = strpos($dir, ZENFOLDER);
26: if ($p !== false) {
27: $dir = substr($dir, 0, $p);
28: }
29: if (OFFSET_PATH) {
30: $where = 'admin';
31: } else {
32: $where = 'gallery';
33: }
34: $dir = rtrim($dir, '/');
35: $location = "http://" . $_SERVER['HTTP_HOST'] . $dir . "/" . ZENFOLDER . "/setup/index.php?autorun=$where";
36: header("Location: $location");
37: exitZP();
38: } else {
39: header('Last-Modified: ' . ZP_LAST_MODIFIED);
40: header('Content-Type: text/html; charset=UTF-8');
41: ?>
42: <!DOCTYPE html>
43: <html xmlns="http://www.w3.org/1999/xhtml">
44: <head>
45: <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
46: <link rel="stylesheet" href="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/admin.css" type="text/css" />
47: <?php reconfigureCS(); ?>
48: </head>
49: <body>
50: <div id="main">
51: <div id="content">
52: <div class="tabbox">
53: <?php reconfigurePage($diff, $needs, $mandatory); ?>
54: </div>
55: </div>
56: </div>
57: </body>
58: </html>
59: <?php
60: exitZP();
61: }
62: } else if (!empty($diff)) {
63: if (function_exists('zp_register_filter')) {
64: zp_register_filter('admin_note', 'signatureChange');
65: zp_register_filter('admin_head', 'reconfigureCS');
66: if (zp_loggedin(ADMIN_RIGHTS)) {
67: zp_register_filter('theme_head', 'reconfigureCS');
68: zp_register_filter('theme_body_open', 'signatureChange');
69: }
70: }
71: }
72: }
73:
74: 75: 76: 77:
78: function checkSignature($auto) {
79: global $_configMutex;
80: global $_zp_DB_connection, $_reconfigureMutex;
81: if (function_exists('query_full_array') && $_zp_DB_connection) {
82: $old = @unserialize(getOption('zenphoto_install'));
83: $new = installSignature();
84: } else {
85: $old = NULL;
86: $new = array();
87: }
88: if (!is_array($old)) {
89: $old = array('ZENPHOTO' => gettext('an unknown release'));
90: }
91: $diff = array();
92: $keys = array_unique(array_merge(array_keys($new), array_keys($old)));
93: foreach ($keys as $key) {
94: if (!array_key_exists($key, $new) || !array_key_exists($key, $old) || $old[$key] != $new[$key]) {
95: $diff[$key] = array('old' => @$old[$key], 'new' => @$new[$key]);
96: }
97: }
98:
99: $package = file_get_contents(dirname(__FILE__) . '/Zenphoto.package');
100: preg_match_all('|' . ZENFOLDER . '/setup/(.*)|', $package, $matches);
101: $needs = array();
102: foreach ($matches[1] as $need) {
103: $needs[] = rtrim(trim($need), ":*");
104: }
105:
106: $_configMutex->lock();
107: if (file_exists(dirname(__FILE__) . '/setup/')) {
108: chdir(dirname(__FILE__) . '/setup/');
109: $found = safe_glob('*.xxx');
110: if (!empty($found) && $auto && zp_loggedin(ADMIN_RIGHTS)) {
111: foreach ($found as $script) {
112: chmod($script, 0777);
113: if (@rename($script, stripSuffix($script))) {
114: chmod(stripSuffix($script), FILE_MOD);
115: } else {
116: chmod($script, FILE_MOD);
117: }
118: }
119: }
120: $found = safe_glob('*.*');
121: $needs = array_diff($needs, $found);
122: }
123: $_configMutex->unlock();
124: return array($diff, $needs);
125: }
126:
127: 128: 129: 130: 131: 132: 133:
134: function signatureChange($tab = NULL, $subtab = NULL) {
135: list($diff, $needs) = checkSignature(false);
136: reconfigurePage($diff, $needs, 0);
137: return $tab;
138: }
139:
140: 141: 142: 143:
144: function reconfigureCS() {
145: ?>
146: <style type="text/css">
147: .reconfigbox {
148: padding: 5px 10px 5px 10px;
149: background-color:
150: border-width: 1px 1px 2px 1px;
151: border-color:
152: border-style: solid;
153: margin-bottom: 10px;
154: font-size: 100%;
155: -moz-border-radius: 5px;
156: -khtml-border-radius: 5px;
157: -webkit-border-radius: 5px;
158: border-radius: 5px;
159: }
160: .reconfigbox h2,.notebox strong {
161: color:
162: font-size: 100%;
163: font-weight: bold;
164: margin-bottom: 1em;
165: }
166:
167: list-style-type: square;
168: }
169:
170: list-style-type: circle;
171: }
172: </style>
173: <?php
174: }
175:
176: 177: 178: 179:
180: function reconfigurePage($diff, $needs, $mandatory) {
181: ?>
182: <div class="reconfigbox">
183: <h1>
184: <?php echo gettext('Zenphoto has detected a change in your installation.'); ?>
185: </h1>
186: <div id="errors">
187: <ul>
188: <?php
189: foreach ($diff as $thing => $rslt) {
190: switch ($thing) {
191: case 'SERVER_SOFTWARE':
192: echo '<li>' . sprintf(gettext('Your server software has changed from %1$s to %2$s.'), $rslt['old'], $rslt['new']) . '</li>';
193: break;
194: case 'DATABASE':
195: $dbs = db_software();
196: echo '<li>' . sprintf(gettext('Your database software has changed from %1$s to %2$s.'), $rslt['old'], $rslt['new']) . '</li>';
197: break;
198: case 'ZENPHOTO':
199: echo '<li>' . sprintf(gettext('Zenphoto %1$s has been copied over %2$s.'), ZENPHOTO_VERSION . '[' . ZENPHOTO_RELEASE . ']', $rslt['old']) . '</li>';
200: break;
201: case 'FOLDER':
202: echo '<li>' . sprintf(gettext('Your installation has moved from %1$s to %2$s.'), $rslt['old'], $rslt['new']) . '</li>';
203: break;
204: default:
205: $sz = @filesize(SERVERPATH . '/' . ZENFOLDER . '/' . $thing);
206: echo '<li>' . sprintf(gettext('The script <code>%1$s</code> has changed.'), $thing) . '</li>';
207: break;
208: }
209: }
210: ?>
211: </ul>
212: </div>
213: <p>
214: <?php
215: if (OFFSET_PATH) {
216: $where = 'admin';
217: } else {
218: $where = 'gallery';
219: }
220: $l1 = '<a href="' . WEBPATH . '/' . ZENFOLDER . '/setup.php?autorun=' . $where . '&xsrfToken=' . getXSRFToken('setup') . '">';
221: $l2 = '</a>';
222: if (array_key_exists('ZENPHOTO', $diff) || array_key_exists('FOLDER', $diff)) {
223: printf(gettext('The change detected is critical. You <strong>must</strong> run %1$ssetup%2$s for your site to function.'), $l1, $l2);
224: } else {
225: printf(gettext('The change detected may not be critical but you should run %1$ssetup%2$s at your earliest convenience.'), $l1, $l2);
226: }
227: ?>
228: </p>
229: </div>
230: <?php
231: }
232: ?>