link.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Manage link administration actions.
  4. *
  5. * This page is accessed by the link management pages and handles the forms and
  6. * Ajax processes for link actions.
  7. *
  8. * @package WordPress
  9. * @subpackage Administration
  10. */
  11. /** Load WordPress Administration Bootstrap */
  12. require_once( dirname( __FILE__ ) . '/admin.php' );
  13. wp_reset_vars( array( 'action', 'cat_id', 'link_id' ) );
  14. if ( ! current_user_can('manage_links') )
  15. wp_link_manager_disabled_message();
  16. if ( !empty($_POST['deletebookmarks']) )
  17. $action = 'deletebookmarks';
  18. if ( !empty($_POST['move']) )
  19. $action = 'move';
  20. if ( !empty($_POST['linkcheck']) )
  21. $linkcheck = $_POST['linkcheck'];
  22. $this_file = admin_url('link-manager.php');
  23. switch ($action) {
  24. case 'deletebookmarks' :
  25. check_admin_referer('bulk-bookmarks');
  26. // For each link id (in $linkcheck[]) change category to selected value.
  27. if (count($linkcheck) == 0) {
  28. wp_redirect($this_file);
  29. exit;
  30. }
  31. $deleted = 0;
  32. foreach ($linkcheck as $link_id) {
  33. $link_id = (int) $link_id;
  34. if ( wp_delete_link($link_id) )
  35. $deleted++;
  36. }
  37. wp_redirect("$this_file?deleted=$deleted");
  38. exit;
  39. case 'move' :
  40. check_admin_referer('bulk-bookmarks');
  41. // For each link id (in $linkcheck[]) change category to selected value.
  42. if (count($linkcheck) == 0) {
  43. wp_redirect($this_file);
  44. exit;
  45. }
  46. $all_links = join(',', $linkcheck);
  47. /*
  48. * Should now have an array of links we can change:
  49. * $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
  50. */
  51. wp_redirect($this_file);
  52. exit;
  53. case 'add' :
  54. check_admin_referer('add-bookmark');
  55. $redir = wp_get_referer();
  56. if ( add_link() )
  57. $redir = add_query_arg( 'added', 'true', $redir );
  58. wp_redirect( $redir );
  59. exit;
  60. case 'save' :
  61. $link_id = (int) $_POST['link_id'];
  62. check_admin_referer('update-bookmark_' . $link_id);
  63. edit_link($link_id);
  64. wp_redirect($this_file);
  65. exit;
  66. case 'delete' :
  67. $link_id = (int) $_GET['link_id'];
  68. check_admin_referer('delete-bookmark_' . $link_id);
  69. wp_delete_link($link_id);
  70. wp_redirect($this_file);
  71. exit;
  72. case 'edit' :
  73. wp_enqueue_script('link');
  74. wp_enqueue_script('xfn');
  75. if ( wp_is_mobile() )
  76. wp_enqueue_script( 'jquery-touch-punch' );
  77. $parent_file = 'link-manager.php';
  78. $submenu_file = 'link-manager.php';
  79. $title = __('Edit Link');
  80. $link_id = (int) $_GET['link_id'];
  81. if (!$link = get_link_to_edit($link_id))
  82. wp_die(__('Link not found.'));
  83. include( ABSPATH . 'wp-admin/edit-link-form.php' );
  84. include( ABSPATH . 'wp-admin/admin-footer.php' );
  85. break;
  86. default :
  87. break;
  88. }