WordPress.org

Plugin Directory

Changeset 531992


Ignore:
Timestamp:
04/16/12 20:08:39 (2 years ago)
Author:
josephscott
Message:

Make the new widget code live

Location:
akismet/trunk
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • akismet/trunk/widget.php

    r509115 r531992  
    33 * @package Akismet 
    44 */ 
    5 // Widget stuff 
    6 function widget_akismet_register() { 
    7     if ( function_exists('register_sidebar_widget') ) : 
    8     function widget_akismet($args) { 
    9         extract($args); 
    10         $options = get_option('widget_akismet'); 
    11         $count = get_option('akismet_spam_count'); 
    12         ?> 
    13             <?php echo $before_widget; ?> 
    14                 <?php echo $before_title . esc_html( $options['title'] ) . $after_title; ?> 
    15                 <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>  
    16             <?php echo $after_widget; ?> 
    17     <?php 
     5class Akismet_New_Widget extends WP_Widget { 
     6 
     7    function __construct() { 
     8        parent::__construct( 
     9            'akismet_new_widget', 
     10            'Akismet New 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', 'Akismet_New_Widget::css' ); 
     16        } 
    1817    } 
    1918 
    20     function widget_akismet_style() { 
    21         $plugin_dir = '/wp-content/plugins'; 
    22         if ( defined( 'PLUGINDIR' ) ) 
    23             $plugin_dir = '/' . PLUGINDIR; 
     19    function css() { 
     20?> 
    2421 
    25         ?> 
    2622<style type="text/css"> 
    27 #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none} 
    28 #aka:hover{border:none;text-decoration:none} 
    29 #aka:hover #akismet1{display:none} 
    30 #aka:hover #akismet2,#akismet1{display:block} 
    31 #akismet2{display:none;padding-top:2px} 
    32 #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none} 
    33 #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none} 
    34 #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} 
     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} 
    3557</style> 
    36         <?php 
     58 
     59<?php 
    3760    } 
    3861 
    39     function widget_akismet_control() { 
    40         $options = $newoptions = get_option('widget_akismet'); 
    41         if ( isset( $_POST['akismet-submit'] ) && $_POST["akismet-submit"] ) { 
    42             $newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"])); 
    43             if ( empty($newoptions['title']) ) $newoptions['title'] = __('Spam Blocked'); 
     62    function form( $instance ) { 
     63        if ( $instance ) { 
     64            $title = esc_attr( $instance['title'] ); 
    4465        } 
    45         if ( $options != $newoptions ) { 
    46             $options = $newoptions; 
    47             update_option('widget_akismet', $options); 
     66        else { 
     67            $title = __( 'Spam Blocked' ); 
    4868        } 
    49         $title = esc_html($options['title']); 
    50     ?> 
    51                 <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> 
    52                 <input type="hidden" id="akismet-submit" name="akismet-submit" value="1" /> 
    53     <?php 
     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  
    5477    } 
    5578 
    56     if ( function_exists( 'wp_register_sidebar_widget' ) ) { 
    57         wp_register_sidebar_widget( 'akismet', 'Akismet', 'widget_akismet', null, 'akismet'); 
    58         wp_register_widget_control( 'akismet', 'Akismet', 'widget_akismet_control', null, 75, 'akismet'); 
    59     } else { 
    60         register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet'); 
    61         register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet'); 
     79    function update( $new_instance, $old_instance ) { 
     80        $instance['title'] = strip_tags( $new_instance['title'] ); 
     81        return $instance; 
    6282    } 
    63     if ( is_active_widget('widget_akismet') ) 
    64         add_action('wp_head', 'widget_akismet_style'); 
    65     endif; 
     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=""><strong class="count"><?php echo number_format_i18n( $count ) . __( ' spam</strong> blocked by <strong>Akismet' ); ?></strong></a> 
     97    </div> 
     98 
     99<?php 
     100        echo $args['after_widget']; 
     101    } 
    66102} 
    67103 
    68 add_action('init', 'widget_akismet_register'); 
     104function akismet_register_widgets() { 
     105    register_widget( 'Akismet_New_Widget' ); 
     106} 
    69107 
    70 // Counter for non-widget users 
    71 function akismet_counter() { 
    72     $plugin_dir = '/wp-content/plugins'; 
    73     if ( defined( 'PLUGINDIR' ) ) 
    74         $plugin_dir = '/' . PLUGINDIR; 
    75  
    76 ?> 
    77 <style type="text/css"> 
    78 #akismetwrap #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none} 
    79 #aka:hover{border:none;text-decoration:none} 
    80 #aka:hover #akismet1{display:none} 
    81 #aka:hover #akismet2,#akismet1{display:block} 
    82 #akismet2{display:none;padding-top:2px} 
    83 #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none} 
    84 #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none} 
    85 #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} 
    86 </style> 
    87 <?php 
    88 $count = get_option('akismet_spam_count'); 
    89 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 ) ); 
    90 } 
     108add_action( 'widgets_init', 'akismet_register_widgets' ); 
Note: See TracChangeset for help on using the changeset viewer.