2010-02-20 16:57:43 -05:00
< ? php
/**
* WordPress Administration Custom Navigation
* Interface functions
*
* @ author Jeffikus < pearce . jp @ gmail . com >
* @ version 1.1 . 0
*
* @ package WordPress
* @ subpackage Administration
*/
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
require_once ( 'admin.php' );
wp_admin_css ( 'custom-navigation' );
2010-02-20 18:35:05 -05:00
wp_enqueue_script ( 'jquery' );
2010-02-20 19:10:20 -05:00
wp_enqueue_script ( 'jquery-ui-draggable' );
wp_enqueue_script ( 'jquery-ui-droppable' );
wp_enqueue_script ( 'jquery-ui-sortable' );
wp_enqueue_script ( 'jquery-ui-dialog' );
2010-02-20 16:57:43 -05:00
wp_enqueue_script ( 'custom-navigation-dynamic-functions' );
wp_enqueue_script ( 'custom-navigation-default-items' );
2010-02-20 18:35:05 -05:00
wp_enqueue_script ( 'jquery-autocomplete' );
2010-02-20 16:57:43 -05:00
wp_enqueue_script ( 'custom-navigation-php-functions' );
2010-02-20 19:10:20 -05:00
2010-02-20 16:57:43 -05:00
require_once ( 'admin-header.php' );
2010-02-20 18:18:57 -05:00
require_once ( ABSPATH . WPINC . '/custom-navigation.php' );
2010-02-20 16:57:43 -05:00
wp_custom_navigation ();
function wp_custom_nav_reset () {
wp_custom_navigation_setup ( true );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
return true ;
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
}
/*-----------------------------------------------------------------------------------*/
/* Custom Navigation Admin Interface
/* wp_custom_navigation () is the main function for the Custom Navigation
/* See functions in admin - functions . php
/*-----------------------------------------------------------------------------------*/
function wp_custom_navigation () {
global $wpdb , $user_ID ;
?>
< div class = " wrap " >
2010-02-22 13:03:03 -05:00
< div id = " no-js " >< h3 >< ? php _e ( 'You do not have JavaScript enabled in your browser. Please enable it to access the Custom Menu functionality.' ); ?> </h3></div>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ? php
$messagesdiv = '' ;
$menu_id_in_edit = 0 ;
2010-02-20 19:03:42 -05:00
2010-02-20 18:58:00 -05:00
// Get the theme name
2010-02-20 19:34:44 -05:00
$themename = get_current_theme ();
2010-02-20 19:03:42 -05:00
2010-02-20 18:58:00 -05:00
// Check which menu is selected and if menu is in edit already
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'switch_menu' ] ) )
2010-02-20 19:34:44 -05:00
$menu_selected_id = ( int ) $_POST [ 'menu_select' ];
2010-02-20 16:57:43 -05:00
elseif ( isset ( $_POST [ 'menu_id_in_edit' ] ) )
2010-02-20 19:34:44 -05:00
$menu_selected_id = ( int ) $_POST [ 'menu_id_in_edit' ];
else
$menu_selected_id = 0 ;
2010-02-20 19:03:42 -05:00
2010-02-20 18:58:00 -05:00
// Default Menu to show
2010-02-21 13:24:41 -05:00
$custom_menus = get_terms ( 'nav_menu' , array ( 'hide_empty' => false ) );
2010-02-20 16:57:43 -05:00
if ( ! empty ( $custom_menus ) )
$menu_selected_id = $custom_menus [ 0 ] -> term_id ;
$menu_title = '' ;
if ( $menu_selected_id > 0 ) {
2010-02-20 19:34:44 -05:00
foreach ( $custom_menus as $menu ) {
2010-02-20 16:57:43 -05:00
if ( $menu -> term_id == $menu_selected_id ) {
$menu_title = $menu -> name ;
break ;
}
}
}
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'set_wp_menu' ] ) ) {
2010-02-20 19:34:44 -05:00
// @todo validate set_wp_menu
update_option ( 'wp_custom_nav_menu' , $_POST [ 'enable_wp_menu' ] );
2010-02-22 13:03:03 -05:00
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __ ( 'Custom Menu has been updated!' ) . '</p></div>' ;
2010-02-20 19:03:42 -05:00
}
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'licount' ] ) )
$postCounter = $_POST [ 'licount' ];
else
2010-02-20 19:34:44 -05:00
$postCounter = 0 ;
2010-02-20 18:58:00 -05:00
// Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'add_menu' ] ) ) {
$insert_menu_name = $_POST [ 'add_menu_name' ];
if ( $insert_menu_name != '' ) {
2010-02-21 13:24:41 -05:00
$existing_term = get_term_by ( 'name' , $insert_menu_name , 'nav_menu' );
2010-02-20 16:57:43 -05:00
if ( $existing_term ) {
2010-02-22 13:03:03 -05:00
$messagesdiv = '<div id="message" class="error fade below-h2"><p>' . esc_html ( sprintf ( e__ ( 'A menu named "%s" already exists; please try another name.' ), $existing_term -> name ) ) . '</p></div>' ;
2010-02-20 19:03:42 -05:00
} else {
2010-02-21 13:24:41 -05:00
$term = wp_insert_term ( $insert_menu_name , 'nav_menu' );
2010-02-21 05:51:34 -05:00
if ( ! is_wp_error ( $term ) ) {
2010-02-21 13:24:41 -05:00
$term = get_term ( $term [ 'term_id' ], 'nav_menu' );
2010-02-21 05:51:34 -05:00
$custom_menus [ $term -> term_id ] = $term ;
$menu_selected_id = $term -> term_id ;
2010-02-20 16:57:43 -05:00
$menu_id_in_edit = $menu_selected_id ;
2010-02-22 13:03:03 -05:00
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . esc_html ( sprintf ( __ ( '"%s" menu has been created!' ), $term -> name ) ) . '</p></div>' ;
2010-02-20 16:57:43 -05:00
$postCounter = 0 ;
}
}
} else {
2010-02-22 13:03:03 -05:00
$messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __ ( 'Please enter a valid menu name.' ) . '</p></div>' ;
2010-02-20 16:57:43 -05:00
}
}
2010-02-20 19:03:42 -05:00
if ( isset ( $_POST [ 'reset_wp_menu' ]) ) {
2010-02-20 19:34:44 -05:00
$success = wp_custom_nav_reset ();
if ( $success ) {
// DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
2010-02-22 13:03:03 -05:00
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __ ( 'The menu has been reset.' ) . '</p></div>' ;
2010-02-20 19:34:44 -05:00
// GET reset menu id
$custom_menus = array ();
$menu_selected_id = 0 ;
} else {
// DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
2010-02-22 13:03:03 -05:00
$messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __ ( 'The menu could not be reset. Please try again.' ) . '</p></div>' ;
2010-02-20 19:34:44 -05:00
}
2010-02-20 16:57:43 -05:00
} elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
2010-02-21 13:24:41 -05:00
$menu_objects = get_objects_in_term ( $menu_selected_id , 'nav_menu' );
2010-02-20 16:57:43 -05:00
$menu_items = wp_custom_navigation_get_menu_items ( $menu_objects );
2010-02-20 19:34:44 -05:00
// Loop through all POST variables
for ( $k = 1 ; $k <= $postCounter ; $k ++ ) {
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'dbid' . $k ])) { $db_id = $_POST [ 'dbid' . $k ]; } else { $db_id = 0 ; }
2010-02-21 13:24:41 -05:00
if ( isset ( $_POST [ 'postmenu' . $k ])) { $object_id = $_POST [ 'postmenu' . $k ]; } else { $object_id = 0 ; }
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'parent' . $k ])) { $parent_id = $_POST [ 'parent' . $k ]; } else { $parent_id = 0 ; }
2010-02-20 19:34:44 -05:00
if ( isset ( $_POST [ 'title' . $k ])) { $custom_title = $_POST [ 'title' . $k ]; } else { $custom_title = '' ; }
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'linkurl' . $k ])) { $custom_linkurl = $_POST [ 'linkurl' . $k ]; } else { $custom_linkurl = '' ; }
2010-02-20 19:34:44 -05:00
if ( isset ( $_POST [ 'description' . $k ])) { $custom_description = $_POST [ 'description' . $k ]; } else { $custom_description = '' ; }
// doesn't seem to be used by UI
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'icon' . $k ])) { $icon = $_POST [ 'icon' . $k ]; } else { $icon = 0 ; }
if ( isset ( $_POST [ 'position' . $k ])) { $position = $_POST [ 'position' . $k ]; } else { $position = 0 ; }
if ( isset ( $_POST [ 'linktype' . $k ])) { $linktype = $_POST [ 'linktype' . $k ]; } else { $linktype = 'custom' ; }
2010-02-20 19:34:44 -05:00
if ( isset ( $_POST [ 'anchortitle' . $k ])) { $custom_anchor_title = $_POST [ 'anchortitle' . $k ]; } else { $custom_anchor_title = $custom_title ; }
2010-02-20 16:57:43 -05:00
if ( isset ( $_POST [ 'newwindow' . $k ])) { $new_window = $_POST [ 'newwindow' . $k ]; } else { $new_window = 0 ; }
2010-02-20 19:03:42 -05:00
2010-02-21 13:24:41 -05:00
$post = array ( 'post_status' => 'publish' , 'post_type' => 'nav_menu_item' , 'post_author' => $user_ID ,
'ping_status' => 0 , 'post_parent' => 0 , 'menu_order' => $position ,
'guid' => $custom_linkurl , 'post_excerpt' => $custom_anchor_title , 'tax_input' => array ( 'nav_menu' => $menu_title ),
2010-02-20 16:57:43 -05:00
'post_content' => $custom_description , 'post_title' => $custom_title );
if ( $new_window )
$post [ 'post_content_filtered' ] = '_blank' ;
else
$post [ 'post_content_filtered' ] = '' ;
2010-02-21 19:26:21 -05:00
if ( $parent_id > 0 && isset ( $_POST [ 'dbid' . $parent_id ] ) )
$post [ 'post_parent' ] = ( int ) $_POST [ 'dbid' . $parent_id ];
2010-02-20 16:57:43 -05:00
2010-02-20 19:34:44 -05:00
// New menu item
if ( $db_id == 0 ) {
2010-02-21 13:24:41 -05:00
$db_id = wp_insert_post ( $post );
2010-02-20 16:57:43 -05:00
} elseif ( isset ( $menu_items [ $db_id ] ) ) {
2010-02-20 19:34:44 -05:00
$post [ 'ID' ] = $db_id ;
wp_update_post ( $post );
2010-02-20 16:57:43 -05:00
unset ( $menu_items [ $db_id ] );
}
2010-02-20 17:44:24 -05:00
update_post_meta ( $db_id , 'menu_type' , $linktype );
2010-02-21 13:24:41 -05:00
update_post_meta ( $db_id , 'object_id' , $object_id );
2010-02-20 16:57:43 -05:00
}
if ( ! empty ( $menu_items ) ) {
2010-02-20 19:34:44 -05:00
foreach ( array_keys ( $menu_items ) as $menu_id ) {
2010-02-20 16:57:43 -05:00
wp_delete_post ( $menu_id );
}
}
2010-02-20 19:34:44 -05:00
// DISPLAY SUCCESS MESSAGE IF POST CORRECT
2010-02-22 13:12:53 -05:00
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __ ( 'The menu has been updated.' ) . '</p></div>' ;
2010-02-20 16:57:43 -05:00
}
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//DISPLAY Custom Navigation
?>
< div id = " pages-left " >
< div class = " inside " >
2010-02-22 13:03:03 -05:00
< h2 class = " maintitle " >< ? php esc_html_e ( 'Custom Navigation' ) ?> </h2>
2010-02-20 16:57:43 -05:00
< ? php
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//CHECK if custom menu has been enabled
$enabled_menu = get_option ( 'wp_custom_nav_menu' );
$checked = strtolower ( $enabled_menu );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
if ( $checked == 'true' ) {
} else {
2010-02-22 13:03:03 -05:00
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>' ;
2010-02-20 16:57:43 -05:00
}
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
?>
< ? php echo $messagesdiv ; ?>
< form onsubmit = " updatepostdata() " action = " custom-navigation.php " method = " post " enctype = " multipart/form-data " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< input type = " hidden " name = " licount " id = " licount " value = " 0 " />
2010-02-22 13:12:53 -05:00
< input type = " hidden " name = " menu_id_in_edit " id = " menu_id_in_edit " value = " <?php echo esc_attr( $menu_selected_id ); ?> " />
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " sidebar-name " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " sidebar-name-arrow " >
< br />
</ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php echo esc_html ( $menu_title ); ?> </h3>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ div >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div id = " nav-container " >
< ul id = " custom-nav " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ? php
//DISPLAY existing menu
if ( $menu_selected_id > 0 ) {
//SET output type
$output_type = " backend " ;
//MAIN OUTPUT FUNCTION
wp_custom_navigation_output ( 'type=' . $output_type . '&name=' . $menu_title . '&id=' . $menu_selected_id );
2010-02-20 19:03:42 -05:00
}
2010-02-20 16:57:43 -05:00
?>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ ul >
</ div ><!-- / #nav-container -->
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< p class = " submit " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< script type = " text/javascript " >
2010-02-20 19:03:42 -05:00
updatepostdata ();
2010-02-20 16:57:43 -05:00
</ script >
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
< input id = " save_bottom " name = " save_bottom " type = " submit " value = " <?php esc_attr_e('Save All Changes'); ?> " /></ p >
2010-02-20 16:57:43 -05:00
</ div ><!-- /. inside -->
</ div >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div id = " menu-right " >
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
< h2 class = " heading " >< ? php esc_html_e ( 'Options' ); ?> </h2>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " widgets-holder-wrap " >
< div class = " sidebar-name " >
< div class = " sidebar-name-arrow " ></ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php esc_html_e ( 'Setup Custom Menu' ); ?> </h3>
2010-02-20 16:57:43 -05:00
</ div >
< div class = " widget-holder " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ? php
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//SETUP Custom Menu
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
$enabled_menu = get_option ( 'wp_custom_nav_menu' );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
$checked = strtolower ( $enabled_menu );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
?>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< span >
2010-02-22 13:03:03 -05:00
< label >< ? php _e ( 'Enable' ); ?> </label><input type="radio" name="enable_wp_menu" value="true" <?php if ($checked=='true') { echo 'checked="checked"'; } ?> />
< label >< ? php _e ( 'Disable' ); ?> </label><input type="radio" name="enable_wp_menu" value="false" <?php if ($checked=='true') { } else { echo 'checked="checked"'; } ?> />
2010-02-20 19:03:42 -05:00
</ span ><!-- /. checkboxes -->
2010-02-22 13:12:53 -05:00
< input id = " set_wp_menu " type = " submit " value = " <?php esc_attr_e('Set Menu'); ?> " name = " set_wp_menu " class = " button " />< br />
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< span >
2010-02-22 13:03:03 -05:00
< label >< ? php _e ( 'Reset Menu to Default' ); ?> </label>
2010-02-22 13:12:53 -05:00
< input id = " reset_wp_menu " type = " submit " value = " Reset " name = " reset_wp_menu " class = " button " onclick = " return confirm('<?php _e('Are you sure you want to reset the menu to its default settings?'); ?>'); " />
2010-02-20 16:57:43 -05:00
</ span >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " fix " ></ div >
</ div >
</ div ><!-- /. widgets - holder - wrap -->
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " widgets-holder-wrap " >
< div class = " sidebar-name " >
< div class = " sidebar-name-arrow " ></ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php esc_html_e ( 'Menu Selector' ); ?> </h3>
2010-02-20 16:57:43 -05:00
</ div >
< div class = " widget-holder " >
< select id = " menu_select " name = " menu_select " >
2010-02-20 19:03:42 -05:00
< ? php
2010-02-20 16:57:43 -05:00
//DISPLAY SELECT OPTIONS
2010-02-21 13:24:41 -05:00
foreach ( $custom_menus as $menu ) {
$menu_term = get_term ( $menu , 'nav_menu' );
2010-02-20 18:58:00 -05:00
if ( ( $menu_id_in_edit == $menu -> term_id ) || ( $menu_selected_id == $menu -> term_id ) )
2010-02-20 16:57:43 -05:00
$selected_option = 'selected="selected"' ;
else
$selected_option = '' ;
?>
2010-02-22 13:12:53 -05:00
< option value = " <?php echo esc_attr( $menu_term->term_id ); ?> " < ? php echo $selected_option ; ?> ><?php echo $menu_term->name; ?></option>
2010-02-20 16:57:43 -05:00
< ? php
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
}
?>
</ select >
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
< input id = " switch_menu " type = " submit " value = " <?php esc_attr_e('Switch'); ?> " name = " switch_menu " class = " button " />
2010-02-20 16:57:43 -05:00
< input id = " add_menu_name " name = " add_menu_name " type = " text " value = " " />
2010-02-22 13:03:03 -05:00
< input id = " add_menu " type = " submit " value = " <?php esc_attr_e('Add Menu'); ?> " name = " add_menu " class = " button " />
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " fix " ></ div >
</ div >
</ div ><!-- /. widgets - holder - wrap -->
< ? php $advanced_option_descriptions = get_option ( 'wp_settings_custom_nav_advanced_options' ); ?>
< div class = " widgets-holder-wrap " style = " display:none; " >
< div class = " sidebar-name " >
< div class = " sidebar-name-arrow " ></ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php esc_html_e ( 'Top Level Menu Descriptions' ); ?> </h3>
2010-02-20 16:57:43 -05:00
</ div >
2010-02-20 19:03:42 -05:00
< div class = " widget-holder " >
2010-02-22 13:03:03 -05:00
< span >< ? php _e ( 'Display Descriptions in Top Level Menu?' ); ?> </span>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ? php
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//UPDATE and DISPLAY Menu Description Option
2010-02-22 13:03:03 -05:00
if ( isset ( $_POST [ 'menu-descriptions' ]) ) {
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
if ( isset ( $_POST [ 'switch_menu' ]) ) {
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
} else {
2010-02-20 16:57:43 -05:00
$menu_options_to_edit = $_POST [ 'menu_id_in_edit' ];
2010-02-20 19:03:42 -05:00
update_option ( 'wp_settings_custom_nav_' . $menu_options_to_edit . '_descriptions' , $_POST [ 'menu-descriptions' ]);
2010-02-20 16:57:43 -05:00
}
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
}
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
if ( $menu_id_in_edit > 0 )
2010-02-20 16:57:43 -05:00
$checkedraw = get_option ( 'wp_settings_custom_nav_' . $menu_id_in_edit . '_descriptions' );
2010-02-22 13:03:03 -05:00
else
2010-02-20 16:57:43 -05:00
$checkedraw = get_option ( 'wp_settings_custom_nav_' . $menu_selected_id . '_descriptions' );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
$checked = strtolower ( $checkedraw );
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
if ( $advanced_option_descriptions == 'no' )
2010-02-20 16:57:43 -05:00
$checked = 'no' ;
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
?>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< span class = " checkboxes " >
2010-02-22 13:03:03 -05:00
< label >< ? php _e ( 'Yes' ); ?> </label><input type="radio" name="menu-descriptions" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
< label >< ? php _e ( 'No' ); ?> </label><input type="radio" name="menu-descriptions" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
2010-02-20 16:57:43 -05:00
</ span ><!-- /. checkboxes -->
</ form >
< div class = " fix " ></ div >
</ div >
</ div ><!-- /. widgets - holder - wrap -->
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " widgets-holder-wrap " >
< div class = " sidebar-name " >
< div class = " sidebar-name-arrow " ></ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php esc_html_e ( 'Add an Existing Page' ); ?> </h3>
2010-02-20 16:57:43 -05:00
</ div >
< div class = " widget-holder " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ? php
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
$pages_args = array (
'child_of' => 0 ,
'sort_order' => 'ASC' ,
'sort_column' => 'post_title' ,
'hierarchical' => 1 ,
'exclude' => '' ,
'include' => '' ,
'meta_key' => '' ,
'meta_value' => '' ,
'authors' => '' ,
'parent' => - 1 ,
'exclude_tree' => '' ,
'number' => '' ,
'offset' => 0 );
2010-02-20 19:03:42 -05:00
//GET all pages
2010-02-20 16:57:43 -05:00
$pages_array = get_pages ( $pages_args );
$page_name = '' ;
//CHECK if pages exist
2010-02-22 13:03:03 -05:00
if ( $pages_array ) {
foreach ( $pages_array as $post ) {
2010-02-20 19:03:42 -05:00
//Add page name to
2010-02-20 16:57:43 -05:00
$page_name .= htmlentities ( $post -> post_title ) . '|' ;
}
2010-02-22 13:03:03 -05:00
} else {
2010-02-20 16:57:43 -05:00
$page_name = " No pages available " ;
}
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
?>
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< script >
2010-02-20 18:35:05 -05:00
jQuery ( document ) . ready ( function (){
2010-02-20 16:57:43 -05:00
//GET PHP pages
2010-02-22 13:12:53 -05:00
var dataposts = " <?php echo esc_js( $page_name ); ?> " . split ( " | " );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//Set autocomplete
2010-02-20 18:35:05 -05:00
jQuery ( " #page-search " ) . autocomplete ( dataposts );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//Handle autocomplete result
2010-02-20 18:35:05 -05:00
jQuery ( " #page-search " ) . result ( function ( event , data , formatted ) {
jQuery ( '#existing-pages' ) . css ( 'display' , 'block' );
jQuery ( " #existing-pages dt:contains(' " + data + " ') " ) . css ( " display " , " block " );
2010-02-20 19:03:42 -05:00
2010-02-20 18:35:05 -05:00
jQuery ( '#show-pages' ) . hide ();
jQuery ( '#hide-pages' ) . show ();
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
});
2010-02-20 18:35:05 -05:00
jQuery ( '#existing-pages' ) . css ( 'display' , 'none' );
2010-02-20 16:57:43 -05:00
});
</ script >
2010-02-22 13:12:53 -05:00
< input type = " text " onfocus = " jQuery('#page-search').attr('value',''); " id = " page-search " value = " <?php esc_attr_e('Search Pages'); ?> " />
2010-02-20 19:03:42 -05:00
< a id = " show-pages " style = " cursor:pointer; " onclick = " jQuery('#existing-pages').css('display','block');jQuery('#page-search').attr('value','');jQuery('#existing-pages dt').css('display','block');jQuery('#show-pages').hide();jQuery('#hide-pages').show(); " > View All </ a >
2010-02-20 16:57:43 -05:00
< a id = " hide-pages " style = " cursor:pointer; " onclick = " jQuery('#existing-pages').css('display','none');jQuery('#page-search').attr('value','Search Pages');jQuery('#existing-pages dt').css('display','none');jQuery('#show-pages').show();jQuery('#hide-pages').hide(); " > Hide All </ a >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< script type = " text/javascript " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
jQuery ( '#hide-pages' ) . hide ();
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ script >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ul id = " existing-pages " class = " list " >
< ? php
$intCounter = 0 ;
//Get default Pages
$intCounter = wp_custom_nav_get_pages ( $intCounter , 'default' );
?>
</ ul >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " fix " ></ div >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ div >
</ div ><!-- /. widgets - holder - wrap -->
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " widgets-holder-wrap " >
< div class = " sidebar-name " >
< div class = " sidebar-name-arrow " ></ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php esc_html_e ( 'Add an Existing Category' ); ?> </h3>
2010-02-20 16:57:43 -05:00
</ div >
< div class = " widget-holder " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ? php
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
// Custom GET categories query
// @todo Use API
2010-02-20 16:57:43 -05:00
$categories = $wpdb -> get_results ( " SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' ORDER BY term_id ASC " );
$cat_name = '' ;
//CHECK for results
2010-02-22 13:03:03 -05:00
if ( $categories ) {
foreach ( $categories as $category ) {
2010-02-20 16:57:43 -05:00
$cat_id = $category -> term_id ;
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
$cat_args = array (
2010-02-20 16:57:43 -05:00
'orderby' => 'name' ,
'include' => $cat_id ,
'hierarchical' => 1 ,
'order' => 'ASC'
);
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
$category_names = get_categories ( $cat_args );
2010-02-20 19:03:42 -05:00
2010-02-22 13:03:03 -05:00
if ( isset ( $category_names [ 0 ] -> name ) ) {
// Add category name to data string
2010-02-20 16:57:43 -05:00
$cat_name .= htmlentities ( $category_names [ 0 ] -> name ) . '|' ;
}
}
2010-02-22 13:03:03 -05:00
} else {
2010-02-22 13:12:53 -05:00
$cat_name = __ ( 'No categories available' );
2010-02-20 16:57:43 -05:00
}
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
?>
< script >
2010-02-20 18:35:05 -05:00
jQuery ( document ) . ready ( function (){
2010-02-20 16:57:43 -05:00
//GET PHP categories
2010-02-22 13:12:53 -05:00
var datacats = " <?php echo esc_js( $cat_name ); ?> " . split ( " | " );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//Set autocomplete
2010-02-20 18:35:05 -05:00
jQuery ( " #cat-search " ) . autocomplete ( datacats );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
//Handle autocomplete result
2010-02-20 18:35:05 -05:00
jQuery ( " #cat-search " ) . result ( function ( event , data , formatted ) {
jQuery ( '#existing-categories' ) . css ( 'display' , 'block' );
jQuery ( " #existing-categories dt:contains(' " + data + " ') " ) . css ( " display " , " block " );
2010-02-20 19:03:42 -05:00
2010-02-20 18:35:05 -05:00
jQuery ( '#show-cats' ) . hide ();
jQuery ( '#hide-cats' ) . show ();
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
});
2010-02-20 18:35:05 -05:00
jQuery ( '#existing-categories' ) . css ( 'display' , 'none' );
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
});
</ script >
2010-02-22 13:03:03 -05:00
< input type = " text " onfocus = " jQuery('#cat-search').attr('value',''); " id = " cat-search " value = " <?php esc_attr_e('Search Categories'); ?> " />
2010-02-20 19:03:42 -05:00
< a id = " show-cats " style = " cursor:pointer; " onclick = " jQuery('#existing-categories').css('display','block');jQuery('#cat-search').attr('value','');jQuery('#existing-categories dt').css('display','block');jQuery('#show-cats').hide();jQuery('#hide-cats').show(); " > View All </ a >
2010-02-20 16:57:43 -05:00
< a id = " hide-cats " style = " cursor:pointer; " onclick = " jQuery('#existing-categories').css('display','none');jQuery('#cat-search').attr('value','Search Categories');jQuery('#existing-categories dt').css('display','none');jQuery('#show-cats').show();jQuery('#hide-cats').hide(); " > Hide All </ a >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< script type = " text/javascript " >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
jQuery ( '#hide-cats' ) . hide ();
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ script >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< ul id = " existing-categories " class = " list " >
< ? php
//Get default Categories
2010-02-20 19:03:42 -05:00
$intCounter = wp_custom_nav_get_categories ( $intCounter , 'default' );
2010-02-20 16:57:43 -05:00
?>
</ ul >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " fix " ></ div >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ div >
</ div ><!-- /. widgets - holder - wrap -->
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< div class = " widgets-holder-wrap " >
< div class = " sidebar-name " >
< div class = " sidebar-name-arrow " ></ div >
2010-02-22 13:03:03 -05:00
< h3 >< ? php esc_html_e ( 'Add a Custom Url' ); ?> </h3>
2010-02-20 16:57:43 -05:00
</ div >
< div class = " widget-holder " >
< input id = " custom_menu_item_url " type = " text " value = " http:// " />
2010-02-22 13:03:03 -05:00
< label >< ? php _e ( 'URL' ); ?> </label><br />
2010-02-20 16:57:43 -05:00
< ? php $templatedir = get_bloginfo ( 'url' ); ?>
2010-02-22 13:03:03 -05:00
< input type = " hidden " id = " templatedir " value = " <?php echo esc_attr( $templatedir ); ?> " />
2010-02-20 16:57:43 -05:00
< input id = " custom_menu_item_name " type = " text " value = " Menu Item " onfocus = " jQuery('#custom_menu_item_name').attr('value',''); " />
2010-02-22 13:12:53 -05:00
< label >< ? php _e ( 'Menu Text' ); ?> </label><br />
< input id = " custom_menu_item_description " type = " text " value = " <?php esc_attr_e('A description'); ?> " < ? php if ( $advanced_option_descriptions == 'no' ) { ?> style="display:none;"<?php } ?> onfocus="jQuery('#custom_menu_item_description').attr('value','');" />
2010-02-22 13:16:34 -05:00
< label < ? php if ( $advanced_option_descriptions == 'no' ) { ?> style="display:none;"<?php } ?> ><?php _e('Description'); ?></label>
2010-02-22 13:12:53 -05:00
< a class = " addtomenu " onclick = " appendToList('<?php echo $templatedir ; ?>','Custom','','','','0','');jQuery('#custom_menu_item_name').attr('value','Menu Item');jQuery('#custom_menu_item_description').attr('value','A description'); " >< ? php _e ( 'Add to menu' ); ?> </a>
2010-02-20 16:57:43 -05:00
< div class = " fix " ></ div >
</ div >
</ div ><!-- /. widgets - holder - wrap -->
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
</ div >
</ div >
2010-02-20 19:03:42 -05:00
2010-02-20 16:57:43 -05:00
< script type = " text/javascript " >
document . getElementById ( 'pages-left' ) . style . display = 'block' ;
document . getElementById ( 'menu-right' ) . style . display = 'block' ;
document . getElementById ( 'no-js' ) . style . display = 'none' ;
</ script >
2010-02-20 19:03:42 -05:00
2010-02-22 13:12:53 -05:00
< div id = " dialog-confirm " title = " <?php esc_attr_e('Edit Menu Item'); ?> " >
2010-02-22 13:16:34 -05:00
</ label >< input id = " edittitle " type = " text " name = " edittitle " value = " " />< label class = " editlabel " for = " edittitle " >< ? php _e ( 'Menu Title' ); ?> </label><br />
< input id = " editlink " type = " text " name = " editlink " value = " " />< label class = " editlabel " for = " editlink " >< ? php _e ( 'URL' ); ?> </label><br />
< input id = " editanchortitle " type = " text " name = " editanchortitle " value = " " />< label class = " editlabel " for = " editanchortitle " >< ? php _e ( 'Link Title' ); ?> </label><br />
2010-02-20 16:57:43 -05:00
< select id = " editnewwindow " name = " editnewwindow " >
2010-02-22 13:16:34 -05:00
< option value = " 1 " >< ? php _e ( 'Yes' ); ?> </option>
< option value = " 0 " >< ? php _e ( 'No' ); ?> </option>
</ select >< label class = " editlabel " for = " editnewwindow " >< ? php _e ( 'Open Link in a new window' ); ?> </label>
< input id = " editdescription " type = " text " name = " editdescription " value = " " < ? php if ( $advanced_option_descriptions == 'no' ) { ?> style="display:none;"<?php } ?> /><label class="editlabel" for="editdescription" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> ><?php _e('Description'); ?></label><br />
2010-02-20 16:57:43 -05:00
</ div >
< ? php
}
include ( " admin-footer.php " );