function wpm_label($item) { switch ($item->type) { case 'PHP': $out = eval($item->selection); $label = is_array($out) ? $out[0] : $item->name; if ($label) { return $label; } } return wpm_display_name($item); }
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; }
function wpm_print_tree($menuid, $item_id, $prev_id, $level, $class) { global $wpm_options, $wpm_error; $item = wpm_read_node($item_id); $next_id = $item->side; $menu = wpm_read_node($menuid); $class = $class == "" ? "alternate" : ""; $url = $wpm_options->menubar_url; $url_up = $wpm_options->form_action . '&action=swap&menuid=' . $menuid . '&itemid=' . $prev_id; $url_down = $wpm_options->form_action . '&action=swap&menuid=' . $menuid . '&itemid=' . $item->id; $url_edit = $wpm_options->form_action . '&action=edit&menuid=' . $menuid . '&itemid=' . $item->id; $url_delete = $wpm_options->form_action . '&action=delete&menuid=' . $menuid . '&itemid=' . $item->id; $up = $prev_id ? "<a href='{$url_up}' class='edit' title='" . __('move up', 'wpm') . "'>\r\n\t\t\t\t<img src='{$url}/up.gif' /></a>" : ""; $down = $next_id ? "<a href='{$url_down}' class='edit' title='" . __('move down', 'wpm') . "'>\r\n\t\t\t\t<img src='{$url}/down.gif' /></a>" : ""; $image = $menu->features['images'] == true && $item->imageurl ? "<img src=\"{$item->imageurl}\" height=\"16\" width=\"16\" />" : ''; $edit = "<a href='{$url_edit}' class='edit'>" . __('Edit', 'wpm') . "</a>"; $delete = "<a href='" . wp_nonce_url($url_delete, 'delete_' . $item->id) . "' class='delete'>" . __('Delete', 'wpm') . "</a>"; $name = wpm_display_name($item); if ($item->down && in_array($item->type, array('CategoryTree', 'PageTree', 'TagList'))) { $name = "<strong style=\"color:red;\">{$name} *</strong>"; $wpm_error = 'ghostchildren'; } echo "<tr class=\"{$class}\">\r\n\t\t<td align='center'>{$up}</td>\r\n\t\t<td align='center'>{$down}</td>\r\n\t\t<td>" . str_repeat("— ", $level) . "{$image} {$name}</td>\r\n\t\t<td>{$item->type}</td>\r\n\t\t<td>"; $sel = wpm_display_selection($item); if ($sel[1]) { echo "<strong>{$sel[0]}</strong> {$sel[1]} "; } echo wpm_display_fields($item); echo "</td>\r\n\t\t<td align='center'>{$edit}</td>\r\n\t\t<td align='center'>{$delete}</td>\r\n\t\t</tr>\n"; if ($item->down) { $class = wpm_print_tree($menuid, $item->down, 0, $level + 1, $class); } if ($item->side) { $class = wpm_print_tree($menuid, $item->side, $item_id, $level, $class); } return $class; }
function wpm_item_list($item_id, $list, $level) { $item = wpm_read_node($item_id); if ($level > 0) { $name = wpm_display_name($item); $list[$item->id] = str_repeat("— ", $level - 1) . $name; } if ($item->down) { $list = wpm_item_list($item->down, $list, $level + 1); } if ($item->side) { $list = wpm_item_list($item->side, $list, $level); } return $list; }