PageRenderTime 57ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/classes/values/link.php

https://bitbucket.org/attitude/codepress-admin-columns
PHP | 124 lines | 62 code | 25 blank | 37 comment | 2 complexity | 98244c333dacf81e141b6f33e8e84cc4 MD5 | raw file
  1. <?php
  2. /**
  3. * CPAC_Link_Values Class
  4. *
  5. * @since 1.4.4
  6. *
  7. */
  8. class CPAC_Link_Values extends CPAC_Values
  9. {
  10. /**
  11. * Constructor
  12. *
  13. * @since 1.4.4
  14. */
  15. function __construct()
  16. {
  17. parent::__construct();
  18. add_action( 'manage_link_custom_column', array( $this, 'manage_link_column_value'), 10, 2 );
  19. }
  20. /**
  21. * Manage custom column for Links
  22. *
  23. * @since 1.3.1
  24. */
  25. public function manage_link_column_value( $column_name, $link_id )
  26. {
  27. $type = $column_name;
  28. // links object... called bookmark
  29. $bookmark = get_bookmark($link_id);
  30. // Hook
  31. do_action('cpac-manage-link-column', $type, $column_name, $link_id);
  32. $result = '';
  33. switch ($type) :
  34. // link id
  35. case "column-link_id" :
  36. $result = $link_id;
  37. break;
  38. // description
  39. case "column-description" :
  40. $result = $bookmark->link_description;
  41. break;
  42. // target
  43. case "column-target" :
  44. $result = $bookmark->link_target;
  45. break;
  46. // notes
  47. case "column-notes" :
  48. $result = $this->get_shortened_string($bookmark->link_notes, $this->excerpt_length);
  49. break;
  50. // rss
  51. case "column-rss" :
  52. $result = $this->get_shorten_url($bookmark->link_rss);
  53. break;
  54. // image
  55. case "column-image" :
  56. $result = $this->get_thumbnail($bookmark->link_image);
  57. break;
  58. // name length
  59. case "column-length" :
  60. $result = strlen($bookmark->link_name);
  61. break;
  62. // owner
  63. case "column-owner" :
  64. $result = $bookmark->link_owner;
  65. // add user link
  66. $userdata = get_userdata( $bookmark->link_owner );
  67. if (!empty($userdata->data)) {
  68. $result = $userdata->data->user_nicename;
  69. //$result = "<a href='user-edit.php?user_id={$bookmark->link_owner}'>{$result}</a>";
  70. }
  71. break;
  72. // link actions
  73. case "column-actions" :
  74. $result = $this->get_column_value_actions($bookmark);
  75. break;
  76. default :
  77. $result = '';
  78. endswitch;
  79. // Filter for customizing the result output
  80. apply_filters('cpac-link-column-result', $result, $type, $column_name, $link_id);
  81. echo $result;
  82. }
  83. /**
  84. * Get column value of link actions
  85. *
  86. * This part is copied from the Link List Table class
  87. *
  88. * @since 1.4.2
  89. */
  90. private function get_column_value_actions( $link )
  91. {
  92. $actions = array();
  93. $edit_link = get_edit_bookmark_link( $link );
  94. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
  95. $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>";
  96. return implode(' | ', $actions);
  97. }
  98. }
  99. ?>