PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/msw/dev/wp-admin/link-manager.php

https://github.com/chrissiebrodigan/USC
PHP | 281 lines | 230 code | 43 blank | 8 comment | 32 complexity | ddedeb362131efa8469f11a283704ae5 MD5 | raw file
  1. <?php
  2. /**
  3. * Link Management Administration Panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** Load WordPress Administration Bootstrap */
  9. require_once ('admin.php');
  10. // Handle bulk deletes
  11. if ( isset($_GET['action']) && isset($_GET['linkcheck']) ) {
  12. check_admin_referer('bulk-bookmarks');
  13. $doaction = $_GET['action'] ? $_GET['action'] : $_GET['action2'];
  14. if ( ! current_user_can('manage_links') )
  15. wp_die( __('You do not have sufficient permissions to edit the links for this site.') );
  16. if ( 'delete' == $doaction ) {
  17. $bulklinks = (array) $_GET['linkcheck'];
  18. foreach ( $bulklinks as $link_id ) {
  19. $link_id = (int) $link_id;
  20. wp_delete_link($link_id);
  21. }
  22. wp_safe_redirect( wp_get_referer() );
  23. exit;
  24. }
  25. } elseif ( ! empty($_GET['_wp_http_referer']) ) {
  26. wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
  27. exit;
  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. if ( empty($cat_id) )
  31. $cat_id = 'all';
  32. if ( empty($order_by) )
  33. $order_by = 'order_name';
  34. $title = __('Edit Links');
  35. $this_file = $parent_file = 'link-manager.php';
  36. include_once ('./admin-header.php');
  37. if ( ! current_user_can('manage_links') )
  38. wp_die(__("You do not have sufficient permissions to edit the links for this site."));
  39. switch ($order_by) {
  40. case 'order_id' :
  41. $sqlorderby = 'id';
  42. break;
  43. case 'order_url' :
  44. $sqlorderby = 'url';
  45. break;
  46. case 'order_desc' :
  47. $sqlorderby = 'description';
  48. break;
  49. case 'order_owner' :
  50. $sqlorderby = 'owner';
  51. break;
  52. case 'order_rating' :
  53. $sqlorderby = 'rating';
  54. break;
  55. case 'order_name' :
  56. default :
  57. $sqlorderby = 'name';
  58. break;
  59. } ?>
  60. <div class="wrap nosubsub">
  61. <?php screen_icon(); ?>
  62. <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
  63. if ( !empty($_GET['s']) )
  64. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
  65. </h2>
  66. <?php
  67. if ( isset($_GET['deleted']) ) {
  68. echo '<div id="message" class="updated"><p>';
  69. $deleted = (int) $_GET['deleted'];
  70. printf(_n('%s link deleted.', '%s links deleted', $deleted), $deleted);
  71. echo '</p></div>';
  72. $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
  73. }
  74. ?>
  75. <form class="search-form" action="" method="get">
  76. <p class="search-box">
  77. <label class="screen-reader-text" for="link-search-input"><?php _e( 'Search Links' ); ?>:</label>
  78. <input type="text" id="link-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  79. <input type="submit" value="<?php esc_attr_e( 'Search Links' ); ?>" class="button" />
  80. </p>
  81. </form>
  82. <br class="clear" />
  83. <form id="posts-filter" action="" method="get">
  84. <div class="tablenav">
  85. <?php
  86. if ( 'all' == $cat_id )
  87. $cat_id = '';
  88. $args = array( 'category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0 );
  89. if ( ! empty( $_GET['s'] ) )
  90. $args['search'] = $_GET['s'];
  91. $links = get_bookmarks( $args );
  92. if ( $links ) {
  93. ?>
  94. <div class="alignleft actions">
  95. <select name="action">
  96. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  97. <option value="delete"><?php _e('Delete'); ?></option>
  98. </select>
  99. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  100. <?php
  101. $categories = get_terms('link_category', array("hide_empty" => 1));
  102. $select_cat = "<select name=\"cat_id\">\n";
  103. $select_cat .= '<option value="all"' . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
  104. foreach ((array) $categories as $cat)
  105. $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";
  106. $select_cat .= "</select>\n";
  107. $select_order = "<select name=\"order_by\">\n";
  108. $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' . __('Order by Link ID') . "</option>\n";
  109. $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' . __('Order by Name') . "</option>\n";
  110. $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' . __('Order by Address') . "</option>\n";
  111. $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' . __('Order by Rating') . "</option>\n";
  112. $select_order .= "</select>\n";
  113. echo $select_cat;
  114. echo $select_order;
  115. ?>
  116. <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
  117. </div>
  118. <br class="clear" />
  119. </div>
  120. <div class="clear"></div>
  121. <?php
  122. $link_columns = get_column_headers('link-manager');
  123. $hidden = get_hidden_columns('link-manager');
  124. ?>
  125. <?php wp_nonce_field('bulk-bookmarks') ?>
  126. <table class="widefat fixed" cellspacing="0">
  127. <thead>
  128. <tr>
  129. <?php print_column_headers('link-manager'); ?>
  130. </tr>
  131. </thead>
  132. <tfoot>
  133. <tr>
  134. <?php print_column_headers('link-manager', false); ?>
  135. </tr>
  136. </tfoot>
  137. <tbody>
  138. <?php
  139. $alt = 0;
  140. foreach ($links as $link) {
  141. $link = sanitize_bookmark($link);
  142. $link->link_name = esc_attr($link->link_name);
  143. $link->link_category = wp_get_link_cats($link->link_id);
  144. $short_url = str_replace('http://', '', $link->link_url);
  145. $short_url = preg_replace('/^www\./i', '', $short_url);
  146. if ('/' == substr($short_url, -1))
  147. $short_url = substr($short_url, 0, -1);
  148. if (strlen($short_url) > 35)
  149. $short_url = substr($short_url, 0, 32).'...';
  150. $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
  151. $rating = $link->link_rating;
  152. $style = ($alt % 2) ? '' : ' class="alternate"';
  153. ++ $alt;
  154. $edit_link = get_edit_bookmark_link();
  155. ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
  156. foreach($link_columns as $column_name=>$column_display_name) {
  157. $class = "class=\"column-$column_name\"";
  158. $style = '';
  159. if ( in_array($column_name, $hidden) )
  160. $style = ' style="display:none;"';
  161. $attributes = "$class$style";
  162. switch($column_name) {
  163. case 'cb':
  164. echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr($link->link_id) .'" /></th>';
  165. break;
  166. case 'name':
  167. 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 />";
  168. $actions = array();
  169. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  170. $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>";
  171. $action_count = count($actions);
  172. $i = 0;
  173. echo '<div class="row-actions">';
  174. foreach ( $actions as $action => $linkaction ) {
  175. ++$i;
  176. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  177. echo "<span class='$action'>$linkaction$sep</span>";
  178. }
  179. echo '</div>';
  180. echo '</td>';
  181. break;
  182. case 'url':
  183. echo "<td $attributes><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
  184. break;
  185. case 'categories':
  186. ?><td <?php echo $attributes ?>><?php
  187. $cat_names = array();
  188. foreach ($link->link_category as $category) {
  189. $cat = get_term($category, 'link_category', OBJECT, 'display');
  190. if ( is_wp_error( $cat ) )
  191. echo $cat->get_error_message();
  192. $cat_name = $cat->name;
  193. if ( $cat_id != $category )
  194. $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
  195. $cat_names[] = $cat_name;
  196. }
  197. echo implode(', ', $cat_names);
  198. ?></td><?php
  199. break;
  200. case 'rel':
  201. ?><td <?php echo $attributes ?>><?php echo empty($link->link_rel) ? '<br />' : $link->link_rel; ?></td><?php
  202. break;
  203. case 'visible':
  204. ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
  205. break;
  206. case 'rating':
  207. ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
  208. break;
  209. default:
  210. ?>
  211. <td <?php echo $attributes ?>><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
  212. <?php
  213. break;
  214. }
  215. }
  216. echo "\n </tr>\n";
  217. }
  218. ?>
  219. </tbody>
  220. </table>
  221. <div class="tablenav">
  222. <div class="alignleft actions">
  223. <select name="action2">
  224. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  225. <option value="delete"><?php _e('Delete'); ?></option>
  226. </select>
  227. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
  228. </div>
  229. <?php } else { ?>
  230. <p><?php _e( 'No links found.' ) ?></p>
  231. <?php } ?>
  232. <br class="clear" />
  233. </div>
  234. </form>
  235. <div id="ajax-response"></div>
  236. </div>
  237. <?php
  238. include('./admin-footer.php');