示例#1
0
function pages_html_menu($elements)
{
    $menu = '';
    global $page_owner;
    if (is_array($elements)) {
        $current_page = pages_current_page();
        $current_uri = !empty($current_page->uri) ? $current_page->uri : '';
        foreach ($elements as $p => $li) {
            if (is_array($li)) {
                $parent = $li[0];
                $childs = isset($li[1]) ? $li[1] : null;
                // workaround
                if (!$parent) {
                    // this never should happen
                    trigger_error(__FUNCTION__ . ": invalid menu element", E_USER_NOTICE);
                    continue;
                }
                // set owner
                if (!isset($owner)) {
                    $owner = $parent->owner;
                }
                if ($parent->uri == $current_uri) {
                    $parent_link = pages_html_a(pages_url($parent->uri, 'pages::page', $parent->owner), $parent->name, array('class' => 'selected'));
                } else {
                    $parent_link = pages_html_a(pages_url($parent->uri, 'pages::page', $parent->owner), $parent->name);
                }
                if (is_array($childs)) {
                    $submenu = '';
                    foreach ($childs as $child) {
                        if ($child->uri == $current_uri) {
                            $_li = pages_html_a(pages_url($child->uri, 'pages::page', $child->owner), $child->name, array('class' => 'selected'));
                        } else {
                            $_li = pages_html_a(pages_url($child->uri, 'pages::page', $child->owner), $child->name);
                        }
                        $submenu .= pages_html_wrap('li', $_li, array('class' => 'menu-item'));
                    }
                    $menu .= pages_html_wrap('li', $parent_link . pages_html_wrap('ul', $submenu), array('class' => 'menu-parent'));
                } else {
                    $menu .= pages_html_wrap('li', $parent_link, array('class' => 'menu-item'));
                }
            } else {
            }
        }
    }
    // workaround
    if (!isset($owner)) {
        $owner = empty($page_owner) ? page_owner() : $page_owner;
    }
    if (empty($menu)) {
        $main_link = pages_html_a(pages_url(__gettext('Main'), 'pages::page', $owner), __gettext('Main'));
        $menu .= pages_html_wrap('li', $main_link, array('class' => 'menu-item'));
    }
    if (!empty($menu)) {
        $menu = pages_html_wrap('ul', $menu);
    }
    return $menu;
}
function pages_get_page($page_name, $owner = -1)
{
    if (empty($page_name)) {
        if ($owner > 0) {
            $page_id = (int) user_flag_get('pages_default', $owner);
        } else {
            $obj = get_config('pages_default');
            $page_id = intval($obj->value);
        }
        //TODO: do header redirect
        if (pages_exists($page_id, $owner)) {
            $page_url = pages_url($page_id, 'pages::page', $owner);
        } else {
            $page_url = pages_url(__gettext('Main'), 'pages::edit', $owner);
        }
        pages_header_redirect($page_url, 301);
    } else {
        // remove trailing slash
        $page_name = preg_replace('|(/)$|', '', $page_name);
    }
    $page = get_record('pages', 'uri', $page_name, 'owner', $owner);
    //FIXME: auto correct parent
    if ($page->ident == $page->parent) {
        $_page = new StdClass();
        $_page->ident = $page->ident;
        $_page->parent = 0;
        update_record('pages', $_page);
        unset($_page);
    }
    if (isset($page->ident) && permissions_check('pages::access', $page->ident) || permissions_check('pages::edit', $owner)) {
        if (isset($page->content)) {
            pages_current_page($page);
        } else {
            // check for legacy content pages
            if ($owner == -1) {
                $page = pages_get_legacy($page_name);
            }
            if (empty($page)) {
                // Page not found
                $page = pages_page_not_found();
            }
        }
    } else {
        if (isset($page->ident)) {
            // page exists?
            $page = pages_page_denied();
        } else {
            // check for legacy content pages
            if ($owner == -1) {
                $page = pages_get_legacy($page_name);
            }
            if (empty($page)) {
                // Page not found
                $page = pages_page_not_found();
            }
        }
    }
    if (!empty($page->title)) {
        $page->title = pages_process_content($page->title);
    }
    if (!empty($page->content)) {
        $page->content = pages_process_content($page->content);
    }
    return $page;
}