|
1 <?php |
|
2 /** |
|
3 * @package Akismet |
|
4 */ |
|
5 class Akismet_Widget extends WP_Widget { |
|
6 |
|
7 function __construct() { |
|
8 parent::__construct( |
|
9 'akismet_widget', |
|
10 __( 'Akismet Widget' ), |
|
11 array( 'description' => __( 'Display the number of spam comments Akismet has caught' ) ) |
|
12 ); |
|
13 |
|
14 if ( is_active_widget( false, false, $this->id_base ) ) { |
|
15 add_action( 'wp_head', array( $this, 'css' ) ); |
|
16 } |
|
17 } |
|
18 |
|
19 function css() { |
|
20 ?> |
|
21 |
|
22 <style type="text/css"> |
|
23 .a-stats { |
|
24 width: auto; |
|
25 } |
|
26 .a-stats a { |
|
27 background: #7CA821; |
|
28 background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821); |
|
29 background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14)); |
|
30 border: 1px solid #5F8E14; |
|
31 border-radius:3px; |
|
32 color: #CFEA93; |
|
33 cursor: pointer; |
|
34 display: block; |
|
35 font-weight: normal; |
|
36 height: 100%; |
|
37 -moz-border-radius:3px; |
|
38 padding: 7px 0 8px; |
|
39 text-align: center; |
|
40 text-decoration: none; |
|
41 -webkit-border-radius:3px; |
|
42 width: 100%; |
|
43 } |
|
44 .a-stats a:hover { |
|
45 text-decoration: none; |
|
46 background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417); |
|
47 background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B)); |
|
48 } |
|
49 .a-stats .count { |
|
50 color: #FFF; |
|
51 display: block; |
|
52 font-size: 15px; |
|
53 line-height: 16px; |
|
54 padding: 0 13px; |
|
55 white-space: nowrap; |
|
56 } |
|
57 </style> |
|
58 |
|
59 <?php |
|
60 } |
|
61 |
|
62 function form( $instance ) { |
|
63 if ( $instance ) { |
|
64 $title = esc_attr( $instance['title'] ); |
|
65 } |
|
66 else { |
|
67 $title = __( 'Spam Blocked' ); |
|
68 } |
|
69 ?> |
|
70 |
|
71 <p> |
|
72 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
|
73 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /> |
|
74 </p> |
|
75 |
|
76 <?php |
|
77 } |
|
78 |
|
79 function update( $new_instance, $old_instance ) { |
|
80 $instance['title'] = strip_tags( $new_instance['title'] ); |
|
81 return $instance; |
|
82 } |
|
83 |
|
84 function widget( $args, $instance ) { |
|
85 $count = get_option( 'akismet_spam_count' ); |
|
86 |
|
87 echo $args['before_widget']; |
|
88 if ( ! empty( $instance['title'] ) ) { |
|
89 echo $args['before_title']; |
|
90 echo esc_html( $instance['title'] ); |
|
91 echo $args['after_title']; |
|
92 } |
|
93 ?> |
|
94 |
|
95 <div class="a-stats"> |
|
96 <a href="http://akismet.com" target="_blank" title=""><?php printf( _n( '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', $count ), number_format_i18n( $count ) ); ?></a> |
|
97 </div> |
|
98 |
|
99 <?php |
|
100 echo $args['after_widget']; |
|
101 } |
|
102 } |
|
103 |
|
104 function akismet_register_widgets() { |
|
105 register_widget( 'Akismet_Widget' ); |
|
106 } |
|
107 |
|
108 add_action( 'widgets_init', 'akismet_register_widgets' ); |