1: <?php
2:
3: 4: 5: 6: 7:
8:
9:
10: 11: 12: 13: 14: 15:
16: function zpRewriteURL($query) {
17: $redirectURL = '';
18: if (isset($query['p'])) {
19: sanitize($query);
20: switch ($query['p']) {
21: case 'news':
22: $redirectURL = _NEWS_;
23: if (isset($query['category'])) {
24: $obj = new ZenpageCategory($query['category'], false);
25: if (!$obj->loaded)
26: return '';
27: $redirectURL = $obj->getLink();
28: unset($query['category']);
29: } else if (isset($query['date'])) {
30: $redirectURL = _NEWS_ARCHIVE_ . '/' . $query['date'];
31: unset($query['date']);
32: }
33: if (isset($query['title'])) {
34: $obj = new ZenpageNews($query['title'], false);
35: if (!$obj->loaded)
36: return '';
37: $redirectURL = $obj->getLink();
38: unset($query['title']);
39: }
40: break;
41: case 'pages':
42: $redirectURL = _PAGES_;
43: if (isset($query['title'])) {
44: $obj = new ZenpagePage($query['title'], false);
45: if (!$obj->loaded)
46: return '';
47: $redirectURL = $obj->getLink();
48: unset($query['title']);
49: }
50: break;
51: case'search':
52: $redirectURL = _SEARCH_;
53: if (isset($query['date'])) {
54: $redirectURL = _ARCHIVE_ . '/' . $query['date'];
55: unset($query['date']);
56: } else if (isset($query['searchfields']) && $query['searchfields'] == 'tags') {
57: $redirectURL = _TAGS_;
58: unset($query['searchfields']);
59: }
60: if (isset($query['words'])) {
61: $redirectURL .= '/' . $query['words'];
62: unset($query['words']);
63: }
64: break;
65: default:
66: $redirectURL = getCustomPageURL($query['p']);
67: break;
68: }
69: unset($query['p']);
70: $redirectURL = preg_replace('~^' . WEBPATH . '/~', '', $redirectURL);
71: if (isset($query['page'])) {
72: $redirectURL.='/' . $query['page'];
73: unset($query['page']);
74: }
75: $q = http_build_query($query);
76: if ($q)
77: $redirectURL .= '?' . $q;
78: } else if (isset($query['album'])) {
79: if (isset($query['image'])) {
80: $obj = newImage(NULL, array('folder' => $query['album'], 'filename' => $query['image']), true);
81: unset($query['image']);
82: } else {
83: $obj = newAlbum($query['album'], NULL, true);
84: }
85: unset($query['album']);
86: if (!$obj->exists)
87: return '';
88: $redirectURL = preg_replace('~^' . WEBPATH . '/~', '', $obj->getLink());
89: $q = http_build_query($query);
90: if ($q)
91: $redirectURL .= '?' . $q;
92: }
93: return $redirectURL;
94: }
95:
96: 97: 98: 99:
100: function fix_path_redirect() {
101: if (MOD_REWRITE) {
102: $request_uri = getRequestURI();
103: $parts = parse_url($request_uri);
104: if (isset($parts['query'])) {
105: parse_str($parts['query'], $query);
106: $redirectURL = zpRewriteURL($query);
107: if ($redirectURL) {
108: header("HTTP/1.0 301 Moved Permanently");
109: header("Status: 301 Moved Permanently");
110: header('Location: ' . FULLWEBPATH . '/' . $redirectURL);
111: exitZP();
112: }
113: }
114: }
115: }
116:
117: function zp_load_page($pagenum = NULL) {
118: global $_zp_page;
119: if (!is_numeric($pagenum)) {
120: $_zp_page = isset($_GET['page']) ? $_GET['page'] : 1;
121: } else {
122: $_zp_page = round($pagenum);
123: }
124: }
125:
126: 127: 128:
129: function zp_load_gallery() {
130: global $_zp_current_album, $_zp_current_album_restore, $_zp_albums,
131: $_zp_current_image, $_zp_current_image_restore, $_zp_images, $_zp_current_comment,
132: $_zp_comments, $_zp_current_context, $_zp_current_search, $_zp_current_zenpage_new,
133: $_zp_current_zenpage_page, $_zp_current_category, $_zp_post_date, $_zp_pre_authorization;
134: $_zp_current_album = NULL;
135: $_zp_current_album_restore = NULL;
136: $_zp_albums = NULL;
137: $_zp_current_image = NULL;
138: $_zp_current_image_restore = NULL;
139: $_zp_images = NULL;
140: $_zp_current_comment = NULL;
141: $_zp_comments = NULL;
142: $_zp_current_context = 0;
143: $_zp_current_search = NULL;
144: $_zp_current_zenpage_news = NULL;
145: $_zp_current_zenpage_page = NULL;
146: $_zp_current_category = NULL;
147: $_zp_post_date = NULL;
148: $_zp_pre_authorization = array();
149: set_context(ZP_INDEX);
150: }
151:
152: 153: 154:
155: function zp_load_search() {
156: global $_zp_current_search;
157: zp_clearCookie("zenphoto_search_params");
158: if (!is_object($_zp_current_search)) {
159: $_zp_current_search = new SearchEngine();
160: }
161: add_context(ZP_SEARCH);
162: $params = $_zp_current_search->getSearchParams();
163: zp_setCookie("zenphoto_search_params", $params, SEARCH_DURATION);
164: return $_zp_current_search;
165: }
166:
167: 168: 169: 170: 171: 172: 173:
174: function zp_load_album($folder, $force_nocache = false) {
175: global $_zp_current_album, $_zp_gallery;
176: $_zp_current_album = newAlbum($folder, !$force_nocache, true);
177: if (!is_object($_zp_current_album) || !$_zp_current_album->exists)
178: return false;
179: add_context(ZP_ALBUM);
180: return $_zp_current_album;
181: }
182:
183: 184: 185: 186: 187: 188: 189:
190: function zp_load_image($folder, $filename) {
191: global $_zp_current_image, $_zp_current_album, $_zp_current_search;
192: if (!is_object($_zp_current_album) || $_zp_current_album->name != $folder) {
193: $album = zp_load_album($folder, true);
194: } else {
195: $album = $_zp_current_album;
196: }
197: if (!is_object($album) || !$album->exists)
198: return false;
199: $_zp_current_image = newImage($album, $filename, true);
200: if (is_null($_zp_current_image) || !$_zp_current_image->exists) {
201: return false;
202: }
203: add_context(ZP_IMAGE | ZP_ALBUM);
204: return $_zp_current_image;
205: }
206:
207: 208: 209: 210: 211: 212: 213: 214:
215: function load_zenpage_pages($titlelink) {
216: global $_zp_current_zenpage_page;
217: $_zp_current_zenpage_page = new ZenpagePage($titlelink);
218: if ($_zp_current_zenpage_page->loaded) {
219: add_context(ZP_ZENPAGE_PAGE | ZP_ZENPAGE_SINGLE);
220: } else {
221: $_GET['p'] = 'PAGES:' . $titlelink;
222: return NULL;
223: }
224: return $_zp_current_zenpage_page;
225: }
226:
227: 228: 229: 230: 231: 232: 233: 234: 235:
236: function load_zenpage_news($request) {
237: global $_zp_current_zenpage_news, $_zp_current_category, $_zp_post_date;
238: if (isset($request['date'])) {
239: add_context(ZP_ZENPAGE_NEWS_DATE);
240: $_zp_post_date = zpFunctions::removeTrailingSlash(sanitize($request['date']));
241: }
242: if (isset($request['category'])) {
243: $titlelink = sanitize(rtrim($request['category'], '/'));
244: $_zp_current_category = new ZenpageCategory($titlelink);
245: if ($_zp_current_category->loaded) {
246: add_context(ZP_ZENPAGE_NEWS_CATEGORY);
247: } else {
248: $_GET['p'] = 'CATEGORY:' . $titlelink;
249: unset($_GET['category']);
250: return false;
251: }
252: }
253: if (isset($request['title'])) {
254: $titlelink = sanitize(rtrim($request['title'], '/'));
255: $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
256: $result = query_single_row($sql);
257: if (is_array($result)) {
258: add_context(ZP_ZENPAGE_NEWS_ARTICLE | ZP_ZENPAGE_SINGLE);
259: $_zp_current_zenpage_news = new ZenpageNews($titlelink);
260: } else {
261: $_GET['p'] = 'NEWS:' . $titlelink;
262: }
263: return $_zp_current_zenpage_news;
264: }
265: return true;
266: }
267:
268: 269: 270: 271: 272:
273: function zp_load_request() {
274: if ($success = zp_apply_filter('load_request', true)) {
275: zp_load_page();
276: if (isset($_GET['p'])) {
277: $page = str_replace(array('/', '\\', '.'), '', sanitize($_GET['p']));
278: switch ($page) {
279: case 'search':
280: return zp_load_search();
281: break;
282: case 'pages':
283: if (extensionEnabled('zenpage')) {
284: return load_zenpage_pages(sanitize(rtrim(@$_GET['title'], '/')));
285: }
286: break;
287: case 'news':
288: if (extensionEnabled('zenpage')) {
289: return load_zenpage_news(sanitize($_GET));
290: }
291: break;
292: }
293: }
294:
295: list($album, $image) = rewrite_get_album_image('album', 'image');
296: if (!empty($image)) {
297: return zp_load_image($album, $image);
298: } else if (!empty($album)) {
299: return zp_load_album($album);
300: }
301: }
302: return $success;
303: }
304:
305: 306: 307: 308: 309:
310: function prepareIndexPage() {
311: global $_zp_gallery_page, $_zp_script;
312: handleSearchParms('index');
313: $theme = setupTheme();
314: $_zp_gallery_page = basename($_zp_script = THEMEFOLDER . "/$theme/index.php");
315: return $theme;
316: }
317:
318: 319: 320: 321:
322: function prepareAlbumPage() {
323: global $_zp_current_album, $_zp_gallery_page, $_zp_script;
324: if ($search = $_zp_current_album->getSearchEngine()) {
325: zp_setCookie("zenphoto_search_params", $search->getSearchParams(), SEARCH_DURATION);
326: } else {
327: handleSearchParms('album', $_zp_current_album);
328: }
329: $theme = setupTheme();
330: $_zp_gallery_page = "album.php";
331: $_zp_script = THEMEFOLDER . "/$theme/album.php";
332: return $theme;
333: }
334:
335: 336: 337: 338: 339:
340: function prepareImagePage() {
341: global $_zp_current_album, $_zp_current_image, $_zp_gallery_page, $_zp_script;
342: handleSearchParms('image', $_zp_current_album, $_zp_current_image);
343: $theme = setupTheme();
344: $_zp_gallery_page = basename($_zp_script = THEMEFOLDER . "/$theme/image.php");
345:
346: if (isImageVideo()) {
347: $_zp_current_image->updateDimensions();
348: }
349: return $theme;
350: }
351:
352: 353: 354: 355: 356:
357: function prepareCustomPage() {
358: global $_zp_current_album, $_zp_current_image, $_zp_gallery_page, $_zp_script, $_zp_current_search;
359: $searchalbums = handleSearchParms('page', $_zp_current_album, $_zp_current_image);
360: $album = NULL;
361: $page = str_replace(array('/', '\\', '.'), '', sanitize($_GET['p']));
362: if (isset($_GET['z'])) {
363: if ($subfolder = sanitize($_GET['z'])) {
364: $subfolder .= '/';
365: }
366: $_zp_gallery_page = $page . '.php';
367: $_zp_script = ZENFOLDER . '/' . $subfolder . $page . '.php';
368: } else {
369: $_zp_gallery_page = $page . '.php';
370: switch ($_zp_gallery_page) {
371: case 'search.php':
372: if (!empty($searchalbums)) {
373: $albums = array();
374: foreach ($searchalbums as $analbum) {
375: $parent = getUrAlbum(newAlbum($analbum));
376: $albums[$parent->getID()] = $parent;
377: }
378: if (count($albums) == 1) {
379: $album = array_shift($albums);
380: }
381: }
382: break;
383: }
384: }
385: $theme = setupTheme($album);
386: if (empty($_zp_script)) {
387: $_zp_script = THEMEFOLDER . "/$theme/$page.php";
388: }
389: return $theme;
390: }
391:
392:
393: if (!getOption('license_accepted')) {
394: if (isset($_GET['z']) && $_GET['z'] != 'setup') {
395:
396: $_GET['p'] = 'license';
397: $_GET['z'] = '';
398: }
399: }
400: ?>
401: