Plugin Directory

Changeset 126622


Ignore:
Timestamp:
06/17/2009 12:58:28 AM (17 years ago)
Author:
scompt
Message:

Updated for WP 2.8

Location:
immerstat/tags/0.5
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • immerstat/tags/0.5/immerstat.php

    r45292 r126622  
    33Plugin Name: ImmerStat
    44Plugin URI: http://scompt.com/projects/immerstat
    5 Description: ImmerStat places a .PNG in the top-right corner of your admin screen with your current WordPress.com pageview statistics.
     5Description: ImmerStat places an image in the header of your admin screen with
     6             your current WordPress.com pageview statistics.
    67Author: Edward Dale
    78Author URI: http://scompt.com/
    8 Version: 0.5
     9Version: 0.6
    910*/
    1011
    1112/**
    12  * ImmerStat places a .PNG in the top-right corner of your admin screen with
     13 * ImmerStat places an image in the header of your admin screen with
    1314 * your current WordPress.com pageview statistics.
    1415 *
     
    3435 * @copyright  Copyright 2008 Edward Dale
    3536 * @license    http://www.gnu.org/licenses/gpl.txt GPL 2.0
    36  * @version    $Id:$
     37 * @version    $Id$
    3738 * @link       http://www.scompt.com/projects/immerstat
    3839 * @since      0.5
     
    4748     */
    4849    function ImmerStat() {
     50        add_settings_section('immerstat_setting_section', 'ImmerStat',
     51                             array(&$this, 'settings_section'), 'misc');
     52        add_settings_field('immerstat_days', 'Number of Days',
     53                           array(&$this, 'settings_field'),
     54                           'misc', 'immerstat_setting_section');
     55        register_setting('misc', 'immerstat_days');
     56        add_option('immerstat_days', 30);
     57       
    4958        if( function_exists('stats_get_csv') && current_user_can( 'manage_options' ) ) {
    5059            $this->load();
    5160        }
    5261    }
     62
     63    /**
     64     * There's not much to say at the top of the ImmerStats section.
     65     */
     66    function settings_section() {
     67        // NOOP
     68    }
     69
     70    /**
     71     * Shows the input field for the number of days.
     72     */
     73    function settings_field() {
     74        $days = get_option('immerstat_days');
     75
     76        echo "<input name='immerstat_days' id='immerstat_days' type='text'
     77        value='".$days."' class='code' />";     
     78    }
    5379   
    5480    /**
     
    6591     */
    6692    function load() {
    67         $num_days = apply_filters('immerstat_days', 30);
     93        $num_days = get_option('immerstat_days');
     94        $old_data = get_option('immerstat_data');
    6895
    6996        // Use this filter to determine when new stats were actually retrieved
    7097        add_filter('update_option_stats_cache', array(&$this, 'enable_load'));
    71         $from_wp = stats_get_csv('views', array('days'=>$num_days, 'limit'=>$num_days, 'summarize'=>false));
     98        $from_wp = stats_get_csv('views', array(     'days'=>$num_days,
     99                                                    'limit'=>$num_days,
     100                                                'summarize'=>false));
    72101        remove_filter('update_option_stats_cache', array(&$this, 'enable_load'));
    73102
     
    75104        $max = $min = $from_wp[0]['views'];
    76105
    77         if( $this->do_load ) {
     106        if( $this->do_load || (isset($old_data['days']) &&
     107                               $old_data['days'] != $num_days) ) {
    78108            foreach( $from_wp as $day ) {
    79109                if( $max<$day['views'] ) $max=$day['views'];
     
    82112            }
    83113
    84             $stats = array('data'=>implode($data, ','), 'min'=>$min, 'max'=>$max, 'days'=>$num_days, 'current'=>$data[count($data)-1]);
     114            $stats = array('data'=>implode($data, ','), 'min'=>$min,
     115                           'max'=>$max, 'days'=>$num_days,
     116                           'current'=>$data[count($data)-1]);
    85117            update_option('immerstat_data', $stats);
    86118        }
    87119
    88         add_action('admin_footer', array(&$this, 'footer'));
    89         add_filter( 'wp_dashboard_widgets', array(&$this,'remove_dashboard_widget'), 11, 1);
    90     }
    91 
    92     /**
    93      * Removes the WordPress.com Stats widget from the dashboard.
    94      */
    95     function remove_dashboard_widget($widgets) {
    96         array_splice($widgets, array_search( "dashboard_stats", $widgets), 1 );
    97         return $widgets;
     120        // This filter gets called at a convenient place in the header
     121        add_filter('favorite_actions', array(&$this, 'show_graph'));
    98122    }
    99123
     
    102126     * and echo it all out.
    103127     */
    104     function footer() {
     128    function show_graph($ret) {
    105129        global $_wp_admin_css_colors;
    106130
    107131        // Figure out a good color scheme to use.
    108132        $scheme_name = get_user_option('admin_color');
    109         if ( empty($scheme_name) || !isset($_wp_admin_css_colors[$scheme_name]) || $scheme_name =='fresh' ) {
    110             $colors = array('bg'=>'E4F2FD', 'under'=>'2583AD', 'line'=>'D54E21');
    111         } else if( $scheme_name == 'classic' ) {
    112             $colors = array('bg'=>'14568A', 'under'=>'CFEBF6', 'line'=>'D54E21');
     133
     134        if ( empty($scheme_name) || !isset($_wp_admin_css_colors[$scheme_name]) ) {
     135            if( $scheme_name == 'fresh' ) {
     136                $colors = array('bg'=>'E4F2FD', 'under'=>'2583AD', 'line'=>'D54E21');
     137            } else { // if( $scheme_name == 'classic' ) {
     138                $colors = array('bg'=>'14568A', 'under'=>'CFEBF6', 'line'=>'D54E21');
     139            }
    113140        } else {
    114141            $colors = array('bg'=>'FF0000', 'under'=>'00FF00', 'line'=>'0000FF');
    115142            $scheme = $_wp_admin_css_colors[$scheme_name];
    116             for( $i=0; $i<3; $i++ ) {
    117                 if( isset( $scheme->colors[$i])) $colors[$i] = substr($scheme->colors[$i],1);
    118             }
     143
     144            if( count($scheme->colors)>3 ) {
     145                $colors['bg']    = substr($scheme->colors[0],1);
     146                $colors['under'] = substr($scheme->colors[1],1);
     147                $colors['line']  = substr($scheme->colors[2],1);
     148            }
    119149        }       
    120150        $colors = apply_filters('immerstat_colors', $colors);
    121151       
    122152        $stats = get_option('immerstat_data');
    123         $current_ratio = (float)(($stats['current']-$stats['min'])/($stats['max']-$stats['min']));
     153
     154        if( $stats['max']==$stats['min']) {
     155            $current_ratio=0;
     156        } else {
     157            $current_ratio = (float)(($stats['current']-$stats['min'])/($stats['max']-$stats['min']));
     158        }
    124159        $width = $stats['days']*4;
    125160
     
    133168       
    134169        $link_args = apply_filters('immerstat_img_link_args', $link_args);
    135         $link = add_query_arg($link_args, 'http://chart.apis.google.com/chart?')       
    136 ?>
    137 <script type="text/javascript">
    138     var img = jQuery('<a href="index.php?page=stats"><img title="<?php echo $stats['current'] ?>" alt="<?php echo $stats['current'] ?>" style="position:absolute;top:35px;right:20px;" height="60" width="<?php echo $width ?>" src="<?php echo $link ?>" /></a>');
    139     jQuery('#wphead').append(img);
    140 </script>
    141 <?php
     170        $link = add_query_arg($link_args, 'http://chart.apis.google.com/chart?');
     171
     172        ?><div id="immerstat" style="float:left">
     173        <a href="index.php?page=stats">
     174        <img title="<?php echo $stats['current'] ?>"
     175             alt="<?php echo $stats['current'] ?>"
     176             height="46" width="<?php echo $width ?>"
     177             src="<?php echo $link ?>" />
     178        </a></div><?php
     179
     180        // Don't break the filter
     181        return $ret;
    142182    }
    143183}
  • immerstat/tags/0.5/readme.txt

    r45294 r126622  
    33Donate link: http://scompt.com/projects/immerstat
    44Tags: stats, wordpress, admin
    5 Requires at least: 2.2
    6 Tested up to: 2.5
    7 Stable tag: 0.5
     5Requires at least: 2.7
     6Tested up to: 2.8
     7Stable tag: 0.6
    88
    9 ImmerStat places a .PNG in the top-right corner of your admin screen with your current WordPress.com pageview statistics.
     9ImmerStat places an image in the header of your admin screen with your current WordPress.com pageview statistics.
    1010
    1111== Description ==
    1212
    13 ImmerStat places a .PNG in the top-right corner of your admin screen with your current WordPress.com pageview statistics.  You must also have the [WordPress.com Stats plugin](http://wordpress.org/extend/plugins/stats/) installed and configured.  The graphic is provided using the [Google Charts API](http://code.google.com/apis/chart/).
    14 
    15 It also removes the WordPress.com Stats panel from the dashboard.  If you want to see all the information that WordPress.com Stats provides, you can still go to that subpage.  Your dashboard no longer has any Flash elements on it!
    16 
    17 ImmerStat has been tested in WordPress 2.5.  It should work in versions 2.3 and 2.2, but it hasn't been tested there.  Please let [me](mailto:[email protected]) know if there are any problems.
     13ImmerStat places an image in the header of your admin screen with your current WordPress.com pageview statistics.  You must also have the [WordPress.com Stats plugin](http://wordpress.org/extend/plugins/stats/) installed and configured.  The graphic is provided using the [Google Charts API](http://code.google.com/apis/chart/).
    1814
    1915== Installation ==
     
    2420== Configuration ==
    2521
    26 There's no Options/Settings panel for ImmerStat.  Instead, a number of filter hooks are provided to change the default behavior.  Here's what they are.
    27 
    28 = immerstat_days =
    29 
    30 This is the number of days that should be displayed.  The default value is `30`.
     22The number of days displayed in the image is controlled in the Miscellaneous Settings page.  The default value is 30.  The rest of the options can be controlled using the following filter hooks:
    3123
    3224= immerstat_colors =
     
    4638== Screenshots ==
    4739
    48 1. ImmerStat adds a small .PNG to the top-right corner of your admin screen.
     401. ImmerStat adds a small image to the header of your admin screen.
    4941
    5042== Future Plans ==
     
    5446== Version History ==
    5547
     48= Version 0.6 =
     49
     50* Updated for WordPress 2.7/2.8
     51* Now shows an image that fits into the empty space in the middle of the admin header
     52* Moved days setting to Settings page
     53* Won't show warning if there's no data
     54
    5655= Version 0.5 =
    5756
Note: See TracChangeset for help on using the changeset viewer.