PageRenderTime 59ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-links-list-table.php

https://gitlab.com/geyson/geyson
PHP | 324 lines | 152 code | 29 blank | 143 comment | 13 complexity | cc394c2ef6268e9001a18232e58503ac MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Links Manager List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_Links_List_Table extends WP_List_Table {
  11. /**
  12. * Constructor.
  13. *
  14. * @since 3.1.0
  15. * @access public
  16. *
  17. * @see WP_List_Table::__construct() for more information on default arguments.
  18. *
  19. * @param array $args An associative array of arguments.
  20. */
  21. public function __construct( $args = array() ) {
  22. parent::__construct( array(
  23. 'plural' => 'bookmarks',
  24. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  25. ) );
  26. }
  27. /**
  28. *
  29. * @return bool
  30. */
  31. public function ajax_user_can() {
  32. return current_user_can( 'manage_links' );
  33. }
  34. /**
  35. *
  36. * @global int $cat_id
  37. * @global string $s
  38. * @global string $orderby
  39. * @global string $order
  40. */
  41. public function prepare_items() {
  42. global $cat_id, $s, $orderby, $order;
  43. wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
  44. $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
  45. if ( 'all' != $cat_id )
  46. $args['category'] = $cat_id;
  47. if ( !empty( $s ) )
  48. $args['search'] = $s;
  49. if ( !empty( $orderby ) )
  50. $args['orderby'] = $orderby;
  51. if ( !empty( $order ) )
  52. $args['order'] = $order;
  53. $this->items = get_bookmarks( $args );
  54. }
  55. /**
  56. * @access public
  57. */
  58. public function no_items() {
  59. _e( 'No links found.' );
  60. }
  61. /**
  62. *
  63. * @return array
  64. */
  65. protected function get_bulk_actions() {
  66. $actions = array();
  67. $actions['delete'] = __( 'Delete' );
  68. return $actions;
  69. }
  70. /**
  71. *
  72. * @global int $cat_id
  73. * @param string $which
  74. */
  75. protected function extra_tablenav( $which ) {
  76. global $cat_id;
  77. if ( 'top' != $which )
  78. return;
  79. ?>
  80. <div class="alignleft actions">
  81. <?php
  82. $dropdown_options = array(
  83. 'selected' => $cat_id,
  84. 'name' => 'cat_id',
  85. 'taxonomy' => 'link_category',
  86. 'show_option_all' => __( 'All categories' ),
  87. 'hide_empty' => true,
  88. 'hierarchical' => 1,
  89. 'show_count' => 0,
  90. 'orderby' => 'name',
  91. );
  92. echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>';
  93. wp_dropdown_categories( $dropdown_options );
  94. submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
  95. ?>
  96. </div>
  97. <?php
  98. }
  99. /**
  100. *
  101. * @return array
  102. */
  103. public function get_columns() {
  104. return array(
  105. 'cb' => '<input type="checkbox" />',
  106. 'name' => _x( 'Name', 'link name' ),
  107. 'url' => __( 'URL' ),
  108. 'categories' => __( 'Categories' ),
  109. 'rel' => __( 'Relationship' ),
  110. 'visible' => __( 'Visible' ),
  111. 'rating' => __( 'Rating' )
  112. );
  113. }
  114. /**
  115. *
  116. * @return array
  117. */
  118. protected function get_sortable_columns() {
  119. return array(
  120. 'name' => 'name',
  121. 'url' => 'url',
  122. 'visible' => 'visible',
  123. 'rating' => 'rating'
  124. );
  125. }
  126. /**
  127. * Get the name of the default primary column.
  128. *
  129. * @since 4.3.0
  130. * @access protected
  131. *
  132. * @return string Name of the default primary column, in this case, 'name'.
  133. */
  134. protected function get_default_primary_column_name() {
  135. return 'name';
  136. }
  137. /**
  138. * Handles the checkbox column ouput.
  139. *
  140. * @since 4.3.0
  141. * @access public
  142. *
  143. * @param object $link The current link object.
  144. */
  145. public function column_cb( $link ) {
  146. ?>
  147. <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
  148. <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
  149. <?php
  150. }
  151. /**
  152. * Handles the link name column ouput.
  153. *
  154. * @since 4.3.0
  155. * @access public
  156. *
  157. * @param object $link The current link object.
  158. */
  159. public function column_name( $link ) {
  160. $edit_link = get_edit_bookmark_link( $link );
  161. ?>
  162. <strong><a class="row-title" href="<?php echo $edit_link ?>" title="<?php
  163. echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) );
  164. ?>"><?php echo $link->link_name ?></a></strong><br />
  165. <?php
  166. }
  167. /**
  168. * Handles the link URL column ouput.
  169. *
  170. * @since 4.3.0
  171. * @access public
  172. *
  173. * @param object $link The current link object.
  174. */
  175. public function column_url( $link ) {
  176. $short_url = url_shorten( $link->link_url );
  177. echo "<a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a>";
  178. }
  179. /**
  180. * Handles the link categories column output.
  181. *
  182. * @since 4.3.0
  183. * @access public
  184. *
  185. * @global $cat_id
  186. *
  187. * @param object $link The current link object.
  188. */
  189. public function column_categories( $link ) {
  190. global $cat_id;
  191. $cat_names = array();
  192. foreach ( $link->link_category as $category ) {
  193. $cat = get_term( $category, 'link_category', OBJECT, 'display' );
  194. if ( is_wp_error( $cat ) ) {
  195. echo $cat->get_error_message();
  196. }
  197. $cat_name = $cat->name;
  198. if ( $cat_id != $category ) {
  199. $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
  200. }
  201. $cat_names[] = $cat_name;
  202. }
  203. echo implode( ', ', $cat_names );
  204. }
  205. /**
  206. * Handles the link relation column ouput.
  207. *
  208. * @since 4.3.0
  209. * @access public
  210. *
  211. * @param object $link The current link object.
  212. */
  213. public function column_rel( $link ) {
  214. echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
  215. }
  216. /**
  217. * Handles the link visibility column ouput.
  218. *
  219. * @since 4.3.0
  220. * @access public
  221. *
  222. * @param object $link The current link object.
  223. */
  224. public function column_visible( $link ) {
  225. if ( 'Y' === $link->link_visible ) {
  226. _e( 'Yes' );
  227. } else {
  228. _e( 'No' );
  229. }
  230. }
  231. /**
  232. * Handles the link rating column ouput.
  233. *
  234. * @since 4.3.0
  235. * @access public
  236. *
  237. * @param object $link The current link object.
  238. */
  239. public function column_rating( $link ) {
  240. echo $link->link_rating;
  241. }
  242. /**
  243. * Handles the default column output.
  244. *
  245. * @since 4.3.0
  246. * @access public
  247. *
  248. * @param object $link Link object.
  249. * @param string $column_name Current column name.
  250. */
  251. public function column_default( $link, $column_name ) {
  252. /**
  253. * Fires for each registered custom link column.
  254. *
  255. * @since 2.1.0
  256. *
  257. * @param string $column_name Name of the custom column.
  258. * @param int $link_id Link ID.
  259. */
  260. do_action( 'manage_link_custom_column', $column_name, $link->link_id );
  261. }
  262. public function display_rows() {
  263. foreach ( $this->items as $link ) {
  264. $link = sanitize_bookmark( $link );
  265. $link->link_name = esc_attr( $link->link_name );
  266. $link->link_category = wp_get_link_cats( $link->link_id );
  267. ?>
  268. <tr id="link-<?php echo $link->link_id; ?>">
  269. <?php $this->single_row_columns( $link ) ?>
  270. </tr>
  271. <?php
  272. }
  273. }
  274. /**
  275. * Generates and displays row action links.
  276. *
  277. * @since 4.3.0
  278. * @access protected
  279. *
  280. * @param object $link Link being acted upon.
  281. * @param string $column_name Current column name.
  282. * @param string $primary Primary column name.
  283. * @return string Row action output for links.
  284. */
  285. protected function handle_row_actions( $link, $column_name, $primary ) {
  286. if ( $primary !== $column_name ) {
  287. return '';
  288. }
  289. $edit_link = get_edit_bookmark_link( $link );
  290. $actions = array();
  291. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  292. $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>";
  293. return $this->row_actions( $actions );
  294. }
  295. }