wid-readers.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. add_action( 'widgets_init', 'd_readers' );
  3. function d_readers() {
  4. register_widget( 'd_reader' );
  5. }
  6. class d_reader extends WP_Widget {
  7. function d_reader() {
  8. $widget_ops = array( 'classname' => 'd_reader', 'description' => '显示近期评论频繁的网友头像等' );
  9. $this->WP_Widget( 'd_reader', 'Yusi-活跃读者', $widget_ops, $control_ops );
  10. }
  11. function widget( $args, $instance ) {
  12. extract( $args );
  13. $title = apply_filters('widget_name', $instance['title']);
  14. $limit = $instance['limit'];
  15. $outer = $instance['outer'];
  16. $timer = $instance['timer'];
  17. $addlink = $instance['addlink'];
  18. $more = $instance['more'];
  19. $link = $instance['link'];
  20. $mo='';
  21. if( $more!='' && $link!='' ) $mo='<a class="btn" href="'.$link.'">'.$more.'</a>';
  22. echo $before_widget;
  23. echo $before_title.$mo.$title.$after_title;
  24. echo '<ul>';
  25. echo dtheme_readers( $out=$outer, $tim=$timer, $lim=$limit, $addlink );;
  26. echo '</ul>';
  27. echo $after_widget;
  28. }
  29. function form($instance) {
  30. ?>
  31. <p>
  32. <label>
  33. 标题:
  34. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" />
  35. </label>
  36. </p>
  37. <p>
  38. <label>
  39. 显示数目:
  40. <input class="widefat" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="number" value="<?php echo $instance['limit']; ?>" />
  41. </label>
  42. </p>
  43. <p>
  44. <label>
  45. 排除某人:
  46. <input class="widefat" id="<?php echo $this->get_field_id('outer'); ?>" name="<?php echo $this->get_field_name('outer'); ?>" type="text" value="<?php echo $instance['outer']; ?>" />
  47. </label>
  48. </p>
  49. <p>
  50. <label>
  51. 几天内:
  52. <input class="widefat" id="<?php echo $this->get_field_id('timer'); ?>" name="<?php echo $this->get_field_name('timer'); ?>" type="number" value="<?php echo $instance['timer']; ?>" />
  53. </label>
  54. </p>
  55. <p>
  56. <label>
  57. <input style="vertical-align:-3px;margin-right:4px;" class="checkbox" type="checkbox" <?php checked( $instance['addlink'], 'on' ); ?> id="<?php echo $this->get_field_id('addlink'); ?>" name="<?php echo $this->get_field_name('addlink'); ?>">加链接
  58. </label>
  59. </p>
  60. <p>
  61. <label>
  62. More 显示文字:
  63. <input style="width:100%;" id="<?php echo $this->get_field_id('more'); ?>" name="<?php echo $this->get_field_name('more'); ?>" type="text" value="<?php echo $instance['more']; ?>" size="24" />
  64. </label>
  65. </p>
  66. <p>
  67. <label>
  68. More 链接:
  69. <input style="width:100%;" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="url" value="<?php echo $instance['link']; ?>" size="24" />
  70. </label>
  71. </p>
  72. <?php
  73. }
  74. }
  75. /*
  76. * 读者墙
  77. * dtheme_readers( $outer='name', $timer='3', $limit='14' );
  78. * $outer 不显示某人
  79. * $timer 几个月时间内
  80. * $limit 显示条数
  81. */
  82. function dtheme_readers($out,$tim,$lim,$addlink){
  83. global $wpdb;
  84. $counts = $wpdb->get_results("select count(comment_author) as cnt, comment_author, comment_author_url, comment_author_email from (select * from $wpdb->comments left outer join $wpdb->posts on ($wpdb->posts.id=$wpdb->comments.comment_post_id) where comment_date > date_sub( now(), interval $tim day ) and user_id='0' and comment_author != '".$out."' and post_password='' and comment_approved='1' and comment_type='') as tempcmt group by comment_author order by cnt desc limit $lim");
  85. foreach ($counts as $count) {
  86. $c_url = $count->comment_author_url;
  87. if ($c_url == '') $c_url = 'javascript:;';
  88. if($addlink == 'on'){
  89. $c_urllink = ' href="'. $c_url . '"';
  90. }else{
  91. $c_urllink = '';
  92. }
  93. $type .= '<li><a title="['.$count->comment_author.'] 近期点评'. $count->cnt .'次" target="_blank"'.$c_urllink.'>'.get_avatar( $count->comment_author_email, $size = '48' , deel_avatar_default() ) .'</a></li>';
  94. }
  95. echo $type;
  96. }
  97. ?>