]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/plugins/akismet/widget.php
WordPress 3.4
[autoinstalls/wordpress.git] / wp-content / plugins / akismet / widget.php
index e9a3f626e0481945986c3da3c564e4964a84ee14..8c5a120f567d800616741345859c10e6b37da7c0 100644 (file)
 /**
  * @package Akismet
  */
-// Widget stuff
-function widget_akismet_register() {
-       if ( function_exists('register_sidebar_widget') ) :
-       function widget_akismet($args) {
-               extract($args);
-               $options = get_option('widget_akismet');
-               $count = get_option('akismet_spam_count');
-               ?>
-                       <?php echo $before_widget; ?>
-                               <?php echo $before_title . $options['title'] . $after_title; ?>
-                <div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><?php printf( _n( '%1$s%2$s%3$s %4$sspam comment%5$s %6$sblocked by%7$s<br />%8$sAkismet%9$s', '%1$s%2$s%3$s %4$sspam comments%5$s %6$sblocked by%7$s<br />%8$sAkismet%9$s', $count ), '<span id="akismet1"><span id="akismetcount">', number_format_i18n( $count ), '</span>', '<span id="akismetsc">', '</span></span>', '<span id="akismet2"><span id="akismetbb">', '</span>', '<span id="akismeta">', '</span></span>' ); ?></a></div></div> 
-                       <?php echo $after_widget; ?>
-       <?php
+class Akismet_Widget extends WP_Widget {
+
+       function __construct() {
+               parent::__construct(
+                       'akismet_widget',
+                       __( 'Akismet Widget' ),
+                       array( 'description' => __( 'Display the number of spam comments Akismet has caught' ) )
+               );
+
+               if ( is_active_widget( false, false, $this->id_base ) ) {
+                       add_action( 'wp_head', array( $this, 'css' ) );
+               }
        }
 
-       function widget_akismet_style() {
-               $plugin_dir = '/wp-content/plugins';
-               if ( defined( 'PLUGINDIR' ) )
-                       $plugin_dir = '/' . PLUGINDIR;
+       function css() {
+?>
 
-               ?>
 <style type="text/css">
-#aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
-#aka:hover{border:none;text-decoration:none}
-#aka:hover #akismet1{display:none}
-#aka:hover #akismet2,#akismet1{display:block}
-#akismet2{display:none;padding-top:2px}
-#akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
-#akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
-#akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
+.a-stats {
+       width: auto;
+}
+.a-stats a { 
+       background: #7CA821;
+       background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821);
+       background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14));
+       border: 1px solid #5F8E14;
+       border-radius:3px;
+       color: #CFEA93;
+       cursor: pointer;
+       display: block;
+       font-weight: normal;
+       height: 100%;
+       -moz-border-radius:3px;
+       padding: 7px 0 8px;
+       text-align: center;
+       text-decoration: none;
+       -webkit-border-radius:3px;
+       width: 100%;
+}
+.a-stats a:hover { 
+       text-decoration: none;
+       background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417);
+       background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B));
+}
+.a-stats .count {
+       color: #FFF;
+       display: block;
+       font-size: 15px;
+       line-height: 16px;
+       padding: 0 13px;
+       white-space: nowrap;
+}
 </style>
-               <?php
+
+<?php
        }
 
-       function widget_akismet_control() {
-               $options = $newoptions = get_option('widget_akismet');
-               if ( isset( $_POST['akismet-submit'] ) && $_POST["akismet-submit"] ) {
-                       $newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"]));
-                       if ( empty($newoptions['title']) ) $newoptions['title'] = __('Spam Blocked');
+       function form( $instance ) {
+               if ( $instance ) {
+                       $title = esc_attr( $instance['title'] );
                }
-               if ( $options != $newoptions ) {
-                       $options = $newoptions;
-                       update_option('widget_akismet', $options);
+               else {
+                       $title = __( 'Spam Blocked' );
                }
-               $title = htmlspecialchars($options['title'], ENT_QUOTES);
-       ?>
-                               <p><label for="akismet-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="akismet-title" name="akismet-title" type="text" value="<?php echo $title; ?>" /></label></p>
-                               <input type="hidden" id="akismet-submit" name="akismet-submit" value="1" />
-       <?php
-       }
+?>
 
-       if ( function_exists( 'wp_register_sidebar_widget' ) ) {
-               wp_register_sidebar_widget( 'akismet', 'Akismet', 'widget_akismet', null, 'akismet');
-               wp_register_widget_control( 'akismet', 'Akismet', 'widget_akismet_control', null, 75, 'akismet');
-       } else {
-               register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
-               register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
+               <p>
+               <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
+               <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; ?>" />
+               </p>
+
+<?php 
        }
-       if ( is_active_widget('widget_akismet') )
-               add_action('wp_head', 'widget_akismet_style');
-       endif;
-}
 
-add_action('init', 'widget_akismet_register');
+       function update( $new_instance, $old_instance ) {
+               $instance['title'] = strip_tags( $new_instance['title'] );
+               return $instance;
+       }
 
-// Counter for non-widget users
-function akismet_counter() {
-       $plugin_dir = '/wp-content/plugins';
-       if ( defined( 'PLUGINDIR' ) )
-               $plugin_dir = '/' . PLUGINDIR;
+       function widget( $args, $instance ) {
+               $count = get_option( 'akismet_spam_count' );
 
+               echo $args['before_widget'];
+               if ( ! empty( $instance['title'] ) ) {
+                       echo $args['before_title'];
+                       echo esc_html( $instance['title'] );
+                       echo $args['after_title'];
+               }
 ?>
-<style type="text/css">
-#akismetwrap #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
-#aka:hover{border:none;text-decoration:none}
-#aka:hover #akismet1{display:none}
-#aka:hover #akismet2,#akismet1{display:block}
-#akismet2{display:none;padding-top:2px}
-#akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
-#akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
-#akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
-</style>
+
+       <div class="a-stats">
+               <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>
+       </div>
+
 <?php
-$count = get_option('akismet_spam_count');
-printf( _n( '<div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount">%1$s</span> <span id="akismetsc">spam comment</span></div> <div id="akismet2"><span id="akismetbb">blocked by</span><br /><span id="akismeta">Akismet</span></div></a></div></div>', '<div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount">%1$s</span> <span id="akismetsc">spam comments</span></div> <div id="akismet2"><span id="akismetbb">blocked by</span><br /><span id="akismeta">Akismet</span></div></a></div></div>', $count ), number_format_i18n( $count ) );
+               echo $args['after_widget'];
+       }
 }
+
+function akismet_register_widgets() {
+       register_widget( 'Akismet_Widget' );
+}
+
+add_action( 'widgets_init', 'akismet_register_widgets' );