function main() { // get the uri string from the query $path = $_SERVER['QUERY_STRING']; // Make sure special characters are decoded (support non-western glyphs like japanese) $path = urldecode($path); // START processing $_GET variables // If we're NOT using mod_rewrite, we check for GET variables we need to integrate if (!USE_MOD_REWRITE && strpos($path, '?') !== false) { $_GET = array(); // empty $_GET array since we're going to rebuild it list($path, $get_var) = explode('?', $path); $exploded_get = explode('&', $get_var); if (count($exploded_get)) { foreach ($exploded_get as $get) { list($key, $value) = explode('=', $get); $_GET[$key] = $value; } } } else { if (!USE_MOD_REWRITE && (strpos($path, '&') !== false || strpos($path, '=') !== false)) { $path = '/'; } } // If we're using mod_rewrite, we should have a WOLFPAGE entry. if (USE_MOD_REWRITE && array_key_exists('WOLFPAGE', $_GET)) { $path = $_GET['WOLFPAGE']; unset($_GET['WOLFPAGE']); } else { if (USE_MOD_REWRITE) { // We're using mod_rewrite but don't have a WOLFPAGE entry, assume site root. $path = '/'; } } // Needed to allow for ajax calls to backend if (array_key_exists('WOLFAJAX', $_GET)) { $path = '/' . ADMIN_DIR . $_GET['WOLFAJAX']; unset($_GET['WOLFAJAX']); } // END processing $_GET variables // remove suffix page if founded if (URL_SUFFIX !== '' and URL_SUFFIX !== '/') { $path = preg_replace('#^(.*)(' . URL_SUFFIX . ')$#i', "\$1", $path); } define('CURRENT_PATH', trim($path, '/')); // Alias for backward compatibility, this constant should no longer be used. define('CURRENT_URI', CURRENT_PATH); if ($path != null && $path[0] != '/') { $path = '/' . $path; } // Check if there's a custom route defined for this URI, // otherwise continue and assume page was requested. if (Dispatcher::hasRoute($path)) { Observer::notify('dispatch_route_found', $path); Dispatcher::dispatch($path); exit; } foreach (Observer::getObserverList('page_requested') as $callback) { $path = call_user_func_array($callback, array(&$path)); } // this is where 80% of the things is done $page = Page::findByPath($path, true); // if we found it, display it! if (is_object($page)) { // If a page is in preview status, only display to logged in users if (Page::STATUS_PREVIEW == $page->status_id) { AuthUser::load(); if (!AuthUser::isLoggedIn() || !AuthUser::hasPermission('page_view')) { pageNotFound($path); } } // If page needs login, redirect to login if ($page->getLoginNeeded() == Page::LOGIN_REQUIRED) { AuthUser::load(); if (!AuthUser::isLoggedIn()) { Flash::set('redirect', $page->url()); redirect(URL_PUBLIC . (USE_MOD_REWRITE ? '' : '?/') . ADMIN_DIR . '/login'); } } Observer::notify('page_found', $page); $page->_executeLayout(); } else { pageNotFound($path); } }
/** * Hack for the page not found plugin. */ public static function page_not_found_hack() { // only throw exception if main page has been found if (defined('page_found') && page_found == true) { throw new Exception('Page not found!'); } // call other observer methods first $observerList = Observer::getObserverList('page_not_found'); unset($observerList['behavior_page_not_found']); $alreadyCalled = true; foreach ($observerList as $callback) { if ($callback == 'FrogTagsHacks::page_not_found_hack') { $alreadyCalled = false; } elseif (!$alreadyCalled) { call_user_func($callback); } } if (function_exists('behavior_page_not_found')) { global $__FROG_CONN__; $query = 'SELECT slug FROM ' . TABLE_PREFIX . "page WHERE behavior_id='page_not_found'"; $statement = $__FROG_CONN__->prepare($query); $statement->execute(); if ($page = $statement->fetchObject()) { $page = find_page_by_uri($page->slug); if (is_object($page)) { header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); frog_tags_main($page); exit; } } } }