Nav cleanup. see #11817

git-svn-id: http://svn.automattic.com/wordpress/trunk@13331 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-02-23 17:13:24 +00:00
parent c5128bb074
commit 5f80b84a4f
2 changed files with 168 additions and 358 deletions

View File

@ -176,22 +176,19 @@ function wp_custom_navigation() {
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';
}
//DISPLAY Custom Navigation
// DISPLAY Custom Navigation
?>
<div id="pages-left">
<div class="inside">
<h2 class="maintitle"><?php esc_html_e('Custom Navigation') ?></h2>
<?php
//CHECK if custom menu has been enabled
// CHECK if custom menu has been enabled
$enabled_menu = get_option('wp_custom_nav_menu');
$checked = strtolower($enabled_menu);
if ($checked == 'true') {
} else {
if ( $checked != 'true' )
echo '<div id="message-enabled" class="error fade below-h2"><p><strong>' . __('The Custom Menu has not been Enabled yet. Please enable it in order to use it -------->') . '</strong></p></div>';
}
?>
<?php echo $messagesdiv; ?>
@ -215,9 +212,9 @@ function wp_custom_navigation() {
<?php
//DISPLAY existing menu
if ( $menu_selected_id > 0 ) {
//SET output type
// SET output type
$output_type = "backend";
//MAIN OUTPUT FUNCTION
// MAIN OUTPUT FUNCTION
wp_custom_navigation_output( 'type='.$output_type.'&name='.$menu_title.'&id='.$menu_selected_id );
}
?>
@ -248,7 +245,7 @@ function wp_custom_navigation() {
<?php
//SETUP Custom Menu
// Setup custom menu
$enabled_menu = get_option('wp_custom_nav_menu');
@ -281,7 +278,7 @@ function wp_custom_navigation() {
<select id="menu_select" name="menu_select">
<?php
//DISPLAY SELECT OPTIONS
// Display select options
foreach ( $custom_menus as $menu ) {
$menu_term = get_term( $menu, 'nav_menu' );
if ( ( $menu_id_in_edit == $menu->term_id ) || ( $menu_selected_id == $menu->term_id ) )
@ -314,16 +311,12 @@ function wp_custom_navigation() {
<?php
//UPDATE and DISPLAY Menu Description Option
// UPDATE and DISPLAY Menu Description Option
if ( isset($_POST['menu-descriptions']) ) {
if ( isset($_POST['switch_menu']) ) {
} else {
if ( !isset($_POST['switch_menu']) ) {
$menu_options_to_edit = $_POST['menu_id_in_edit'];
update_option('wp_settings_custom_nav_'.$menu_options_to_edit.'_descriptions',$_POST['menu-descriptions']);
}
}
if ( $menu_id_in_edit > 0 )
@ -381,7 +374,7 @@ function wp_custom_navigation() {
$page_name .= htmlentities($post->post_title).'|';
}
} else {
$page_name = "No pages available";
$page_name = __('No pages available');
}
?>
@ -448,7 +441,7 @@ function wp_custom_navigation() {
$cat_name = '';
//CHECK for results
if ( $categories ) {
foreach( $categories as $category ) {
foreach ( $categories as $category ) {
$cat_id = $category->term_id;
$cat_args = array(
@ -507,8 +500,8 @@ function wp_custom_navigation() {
<ul id="existing-categories" class="list">
<?php
//Get default Categories
$intCounter = wp_custom_nav_get_categories($intCounter,'default');
// Get default Categories
$intCounter = wp_custom_nav_get_categories($intCounter, 'default');
?>
</ul>
@ -557,7 +550,6 @@ function wp_custom_navigation() {
</div>
<?php
}
include("admin-footer.php");

View File

@ -31,7 +31,6 @@ function wp_custom_navigation_get_menu_items( $menu_objects, $key = 'ID' ) {
}
function wp_custom_navigation_setup($override = false) {
// Custom Navigation Menu Setup
// Override for menu descriptions
@ -44,6 +43,7 @@ function wp_custom_navigation_setup($override = false) {
}
}
}
function wp_custom_navigation_delete_menu( $menu_term_id ) {
$term_id = (int) $menu_term_id;
if ( $term_id > 0 ) {
@ -57,110 +57,70 @@ function wp_custom_navigation_delete_menu( $menu_term_id ) {
}
}
/*-----------------------------------------------------------------------------------*/
/* Custom Navigation Functions */
/* wp_custom_navigation_output() displays the menu in the back/frontend
/* wp_custom_navigation_sub_items() is a recursive sub menu item function
/* wp_custom_nav_get_pages()
/* wp_custom_nav_get_categories()
/* wp_custom_navigation_default_sub_items() is a recursive sub menu item function
/*-----------------------------------------------------------------------------------*/
function setup_menu_item($menu_item) {
global $parent_menu_order;
/*-----------------------------------------------------------------------------------*/
/* Main Output Function
/* args list
/* type - frontend or backend
/* name - name of your menu
/* id - id of menu in db
/* desc - 1 = show descriptions, 2 = dont show descriptions
/* before_title - html before title is outputted in <a> tag
/* after_title - html after title is outputted in <a> tag
/*-----------------------------------------------------------------------------------*/
$menu_item->type = get_post_meta($menu_item->ID, 'menu_type', true);
$menu_item->object_id = get_post_meta($menu_item->ID, 'object_id', true);
//$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) )
$menu_item->parent_item = $parent_menu_order[ $menu_item->post_parent ];
else
$menu_item->parent_item = 0;
function wp_custom_navigation_output( $args = array() ) {
// Defaults
$defaults = array( 'type' => 'frontend', 'name' => 'Menu 1', 'id' => 0, 'desc' => 2, 'before_title' => '', 'after_title' => '');
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
$menu_objects = get_objects_in_term( $id, 'nav_menu' );
$menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' );
//O verride for menu descriptions
$advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options');
if ( $advanced_option_descriptions == 'no' )
$desc = 2;
$queried_id = 0;
global $wp_query;
if ( is_page() )
$queried_id = $wp_query->get_queried_object_id();
elseif ( is_category() )
$queried_id = $wp_query->get_queried_object_id();
$parent_stack = array();
$current_parent = 0;
$parent_menu_order = array();
// Display Loop
foreach ( $menu_items as $key => $menu_item ) {
$menu_type = get_post_meta($menu_item->ID, 'menu_type', true);
$object_id = get_post_meta($menu_item->ID, 'object_id', true);
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) )
$parent_item = $parent_menu_order[ $menu_item->post_parent ];
switch ( $menu_item->type ) {
// Page Menu Item
case 'page':
if ( $menu_item->guid == '' )
$menu_item->link = get_permalink( $menu_item->object_id );
else
$parent_item = 0;
$menu_item->link = $menu_item->guid;
switch ( $menu_type ) {
// Page Menu Item
case 'page':
if ( $menu_item->guid == '' )
$link = get_permalink( $object_id );
else
$link = $menu_item->guid;
if ( $menu_item->post_title == '' )
$menu_item->title = htmlentities( get_the_title( $menu_item->object_id ) );
else
$menu_item->title = htmlentities( $menu_item->post_title );
if ( $menu_item->post_title == '' )
$title = htmlentities( get_the_title( $object_id ) );
else
$title = htmlentities( $menu_item->post_title );
if ( $menu_item->post_content == '' )
$menu_item->description = htmlentities( get_post_meta( $menu_item->ID, 'page-description', true ) );
else
$menu_item->description = htmlentities( $menu_item->post_content );
$menu_item->target = '';
break;
// Category Menu Item
case 'category':
if ( $menu_item->guid == '' )
$menu_item->link = get_category_link( $menu_item->object_id );
else
$menu_item->link = $menu_item->guid;
if ( $menu_item->post_content == '' )
$description = htmlentities( get_post_meta( $menu_item->ID, 'page-description', true ) );
else
$description = htmlentities( $menu_item->post_content );
$target = '';
break;
// Category Menu Item
case 'category':
if ( $menu_item->guid == '' )
$link = get_category_link( $object_id );
else
$link = $menu_item->guid;
if ( $menu_item->post_title == '' ) {
$title_raw = get_categories( array('include' => $object_id) );
$title = htmlentities($title_raw[0]->cat_name);
} else {
$title = htmlentities( $menu_item->post_title );
}
if ( $menu_item->post_content == '' )
$description = htmlentities( strip_tags( category_description( $object_id ) ) );
else
$description = htmlentities( $menu_item->post_content );
$target = '';
break;
default:
// Custom Menu Item
$link = $menu_item->guid;
$title = htmlentities( $menu_item->post_title );
$description = htmlentities( $menu_item->post_content );
$target = 'target="_blank"';
break;
if ( $menu_item->post_title == '' ) {
$title_raw = get_categories( array('include' => $menu_item->object_id) );
$menu_item->title = htmlentities($title_raw[0]->cat_name);
} else {
$menu_item->title = htmlentities( $menu_item->post_title );
}
$li_class = '';
if ( $menu_item->post_content == '' )
$menu_item->description = htmlentities( strip_tags( category_description( $menu_item->object_id ) ) );
else
$menu_item->description = htmlentities( $menu_item->post_content );
$menu_item->target = '';
break;
default:
// Custom Menu Item
$menu_item->link = $menu_item->guid;
$menu_item->title = htmlentities( $menu_item->post_title );
$menu_item->description = htmlentities( $menu_item->post_content );
$menu_item->target = 'target="_blank"';
break;
}
$menu_item->li_class = '';
global $wp_query;
if ( $menu_item->ID == $wp_query->get_queried_object_id() )
$menu_item->li_class = 'class="current_page_item"';
/* @todo: update to use tax/post data
//SET anchor title
@ -184,42 +144,88 @@ function wp_custom_navigation_output( $args = array() ) {
}
}
*/
return $menu_item;
}
/*-----------------------------------------------------------------------------------*/
/* Custom Navigation Functions */
/* wp_custom_navigation_output() displays the menu in the back/frontend
/* wp_custom_nav_get_pages()
/* wp_custom_nav_get_categories()
/* wp_custom_navigation_default_sub_items() is a recursive sub menu item function
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Main Output Function
/* args list
/* type - frontend or backend
/* name - name of your menu
/* id - id of menu in db
/* desc - 1 = show descriptions, 2 = dont show descriptions
/* before_title - html before title is outputted in <a> tag
/* after_title - html after title is outputted in <a> tag
/*-----------------------------------------------------------------------------------*/
function wp_custom_navigation_output( $args = array() ) {
// Defaults
$defaults = array( 'type' => 'frontend', 'name' => 'Menu 1', 'id' => 0, 'desc' => 2, 'before_title' => '', 'after_title' => '');
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
$menu_objects = get_objects_in_term( $id, 'nav_menu' );
$menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' );
// Override for menu descriptions
$advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options');
if ( $advanced_option_descriptions == 'no' )
$desc = 2;
$parent_stack = array();
$current_parent = 0;
$parent_menu_order = array();
// Setup parentage
foreach ( $menu_items as $key => $menu_item ) {
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
}
// Display Loop
foreach ( $menu_items as $key => $menu_item ) {
$menu_item = setup_menu_item($menu_item);
// List Items
?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $li_class; ?>><?php
?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $menu_item->li_class; ?>><?php
//@todo: update front end to use post data
//FRONTEND Link
if ( $type == 'frontend' ) {
?><a title="<?php echo $anchor_title; ?>" href="<?php echo $link; ?>" <?php echo $target; ?>><?php echo $before_title.$title.$after_title; ?><?php
?><a title="<?php echo $menu_item->anchor_title; ?>" href="<?php echo $menu_item->link; ?>" <?php echo $menu_item->target; ?>><?php echo $before_title.$menu_item->title.$after_title; ?><?php
if ( $advanced_option_descriptions == 'no' ) {
// 2 widget override do NOT display descriptions
// 1 widget override display descriptions
// 0 widget override not set
if ( ($desc == 1) || ($desc == 0) ) {
?><span class="nav-description"><?php echo $description; ?></span><?php
?><span class="nav-description"><?php echo $menu_item->description; ?></span><?php
}
} else {
// 2 widget override do NOT display descriptions
// 1 widget override display descriptions
// 0 widget override not set
if ( $desc == 1 ) {
?><span class="nav-description"><?php echo $description; ?></span><?php
?><span class="nav-description"><?php echo $menu_item->description; ?></span><?php
}
}
?></a><?php
} elseif ( $type == 'backend' ) {
$link_type = $menu_type;
?>
<dl>
<dt>
<span class="title"><?php echo $title; ?></span>
<span class="title"><?php echo $menu_item->title; ?></span>
<span class="controls">
<span class="type"><?php echo $link_type; ?></span>
<a id="edit<?php echo $menu_item->menu_order; ?>" onclick="edititem(<?php echo $menu_item->menu_order; ?>)" value="<?php echo $menu_item->menu_order; ?>"><img class="edit" alt="Edit Menu Item" title="Edit Menu Item" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-edit.png" /></a>
<a id="remove<?php echo $menu_item->menu_order; ?>" onclick="removeitem(<?php echo $menu_item->menu_order; ?>)" value="<?php echo $menu_item->menu_order; ?>"><img class="remove" alt="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-close.png" /></a>
<a id="view<?php echo $menu_item->menu_order; ?>" target="_blank" href="<?php echo $link; ?>"><img alt="View Page" title="View Page" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-viewpage.png" /></a>
<span class="type"><?php echo $menu_item->type; ?></span>
<a id="edit<?php echo $menu_item->menu_order; ?>" onclick="edititem(<?php echo $menu_item->menu_order; ?>)" value="<?php echo $menu_item->menu_order; ?>"><img class="edit" alt="Edit Menu Item" title="Edit Menu Item" src="<?php echo admin_url('images/ico-edit.png'); ?>" /></a>
<a id="remove<?php echo $menu_item->menu_order; ?>" onclick="removeitem(<?php echo $menu_item->menu_order; ?>)" value="<?php echo $menu_item->menu_order; ?>"><img class="remove" alt="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php echo admin_url('images/ico-close.png'); ?>" /></a>
<a id="view<?php echo $menu_item->menu_order; ?>" target="_blank" href="<?php echo $menu_item->link; ?>"><img alt="View Page" title="View Page" src="<?php echo admin_url('images/ico-viewpage.png'); ?>" /></a>
</span>
</dt>
</dl>
@ -227,13 +233,13 @@ function wp_custom_navigation_output( $args = array() ) {
<a><span class=""></span></a>
<input type="hidden" name="dbid<?php echo $menu_item->menu_order; ?>" id="dbid<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->ID; ?>" />
<input type="hidden" name="postmenu<?php echo $menu_item->menu_order; ?>" id="postmenu<?php echo $menu_item->menu_order; ?>" value="<?php echo $id; ?>" />
<input type="hidden" name="parent<?php echo $menu_item->menu_order; ?>" id="parent<?php echo $menu_item->menu_order; ?>" value="<?php echo $parent_item; ?>" />
<input type="hidden" name="title<?php echo $menu_item->menu_order; ?>" id="title<?php echo $menu_item->menu_order; ?>" value="<?php echo $title; ?>" />
<input type="hidden" name="linkurl<?php echo $menu_item->menu_order; ?>" id="linkurl<?php echo $menu_item->menu_order; ?>" value="<?php echo $link; ?>" />
<input type="hidden" name="description<?php echo $menu_item->menu_order; ?>" id="description<?php echo $menu_item->menu_order; ?>" value="<?php echo $description; ?>" />
<input type="hidden" name="parent<?php echo $menu_item->menu_order; ?>" id="parent<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->parent_item; ?>" />
<input type="hidden" name="title<?php echo $menu_item->menu_order; ?>" id="title<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->title; ?>" />
<input type="hidden" name="linkurl<?php echo $menu_item->menu_order; ?>" id="linkurl<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->link; ?>" />
<input type="hidden" name="description<?php echo $menu_item->menu_order; ?>" id="description<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->description; ?>" />
<input type="hidden" name="icon<?php echo $menu_item->menu_order; ?>" id="icon<?php echo $menu_item->menu_order; ?>" value="0" />
<input type="hidden" name="position<?php echo $menu_item->menu_order; ?>" id="position<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->menu_order; ?>" />
<input type="hidden" name="linktype<?php echo $menu_item->menu_order; ?>" id="linktype<?php echo $menu_item->menu_order; ?>" value="<?php echo $link_type; ?>" />
<input type="hidden" name="linktype<?php echo $menu_item->menu_order; ?>" id="linktype<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->type; ?>" />
<input type="hidden" name="anchortitle<?php echo $menu_item->menu_order; ?>" id="anchortitle<?php echo $menu_item->menu_order; ?>" value="<?php echo esc_html( $menu_item->post_excerpt ); ?>" />
<input type="hidden" name="newwindow<?php echo $menu_item->menu_order; ?>" id="newwindow<?php echo $menu_item->menu_order; ?>" value="<?php echo ( '' == $menu_item->post_content_filtered ? '0' : '1' ); ?>" />
@ -259,186 +265,6 @@ function wp_custom_navigation_output( $args = array() ) {
<?php }
}
}
//@todo: implement menu heirarchy
//RECURSIVE Sub Menu Items
function wp_custom_navigation_sub_items($post_id, $type, $table_name, $output_type, $menu_id = 0) {
$parent_id = 0;
global $wpdb;
//GET sub menu items
$wp_custom_nav_menu = $wpdb->get_results("SELECT id,post_id,parent_id,position,custom_title,custom_link,custom_description,menu_icon,link_type,custom_anchor_title,new_window FROM ".$table_name." WHERE parent_id = '".$post_id."' AND menu_id='".$menu_id."' ORDER BY position ASC");
if (empty($wp_custom_nav_menu))
{
}
else
{
?><ul id="sub-custom-nav">
<?php
$queried_id = 0;
global $wp_query;
if (is_page()) {
$queried_id = $wp_query->post->ID;
}
elseif (is_category()) {
$queried_id = $wp_query->query_vars['cat'];
}
else {
}
//DISPLAY Loop
foreach ($wp_custom_nav_menu as $sub_item)
{
//Figure out where the menu item sits
$counter=$sub_item->position;
//Prepare Menu Data
//Category Menu Item
if ($sub_item->link_type == 'category')
{
$parent_id = $sub_item->parent_id;
$post_id = $sub_item->post_id;
if ($sub_item->custom_link == '') {
$link = get_category_link($sub_item->post_id);
}
else {
$link = $sub_item->custom_link;
}
if ($sub_item->custom_title == '') {
$title_raw = get_categories('include='.$sub_item->post_id);
$title = htmlentities($title_raw[0]->cat_name);
}
else {
$title = htmlentities($sub_item->custom_title);
}
if ($sub_item->custom_description == '') {
$description = strip_tags(category_description($sub_item->post_id));
}
else {
$description = $sub_item->custom_description;
}
$target = '';
}
//Page Menu Item
elseif ($sub_item->link_type == 'page')
{
$parent_id = $sub_item->parent_id;
$post_id = $sub_item->post_id;
if ($sub_item->custom_link == '') {
$link = get_permalink($sub_item->post_id);
}
else {
$link = $sub_item->custom_link;
}
if ($sub_item->custom_title == '') {
$title = htmlentities(get_the_title($sub_item->post_id));
}
else {
$title = htmlentities($sub_item->custom_title);
}
if ($sub_item->custom_description == '') {
$description = get_post_meta($sub_item->post_id, 'page-description', true);
}
else {
$description = $sub_item->custom_description;
}
$target = '';
}
//Custom Menu Item
else
{
$link = $sub_item->custom_link;
$title = htmlentities($sub_item->custom_title);
$parent_id = $sub_item->parent_id;
$post_id = $sub_item->post_id;
$description = $sub_item->custom_description;
$target = 'target="_blank"';
}
if ($queried_id == $sub_item->post_id) {
$li_class = 'class="current_page_item"';
}
else {
$li_class = '';
}
//SET anchor title
if (isset($sub_item->custom_anchor_title)) {
$anchor_title = htmlentities($sub_item->custom_anchor_title);
}
else {
$anchor_title = $title;
}
if (isset($sub_item->new_window)) {
if ($sub_item->new_window > 0) {
$target = 'target="_blank"';
}
}
//List Items
?><li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>" <?php echo $li_class; ?>><?php
//FRONTEND
if ($output_type == "frontend")
{
?><a title="<?php echo $anchor_title; ?>" href="<?php echo $link; ?>" <?php echo $target; ?>><?php echo $title; ?></a><?php
}
//BACKEND
elseif ($output_type == "backend")
{
?>
<dl>
<dt>
<span class="title"><?php echo $title; ?></span>
<span class="controls">
<span class="type"><?php echo $sub_item->link_type; ?></span>
<a id="edit<?php echo $counter; ?>" onclick="edititem(<?php echo $counter; ?>)" value="<?php echo $counter; ?>"><img class="edit" alt="Edit Menu Item" title="Edit Menu Item" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-edit.png" /></a>
<a id="remove<?php echo $counter; ?>" onclick="removeitem(<?php echo $counter; ?>)" value="<?php echo $counter; ?>"><img class="remove" alt="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-close.png" /></a>
<a id="view<?php echo $counter; ?>" target="_blank" href="<?php echo $link; ?>"><img alt="View Page" title="View Page" src="<?php echo get_bloginfo('url'); ?>/wp-admin/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 $post_id; ?>" />
<input type="hidden" name="parent<?php echo $counter; ?>" id="parent<?php echo $counter; ?>" value="<?php echo $parent_id; ?>" />
<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 $sub_item->link_type; ?>" />
<input type="hidden" name="anchortitle<?php echo $counter; ?>" id="anchortitle<?php echo $counter; ?>" value="<?php echo $anchor_title; ?>" />
<input type="hidden" name="newwindow<?php echo $counter; ?>" id="newwindow<?php echo $counter; ?>" value="<?php echo $sub_item->new_window; ?>" />
<?php
}
//Do recursion
wp_custom_navigation_sub_items($sub_item->id,$sub_item->link_type,$table_name,$output_type,$menu_id);
?></li>
<?php
}
?></ul>
<?php
}
return $parent_id;
}
// Outputs All Pages and Sub Items
function wp_custom_nav_get_pages($counter, $type) {
@ -561,7 +387,7 @@ function wp_custom_nav_get_pages($counter, $type) {
return $intCounter;
}
//Outputs All Categories and Sub Items
// Outputs All Categories and Sub Items
function wp_custom_nav_get_categories($counter, $type) {
$category_args = array(
@ -589,7 +415,6 @@ function wp_custom_nav_get_categories($counter, $type) {
// Display Loop
foreach ( $categories_array as $cat_item ) {
if ( $cat_item->parent == 0 ) {
// Custom Menu
if ( $type == 'menu' ) {
@ -598,15 +423,15 @@ function wp_custom_nav_get_categories($counter, $type) {
<li id="menu-<?php echo $intCounter; ?>" value="<?php echo $intCounter; ?>">
<dl>
<dt>
<span class="title"><?php echo $cat_item->cat_name; ?></span>
<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="Edit Menu Item" title="Edit Menu Item" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-edit.png" /></a>
<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="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-close.png" />
<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="View Page" title="View Page" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-viewpage.png" />
<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>
@ -622,20 +447,20 @@ function wp_custom_nav_get_categories($counter, $type) {
</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 htmlentities($cat_item->cat_name); ?>" />
<input type="hidden" name="linkurl<?php echo $intCounter; ?>" id="linkurl<?php echo $intCounter; ?>" value="<?php echo get_category_link($cat_item->cat_ID); ?>" />
<input type="hidden" name="description<?php echo $intCounter; ?>" id="description<?php echo $intCounter; ?>" value="<?php echo htmlentities($cat_item->category_description); ?>" />
<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 htmlentities($cat_item->cat_name); ?>" />
<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 $intCounter++; ?>
<?php
//Recursive function
// Recursive function
$intCounter = wp_custom_navigation_default_sub_items($cat_item->cat_ID, $intCounter, $parentli, 'categories','menu');
?>
@ -643,7 +468,7 @@ function wp_custom_nav_get_categories($counter, $type) {
</li>
<?php
} elseif ($type == 'default') {
} elseif ( $type == 'default' ) {
// Sidebar Menu
?>
<li>
@ -657,13 +482,13 @@ function wp_custom_nav_get_categories($counter, $type) {
$description = htmlentities(strip_tags($cat_item->description));
?>
<?php $templatedir = get_bloginfo('url'); ?>
<span class="title"><?php echo $cat_item->cat_name; ?></span> <a onclick="appendToList('<?php echo $templatedir; ?>','Category','<?php echo $post_text; ?>','<?php echo $post_url; ?>','<?php echo $post_id; ?>','<?php echo $post_parent_id ?>','<?php echo $description; ?>')" name="<?php echo $post_text; ?>" value="<?php echo $post_url; ?>"><img alt="Add to Custom Menu" title="Add to Custom Menu" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-add.png" /></a> </dt>
<span class="title"><?php echo esc_html($cat_item->cat_name); ?></span> <a onclick="appendToList('<?php echo $templatedir; ?>','Category','<?php echo $post_text; ?>','<?php echo $post_url; ?>','<?php echo $post_id; ?>','<?php echo $post_parent_id ?>','<?php echo $description; ?>')" name="<?php echo $post_text; ?>" value="<?php echo $post_url; ?>"><img alt="="<?php esc_attr_e('Add to Custom Menu'); ?>" title="="<?php esc_attr_e('Add to Custom Menu'); ?>" src="<?php echo admin_url('images/ico-add.png'); ?>" /></a> </dt>
</dl>
<?php $parentli = $cat_item->cat_ID; ?>
<?php $intCounter++; ?>
<?php
//Recursive function
$intCounter = wp_custom_navigation_default_sub_items($cat_item->cat_ID, $intCounter, $parentli, 'categories','default');
// Recursive function
$intCounter = wp_custom_navigation_default_sub_items($cat_item->cat_ID, $intCounter, $parentli, 'categories', 'default');
?>
</li>
@ -682,12 +507,12 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
$counter = $intCounter;
// Custom Menu
if ($output_type == 'menu') {
if ( $output_type == 'menu' ) {
$sub_args = array(
'child_of' => $childof,
'hide_empty' => false,
'parent' => $childof);
} elseif ($output_type == 'default') {
} elseif ( $output_type == 'default' ) {
// Sidebar Menu
$sub_args = array(
'child_of' => $childof,
@ -708,15 +533,14 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
if ( $sub_array ) {
?>
<ul id="sub-custom-nav-<?php echo $type ?>">
<?php
// Display Loop
foreach ( $sub_array as $sub_item ) {
//Prepare Menu Data
//Category Menu Item
// Prepare Menu Data
if ( $type == 'categories' ) {
// Category Menu Item
$link = get_category_link($sub_item->cat_ID);
$title = htmlentities($sub_item->cat_name);
$parent_id = $sub_item->cat_ID;
@ -749,12 +573,12 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
<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="Edit Menu Item" title="Edit Menu Item" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-edit.png" /></a>
<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="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-close.png" />
<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="View Page" title="View Page" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-viewpage.png" />
<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>
@ -776,7 +600,7 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
<?php $counter++; ?>
<?php
//Do recursion
// Do recursion
$counter = wp_custom_navigation_default_sub_items($parent_id, $counter, $parent_id, $type, 'menu');
?>
@ -791,11 +615,11 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli
<dt>
<?php $templatedir = get_bloginfo('url'); ?>
<span class="title"><?php echo $title; ?></span> <a onclick="appendToList('<?php echo $templatedir; ?>','<?php echo $appendtype; ?>','<?php echo $title; ?>','<?php echo $link; ?>','<?php echo $itemid; ?>','<?php echo $parent_id ?>','<?php echo $description; ?>')" name="<?php echo $title; ?>" value="<?php echo $link; ?>"><img alt="Add to Custom Menu" title="Add to Custom Menu" src="<?php echo get_bloginfo('url'); ?>/wp-admin/images/ico-add.png" /></a> </dt>
<span class="title"><?php echo $title; ?></span> <a onclick="appendToList('<?php echo $templatedir; ?>','<?php echo $appendtype; ?>','<?php echo $title; ?>','<?php echo $link; ?>','<?php echo $itemid; ?>','<?php echo $parent_id ?>','<?php echo $description; ?>')" name="<?php echo $title; ?>" value="<?php echo $link; ?>"><img alt="<?php esc_attr_e('Add to Custom Menu'); ?>" title="<?php esc_attr_e('Add to Custom Menu'); ?>" src="<?php echo admin_url('images/ico-add.png'); ?>" /></a> </dt>
</dl>
<?php
//Do recursion
// Do recursion
$counter = wp_custom_navigation_default_sub_items($itemid, $counter, $parent_id, $type, 'default');
?>
@ -824,17 +648,15 @@ function get_children_menu_elements($childof, $intCounter, $parentli, $type, $me
$counter = $intCounter;
//Get Sub Category Items
if ( $type == 'categories' ) {
// Get Sub Category Items
$sub_args = array(
'child_of' => $childof,
'hide_empty' => false,
'parent' => $childof);
$sub_array = get_categories($sub_args);
}
//Get Sub Page Items
elseif ($type == 'pages')
{
} elseif ($type == 'pages') {
// Get Sub Page Items
$sub_args = array(
'child_of' => $childof,
'parent' => $childof);
@ -846,18 +668,17 @@ function get_children_menu_elements($childof, $intCounter, $parentli, $type, $me
}
if ( $sub_array ) {
//DISPLAY Loop
// DISPLAY Loop
foreach ( $sub_array as $sub_item ) {
if ( isset($sub_item->parent) ) {
if ( isset($sub_item->parent) )
$sub_item_parent = $sub_item->parent;
} elseif (isset($sub_item->post_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
// Prepare Menu Data
// Category Menu Item
if ( $type == 'categories' ) {
$link = get_category_link($sub_item->cat_ID);
$title = htmlentities($sub_item->cat_name);
@ -866,7 +687,7 @@ function get_children_menu_elements($childof, $intCounter, $parentli, $type, $me
$linktype = 'category';
$appendtype= 'Category';
}
//Page Menu Item
// Page Menu Item
elseif ( $type == 'pages' ) {
$link = get_permalink($sub_item->ID);
$title = htmlentities($sub_item->post_title);
@ -875,21 +696,18 @@ function get_children_menu_elements($childof, $intCounter, $parentli, $type, $me
$itemid = $sub_item->ID;
$appendtype= 'Page';
}
//Custom Menu Item
// Custom Menu Item
else {
$title = '';
$linktype = 'custom';
$appendtype= 'Custom';
}
//CHECK for existing parent records
//echo $parent_id;
// 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)) {
if ( $wp_result > 0 && isset($wp_result[0]->id) )
$parent_id = $wp_result[0]->id;
} else {
//$parent_id = 0;
}
//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."')";