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:
<?php
function zpRewriteURL($query) {
$redirectURL = '';
if (isset($query['p'])) {
sanitize($query);
switch ($query['p']) {
case 'news':
$redirectURL = _NEWS_;
if (isset($query['category'])) {
$obj = new ZenpageCategory($query['category'], false);
if (!$obj->loaded)
return '';
$redirectURL = $obj->getLink();
unset($query['category']);
} else if (isset($query['date'])) {
$redirectURL = _NEWS_ARCHIVE_ . '/' . $query['date'];
unset($query['date']);
}
if (isset($query['title'])) {
$obj = new ZenpageNews($query['title'], false);
if (!$obj->loaded)
return '';
$redirectURL = $obj->getLink();
unset($query['title']);
}
break;
case 'pages':
$redirectURL = _PAGES_;
if (isset($query['title'])) {
$obj = new ZenpagePage($query['title'], false);
if (!$obj->loaded)
return '';
$redirectURL = $obj->getLink();
unset($query['title']);
}
break;
case'search':
$redirectURL = _SEARCH_;
if (isset($query['date'])) {
$redirectURL = _ARCHIVE_ . '/' . $query['date'];
unset($query['date']);
} else if (isset($query['searchfields']) && $query['searchfields'] == 'tags') {
$redirectURL = _TAGS_;
unset($query['searchfields']);
}
if (isset($query['words'])) {
$redirectURL .= '/' . $query['words'];
unset($query['words']);
}
break;
default:
$redirectURL = getCustomPageURL($query['p']);
break;
}
unset($query['p']);
$redirectURL = preg_replace('~^' . WEBPATH . '/~', '', $redirectURL);
if (isset($query['page'])) {
$redirectURL.='/' . $query['page'];
unset($query['page']);
}
$q = http_build_query($query);
if ($q)
$redirectURL .= '?' . $q;
} else if (isset($query['album'])) {
if (isset($query['image'])) {
$obj = newImage(NULL, array('folder' => $query['album'], 'filename' => $query['image']), true);
unset($query['image']);
} else {
$obj = newAlbum($query['album'], NULL, true);
}
unset($query['album']);
if (!$obj->exists)
return '';
$redirectURL = preg_replace('~^' . WEBPATH . '/~', '', $obj->getLink());
$q = http_build_query($query);
if ($q)
$redirectURL .= '?' . $q;
}
return $redirectURL;
}
function fix_path_redirect() {
if (MOD_REWRITE) {
$request_uri = getRequestURI();
$parts = parse_url($request_uri);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
$redirectURL = zpRewriteURL($query);
if ($redirectURL) {
redirectURL($redirectURL, '301');
}
}
}
}
function zp_load_page($pagenum = NULL) {
global $_zp_page;
if (!is_numeric($pagenum)) {
$_zp_page = isset($_GET['page']) ? $_GET['page'] : 1;
} else {
$_zp_page = round($pagenum);
}
}
function zp_load_gallery() {
global $_zp_current_album, $_zp_current_album_restore, $_zp_albums,
$_zp_current_image, $_zp_current_image_restore, $_zp_images, $_zp_current_comment,
$_zp_comments, $_zp_current_context, $_zp_current_search, $_zp_current_zenpage_new,
$_zp_current_zenpage_page, $_zp_current_category, $_zp_post_date, $_zp_pre_authorization;
$_zp_current_album = NULL;
$_zp_current_album_restore = NULL;
$_zp_albums = NULL;
$_zp_current_image = NULL;
$_zp_current_image_restore = NULL;
$_zp_images = NULL;
$_zp_current_comment = NULL;
$_zp_comments = NULL;
$_zp_current_context = 0;
$_zp_current_search = NULL;
$_zp_current_zenpage_news = NULL;
$_zp_current_zenpage_page = NULL;
$_zp_current_category = NULL;
$_zp_post_date = NULL;
$_zp_pre_authorization = array();
set_context(ZP_INDEX);
}
function zp_load_search() {
global $_zp_current_search;
zp_clearCookie("zpcms_search_params");
if (!is_object($_zp_current_search)) {
$_zp_current_search = new SearchEngine();
}
add_context(ZP_SEARCH);
$params = $_zp_current_search->getSearchParams();
zp_setCookie("zpcms_search_params", $params, SEARCH_DURATION);
return $_zp_current_search;
}
function zp_load_album($folder, $force_nocache = false) {
global $_zp_current_album, $_zp_gallery;
$_zp_current_album = newAlbum($folder, !$force_nocache, true);
if (!is_object($_zp_current_album) || !$_zp_current_album->exists)
return false;
add_context(ZP_ALBUM);
return $_zp_current_album;
}
function zp_load_image($folder, $filename) {
global $_zp_current_image, $_zp_current_album, $_zp_current_search;
if (!is_object($_zp_current_album) || $_zp_current_album->name != $folder) {
$album = zp_load_album($folder, true);
} else {
$album = $_zp_current_album;
}
if (!is_object($album) || !$album->exists)
return false;
$_zp_current_image = newImage($album, $filename, true);
if (is_null($_zp_current_image) || !$_zp_current_image->exists) {
return false;
}
add_context(ZP_IMAGE | ZP_ALBUM);
return $_zp_current_image;
}
function load_zenpage_pages($titlelink) {
global $_zp_current_zenpage_page;
if (!ZP_PAGES_ENABLED) {
return false;
}
$_zp_current_zenpage_page = new ZenpagePage($titlelink);
if ($_zp_current_zenpage_page->loaded) {
add_context(ZP_ZENPAGE_PAGE | ZP_ZENPAGE_SINGLE);
} else {
$_GET['p'] = 'PAGES:' . $titlelink;
return false;
}
return $_zp_current_zenpage_page;
}
function load_zenpage_news($request) {
global $_zp_current_zenpage_news, $_zp_current_category, $_zp_post_date;
if (!ZP_NEWS_ENABLED) {
return false;
}
if (isset($request['date'])) {
add_context(ZP_ZENPAGE_NEWS_DATE);
$_zp_post_date = removeTrailingSlash(sanitize($request['date']));
}
if (isset($request['category'])) {
$titlelink = sanitize(rtrim($request['category'], '/'));
$_zp_current_category = new ZenpageCategory($titlelink);
if ($_zp_current_category->loaded) {
add_context(ZP_ZENPAGE_NEWS_CATEGORY);
} else {
$_GET['p'] = 'CATEGORY:' . $titlelink;
unset($_GET['category']);
return false;
}
}
if (isset($request['title'])) {
$titlelink = sanitize(rtrim($request['title'], '/'));
$sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
$result = query_single_row($sql);
if (is_array($result)) {
add_context(ZP_ZENPAGE_NEWS_ARTICLE | ZP_ZENPAGE_SINGLE);
$_zp_current_zenpage_news = new ZenpageNews($titlelink);
} else {
$_GET['p'] = 'NEWS:' . $titlelink;
}
return $_zp_current_zenpage_news;
}
return true;
}
function zp_load_request() {
if ($success = zp_apply_filter('load_request', true)) {
zp_load_page();
if (isset($_GET['p'])) {
$page = str_replace(array('/', '\\', '.'), '', sanitize($_GET['p']));
switch ($page) {
case 'search':
return zp_load_search();
break;
case 'pages':
if (extensionEnabled('zenpage')) {
return load_zenpage_pages(sanitize(rtrim(@$_GET['title'], '/')));
}
break;
case 'news':
if (extensionEnabled('zenpage')) {
return load_zenpage_news(sanitize($_GET));
}
break;
}
}
list($album, $image) = rewrite_get_album_image('album', 'image');
if (!empty($image)) {
return zp_load_image($album, $image);
} else if (!empty($album)) {
return zp_load_album($album);
}
}
return $success;
}
function prepareIndexPage() {
global $_zp_gallery_page, $_zp_script;
handleSearchParms('index');
$theme = setupTheme();
$_zp_gallery_page = basename($_zp_script = THEMEFOLDER . "/$theme/index.php");
return $theme;
}
function prepareAlbumPage() {
global $_zp_current_album, $_zp_gallery_page, $_zp_script;
$theme = setupTheme();
$_zp_gallery_page = "album.php";
$_zp_script = THEMEFOLDER . "/$theme/album.php";
if ($search = $_zp_current_album->getSearchEngine()) {
zp_setCookie("zpcms_search_params", $search->getSearchParams(), SEARCH_DURATION);
} else {
handleSearchParms('album', $_zp_current_album);
}
return $theme;
}
function prepareImagePage() {
global $_zp_current_album, $_zp_current_image, $_zp_gallery_page, $_zp_script;
handleSearchParms('image', $_zp_current_album, $_zp_current_image);
$theme = setupTheme();
$_zp_gallery_page = basename($_zp_script = THEMEFOLDER . "/$theme/image.php");
if (isImageVideo()) {
$_zp_current_image->updateDimensions();
}
return $theme;
}
function prepareCustomPage() {
global $_zp_current_album, $_zp_current_image, $_zp_gallery_page, $_zp_script, $_zp_current_search;
$searchalbums = handleSearchParms('page', $_zp_current_album, $_zp_current_image);
$album = NULL;
$replace = array('/', '\\', '.');
$page = str_replace($replace, '', sanitize($_GET['p']));
if (isset($_GET['z'])) {
if ($subfolder = str_replace($replace, '', sanitize($_GET['z']))) {
$subfolder .= '/';
}
$_zp_gallery_page = $page . '.php';
$_zp_script = ZENFOLDER . '/' . $subfolder . $page . '.php';
} else {
$_zp_gallery_page = $page . '.php';
switch ($_zp_gallery_page) {
case 'search.php':
if (!empty($searchalbums)) {
$albums = array();
foreach ($searchalbums as $analbum) {
$parent = getUrAlbum(newAlbum($analbum));
$albums[$parent->getID()] = $parent;
}
if (count($albums) == 1) {
$album = array_shift($albums);
}
}
break;
}
}
$theme = setupTheme($album);
if (empty($_zp_script)) {
$_zp_script = THEMEFOLDER . "/$theme/$page.php";
}
return $theme;
}
function redirectionHandler() {
if (zp_has_filter('redirection_handler')) {
$url = SERVER_HTTP_HOST . getRequestURI();
$redirect_url = zp_apply_filter('redirection_handler', $url);
if ($redirect_url != $url) {
redirectURL($redirect_url, '301');
}
}
}
if (!getOption('license_accepted')) {
if (isset($_GET['z']) && $_GET['z'] != 'setup') {
$_GET['p'] = 'license';
$_GET['z'] = '';
}
}
?>