/** * * @global <type> $__FROG_CONN__ */ function behavior_page_not_found() { global $__FROG_CONN__; $sql = 'SELECT * FROM ' . TABLE_PREFIX . "page WHERE behavior_id='page_not_found'"; $stmt = $__FROG_CONN__->prepare($sql); $stmt->execute(); if ($page = $stmt->fetchObject()) { $page = find_page_by_uri($page->slug); // if we fund it, display it! if (is_object($page)) { header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); $page->_executeLayout(); exit; // need to exit here otherwise the true error page will be sended } } }
/** * 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; } } } }
public function find($uri) { return find_page_by_uri($uri); }
function main() { // get the uri string from the query $uri = $_SERVER['QUERY_STRING']; // 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($uri, '?') !== false) { $_GET = array(); // empty $_GET array since we're going to rebuild it list($uri, $get_var) = explode('?', $uri); $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($uri, '&') !== false || strpos($uri, '=') !== false)) { $uri = ''; } } // If we're using mod_rewrite, we should have a PAGE entry. if (USE_MOD_REWRITE && array_key_exists('PAGE', $_GET)) { $uri = $_GET['PAGE']; unset($_GET['PAGE']); } else { if (USE_MOD_REWRITE) { // We're using mod_rewrite but don't have a PAGE entry, assume site root. $uri = ''; } } // END processing $_GET variables // remove suffix page if founded if (URL_SUFFIX !== '' and URL_SUFFIX !== '/') { $uri = preg_replace('#^(.*)(' . URL_SUFFIX . ')$#i', "\$1", $uri); } define('CURRENT_URI', trim($uri, '/')); Observer::notify('page_requested', $uri); // this is where 80% of the things is done $page = find_page_by_uri($uri); // if we fund it, display it! if (is_object($page)) { // 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 . ADMIN_DIR . (USE_MOD_REWRITE ? '/' : '/?/') . 'login'); } } Observer::notify('page_found', $page); $page->_executeLayout(); } else { page_not_found(); } }