More output consolidation. see #11817

git-svn-id: https://develop.svn.wordpress.org/trunk@13334 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-02-23 18:45:59 +00:00
parent 30eafc7ecd
commit 7976d36ca2

View File

@ -70,6 +70,7 @@ function setup_menu_item($menu_item, $type = 'item', $position = 0) {
} elseif ( 'category' == $type ) { } elseif ( 'category' == $type ) {
$menu_item->type = $type; $menu_item->type = $type;
$menu_item->object_id = $menu_item->term_id; $menu_item->object_id = $menu_item->term_id;
$menu_item->ID = $menu_item->term_id;
$menu_item->parent_item = $menu_item->parent; $menu_item->parent_item = $menu_item->parent;
$menu_item->menu_order = $position; $menu_item->menu_order = $position;
} elseif ( 'page' == $type ) { } elseif ( 'page' == $type ) {
@ -101,19 +102,19 @@ function setup_menu_item($menu_item, $type = 'item', $position = 0) {
break; break;
// Category Menu Item // Category Menu Item
case 'category': case 'category':
if ( $menu_item->guid == '' ) if ( empty($menu_item->guid) )
$menu_item->link = get_category_link( $menu_item->object_id ); $menu_item->link = get_category_link( $menu_item->object_id );
else else
$menu_item->link = $menu_item->guid; $menu_item->link = $menu_item->guid;
if ( $menu_item->post_title == '' ) { if ( empty($menu_item->post_title) ) {
$title_raw = get_categories( array('include' => $menu_item->object_id) ); $title_raw = get_category( $menu_item->object_id );
$menu_item->title = htmlentities($title_raw[0]->cat_name); $menu_item->title = htmlentities($title_raw->cat_name);
} else { } else {
$menu_item->title = htmlentities( $menu_item->post_title ); $menu_item->title = htmlentities( $menu_item->post_title );
} }
if ( $menu_item->post_content == '' ) if ( empty($menu_item->post_content) )
$menu_item->description = htmlentities( strip_tags( category_description( $menu_item->object_id ) ) ); $menu_item->description = htmlentities( strip_tags( category_description( $menu_item->object_id ) ) );
else else
$menu_item->description = htmlentities( $menu_item->post_content ); $menu_item->description = htmlentities( $menu_item->post_content );
@ -324,7 +325,6 @@ function wp_custom_nav_get_pages($counter, $type) {
if ($post->post_parent == 0) { if ($post->post_parent == 0) {
// Custom Menu // Custom Menu
if ( $type == 'menu' ) { if ( $type == 'menu' ) {
$description = get_post_meta($post->ID, 'page-description', true);
$post = setup_menu_item($post, 'page', $intCounter); $post = setup_menu_item($post, 'page', $intCounter);
?> ?>
@ -414,46 +414,13 @@ function wp_custom_nav_get_categories($counter, $type) {
// Display Loop // Display Loop
foreach ( $categories_array as $cat_item ) { foreach ( $categories_array as $cat_item ) {
if ( $cat_item->parent == 0 ) { if ( $cat_item->parent == 0 ) {
$cat_item = setup_menu_item($cat_item, 'category', $intCounter);
// Custom Menu // Custom Menu
if ( $type == 'menu' ) { if ( $type == 'menu' ) {
?> ?>
<li id="menu-<?php echo $intCounter; ?>" value="<?php echo $intCounter; ?>"> <li id="menu-<?php echo $intCounter; ?>" value="<?php echo $intCounter; ?>">
<dl> <?php output_menu_item($cat_item, 'menu'); ?>
<dt>
<span class="title"><?php echo esc_html($cat_item->cat_name); ?></span>
<span class="controls">
<span class="type">category</span>
<a id="edit<?php echo $intCounter; ?>" onclick="edititem(<?php echo $intCounter; ?>)" value="<?php echo $intCounter; ?>"><img class="edit" alt="<?php esc_attr_e('Edit Menu Item'); ?>" title="="<?php esc_attr_e('Edit Menu Item'); ?>" src="<?php echo admin_url('images/ico-edit.png'); ?>" /></a>
<a id="remove<?php echo $intCounter; ?>" onclick="removeitem(<?php echo $intCounter; ?>)" value="<?php echo $intCounter; ?>">
<img class="remove" alt="="<?php esc_attr_e('Remove from Custom Menu'); ?>" title="="<?php esc_attr_e('Remove from Custom Menu'); ?>" src="<?php echo admin_url('images/ico-close.png'); ?>" />
</a>
<a target="_blank" href="<?php echo get_category_link($cat_item->cat_ID); ?>">
<img alt="="<?php esc_attr_e('View Page'); ?>" title="="<?php esc_attr_e('View Page'); ?>" src="<?php echo admin_url('images/ico-viewpage.png'); ?>" />
</a>
</span>
</dt>
</dl>
<a class="hide" href="<?php echo get_category_link($cat_item->cat_ID); ?>"><span class="title"><?php echo $cat_item->cat_name; ?></span>
<?php
$use_cats_raw = get_option('wp_settings_custom_nav_descriptions');
$use_cats = strtolower($use_cats_raw);
if ( $use_cats == 'yes' ) { ?>
<br/> <span><?php echo $cat_item->category_description; ?></span>
<?php } ?>
</a>
<input type="hidden" name="postmenu<?php echo $intCounter; ?>" id="postmenu<?php echo $intCounter; ?>" value="<?php echo $cat_item->cat_ID; ?>" />
<input type="hidden" name="parent<?php echo $intCounter; ?>" id="parent<?php echo $intCounter; ?>" value="0" />
<input type="hidden" name="title<?php echo $intCounter; ?>" id="title<?php echo $intCounter; ?>" value="<?php echo esc_attr($cat_item->cat_name); ?>" />
<input type="hidden" name="linkurl<?php echo $intCounter; ?>" id="linkurl<?php echo $intCounter; ?>" value="<?php echo esc_attr(get_category_link($cat_item->cat_ID)); ?>" />
<input type="hidden" name="description<?php echo $intCounter; ?>" id="description<?php echo $intCounter; ?>" value="<?php echo esc_attr($cat_item->category_description); ?>" />
<input type="hidden" name="icon<?php echo $intCounter; ?>" id="icon<?php echo $intCounter; ?>" value="0" />
<input type="hidden" name="position<?php echo $intCounter; ?>" id="position<?php echo $intCounter; ?>" value="<?php echo $intCounter; ?>" />
<input type="hidden" name="linktype<?php echo $intCounter; ?>" id="linktype<?php echo $intCounter; ?>" value="category" />
<input type="hidden" name="anchortitle<?php echo $intCounter; ?>" id="anchortitle<?php echo $intCounter; ?>" value="<?php echo esc_attr($cat_item->cat_name); ?>" />
<input type="hidden" name="newwindow<?php echo $intCounter; ?>" id="newwindow<?php echo $intCounter; ?>" value="0" />
<?php $parentli = $cat_item->cat_ID; ?> <?php $parentli = $cat_item->cat_ID; ?>
<?php $intCounter++; ?> <?php $intCounter++; ?>
<?php <?php
@ -520,11 +487,14 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
if ( $type == 'categories' ) { if ( $type == 'categories' ) {
// Get Sub Category Items // Get Sub Category Items
$item_type = 'category';
$sub_array = get_categories($sub_args); $sub_array = get_categories($sub_args);
} elseif ($type == 'pages') { } elseif ($type == 'pages') {
// Get Sub Page Items // Get Sub Page Items
$item_type = 'page';
$sub_array = get_pages($sub_args); $sub_array = get_pages($sub_args);
} else { } else {
$item_type = 'custom';
$sub_array = array(); $sub_array = array();
} }
@ -537,6 +507,8 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
// Display Loop // Display Loop
foreach ( $sub_array as $sub_item ) { foreach ( $sub_array as $sub_item ) {
// Prepare Menu Data // Prepare Menu Data
$sub_item = setup_menu_item($sub_item, $item_type, $counter);
if ( $type == 'categories' ) { if ( $type == 'categories' ) {
// Category Menu Item // Category Menu Item
$link = get_category_link($sub_item->cat_ID); $link = get_category_link($sub_item->cat_ID);
@ -566,35 +538,7 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
if ( $output_type == 'menu' ) { if ( $output_type == 'menu' ) {
?> ?>
<li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>"> <li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>">
<dl> <?php output_menu_item($sub_item, 'menu'); ?>
<dt>
<span class="title"><?php echo $title; ?></span>
<span class="controls">
<span class="type"><?php echo $linktype; ?></span>
<a id="edit<?php echo $counter; ?>" onclick="edititem(<?php echo $counter; ?>)" value="<?php echo $counter; ?>"><img class="edit" alt="<?php esc_attr_e('Edit Menu Item'); ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" src="<?php echo admin_url('images/ico-edit.png'); ?>" /></a>
<a id="remove<?php echo $counter; ?>" onclick="removeitem(<?php echo $counter; ?>)" value="<?php echo $counter; ?>">
<img class="remove" alt="<?php esc_attr_e('Remove from Custom Menu'); ?>" title="<?php esc_attr_e('Remove from Custom Menu'); ?>" src="<?php echo admin_url('images/ico-close.png'); ?>" />
</a>
<a target="_blank" href="<?php echo $link; ?>">
<img alt="<?php esc_attr_e('View Page'); ?>" title="<?php esc_attr_e('View Page'); ?>" src="<?php echo admin_url('images/ico-viewpage.png'); ?>" />
</a>
</span>
</dt>
</dl>
<a class="hide" href="<?php echo $link; ?>"><?php echo $title; ?></a>
<input type="hidden" name="dbid<?php echo $counter; ?>" id="dbid<?php echo $counter; ?>" value="<?php echo $sub_item->id; ?>" />
<input type="hidden" name="postmenu<?php echo $counter; ?>" id="postmenu<?php echo $counter; ?>" value="<?php echo $parent_id; ?>" />
<input type="hidden" name="parent<?php echo $counter; ?>" id="parent<?php echo $counter; ?>" value="<?php echo $parentli; ?>" />
<input type="hidden" name="title<?php echo $counter; ?>" id="title<?php echo $counter; ?>" value="<?php echo $title; ?>" />
<input type="hidden" name="linkurl<?php echo $counter; ?>" id="linkurl<?php echo $counter; ?>" value="<?php echo $link; ?>" />
<input type="hidden" name="description<?php echo $counter; ?>" id="description<?php echo $counter; ?>" value="<?php echo $description; ?>" />
<input type="hidden" name="icon<?php echo $counter; ?>" id="icon<?php echo $counter; ?>" value="0" />
<input type="hidden" name="position<?php echo $counter; ?>" id="position<?php echo $counter; ?>" value="<?php echo $counter; ?>" />
<input type="hidden" name="linktype<?php echo $counter; ?>" id="linktype<?php echo $counter; ?>" value="<?php echo $linktype; ?>" />
<input type="hidden" name="anchortitle<?php echo $counter; ?>" id="anchortitle<?php echo $counter; ?>" value="<?php echo $title; ?>" />
<input type="hidden" name="newwindow<?php echo $counter; ?>" id="newwindow<?php echo $counter; ?>" value="0" />
<?php $counter++; ?> <?php $counter++; ?>
<?php <?php
@ -637,86 +581,4 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
return $counter; return $counter;
} }
/*-----------------------------------------------------------------------------------*/
/* Recursive get children */
/*-----------------------------------------------------------------------------------*/
function get_children_menu_elements($childof, $intCounter, $parentli, $type, $menu_id, $table_name) {
global $wpdb;
$counter = $intCounter;
if ( $type == 'categories' ) {
// Get Sub Category Items
$sub_args = array(
'child_of' => $childof,
'hide_empty' => false,
'parent' => $childof);
$sub_array = get_categories($sub_args);
} elseif ($type == 'pages') {
// Get Sub Page Items
$sub_args = array(
'child_of' => $childof,
'parent' => $childof);
$sub_array = get_pages($sub_args);
} else {
$sub_array = array();
}
if ( $sub_array ) {
// DISPLAY Loop
foreach ( $sub_array as $sub_item ) {
if ( isset($sub_item->parent) )
$sub_item_parent = $sub_item->parent;
elseif (isset($sub_item->post_parent))
$sub_item_parent = $sub_item->post_parent;
// Is child
if ( $sub_item_parent == $childof ) {
// Prepare Menu Data
// Category Menu Item
if ( $type == 'categories' ) {
$link = get_category_link($sub_item->cat_ID);
$title = htmlentities($sub_item->cat_name);
$parent_id = $sub_item->category_parent;
$itemid = $sub_item->cat_ID;
$linktype = 'category';
$appendtype= 'Category';
}
// Page Menu Item
elseif ( $type == 'pages' ) {
$link = get_permalink($sub_item->ID);
$title = htmlentities($sub_item->post_title);
$parent_id = $sub_item->post_parent;
$linktype = 'page';
$itemid = $sub_item->ID;
$appendtype= 'Page';
}
// Custom Menu Item
else {
$title = '';
$linktype = 'custom';
$appendtype= 'Custom';
}
// CHECK for existing parent records
// echo $parent_id;
$wp_result = $wpdb->get_results("SELECT id FROM ".$table_name." WHERE post_id='".$parent_id."' AND link_type='".$linktype."' AND menu_id='".$menu_id."'");
if ( $wp_result > 0 && isset($wp_result[0]->id) )
$parent_id = $wp_result[0]->id;
//INSERT item
$insert = "INSERT INTO ".$table_name." (position,post_id,parent_id,custom_title,custom_link,custom_description,menu_icon,link_type,menu_id,custom_anchor_title) "."VALUES ('".$counter."','".$itemid."','".$parent_id."','".$title."','".$link."','','','".$linktype."','".$menu_id."','".$title."')";
$results = $wpdb->query( $insert );
$counter++;
$counter = get_children_menu_elements($itemid, $counter, $parent_id, $type, $menu_id, $table_name);
}
}
}
return $counter;
}
?> ?>