]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/link-manager.php
Wordpress 2.5.1-scripts
[autoinstalls/wordpress.git] / wp-admin / link-manager.php
1 <?php
2
3 require_once ('admin.php');
4
5 // Handle bulk deletes
6 if ( isset($_GET['deleteit']) && isset($_GET['linkcheck']) ) {
7         check_admin_referer('bulk-bookmarks');
8
9         if ( ! current_user_can('manage_links') )
10                 wp_die( __('You do not have sufficient permissions to edit the links for this blog.') );
11
12         foreach ( (array) $_GET['linkcheck'] as $link_id) {
13                 $link_id = (int) $link_id;
14
15                 wp_delete_link($link_id);
16         }
17
18         $sendback = wp_get_referer();
19         $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
20         wp_redirect($sendback);
21         exit;
22 } elseif ( !empty($_GET['_wp_http_referer']) ) {
23          wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
24          exit;
25 }
26
27 wp_enqueue_script('admin-forms');
28
29 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[]'));
30
31 if (empty ($cat_id))
32         $cat_id = 'all';
33
34 if (empty ($order_by))
35         $order_by = 'order_name';
36
37 $title = __('Manage Links');
38 $this_file = $parent_file = 'edit.php';
39 include_once ("./admin-header.php");
40
41 if (!current_user_can('manage_links'))
42         wp_die(__("You do not have sufficient permissions to edit the links for this blog."));
43
44 switch ($order_by) {
45         case 'order_id' :
46                 $sqlorderby = 'id';
47                 break;
48         case 'order_url' :
49                 $sqlorderby = 'url';
50                 break;
51         case 'order_desc' :
52                 $sqlorderby = 'description';
53                 break;
54         case 'order_owner' :
55                 $sqlorderby = 'owner';
56                 break;
57         case 'order_rating' :
58                 $sqlorderby = 'rating';
59                 break;
60         case 'order_name' :
61         default :
62                 $sqlorderby = 'name';
63                 break;
64 }
65
66 if ( isset($_GET['deleted']) ) {
67         echo '<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p>';
68         $deleted = (int) $_GET['deleted'];
69         printf(__ngettext('%s link deleted.', '%s links deleted', $deleted), $deleted);
70         echo '</p></div>';
71         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
72 }
73 ?>
74
75 <div class="wrap">
76
77 <form id="posts-filter" action="" method="get">
78 <h2><?php printf( __( 'Manage Links (<a href="%s">add new</a>)' ), 'link-add.php' ); ?></h2>
79
80 <p id="post-search">
81         <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
82         <input type="submit" value="<?php _e( 'Search Links' ); ?>" class="button" />
83 </p>
84
85 <br class="clear" />
86
87 <div class="tablenav">
88
89 <div class="alignleft">
90 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
91 <?php
92 $categories = get_terms('link_category', "hide_empty=1");
93 $select_cat = "<select name=\"cat_id\">\n";
94 $select_cat .= '<option value="all"'  . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
95 foreach ((array) $categories as $cat)
96         $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";
97 $select_cat .= "</select>\n";
98
99 $select_order = "<select name=\"order_by\">\n";
100 $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' .  __('Order by Link ID') . "</option>\n";
101 $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' .  __('Order by Name') . "</option>\n";
102 $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' .  __('Order by Address') . "</option>\n";
103 $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' .  __('Order by Rating') . "</option>\n";
104 $select_order .= "</select>\n";
105
106 echo $select_cat;
107 echo $select_order;
108
109 ?>
110 <input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
111
112 </div>
113
114 <br class="clear" />
115 </div>
116
117 <br class="clear" />
118
119 <?php
120 $link_columns = array(
121         'name'       => '<th style="width: 15%;">' . __('Name') . '</th>',
122         'url'       => '<th>' . __('URL') . '</th>',
123         'categories' => '<th>' . __('Categories') . '</th>',
124         'rel'      => '<th style="text-align: center">' . __('rel') . '</th>',
125         'visible'   => '<th style="text-align: center">' . __('Visible') . '</th>',
126 );
127 $link_columns = apply_filters('manage_link_columns', $link_columns);
128 ?>
129
130 <?php
131 if ( 'all' == $cat_id )
132         $cat_id = '';
133 $args = array('category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0);
134 if ( !empty($_GET['s']) )
135         $args['search'] = $_GET['s'];
136 $links = get_bookmarks( $args );
137 if ( $links ) {
138 ?>
139
140 <?php wp_nonce_field('bulk-bookmarks') ?>
141 <table class="widefat">
142         <thead>
143         <tr>
144         <th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('posts-filter'));" /></th>
145 <?php foreach($link_columns as $column_display_name) {
146         echo $column_display_name;
147 } ?>
148         </tr>
149         </thead>
150         <tbody>
151 <?php
152         foreach ($links as $link) {
153                 $link = sanitize_bookmark($link);
154                 $link->link_name = attribute_escape($link->link_name);
155                 $link->link_category = wp_get_link_cats($link->link_id);
156                 $short_url = str_replace('http://', '', $link->link_url);
157                 $short_url = str_replace('www.', '', $short_url);
158                 if ('/' == substr($short_url, -1))
159                         $short_url = substr($short_url, 0, -1);
160                 if (strlen($short_url) > 35)
161                         $short_url = substr($short_url, 0, 32).'...';
162
163                 $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
164                 ++ $i;
165                 $style = ($i % 2) ? '' : ' class="alternate"';
166                 ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
167                 echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'.$link->link_id.'" /></th>';
168                 foreach($link_columns as $column_name=>$column_display_name) {
169                         switch($column_name) {
170                                 case 'name':
171
172                                         echo "<td><strong><a class='row-title' href='link.php?link_id=$link->link_id&amp;action=edit' title='" . attribute_escape(sprintf(__('Edit "%s"'), $link->link_name)) . "' class='edit'>$link->link_name</a></strong><br />";
173                                         echo $link->link_description . "</td>";
174                                         break;
175                                 case 'url':
176                                         echo "<td><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
177                                         break;
178                                 case 'categories':
179                                         ?><td><?php
180                                         $cat_names = array();
181                                         foreach ($link->link_category as $category) {
182                                                 $cat = get_term($category, 'link_category', OBJECT, 'display');
183                                                 if ( is_wp_error( $cat ) )
184                                                         echo $cat->get_error_message();
185                                                 $cat_name = $cat->name;
186                                                 if ( $cat_id != $category )
187                                                         $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
188                                                 $cat_names[] = $cat_name;
189                                         }
190                                         echo implode(', ', $cat_names);
191                                         ?> </td><?php
192                                         break;
193                                 case 'rel':
194                                         ?><td><?php echo $link->link_rel; ?></td><?php
195                                         break;
196                                 case 'visible':
197                                         ?><td style='text-align: center;'><?php echo $visible; ?></td><?php
198                                         break;
199                                 default:
200                                         ?>
201                                         <td><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
202                                         <?php
203                                         break;
204
205                         }
206                 }
207                 echo "\n    </tr>\n";
208         }
209 ?>
210         </tbody>
211 </table>
212
213 <?php } else { ?>
214 <p><?php _e('No links found.') ?></p>
215 <?php } ?>
216 </form>
217
218 <div id="ajax-response"></div>
219
220 <div class="tablenav">
221 <br class="clear" />
222 </div>
223
224
225 </div>
226
227 <?php include('admin-footer.php'); ?>