web/wp-admin/link-manager.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Link Management Administration Panel.
     3  * Link Management Administration Screen.
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /** Load WordPress Administration Bootstrap */
     9 /** Load WordPress Administration Bootstrap */
    10 require_once ('admin.php');
    10 require_once ('admin.php');
       
    11 if ( ! current_user_can( 'manage_links' ) )
       
    12 	wp_die( __( 'You do not have sufficient permissions to edit the links for this site.' ) );
       
    13 
       
    14 $wp_list_table = _get_list_table('WP_Links_List_Table');
    11 
    15 
    12 // Handle bulk deletes
    16 // Handle bulk deletes
    13 if ( isset($_GET['action']) && isset($_GET['linkcheck']) ) {
    17 $doaction = $wp_list_table->current_action();
    14 	check_admin_referer('bulk-bookmarks');
       
    15 	$doaction = $_GET['action'] ? $_GET['action'] : $_GET['action2'];
       
    16 
    18 
    17 	if ( ! current_user_can('manage_links') )
    19 if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
    18 		wp_die( __('You do not have sufficient permissions to edit the links for this blog.') );
    20 	check_admin_referer( 'bulk-bookmarks' );
    19 
    21 
    20 	if ( 'delete' == $doaction ) {
    22 	if ( 'delete' == $doaction ) {
    21 		$bulklinks = (array) $_GET['linkcheck'];
    23 		$bulklinks = (array) $_REQUEST['linkcheck'];
    22 		foreach ( $bulklinks as $link_id ) {
    24 		foreach ( $bulklinks as $link_id ) {
    23 			$link_id = (int) $link_id;
    25 			$link_id = (int) $link_id;
    24 
    26 
    25 			wp_delete_link($link_id);
    27 			wp_delete_link( $link_id );
    26 		}
    28 		}
    27 
    29 
    28 		wp_safe_redirect( wp_get_referer() );
    30 		wp_redirect( add_query_arg('deleted', count( $bulklinks ), admin_url( 'link-manager.php' ) ) );
    29 		exit;
    31 		exit;
    30 	}
    32 	}
    31 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
    33 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
    32 	 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
    34 	 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
    33 	 exit;
    35 	 exit;
    34 }
    36 }
    35 
    37 
    36 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[]'));
    38 $wp_list_table->prepare_items();
    37 
    39 
    38 if ( empty($cat_id) )
    40 $title = __('Links');
    39 	$cat_id = 'all';
    41 $this_file = $parent_file = 'link-manager.php';
    40 
    42 
    41 if ( empty($order_by) )
    43 get_current_screen()->add_help_tab( array(
    42 	$order_by = 'order_name';
    44 'id'		=> 'overview',
       
    45 'title'		=> __('Overview'),
       
    46 'content'	=>
       
    47 	'<p>' . sprintf(__('You can add links here to be displayed on your site, usually using <a href="%s">Widgets</a>. By default, links to several sites in the WordPress community are included as examples.'), 'widgets.php') . '</p>' .
       
    48     '<p>' . __('Links may be separated into Link Categories; these are different than the categories used on your posts.') . '</p>' .
       
    49     '<p>' . __('You can customize the display of this screen using the Screen Options tab and/or the dropdown filters above the links table.') . '</p>'
       
    50 ) );
       
    51 get_current_screen()->add_help_tab( array(
       
    52 'id'		=> 'deleting-links',
       
    53 'title'		=> __('Deleting Links'),
       
    54 'content'	=>
       
    55     '<p>' . __('If you delete a link, it will be removed permanently, as Links do not have a Trash function yet.') . '</p>'
       
    56 ) );
    43 
    57 
    44 $title = __('Edit Links');
    58 get_current_screen()->set_help_sidebar(
    45 $this_file = $parent_file = 'link-manager.php';
    59 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    46 include_once ("./admin-header.php");
    60 	'<p>' . __('<a href="http://codex.wordpress.org/Links_Screen" target="_blank">Documentation on Managing Links</a>') . '</p>' .
       
    61 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
       
    62 );
    47 
    63 
    48 if (!current_user_can('manage_links'))
    64 include_once ('./admin-header.php');
    49 	wp_die(__("You do not have sufficient permissions to edit the links for this blog."));
       
    50 
    65 
    51 switch ($order_by) {
    66 if ( ! current_user_can('manage_links') )
    52 	case 'order_id' :
    67 	wp_die(__("You do not have sufficient permissions to edit the links for this site."));
    53 		$sqlorderby = 'id';
    68 
    54 		break;
    69 ?>
    55 	case 'order_url' :
       
    56 		$sqlorderby = 'url';
       
    57 		break;
       
    58 	case 'order_desc' :
       
    59 		$sqlorderby = 'description';
       
    60 		break;
       
    61 	case 'order_owner' :
       
    62 		$sqlorderby = 'owner';
       
    63 		break;
       
    64 	case 'order_rating' :
       
    65 		$sqlorderby = 'rating';
       
    66 		break;
       
    67 	case 'order_name' :
       
    68 	default :
       
    69 		$sqlorderby = 'name';
       
    70 		break;
       
    71 } ?>
       
    72 
    70 
    73 <div class="wrap nosubsub">
    71 <div class="wrap nosubsub">
    74 <?php screen_icon(); ?>
    72 <?php screen_icon(); ?>
    75 <h2><?php echo esc_html( $title ); ?> <a href="link-add.php" class="button add-new-h2"><?php esc_html_e('Add New'); ?></a> <?php
    73 <h2><?php echo esc_html( $title ); ?> <a href="link-add.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'link'); ?></a> <?php
    76 if ( isset($_GET['s']) && $_GET['s'] )
    74 if ( !empty($_REQUEST['s']) )
    77 	printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
    75 	printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
    78 </h2>
    76 </h2>
    79 
    77 
    80 <?php
    78 <?php
    81 if ( isset($_GET['deleted']) ) {
    79 if ( isset($_REQUEST['deleted']) ) {
    82 	echo '<div id="message" class="updated fade"><p>';
    80 	echo '<div id="message" class="updated"><p>';
    83 	$deleted = (int) $_GET['deleted'];
    81 	$deleted = (int) $_REQUEST['deleted'];
    84 	printf(_n('%s link deleted.', '%s links deleted', $deleted), $deleted);
    82 	printf(_n('%s link deleted.', '%s links deleted', $deleted), $deleted);
    85 	echo '</p></div>';
    83 	echo '</p></div>';
    86 	$_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
    84 	$_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
    87 }
    85 }
    88 ?>
    86 ?>
    89 
    87 
    90 <form class="search-form" action="" method="get">
    88 <form id="posts-filter" action="" method="get">
    91 <p class="search-box">
       
    92 	<label class="screen-reader-text" for="link-search-input"><?php _e( 'Search Links' ); ?>:</label>
       
    93 	<input type="text" id="link-search-input" name="s" value="<?php _admin_search_query(); ?>" />
       
    94 	<input type="submit" value="<?php esc_attr_e( 'Search Links' ); ?>" class="button" />
       
    95 </p>
       
    96 </form>
       
    97 <br class="clear" />
       
    98 
    89 
    99 <form id="posts-filter" action="" method="get">
    90 <?php $wp_list_table->search_box( __( 'Search Links' ), 'link' ); ?>
   100 <div class="tablenav">
       
   101 
    91 
   102 <div class="alignleft actions">
    92 <?php $wp_list_table->display(); ?>
   103 <select name="action">
       
   104 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
       
   105 <option value="delete"><?php _e('Delete'); ?></option>
       
   106 </select>
       
   107 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
       
   108 
       
   109 <?php
       
   110 $categories = get_terms('link_category', "hide_empty=1");
       
   111 $select_cat = "<select name=\"cat_id\">\n";
       
   112 $select_cat .= '<option value="all"'  . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
       
   113 foreach ((array) $categories as $cat)
       
   114 	$select_cat .= '<option value="' . esc_attr($cat->term_id) . '"' . (($cat->term_id == $cat_id) ? " selected='selected'" : '') . '>' . sanitize_term_field('name', $cat->name, $cat->term_id, 'link_category', 'display') . "</option>\n";
       
   115 $select_cat .= "</select>\n";
       
   116 
       
   117 $select_order = "<select name=\"order_by\">\n";
       
   118 $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' .  __('Order by Link ID') . "</option>\n";
       
   119 $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' .  __('Order by Name') . "</option>\n";
       
   120 $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' .  __('Order by Address') . "</option>\n";
       
   121 $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' .  __('Order by Rating') . "</option>\n";
       
   122 $select_order .= "</select>\n";
       
   123 
       
   124 echo $select_cat;
       
   125 echo $select_order;
       
   126 
       
   127 ?>
       
   128 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
       
   129 
       
   130 </div>
       
   131 
       
   132 <br class="clear" />
       
   133 </div>
       
   134 
       
   135 <div class="clear"></div>
       
   136 
       
   137 <?php
       
   138 if ( 'all' == $cat_id )
       
   139 	$cat_id = '';
       
   140 $args = array('category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0);
       
   141 if ( !empty($_GET['s']) )
       
   142 	$args['search'] = $_GET['s'];
       
   143 $links = get_bookmarks( $args );
       
   144 if ( $links ) {
       
   145 	$link_columns = get_column_headers('link-manager');
       
   146 	$hidden = get_hidden_columns('link-manager');
       
   147 ?>
       
   148 
       
   149 <?php wp_nonce_field('bulk-bookmarks') ?>
       
   150 <table class="widefat fixed" cellspacing="0">
       
   151 	<thead>
       
   152 	<tr>
       
   153 <?php print_column_headers('link-manager'); ?>
       
   154 	</tr>
       
   155 	</thead>
       
   156 
       
   157 	<tfoot>
       
   158 	<tr>
       
   159 <?php print_column_headers('link-manager', false); ?>
       
   160 	</tr>
       
   161 	</tfoot>
       
   162 
       
   163 	<tbody>
       
   164 <?php
       
   165 	$alt = 0;
       
   166 
       
   167 	foreach ($links as $link) {
       
   168 		$link = sanitize_bookmark($link);
       
   169 		$link->link_name = esc_attr($link->link_name);
       
   170 		$link->link_category = wp_get_link_cats($link->link_id);
       
   171 		$short_url = str_replace('http://', '', $link->link_url);
       
   172 		$short_url = preg_replace('/^www\./i', '', $short_url);
       
   173 		if ('/' == substr($short_url, -1))
       
   174 			$short_url = substr($short_url, 0, -1);
       
   175 		if (strlen($short_url) > 35)
       
   176 			$short_url = substr($short_url, 0, 32).'...';
       
   177 		$visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
       
   178 		$rating  = $link->link_rating;
       
   179 		$style = ($alt % 2) ? '' : ' class="alternate"';
       
   180 		++ $alt;
       
   181 		$edit_link = get_edit_bookmark_link();
       
   182 		?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
       
   183 		foreach($link_columns as $column_name=>$column_display_name) {
       
   184 			$class = "class=\"column-$column_name\"";
       
   185 
       
   186 			$style = '';
       
   187 			if ( in_array($column_name, $hidden) )
       
   188 				$style = ' style="display:none;"';
       
   189 
       
   190 			$attributes = "$class$style";
       
   191 
       
   192 			switch($column_name) {
       
   193 				case 'cb':
       
   194 					echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr($link->link_id) .'" /></th>';
       
   195 					break;
       
   196 				case 'name':
       
   197 
       
   198 					echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $link->link_name)) . "'>$link->link_name</a></strong><br />";
       
   199 					$actions = array();
       
   200 					$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
       
   201 					$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('" . esc_js(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>";
       
   202 					$action_count = count($actions);
       
   203 					$i = 0;
       
   204 					echo '<div class="row-actions">';
       
   205 					foreach ( $actions as $action => $linkaction ) {
       
   206 						++$i;
       
   207 						( $i == $action_count ) ? $sep = '' : $sep = ' | ';
       
   208 						echo "<span class='$action'>$linkaction$sep</span>";
       
   209 					}
       
   210 					echo '</div>';
       
   211 					echo '</td>';
       
   212 					break;
       
   213 				case 'url':
       
   214 					echo "<td $attributes><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
       
   215 					break;
       
   216 				case 'categories':
       
   217 					?><td <?php echo $attributes ?>><?php
       
   218 					$cat_names = array();
       
   219 					foreach ($link->link_category as $category) {
       
   220 						$cat = get_term($category, 'link_category', OBJECT, 'display');
       
   221 						if ( is_wp_error( $cat ) )
       
   222 							echo $cat->get_error_message();
       
   223 						$cat_name = $cat->name;
       
   224 						if ( $cat_id != $category )
       
   225 							$cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
       
   226 						$cat_names[] = $cat_name;
       
   227 					}
       
   228 					echo implode(', ', $cat_names);
       
   229 					?></td><?php
       
   230 					break;
       
   231 				case 'rel':
       
   232 					?><td <?php echo $attributes ?>><?php echo empty($link->link_rel) ? '<br />' : $link->link_rel; ?></td><?php
       
   233 					break;
       
   234 				case 'visible':
       
   235 					?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
       
   236 					break;
       
   237 				case 'rating':
       
   238  					?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
       
   239 					break;
       
   240 				default:
       
   241 					?>
       
   242 					<td><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
       
   243 					<?php
       
   244 					break;
       
   245 
       
   246 			}
       
   247 		}
       
   248 		echo "\n    </tr>\n";
       
   249 	}
       
   250 ?>
       
   251 	</tbody>
       
   252 </table>
       
   253 
       
   254 <?php } else { ?>
       
   255 <p><?php _e('No links found.') ?></p>
       
   256 <?php } ?>
       
   257 
       
   258 <div class="tablenav">
       
   259 
       
   260 <div class="alignleft actions">
       
   261 <select name="action2">
       
   262 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
       
   263 <option value="delete"><?php _e('Delete'); ?></option>
       
   264 </select>
       
   265 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
       
   266 </div>
       
   267 
       
   268 <br class="clear" />
       
   269 </div>
       
   270 
       
   271 </form>
       
   272 
    93 
   273 <div id="ajax-response"></div>
    94 <div id="ajax-response"></div>
       
    95 </form>
   274 
    96 
   275 </div>
    97 </div>
   276 
    98 
   277 <?php
    99 <?php
   278 include('admin-footer.php');
   100 include('./admin-footer.php');