PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/link-manager.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 292 lines | 239 code | 45 blank | 8 comment | 32 complexity | bb9d3f003a878da2f91fd4ee6523c9f5 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 = __('Links');
  35. $this_file = $parent_file = 'link-manager.php';
  36. add_contextual_help( $current_screen,
  37. '<p>' . sprintf(__('You can add links here to be displayed on your site, usually using <a href="%s">Widgets</a>. By default, links to several sites in the WordPress community are included as examples.'), 'widgets.php') . '</p>' .
  38. '<p>' . __('Links may be separated into categories; these are different than the categories used on your posts.') . '</p>' .
  39. '<p>' . __('You can customize the display of this screen using the Screen Options tab and/or the dropdown filters above the links table.') . '</p>' .
  40. '<p>' . __('If you delete a link, it will be removed permanently, as Links do not have a Trash function yet.') . '</p>' .
  41. '<p><strong>' . __('For more information:') . '</strong></p>' .
  42. '<p>' . __('<a href="http://codex.wordpress.org/Links_Edit_SubPanel">Link Management Documentation</a>') . '</p>' .
  43. '<p>' . __('<a href="http://wordpress.org/support/">Support Forums</a>') . '</p>'
  44. );
  45. include_once ('./admin-header.php');
  46. if ( ! current_user_can('manage_links') )
  47. wp_die(__("You do not have sufficient permissions to edit the links for this site."));
  48. switch ($order_by) {
  49. case 'order_id' :
  50. $sqlorderby = 'id';
  51. break;
  52. case 'order_url' :
  53. $sqlorderby = 'url';
  54. break;
  55. case 'order_desc' :
  56. $sqlorderby = 'description';
  57. break;
  58. case 'order_owner' :
  59. $sqlorderby = 'owner';
  60. break;
  61. case 'order_rating' :
  62. $sqlorderby = 'rating';
  63. break;
  64. case 'order_name' :
  65. default :
  66. $sqlorderby = 'name';
  67. break;
  68. } ?>
  69. <div class="wrap nosubsub">
  70. <?php screen_icon(); ?>
  71. <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
  72. if ( !empty($_GET['s']) )
  73. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
  74. </h2>
  75. <?php
  76. if ( isset($_GET['deleted']) ) {
  77. echo '<div id="message" class="updated"><p>';
  78. $deleted = (int) $_GET['deleted'];
  79. printf(_n('%s link deleted.', '%s links deleted', $deleted), $deleted);
  80. echo '</p></div>';
  81. $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
  82. }
  83. ?>
  84. <form class="search-form" action="" method="get">
  85. <p class="search-box">
  86. <label class="screen-reader-text" for="link-search-input"><?php _e( 'Search Links' ); ?>:</label>
  87. <input type="text" id="link-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  88. <input type="submit" value="<?php esc_attr_e( 'Search Links' ); ?>" class="button" />
  89. </p>
  90. </form>
  91. <br class="clear" />
  92. <form id="posts-filter" action="" method="get">
  93. <div class="tablenav">
  94. <?php
  95. if ( 'all' == $cat_id )
  96. $cat_id = '';
  97. $args = array( 'category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0 );
  98. if ( ! empty( $_GET['s'] ) )
  99. $args['search'] = $_GET['s'];
  100. $links = get_bookmarks( $args );
  101. if ( $links ) {
  102. ?>
  103. <div class="alignleft actions">
  104. <select name="action">
  105. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  106. <option value="delete"><?php _e('Delete'); ?></option>
  107. </select>
  108. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  109. <?php
  110. $categories = get_terms('link_category', array("hide_empty" => 1));
  111. $select_cat = "<select name=\"cat_id\">\n";
  112. $select_cat .= '<option value="all"' . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
  113. foreach ((array) $categories as $cat)
  114. $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";
  115. $select_cat .= "</select>\n";
  116. $select_order = "<select name=\"order_by\">\n";
  117. $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' . __('Order by Link ID') . "</option>\n";
  118. $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' . __('Order by Name') . "</option>\n";
  119. $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' . __('Order by Address') . "</option>\n";
  120. $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' . __('Order by Rating') . "</option>\n";
  121. $select_order .= "</select>\n";
  122. echo $select_cat;
  123. echo $select_order;
  124. ?>
  125. <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
  126. </div>
  127. <br class="clear" />
  128. </div>
  129. <div class="clear"></div>
  130. <?php
  131. $link_columns = get_column_headers('link-manager');
  132. $hidden = get_hidden_columns('link-manager');
  133. ?>
  134. <?php wp_nonce_field('bulk-bookmarks') ?>
  135. <table class="widefat fixed" cellspacing="0">
  136. <thead>
  137. <tr>
  138. <?php print_column_headers('link-manager'); ?>
  139. </tr>
  140. </thead>
  141. <tfoot>
  142. <tr>
  143. <?php print_column_headers('link-manager', false); ?>
  144. </tr>
  145. </tfoot>
  146. <tbody>
  147. <?php
  148. $alt = 0;
  149. foreach ($links as $link) {
  150. $link = sanitize_bookmark($link);
  151. $link->link_name = esc_attr($link->link_name);
  152. $link->link_category = wp_get_link_cats($link->link_id);
  153. $short_url = str_replace('http://', '', $link->link_url);
  154. $short_url = preg_replace('/^www\./i', '', $short_url);
  155. if ('/' == substr($short_url, -1))
  156. $short_url = substr($short_url, 0, -1);
  157. if (strlen($short_url) > 35)
  158. $short_url = substr($short_url, 0, 32).'...';
  159. $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
  160. $rating = $link->link_rating;
  161. $style = ($alt % 2) ? '' : ' class="alternate"';
  162. ++ $alt;
  163. $edit_link = get_edit_bookmark_link();
  164. ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
  165. foreach($link_columns as $column_name=>$column_display_name) {
  166. $class = "class=\"column-$column_name\"";
  167. $style = '';
  168. if ( in_array($column_name, $hidden) )
  169. $style = ' style="display:none;"';
  170. $attributes = "$class$style";
  171. switch($column_name) {
  172. case 'cb':
  173. echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr($link->link_id) .'" /></th>';
  174. break;
  175. case 'name':
  176. 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 />";
  177. $actions = array();
  178. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  179. $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>";
  180. $action_count = count($actions);
  181. $i = 0;
  182. echo '<div class="row-actions">';
  183. foreach ( $actions as $action => $linkaction ) {
  184. ++$i;
  185. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  186. echo "<span class='$action'>$linkaction$sep</span>";
  187. }
  188. echo '</div>';
  189. echo '</td>';
  190. break;
  191. case 'url':
  192. echo "<td $attributes><a href='$link->link_url' title='".sprintf(__('Visit %s'), $link->link_name)."'>$short_url</a></td>";
  193. break;
  194. case 'categories':
  195. ?><td <?php echo $attributes ?>><?php
  196. $cat_names = array();
  197. foreach ($link->link_category as $category) {
  198. $cat = get_term($category, 'link_category', OBJECT, 'display');
  199. if ( is_wp_error( $cat ) )
  200. echo $cat->get_error_message();
  201. $cat_name = $cat->name;
  202. if ( $cat_id != $category )
  203. $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
  204. $cat_names[] = $cat_name;
  205. }
  206. echo implode(', ', $cat_names);
  207. ?></td><?php
  208. break;
  209. case 'rel':
  210. ?><td <?php echo $attributes ?>><?php echo empty($link->link_rel) ? '<br />' : $link->link_rel; ?></td><?php
  211. break;
  212. case 'visible':
  213. ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
  214. break;
  215. case 'rating':
  216. ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
  217. break;
  218. default:
  219. ?>
  220. <td <?php echo $attributes ?>><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
  221. <?php
  222. break;
  223. }
  224. }
  225. echo "\n </tr>\n";
  226. }
  227. ?>
  228. </tbody>
  229. </table>
  230. <div class="tablenav">
  231. <div class="alignleft actions">
  232. <select name="action2">
  233. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  234. <option value="delete"><?php _e('Delete'); ?></option>
  235. </select>
  236. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
  237. </div>
  238. <?php } else { ?>
  239. <p><?php _e( 'No links found.' ) ?></p>
  240. <?php } ?>
  241. <br class="clear" />
  242. </div>
  243. </form>
  244. <div id="ajax-response"></div>
  245. </div>
  246. <?php
  247. include('./admin-footer.php');