Cleanups. see #11817

git-svn-id: https://develop.svn.wordpress.org/trunk@13342 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-02-23 20:48:50 +00:00
parent 19db2cc569
commit 47d6a81f35
1 changed files with 459 additions and 494 deletions

View File

@ -12,6 +12,9 @@
require_once('admin.php');
if ( ! current_user_can('switch_themes') )
wp_die( __( 'Cheatin’ uh?' ));
wp_admin_css( 'custom-navigation' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-draggable' );
@ -26,71 +29,51 @@ wp_enqueue_script( 'custom-navigation-php-functions' );
require_once('admin-header.php');
require_once (ABSPATH . WPINC . '/custom-navigation.php');
wp_custom_navigation();
function wp_custom_nav_reset() {
wp_custom_navigation_setup(true);
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Custom Navigation Admin Interface
/* wp_custom_navigation() is the main function for the Custom Navigation
/* See functions in admin-functions.php
/*-----------------------------------------------------------------------------------*/
$messagesdiv = '';
$menu_id_in_edit = 0;
function wp_custom_navigation() {
global $wpdb, $user_ID;
?>
<div class="wrap">
<div id="no-js"><h3><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></h3></div>
<?php
$messagesdiv = '';
$menu_id_in_edit = 0;
// Get the theme name
$themename = get_current_theme();
// Check which menu is selected and if menu is in edit already
if ( isset( $_POST['switch_menu'] ) )
// Check which menu is selected and if menu is in edit already
if ( isset( $_POST['switch_menu'] ) )
$menu_selected_id = (int) $_POST['menu_select'];
elseif ( isset( $_POST['menu_id_in_edit'] ) )
elseif ( isset( $_POST['menu_id_in_edit'] ) )
$menu_selected_id = (int) $_POST['menu_id_in_edit'];
else
else
$menu_selected_id = 0;
// Default Menu to show
$custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
if ( !empty( $custom_menus ) )
// Default Menu to show
$custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
if ( !empty( $custom_menus ) )
$menu_selected_id = $custom_menus[0]->term_id;
$menu_title = '';
if ( $menu_selected_id > 0 ) {
$menu_title = '';
if ( $menu_selected_id > 0 ) {
foreach ( $custom_menus as $menu ) {
if ( $menu->term_id == $menu_selected_id ) {
$menu_title = $menu->name;
break;
}
}
}
}
if ( isset( $_POST['set_wp_menu'] ) ) {
if ( isset( $_POST['set_wp_menu'] ) ) {
// @todo validate set_wp_menu
update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('Menu has been updated!') . '</p></div>';
}
}
if ( isset( $_POST['licount'] ) )
if ( isset( $_POST['licount'] ) )
$postCounter = $_POST['licount'];
else
else
$postCounter = 0;
// Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
if ( isset( $_POST['add_menu'] ) ) {
// Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
if ( isset( $_POST['add_menu'] ) ) {
$insert_menu_name = $_POST['add_menu_name'];
if ( $insert_menu_name != '' ) {
@ -112,9 +95,9 @@ function wp_custom_navigation() {
} else {
$messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>';
}
}
}
if ( isset($_POST['reset_wp_menu']) ) {
if ( isset($_POST['reset_wp_menu']) ) {
$success = wp_custom_nav_reset();
if ( $success ) {
// DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
@ -126,7 +109,7 @@ function wp_custom_navigation() {
// DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
$messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('The menu could not be reset. Please try again.') . '</p></div>';
}
} elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
} elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
$menu_objects = get_objects_in_term( $menu_selected_id, 'nav_menu' );
$menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
@ -174,23 +157,23 @@ function wp_custom_navigation() {
}
// DISPLAY SUCCESS MESSAGE IF POST CORRECT
$messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';
}
}
// DISPLAY Custom Navigation
?>
<?php screen_icon(); ?>
<h2 class="maintitle"><?php esc_html_e('Menus') ?></h2>
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2 class="maintitle"><?php esc_html_e('Menus') ?></h2>
<div id="no-js"><h3><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></h3></div>
<div id="pages-left">
<div class="inside">
<?php
// CHECK if custom menu has been enabled
$enabled_menu = get_option('wp_custom_nav_menu');
$checked = strtolower($enabled_menu);
if ( $checked != 'true' )
echo '<div id="message-enabled" class="error fade below-h2"><p><strong>' . __('Menu editing has not been Enabled yet. Please enable it in order to use it -------->') . '</strong></p></div>';
?>
<?php echo $messagesdiv; ?>
<form onsubmit="updatepostdata()" action="custom-navigation.php" method="post" enctype="multipart/form-data">
@ -242,13 +225,9 @@ function wp_custom_navigation() {
<div class="widget-holder">
<?php
// Setup custom menu
$enabled_menu = get_option('wp_custom_nav_menu');
$checked = strtolower($enabled_menu);
?>
<span >
@ -275,7 +254,6 @@ function wp_custom_navigation() {
<div class="widget-holder">
<select id="menu_select" name="menu_select">
<?php
// Display select options
foreach ( $custom_menus as $menu ) {
$menu_term = get_term( $menu, 'nav_menu' );
@ -286,7 +264,6 @@ function wp_custom_navigation() {
?>
<option value="<?php echo esc_attr($menu_term->term_id); ?>" <?php echo $selected_option; ?>><?php echo $menu_term->name; ?></option>
<?php
}
?>
</select>
@ -308,7 +285,6 @@ function wp_custom_navigation() {
<span><?php _e('Display Descriptions in Top Level Menu?'); ?></span>
<?php
// UPDATE and DISPLAY Menu Description Option
if ( isset($_POST['menu-descriptions']) ) {
if ( !isset($_POST['switch_menu']) ) {
@ -326,7 +302,6 @@ function wp_custom_navigation() {
if ( $advanced_option_descriptions == 'no' )
$checked = 'no';
?>
<span class="checkboxes">
@ -346,7 +321,6 @@ function wp_custom_navigation() {
<div class="widget-holder">
<?php
$pages_args = array(
'child_of' => 0,
'sort_order' => 'ASC',
@ -374,7 +348,6 @@ function wp_custom_navigation() {
} else {
$page_name = __('No pages available');
}
?>
<script>
@ -399,16 +372,13 @@ function wp_custom_navigation() {
});
</script>
<input type="text" onfocus="jQuery('#page-search').attr('value','');" id="page-search" value="<?php esc_attr_e('Search Pages'); ?>" />
<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>
<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>
<script type="text/javascript">
jQuery('#hide-pages').hide();
</script>
<ul id="existing-pages" class="list">
@ -432,7 +402,6 @@ function wp_custom_navigation() {
<div class="widget-holder">
<?php
// Custom GET categories query
// @todo Use API
$categories = $wpdb->get_results("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' ORDER BY term_id ASC");
@ -459,7 +428,6 @@ function wp_custom_navigation() {
} else {
$cat_name = __('No categories available');
}
?>
<script>
@ -491,9 +459,7 @@ function wp_custom_navigation() {
<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>
<script type="text/javascript">
jQuery('#hide-cats').hide();
</script>
<ul id="existing-categories" class="list">
@ -528,15 +494,15 @@ function wp_custom_navigation() {
</div><!-- /.widgets-holder-wrap -->
</div>
</div>
</div>
<script type="text/javascript">
<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>
</script>
<div id="dialog-confirm" title="<?php esc_attr_e('Edit Menu Item'); ?>">
<div id="dialog-confirm" title="<?php esc_attr_e('Edit Menu Item'); ?>">
</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 />
@ -545,9 +511,8 @@ function wp_custom_navigation() {
<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 />
</div>
</div>
<?php
}
include("admin-footer.php");