home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / link-manager.php < prev    next >
Encoding:
PHP Script  |  2008-05-04  |  7.3 KB  |  229 lines

  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.     <label class="hidden" for="post-search-input"><?php _e( 'Search Links' ); ?>:</label>
  82.     <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
  83.     <input type="submit" value="<?php _e( 'Search Links' ); ?>" class="button" />
  84. </p>
  85.  
  86. <br class="clear" />
  87.  
  88. <div class="tablenav">
  89.  
  90. <div class="alignleft">
  91. <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
  92. <?php
  93. $categories = get_terms('link_category', "hide_empty=1");
  94. $select_cat = "<select name=\"cat_id\">\n";
  95. $select_cat .= '<option value="all"'  . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
  96. foreach ((array) $categories as $cat)
  97.     $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";
  98. $select_cat .= "</select>\n";
  99.  
  100. $select_order = "<select name=\"order_by\">\n";
  101. $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' .  __('Order by Link ID') . "</option>\n";
  102. $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' .  __('Order by Name') . "</option>\n";
  103. $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' .  __('Order by Address') . "</option>\n";
  104. $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' .  __('Order by Rating') . "</option>\n";
  105. $select_order .= "</select>\n";
  106.  
  107. echo $select_cat;
  108. echo $select_order;
  109.  
  110. ?>
  111. <input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
  112.  
  113. </div>
  114.  
  115. <br class="clear" />
  116. </div>
  117.  
  118. <br class="clear" />
  119.  
  120. <?php
  121. $link_columns = array(
  122.     'name'       => '<th style="width: 15%;">' . __('Name') . '</th>',
  123.     'url'       => '<th>' . __('URL') . '</th>',
  124.     'categories' => '<th>' . __('Categories') . '</th>',
  125.     'rel'      => '<th style="text-align: center">' . __('rel') . '</th>',
  126.     'visible'   => '<th style="text-align: center">' . __('Visible') . '</th>',
  127. );
  128. $link_columns = apply_filters('manage_link_columns', $link_columns);
  129. ?>
  130.  
  131. <?php
  132. if ( 'all' == $cat_id )
  133.     $cat_id = '';
  134. $args = array('category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0);
  135. if ( !empty($_GET['s']) )
  136.     $args['search'] = $_GET['s'];
  137. $links = get_bookmarks( $args );
  138. if ( $links ) {
  139. ?>
  140.  
  141. <?php wp_nonce_field('bulk-bookmarks') ?>
  142. <table class="widefat">
  143.     <thead>
  144.     <tr>
  145.     <th scope="col" class="check-column"><input type="checkbox" /></th>
  146. <?php foreach($link_columns as $column_display_name) {
  147.     echo $column_display_name;
  148. } ?>
  149.     </tr>
  150.     </thead>
  151.     <tbody>
  152. <?php
  153.     foreach ($links as $link) {
  154.         $link = sanitize_bookmark($link);
  155.         $link->link_name = attribute_escape($link->link_name);
  156.         $link->link_category = wp_get_link_cats($link->link_id);
  157.         $short_url = str_replace('http://', '', $link->link_url);
  158.         $short_url = str_replace('www.', '', $short_url);
  159.         if ('/' == substr($short_url, -1))
  160.             $short_url = substr($short_url, 0, -1);
  161.         if (strlen($short_url) > 35)
  162.             $short_url = substr($short_url, 0, 32).'...';
  163.  
  164.         $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
  165.         ++ $i;
  166.         $style = ($i % 2) ? '' : ' class="alternate"';
  167.         ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
  168.         echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'.$link->link_id.'" /></th>';
  169.         foreach($link_columns as $column_name=>$column_display_name) {
  170.             switch($column_name) {
  171.                 case 'name':
  172.  
  173.                     echo "<td><strong><a class='row-title' href='link.php?link_id=$link->link_id&action=edit' title='" . attribute_escape(sprintf(__('Edit "%s"'), $link->link_name)) . "' class='edit'>$link->link_name</a></strong><br />";
  174.                     echo $link->link_description . "</td>";
  175.                     break;
  176.                 case 'url':
  177.                     echo "<td><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
  178.                     break;
  179.                 case 'categories':
  180.                     ?><td><?php
  181.                     $cat_names = array();
  182.                     foreach ($link->link_category as $category) {
  183.                         $cat = get_term($category, 'link_category', OBJECT, 'display');
  184.                         if ( is_wp_error( $cat ) )
  185.                             echo $cat->get_error_message();
  186.                         $cat_name = $cat->name;
  187.                         if ( $cat_id != $category )
  188.                             $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
  189.                         $cat_names[] = $cat_name;
  190.                     }
  191.                     echo implode(', ', $cat_names);
  192.                     ?> </td><?php
  193.                     break;
  194.                 case 'rel':
  195.                     ?><td><?php echo $link->link_rel; ?></td><?php
  196.                     break;
  197.                 case 'visible':
  198.                     ?><td style='text-align: center;'><?php echo $visible; ?></td><?php
  199.                     break;
  200.                 default:
  201.                     ?>
  202.                     <td><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
  203.                     <?php
  204.                     break;
  205.  
  206.             }
  207.         }
  208.         echo "\n    </tr>\n";
  209.     }
  210. ?>
  211.     </tbody>
  212. </table>
  213.  
  214. <?php } else { ?>
  215. <p><?php _e('No links found.') ?></p>
  216. <?php } ?>
  217. </form>
  218.  
  219. <div id="ajax-response"></div>
  220.  
  221. <div class="tablenav">
  222. <br class="clear" />
  223. </div>
  224.  
  225.  
  226. </div>
  227.  
  228. <?php include('admin-footer.php'); ?>
  229.