PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/stavBlog.old/wp-admin/link-manager.php

https://github.com/mikitracey/ifusa
PHP | 278 lines | 228 code | 42 blank | 8 comment | 34 complexity | 3f04b94d1d166d00e386c94bd6e0a745 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 blog.') );
  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 ( isset($_GET['_wp_http_referer']) && ! 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 blog."));
  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 esc_html_e('Add New'); ?></a> <?php
  63. if ( isset($_GET['s']) && $_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 fade"><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. <div class="alignleft actions">
  86. <select name="action">
  87. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  88. <option value="delete"><?php _e('Delete'); ?></option>
  89. </select>
  90. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  91. <?php
  92. $categories = get_terms('link_category', "hide_empty=1");
  93. $select_cat = "<select name=\"cat_id\">\n";
  94. $select_cat .= '<option value="all"' . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('View all Categories') . "</option>\n";
  95. foreach ((array) $categories as $cat)
  96. $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";
  97. $select_cat .= "</select>\n";
  98. $select_order = "<select name=\"order_by\">\n";
  99. $select_order .= '<option value="order_id"' . (($order_by == 'order_id') ? " selected='selected'" : '') . '>' . __('Order by Link ID') . "</option>\n";
  100. $select_order .= '<option value="order_name"' . (($order_by == 'order_name') ? " selected='selected'" : '') . '>' . __('Order by Name') . "</option>\n";
  101. $select_order .= '<option value="order_url"' . (($order_by == 'order_url') ? " selected='selected'" : '') . '>' . __('Order by Address') . "</option>\n";
  102. $select_order .= '<option value="order_rating"' . (($order_by == 'order_rating') ? " selected='selected'" : '') . '>' . __('Order by Rating') . "</option>\n";
  103. $select_order .= "</select>\n";
  104. echo $select_cat;
  105. echo $select_order;
  106. ?>
  107. <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
  108. </div>
  109. <br class="clear" />
  110. </div>
  111. <div class="clear"></div>
  112. <?php
  113. if ( 'all' == $cat_id )
  114. $cat_id = '';
  115. $args = array('category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0);
  116. if ( !empty($_GET['s']) )
  117. $args['search'] = $_GET['s'];
  118. $links = get_bookmarks( $args );
  119. if ( $links ) {
  120. $link_columns = get_column_headers('link-manager');
  121. $hidden = get_hidden_columns('link-manager');
  122. ?>
  123. <?php wp_nonce_field('bulk-bookmarks') ?>
  124. <table class="widefat fixed" cellspacing="0">
  125. <thead>
  126. <tr>
  127. <?php print_column_headers('link-manager'); ?>
  128. </tr>
  129. </thead>
  130. <tfoot>
  131. <tr>
  132. <?php print_column_headers('link-manager', false); ?>
  133. </tr>
  134. </tfoot>
  135. <tbody>
  136. <?php
  137. $alt = 0;
  138. foreach ($links as $link) {
  139. $link = sanitize_bookmark($link);
  140. $link->link_name = esc_attr($link->link_name);
  141. $link->link_category = wp_get_link_cats($link->link_id);
  142. $short_url = str_replace('http://', '', $link->link_url);
  143. $short_url = preg_replace('/^www\./i', '', $short_url);
  144. if ('/' == substr($short_url, -1))
  145. $short_url = substr($short_url, 0, -1);
  146. if (strlen($short_url) > 35)
  147. $short_url = substr($short_url, 0, 32).'...';
  148. $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
  149. $rating = $link->link_rating;
  150. $style = ($alt % 2) ? '' : ' class="alternate"';
  151. ++ $alt;
  152. $edit_link = get_edit_bookmark_link();
  153. ?><tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>><?php
  154. foreach($link_columns as $column_name=>$column_display_name) {
  155. $class = "class=\"column-$column_name\"";
  156. $style = '';
  157. if ( in_array($column_name, $hidden) )
  158. $style = ' style="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="'. esc_attr($link->link_id) .'" /></th>';
  163. break;
  164. case 'name':
  165. 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 />";
  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('" . 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>";
  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 empty($link->link_rel) ? '<br />' : $link->link_rel; ?></td><?php
  200. break;
  201. case 'visible':
  202. ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
  203. break;
  204. case 'rating':
  205. ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
  206. break;
  207. default:
  208. ?>
  209. <td><?php do_action('manage_link_custom_column', $column_name, $link->link_id); ?></td>
  210. <?php
  211. break;
  212. }
  213. }
  214. echo "\n </tr>\n";
  215. }
  216. ?>
  217. </tbody>
  218. </table>
  219. <?php } else { ?>
  220. <p><?php _e('No links found.') ?></p>
  221. <?php } ?>
  222. <div class="tablenav">
  223. <div class="alignleft actions">
  224. <select name="action2">
  225. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  226. <option value="delete"><?php _e('Delete'); ?></option>
  227. </select>
  228. <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
  229. </div>
  230. <br class="clear" />
  231. </div>
  232. </form>
  233. <div id="ajax-response"></div>
  234. </div>
  235. <?php
  236. include('admin-footer.php');