b8dfebcfaa3d020bdc11f8e00fb4c6d5fab4bc0f
[autoinstalls/wordpress.git] / wp-admin / edit-link-categories.php
1 <?php
2 require_once('admin.php');
3
4 // Handle bulk deletes
5 if ( isset($_GET['deleteit']) && isset($_GET['delete']) ) {
6         check_admin_referer('bulk-link-categories');
7
8         if ( !current_user_can('manage_categories') )
9                 wp_die(__('Cheatin&#8217; uh?'));
10
11         foreach( (array) $_GET['delete'] as $cat_ID ) {
12                 $cat_name = get_term_field('name', $cat_ID, 'link_category');
13
14                 // Don't delete the default cats.
15                 if ( $cat_ID == get_option('default_link_category') )
16                         wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
17
18                 wp_delete_term($cat_ID, 'link_category');
19         }
20
21         $location = 'edit-link-categories.php';
22         if ( $referer = wp_get_referer() ) {
23                 if ( false !== strpos($referer, 'edit-link-categories.php') )
24                         $location = $referer;
25         }
26
27         $location = add_query_arg('message', 6, $location);
28         wp_redirect($location);
29         exit();
30 } elseif ( !empty($_GET['_wp_http_referer']) ) {
31          wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
32          exit;
33 }
34
35 $title = __('Link Categories');
36 $parent_file = 'edit.php';
37
38 wp_enqueue_script( 'admin-categories' );
39 wp_enqueue_script('admin-forms');
40
41 require_once ('admin-header.php');
42
43 $messages[1] = __('Category added.');
44 $messages[2] = __('Category deleted.');
45 $messages[3] = __('Category updated.');
46 $messages[4] = __('Category not added.');
47 $messages[5] = __('Category not updated.');
48 $messages[6] = __('Categories deleted.');
49
50 if (isset($_GET['message'])) : ?>
51 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
52 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
53 endif; ?>
54
55 <div class="wrap">
56
57 <form id="posts-filter" action="" method="get">
58 <?php if ( current_user_can('manage_categories') ) : ?>
59         <h2><?php printf(__('Manage Link Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
60 <?php else : ?>
61         <h2><?php _e('Manage Link Categories') ?> </h2>
62 <?php endif; ?>
63
64 <p id="post-search">
65         <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
66         <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
67 </p>
68
69 <br class="clear" />
70
71 <div class="tablenav">
72
73 <?php
74 $pagenum = absint( $_GET['pagenum'] );
75 if ( empty($pagenum) )
76         $pagenum = 1;
77 if( !$catsperpage || $catsperpage < 0 )
78         $catsperpage = 20;
79
80 $page_links = paginate_links( array(
81         'base' => add_query_arg( 'pagenum', '%#%' ),
82         'format' => '',
83         'total' => ceil(wp_count_terms('link_category') / $catsperpage),
84         'current' => $pagenum
85 ));
86
87 if ( $page_links )
88         echo "<div class='tablenav-pages'>$page_links</div>";
89 ?>
90
91 <div class="alignleft">
92 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
93 <?php wp_nonce_field('bulk-link-categories'); ?>
94 </div>
95
96 <br class="clear" />
97 </div>
98
99 <br class="clear" />
100
101 <table class="widefat">
102         <thead>
103         <tr>
104         <th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('posts-filter'));" /></th>
105         <th scope="col"><?php _e('Name') ?></th>
106         <th scope="col"><?php _e('Description') ?></th>
107         <th scope="col" class="num" style="width: 90px;"><?php _e('Links') ?></th>
108         </tr>
109         </thead>
110         <tbody id="the-list" class="list:link-cat">
111 <?php
112 $start = ($pagenum - 1) * $catsperpage;
113 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
114 if ( !empty( $_GET['s'] ) )
115         $args['search'] = $_GET['s'];
116
117 $categories = get_terms( 'link_category', $args );
118 if ( $categories ) {
119         $output = '';
120         foreach ( $categories as $category ) {
121                 $category = sanitize_term($category, 'link_category', 'display');
122                 $output .= link_cat_row($category);
123         }
124         $output = apply_filters('cat_rows', $output);
125         echo $output;
126         unset($category);
127 }
128
129 ?>
130         </tbody>
131 </table>
132 </form>
133
134 <div class="tablenav">
135
136 <?php
137 if ( $page_links )
138         echo "<div class='tablenav-pages'>$page_links</div>";
139 ?>
140 <br class="clear" />
141 </div>
142 <br class="clear" />
143
144 </div>
145
146 <?php if ( current_user_can('manage_categories') ) : ?>
147 <div class="wrap">
148 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the links in that category. Instead, links that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), get_term_field('name', get_option('default_link_category'), 'link_category')) ?></p>
149 </div>
150
151 <?php include('edit-link-category-form.php'); ?>
152
153 <?php endif; ?>
154
155 <?php include('admin-footer.php'); ?>