/class.filter.php

  1. <?php 
  2.  
  3. /** 
  4. * * * * * * * * * * * * * * * * * * * 
  5. * Shows the author links 
  6. * * * * * * * * * * * * * * * * * * * 
  7. */ 
  8.  
  9. class GPAISRFilter { 
  10.  
  11. /** 
  12. * @since 0.6 
  13. */ 
  14. function __construct() { 
  15. $options = get_option( 'gpaisr' ); 
  16.  
  17. if ( isset( $options['into_header'] ) && 1 == $options['into_header'] ) { 
  18. add_action( 'wp_head', array( &$this, 'to_header' ) ); 
  19. elseif ( isset( $options['replacement'] ) && $options['replacement'] == 1 ) { 
  20. add_filter( 'author_link', array( $this, 'author_link_filter' ), 0, 3 ); 
  21. else { 
  22. add_filter( 'the_content', array( $this, 'author_link_in_content' ), 15 ); 
  23.  
  24. /** 
  25. * Just replaces the link with the google+ url 
  26. * 
  27. * @param $link 
  28. * @param $author_id 
  29. * @param $author_nicename 
  30. * 
  31. * @since 0.6 
  32. * 
  33. * @return string 
  34. */ 
  35. function author_link_filter( $link, $author_id, $author_nicename ) { 
  36. $gplus_author_link = get_the_author_meta( 'googleplus', $author_id ); 
  37. if ( ! empty( $gplus_author_link ) ) { 
  38. return $gplus_author_link . '?rel=author'; 
  39. return $link; 
  40.  
  41. /** 
  42. * Writes the Google+-URL right after the Content 
  43. * 
  44. * @param $content 
  45. * 
  46. * @since 0.6 
  47. * 
  48. * @return string 
  49. */ 
  50. function author_link_in_content( $content ) { 
  51.  
  52. if ( ! is_singular() ) { 
  53. return $content; 
  54.  
  55. // load the options from the settings page 
  56. $options = get_option( 'gpaisr' ); 
  57.  
  58. // is this the feed? if yes, should we display the link? 
  59. if ( ! isset( $options['in_feed'] ) ) { 
  60. $options['in_feed'] = 0; 
  61. if ( is_feed() && $options['in_feed'] != 1 ) { 
  62. return $content; 
  63.  
  64. // what's the author id? 
  65. $authorId = get_the_author_meta( 'ID' ); 
  66.  
  67. // find the link 
  68. $gplus_author_link = get_the_author_meta( 'googleplus', $authorId ); 
  69. if ( ! empty( $gplus_author_link ) ) { 
  70. $gplus_author_link = $gplus_author_link . '?rel=author'; 
  71.  
  72. // open in a new window? 
  73. $newWindow = ''; 
  74. if ( isset( $options['new_window'] ) && $options['new_window'] == 1 ) { 
  75. $newWindow = 'target="_blank"'; 
  76.  
  77. // show or hide? 
  78. $showHide = ''; 
  79. if ( isset( $options['hide'] ) && $options['hide'] == 1 ) { 
  80. $showHide = 'style="display:none;"'; 
  81.  
  82. // is there a linktext? 
  83. $linktext = 'Google+'; 
  84. if ( ! empty( $options['link_text'] ) ) { 
  85. $linktext = $options['link_text']; 
  86.  
  87. return $content .= '<a rel="author" href="' . $gplus_author_link . '" ' . $newWindow . ' ' . $showHide . '>' . $linktext . '</a>'; 
  88.  
  89.  
  90. /** 
  91. * Adds the Google profile link to the header 
  92. * @since 0.7.2 
  93. * @return void 
  94. */ 
  95. function to_header() { 
  96.  
  97. global $post; 
  98. if ( ! $post instanceof WP_Post ) { 
  99. return; 
  100.  
  101. if ( ! is_singular() ) { 
  102. return; 
  103.  
  104. $authorId = $post->post_author; 
  105.  
  106. // find the link 
  107. $gplus_author_link = get_the_author_meta( 'googleplus', $authorId ); 
  108.  
  109. if ( ! empty( $gplus_author_link ) ) { 
  110. echo '<link href="' . $gplus_author_link . '" rel="author" />'; 
  111.  
  112.  
  113.  
.