PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/link-manager.php

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