Wordpress 2.7.1
[autoinstalls/wordpress.git] / wp-admin / link-manager.php
1 <?php
2 /**
3  * Link Management Administration Panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** Load WordPress Administration Bootstrap */
10 require_once ('admin.php');
11
12 // Handle bulk deletes
13 if ( isset($_GET['action']) && isset($_GET['linkcheck']) ) {
14         check_admin_referer('bulk-bookmarks');
15         $doaction = $_GET['action'] ? $_GET['action'] : $_GET['action2'];
16
17         if ( ! current_user_can('manage_links') )
18                 wp_die( __('You do not have sufficient permissions to edit the links for this blog.') );
19
20         if ( 'delete' == $doaction ) {
21                 foreach ( (array) $_GET['linkcheck'] as $link_id ) {
22                         $link_id = (int) $link_id;
23
24                         wp_delete_link($link_id);
25                 }
26
27                 wp_redirect( wp_get_referer() );
28                 exit;
29         }
30 } elseif ( isset($_GET['_wp_http_referer']) && ! 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 wp_reset_vars(array('action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]'));
36
37 if ( empty($cat_id) )
38         $cat_id = 'all';
39
40 if ( empty($order_by) )
41         $order_by = 'order_name';
42
43 $title = __('Edit Links');
44 $this_file = $parent_file = 'link-manager.php';
45 include_once ("./admin-header.php");
46
47 if (!current_user_can('manage_links'))
48         wp_die(__("You do not have sufficient permissions to edit the links for this blog."));
49
50 switch ($order_by) {
51         case 'order_id' :
52                 $sqlorderby = 'id';
53                 break;
54         case 'order_url' :
55                 $sqlorderby = 'url';
56                 break;
57         case 'order_desc' :
58                 $sqlorderby = 'description';
59                 break;
60         case 'order_owner' :
61                 $sqlorderby = 'owner';
62                 break;
63         case 'order_rating' :
64                 $sqlorderby = 'rating';
65                 break;
66         case 'order_name' :
67         default :
68                 $sqlorderby = 'name';
69                 break;
70 } ?>
71
72 <div class="wrap nosubsub">
73 <?php screen_icon(); ?>
74 <h2><?php echo wp_specialchars( $title );
75 if ( isset($_GET['s']) && $_GET['s'] )
76         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', wp_specialchars( stripslashes($_GET['s']) ) ); ?>
77 </h2>
78
79 <?php
80 if ( isset($_GET['deleted']) ) {
81         echo '<div id="message" class="updated fade"><p>';
82         $deleted = (int) $_GET['deleted'];
83         printf(__ngettext('%s link deleted.', '%s links deleted', $deleted), $deleted);
84         echo '</p></div>';
85         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
86 }
87 ?>
88
89 <form class="search-form" action="" method="get">
90 <p class="search-box">
91         <label class="hidden" for="link-search-input"><?php _e( 'Search Links' ); ?>:</label>
92         <input type="text" class="search-input" id="link-search-input" name="s" value="<?php _admin_search_query(); ?>" />
93         <input type="submit" value="<?php _e( 'Search Links' ); ?>" class="button" />
94 </p>
95 </form>
96 <br class="clear" />
97
98 <form id="posts-filter" action="" method="get">
99 <div class="tablenav">
100
101 <div class="alignleft actions">
102 <select name="action">
103 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
104 <option value="delete"><?php _e('Delete'); ?></option>
105 </select>
106 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
107
108 <?php
109 $categories = get_terms('link_category', "hide_empty=1");
110 $select_cat = "<select name=\"cat_id\">\n";
111 $select_cat .= '<option value="all"'  . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
112 foreach ((array) $categories as $cat)
113         $select_cat .= '<option value="' . $cat->term_id . '"' . (($cat->term_id == $cat_id) ? " selected='selected'" : '') . '>' . sanitize_term_field('name', $cat->name, $cat->term_id, 'link_category', 'display') . "</option>\n";
114 $select_cat .= "</select>\n";
115
116 $select_order = "<select name=\"order_by\">\n";
117 $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' .  __('Order by Link ID') . "</option>\n";
118 $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' .  __('Order by Name') . "</option>\n";
119 $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' .  __('Order by Address') . "</option>\n";
120 $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' .  __('Order by Rating') . "</option>\n";
121 $select_order .= "</select>\n";
122
123 echo $select_cat;
124 echo $select_order;
125
126 ?>
127 <input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
128
129 </div>
130
131 <br class="clear" />
132 </div>
133
134 <div class="clear"></div>
135
136 <?php
137 if ( 'all' == $cat_id )
138         $cat_id = '';
139 $args = array('category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0);
140 if ( !empty($_GET['s']) )
141         $args['search'] = $_GET['s'];
142 $links = get_bookmarks( $args );
143 if ( $links ) {
144         $link_columns = get_column_headers('link-manager');
145         $hidden = get_hidden_columns('link-manager');
146 ?>
147
148 <?php wp_nonce_field('bulk-bookmarks') ?>
149 <table class="widefat fixed" cellspacing="0">
150         <thead>
151         <tr>
152 <?php print_column_headers('link-manager'); ?>
153         </tr>
154         </thead>
155
156         <tfoot>
157         <tr>
158 <?php print_column_headers('link-manager', false); ?>
159         </tr>
160         </tfoot>
161
162         <tbody>
163 <?php
164         $alt = 0;
165
166         foreach ($links as $link) {
167                 $link = sanitize_bookmark($link);
168                 $link->link_name = attribute_escape($link->link_name);
169                 $link->link_category = wp_get_link_cats($link->link_id);
170                 $short_url = str_replace('http://', '', $link->link_url);
171                 $short_url = preg_replace('/^www./i', '', $short_url);
172                 if ('/' == substr($short_url, -1))
173                         $short_url = substr($short_url, 0, -1);
174                 if (strlen($short_url) > 35)
175                         $short_url = substr($short_url, 0, 32).'...';
176                 $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
177                 $style = ($alt % 2) ? '' : ' class="alternate"';
178                 ++ $alt;
179                 $edit_link = get_edit_bookmark_link();
180                 ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
181                 foreach($link_columns as $column_name=>$column_display_name) {
182                         $class = "class=\"column-$column_name\"";
183
184                         $style = '';
185                         if ( in_array($column_name, $hidden) )
186                                 $style = ' style="display:none;"';
187                         if ( 'visible' == $column_name )
188                                 $style = empty($style) ? ' style="text-align: center;"' : ' style="text-align: center; display: none;"';
189                         $attributes = "$class$style";
190
191                         switch($column_name) {
192                                 case 'cb':
193                                         echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'.$link->link_id.'" /></th>';
194                                         break;
195                                 case 'name':
196
197                                         echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . attribute_escape(sprintf(__('Edit "%s"'), $link->link_name)) . "'>$link->link_name</a></strong><br />";
198                                         $actions = array();
199                                         $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
200                                         $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf( __("You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete."), $link->link_name )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
201                                         $action_count = count($actions);
202                                         $i = 0;
203                                         echo '<div class="row-actions">';
204                                         foreach ( $actions as $action => $linkaction ) {
205                                                 ++$i;
206                                                 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
207                                                 echo "<span class='$action'>$linkaction$sep</span>";
208                                         }
209                                         echo '</div>';
210                                         echo '</td>';
211                                         break;
212                                 case 'url':
213                                         echo "<td $attributes><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
214                                         break;
215                                 case 'categories':
216                                         ?><td <?php echo $attributes ?>><?php
217                                         $cat_names = array();
218                                         foreach ($link->link_category as $category) {
219                                                 $cat = get_term($category, 'link_category', OBJECT, 'display');
220                                                 if ( is_wp_error( $cat ) )
221                                                         echo $cat->get_error_message();
222                                                 $cat_name = $cat->name;
223                                                 if ( $cat_id != $category )
224                                                         $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
225                                                 $cat_names[] = $cat_name;
226                                         }
227                                         echo implode(', ', $cat_names);
228                                         ?></td><?php
229                                         break;
230                                 case 'rel':
231                                         ?><td <?php echo $attributes ?>><?php echo $link->link_rel; ?></td><?php
232                                         break;
233                                 case 'visible':
234                                         ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
235                                         break;
236                                 default:
237                                         ?>
238                                         <td><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
239                                         <?php
240                                         break;
241
242                         }
243                 }
244                 echo "\n    </tr>\n";
245         }
246 ?>
247         </tbody>
248 </table>
249
250 <?php } else { ?>
251 <p><?php _e('No links found.') ?></p>
252 <?php } ?>
253
254 <div class="tablenav">
255
256 <div class="alignleft actions">
257 <select name="action2">
258 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
259 <option value="delete"><?php _e('Delete'); ?></option>
260 </select>
261 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
262 </div>
263
264 <br class="clear" />
265 </div>
266
267 </form>
268
269 <div id="ajax-response"></div>
270
271 </div>
272
273 <script type="text/javascript">
274 /* <![CDATA[ */
275 (function($){
276         $(document).ready(function(){
277                 $('#doaction, #doaction2').click(function(){
278                         if ( $('select[name^="action"]').val() == 'delete' ) {
279                                 var m = '<?php echo js_escape(__("You are about to delete the selected links.\n  'Cancel' to stop, 'OK' to delete.")); ?>';
280                                 return showNotice.warn(m);
281                         }
282                 });
283         });
284 })(jQuery);
285 columns.init('link-manager');
286 /* ]]> */
287 </script>
288
289 <?php include('admin-footer.php'); ?>