[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/wp-admin/ -> link-manager.php (source)

   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          $bulklinks = (array) $_GET['linkcheck'];
  22          foreach ( $bulklinks as $link_id ) {
  23              $link_id = (int) $link_id;
  24  
  25              wp_delete_link($link_id);
  26          }
  27  
  28          wp_safe_redirect( wp_get_referer() );
  29          exit;
  30      }
  31  } elseif ( ! empty($_GET['_wp_http_referer']) ) {
  32       wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
  33       exit;
  34  }
  35  
  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[]'));
  37  
  38  if ( empty($cat_id) )
  39      $cat_id = 'all';
  40  
  41  if ( empty($order_by) )
  42      $order_by = 'order_name';
  43  
  44  $title = __('Edit Links');
  45  $this_file = $parent_file = 'link-manager.php';
  46  include_once  ('./admin-header.php');
  47  
  48  if ( ! current_user_can('manage_links') )
  49      wp_die(__("You do not have sufficient permissions to edit the links for this blog."));
  50  
  51  switch ($order_by) {
  52      case 'order_id' :
  53          $sqlorderby = 'id';
  54          break;
  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  
  73  <div class="wrap nosubsub">
  74  <?php screen_icon(); ?>
  75  <h2><?php echo esc_html( $title ); ?> <a href="link-add.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'link'); ?></a> <?php
  76  if ( !empty($_GET['s']) )
  77      printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
  78  </h2>
  79  
  80  <?php
  81  if ( isset($_GET['deleted']) ) {
  82      echo '<div id="message" class="updated"><p>';
  83      $deleted = (int) $_GET['deleted'];
  84      printf(_n('%s link deleted.', '%s links deleted', $deleted), $deleted);
  85      echo '</p></div>';
  86      $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
  87  }
  88  ?>
  89  
  90  <form class="search-form" 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  
  99  <form id="posts-filter" action="" method="get">
 100  <div class="tablenav">
 101  
 102  <?php
 103  if ( 'all' == $cat_id )
 104      $cat_id = '';
 105  $args = array( 'category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0 );
 106  if ( ! empty( $_GET['s'] ) )
 107      $args['search'] = $_GET['s'];
 108  $links = get_bookmarks( $args );
 109  if ( $links ) {
 110  ?>
 111  
 112  <div class="alignleft actions">
 113  <select name="action">
 114  <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
 115  <option value="delete"><?php _e('Delete'); ?></option>
 116  </select>
 117  <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
 118  
 119  <?php
 120  $categories = get_terms('link_category', array("hide_empty" => 1));
 121  $select_cat = "<select name=\"cat_id\">\n";
 122  $select_cat .= '<option value="all"'  . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
 123  foreach ((array) $categories as $cat)
 124      $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";
 125  $select_cat .= "</select>\n";
 126  
 127  $select_order = "<select name=\"order_by\">\n";
 128  $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' .  __('Order by Link ID') . "</option>\n";
 129  $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' .  __('Order by Name') . "</option>\n";
 130  $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' .  __('Order by Address') . "</option>\n";
 131  $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' .  __('Order by Rating') . "</option>\n";
 132  $select_order .= "</select>\n";
 133  
 134  echo $select_cat;
 135  echo $select_order;
 136  
 137  ?>
 138  <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
 139  
 140  </div>
 141  
 142  <br class="clear" />
 143  </div>
 144  
 145  <div class="clear"></div>
 146  
 147  <?php
 148      $link_columns = get_column_headers('link-manager');
 149      $hidden = get_hidden_columns('link-manager');
 150  ?>
 151  
 152  <?php wp_nonce_field('bulk-bookmarks') ?>
 153  <table class="widefat fixed" cellspacing="0">
 154      <thead>
 155      <tr>
 156  <?php print_column_headers('link-manager'); ?>
 157      </tr>
 158      </thead>
 159  
 160      <tfoot>
 161      <tr>
 162  <?php print_column_headers('link-manager', false); ?>
 163      </tr>
 164      </tfoot>
 165  
 166      <tbody>
 167  <?php
 168      $alt = 0;
 169  
 170      foreach ($links as $link) {
 171          $link = sanitize_bookmark($link);
 172          $link->link_name = esc_attr($link->link_name);
 173          $link->link_category = wp_get_link_cats($link->link_id);
 174          $short_url = str_replace('http://', '', $link->link_url);
 175          $short_url = preg_replace('/^www\./i', '', $short_url);
 176          if ('/' == substr($short_url, -1))
 177              $short_url = substr($short_url, 0, -1);
 178          if (strlen($short_url) > 35)
 179              $short_url = substr($short_url, 0, 32).'...';
 180          $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
 181          $rating  = $link->link_rating;
 182          $style = ($alt % 2) ? '' : ' class="alternate"';
 183          ++ $alt;
 184          $edit_link = get_edit_bookmark_link();
 185          ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
 186          foreach($link_columns as $column_name=>$column_display_name) {
 187              $class = "class=\"column-$column_name\"";
 188  
 189              $style = '';
 190              if ( in_array($column_name, $hidden) )
 191                  $style = ' style="display:none;"';
 192  
 193              $attributes = "$class$style";
 194  
 195              switch($column_name) {
 196                  case 'cb':
 197                      echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr($link->link_id) .'" /></th>';
 198                      break;
 199                  case 'name':
 200  
 201                      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 />";
 202                      $actions = array();
 203                      $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
 204                      $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>";
 205                      $action_count = count($actions);
 206                      $i = 0;
 207                      echo '<div class="row-actions">';
 208                      foreach ( $actions as $action => $linkaction ) {
 209                          ++$i;
 210                          ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
 211                          echo "<span class='$action'>$linkaction$sep</span>";
 212                      }
 213                      echo '</div>';
 214                      echo '</td>';
 215                      break;
 216                  case 'url':
 217                      echo "<td $attributes><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
 218                      break;
 219                  case 'categories':
 220                      ?><td <?php echo $attributes ?>><?php
 221                      $cat_names = array();
 222                      foreach ($link->link_category as $category) {
 223                          $cat = get_term($category, 'link_category', OBJECT, 'display');
 224                          if ( is_wp_error( $cat ) )
 225                              echo $cat->get_error_message();
 226                          $cat_name = $cat->name;
 227                          if ( $cat_id != $category )
 228                              $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
 229                          $cat_names[] = $cat_name;
 230                      }
 231                      echo implode(', ', $cat_names);
 232                      ?></td><?php
 233                      break;
 234                  case 'rel':
 235                      ?><td <?php echo $attributes ?>><?php echo empty($link->link_rel) ? '<br />' : $link->link_rel; ?></td><?php
 236                      break;
 237                  case 'visible':
 238                      ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
 239                      break;
 240                  case 'rating':
 241                       ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
 242                      break;
 243                  default:
 244                      ?>
 245                      <td <?php echo $attributes ?>><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
 246                      <?php
 247                      break;
 248  
 249              }
 250          }
 251          echo "\n    </tr>\n";
 252      }
 253  ?>
 254      </tbody>
 255  </table>
 256  
 257  <div class="tablenav">
 258  
 259  <div class="alignleft actions">
 260  <select name="action2">
 261  <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
 262  <option value="delete"><?php _e('Delete'); ?></option>
 263  </select>
 264  <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
 265  </div>
 266  
 267  <?php } else { ?>
 268  <p><?php _e( 'No links found.' ) ?></p>
 269  <?php } ?>
 270  
 271  <br class="clear" />
 272  </div>
 273  
 274  </form>
 275  
 276  <div id="ajax-response"></div>
 277  
 278  </div>
 279  
 280  <?php
 281  include ('admin-footer.php');


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7