Exemple #1
0
function display_page($params = array())
{
    // canonicalize the input
    $area_name = $page_name = "";
    // GET /
    if (count($params) == 0) {
        $area_name = "index";
        $page_name = "index";
    }
    // GET /area_name
    if (count($params) == 1) {
        $area_name = $params[0];
        $page_name = "index";
    }
    // GET /area_name/page_name
    if (count($params) > 1) {
        $area_name = $params[0];
        $page_name = $params[1];
    }
    if (ALIAS_INSTALL) {
        // Test the MyActiveRecord connection
        if (mysql_num_rows(mysql_query("SHOW TABLES LIKE 'alias'")) == 1) {
            // check the alias' in the database and see if there is a match
            $alias = Alias::FindAll();
            /* die(print_r($alias)); */
            foreach ($alias as $entry) {
                if ($entry->alias == $area_name || $entry->alias == "/" . $area_name) {
                    redirect($entry->path);
                }
            }
        }
    }
    // check the routes to see if the requested page has an explicit route setup
    $page_options = $GLOBALS['ROUTES'];
    if (isset($page_options["/" . $area_name . "/" . $page_name])) {
        $page = StaticPage::FindByAreaAndName($area_name, $page_name);
        if (isset($page)) {
            display_admin_with_template($page);
            return true;
        }
    }
    // check for pages that are in the "global" area and have params (ie /calendar/2008/1)
    $global_area = Areas::FindByName('index');
    $possible_page = Pages::FindByAreaAndName($global_area, $page_name) ? Pages::FindByAreaAndName($global_area, $area_name) : '';
    if (!empty($possible_page)) {
        $area = $global_area;
        $page = $possible_page;
    } else {
        // for now, just include the first page that comes back. later we can handle multiple pages
        $area = Areas::FindByName($area_name);
        if (!isset($area)) {
            return false;
        }
        if (strstr($area_name, "-portfolio")) {
            if ($page_name != "index") {
                $page = Sections::FindByName($page_name);
            } else {
                $pages = $area->getSections();
                $page = array_shift($pages);
            }
        } else {
            $page = Pages::FindPageOrIndex($area, $page_name);
        }
    }
    if (!isset($page)) {
        return false;
    }
    // check if the page is public or not
    $is_admin = false;
    $user = Users::GetCurrentUser();
    if ($user) {
        $logged_in = true;
    }
    if ($page->public || !$page->public && $logged_in) {
        display_with_template($area, $page);
    } else {
        return false;
    }
    return true;
}