Пример #1
0
function wptouch_admin_has_menu_items()
{
    global $wptouch_admin_menu_items;
    global $wptouch_admin_menu_iterator;
    wptouch_build_menu_tree(0, 1, $wptouch_admin_menu_items);
    $wptouch_admin_menu_iterator = new WPtouchArrayIterator($wptouch_menu_items);
    return $wptouch_admin_menu_iterator->have_items();
}
Пример #2
0
function wptouch_build_menu_tree($parent = 0, $depth = 1, &$data, $exclude_disabled = false)
{
    global $wpdb;
    global $wptouch_pro;
    if (wptouch_should_cache_menu_items($parent, $depth)) {
        $menu_data = wptouch_get_menu_cache_data($exclude_disabled);
        if ($menu_data) {
            $data = $menu_data;
            return;
        }
    }
    $settings = $wptouch_pro->get_settings();
    if ($settings->custom_menu_name != 'none') {
        @wptouch_build_wordpress_menu_tree($parent, $depth, $data, $exclude_disabled);
    } else {
        if ($settings->menu_sort_order == 'alpha') {
            $sql = "SELECT * FROM {$wpdb->posts} WHERE post_type = 'page' AND post_parent = {$parent} AND post_status = 'publish' ORDER BY post_title";
        } else {
            $sql = "SELECT * FROM {$wpdb->posts} WHERE post_type = 'page' AND post_parent = {$parent} AND post_status = 'publish' ORDER BY menu_order";
        }
        $pages = $wpdb->get_results($sql);
        if ($pages) {
            if ($parent) {
                $page = get_post($parent);
                $menu_options = new stdClass();
                $menu_options->page_id = $parent;
                $menu_options->depth = $depth;
                $menu_options->title = $page->post_title;
                $menu_options->item_type = 'link';
                $menu_options->has_children = false;
                $menu_options->post_parent = $parent;
                $menu_options->duplicate_link = true;
                $menu_options->item_link = $wptouch_pro->convert_to_internal_url(get_permalink($parent));
                $menu_options->item_class = $wptouch_pro->get_class_for_webapp_ignore($menu_options->item_link);
                $data[$page->ID] = $menu_options;
            }
            foreach ($pages as $page) {
                if ($exclude_disabled) {
                    if (isset($settings->disabled_menu_items[$page->ID])) {
                        continue;
                    }
                }
                $menu_options = new stdClass();
                $menu_options->title = $page->post_title;
                $menu_options->depth = $depth;
                $menu_options->page_id = $page->ID;
                if ($parent) {
                    $menu_options->post_parent = $parent;
                }
                if (wptouch_page_has_children($page->ID)) {
                    $menu_options->item_type = 'menu';
                    $menu_options->has_children = true;
                    $submenu = array();
                    wptouch_build_menu_tree($page->ID, $depth + 1, $submenu, $exclude_disabled);
                    if (count($submenu) == 1) {
                        $menu_options->item_type = 'link';
                        $menu_options->has_children = false;
                        $menu_options->item_link = $wptouch_pro->convert_to_internal_url(get_permalink($page->ID));
                        $menu_options->item_class = $wptouch_pro->get_class_for_webapp_ignore($menu_options->item_link);
                    } else {
                        $menu_options->submenu = $submenu;
                    }
                } else {
                    $menu_options->item_type = 'link';
                    $menu_options->has_children = false;
                    $menu_options->item_link = $wptouch_pro->convert_to_internal_url(get_permalink($page->ID));
                    $menu_options->item_class = $wptouch_pro->get_class_for_webapp_ignore($menu_options->item_link);
                }
                $data[$page->ID] = $menu_options;
            }
        }
    }
    if (wptouch_should_cache_menu_items($parent, $depth)) {
        wptouch_set_menu_cache($exclude_disabled, $data);
    }
}