Exemplo n.º 1
0
function wpm_append_nodes($id)
{
    global $wpm_options;
    $wpm_options->update_option = false;
    $item = wpm_readnode($id);
    switch ($item->type) {
        case 'TagList':
            $item->down = 0;
            _wpm_update_links($item);
            $node->type = 'Heading';
            $node->name = wpm_display_name($item);
            wpm_update_node($item->id, $node);
            $tags = wpm_get_tags();
            foreach ($tags as $tag) {
                if (in_array($tag->term_id, (array) $item->exclude)) {
                    continue;
                }
                $node->type = 'Tag';
                $node->name = $tag->name;
                $node->selection = $tag->term_id;
                wpm_create_child($item->id, $node);
            }
            break;
        case 'CategoryTree':
            $item->down = 0;
            _wpm_update_links($item);
            $node->type = !$item->selection || in_array($item->selection, (array) $item->headings) ? 'Heading' : 'Category';
            $node->name = wpm_display_name($item);
            wpm_update_node($item->id, $node);
            $cats = wpm_get_cats();
            $newparents = array($item->selection);
            while (++$level) {
                if ($item->depth > 0 && $level > $item->depth) {
                    break;
                }
                if (count($newparents) == 0) {
                    break;
                }
                $parents = $newparents;
                $newparents = array();
                foreach ($cats as $cat) {
                    if (in_array($cat->term_id, (array) $item->exclude)) {
                        continue;
                    }
                    if (in_array($cat->parent, $parents)) {
                        $newparents[] = $cat->term_id;
                        $node->type = in_array($cat->term_id, (array) $item->headings) ? 'Heading' : 'Category';
                        $node->name = get_cat_name($cat->term_id);
                        $node->selection = $cat->term_id;
                        $parent = wpm_find_node($item->id, 'selection', $cat->parent);
                        wpm_create_child($parent->id, $node);
                    }
                }
            }
            break;
        case 'PageTree':
            $item->down = 0;
            _wpm_update_links($item);
            $node->type = !$item->selection || in_array($item->selection, (array) $item->headings) ? 'Heading' : 'Page';
            $node->name = wpm_display_name($item);
            wpm_update_node($item->id, $node);
            $pages = wpm_get_pages();
            $newparents = array($item->selection);
            while (++$level) {
                if ($item->depth > 0 && $level > $item->depth) {
                    break;
                }
                if (count($newparents) == 0) {
                    break;
                }
                $parents = $newparents;
                $newparents = array();
                foreach ($pages as $page) {
                    if (in_array($page->ID, (array) $item->exclude)) {
                        continue;
                    }
                    if (in_array($page->post_parent, $parents)) {
                        $newparents[] = $page->ID;
                        $node->type = in_array($page->ID, (array) $item->headings) ? 'Heading' : 'Page';
                        $node->name = get_the_title($page->ID);
                        $node->selection = $page->ID;
                        $parent = wpm_find_node($item->id, 'selection', $page->post_parent);
                        wpm_create_child($parent->id, $node);
                    }
                }
            }
            break;
    }
    $wpm_options->update_option = true;
}
Exemplo n.º 2
0
function wpm_find_node($node_id, $field, $value)
{
    if ($node_id == 0) {
        return null;
    }
    $node = wpm_read_node($node_id);
    if ($node->{$field} == $value) {
        return $node;
    }
    if ($down = wpm_find_node($node->down, $field, $value)) {
        return $down;
    }
    if ($side = wpm_find_node($node->side, $field, $value)) {
        return $side;
    }
    return null;
}