Changeset 45292

Show
Ignore:
Timestamp:
05/11/08 19:20:29 (2 months ago)
Author:
scompt
Message:

tweeks.
No longer does much work if no new stats were downloaded.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • immerstat/trunk/immerstat.php

    • Property svn:keywords set to Id
    r45215 r45292  
    33Plugin Name: ImmerStat 
    44Plugin URI: http://scompt.com/projects/immerstat 
    5 Description: Replaces the Flash-based WordPress.com stats display on the dashboard with an ever-present .PNG in the top-right corner
     5Description: ImmerStat places a .PNG in the top-right corner of your admin screen with your current WordPress.com pageview statistics
    66Author: Edward Dale 
    77Author URI: http://scompt.com/ 
     
    99*/ 
    1010 
     11/** 
     12 * ImmerStat places a .PNG in the top-right corner of your admin screen with  
     13 * your current WordPress.com pageview statistics. 
     14 * 
     15 * LICENSE 
     16 * This file is part of ImmerStat. 
     17 * 
     18 * ImmerStat is free software; you can redistribute it and/or 
     19 * modify it under the terms of the GNU General Public License 
     20 * as published by the Free Software Foundation; either version 2 
     21 * of the License, or (at your option) any later version. 
     22 * 
     23 * This program is distributed in the hope that it will be useful, 
     24 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     26 * GNU General Public License for more details. 
     27 * 
     28 * You should have received a copy of the GNU General Public License 
     29 * along with this program; if not, write to the Free Software 
     30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
     31 * 
     32 * @package    ImmerStat 
     33 * @author     Edward Dale <scompt@scompt.com> 
     34 * @copyright  Copyright 2008 Edward Dale 
     35 * @license    http://www.gnu.org/licenses/gpl.txt GPL 2.0 
     36 * @version    $Id:$ 
     37 * @link       http://www.scompt.com/projects/immerstat 
     38 * @since      0.5 
     39 */ 
    1140class ImmerStat { 
     41     
     42    // Whether to regenerate stats 
     43    var $do_load = False; 
     44     
    1245    /** 
    1346     * Make sure we've got all we need to run and the run. 
     
    1851        } 
    1952    } 
     53     
     54    /** 
     55     * A filter hook used to pick up on whether new stats were downloaded. 
     56     */ 
     57    function enable_load($ret) { 
     58        $this->do_load = True; 
     59        return $ret; 
     60    } 
    2061 
    2162    /** 
    2263     * Gets the view count from the WordPress.com Stats plugin and saves it 
    2364     * in a form that we can use later in the footer. 
    24      * 
    25      * TODO: If the stats haven't changed, don't do all this stuff. 
    2665     */ 
    2766    function load() { 
    2867        $num_days = apply_filters('immerstat_days', 30); 
     68 
     69        // Use this filter to determine when new stats were actually retrieved 
     70        add_filter('update_option_stats_cache', array(&$this, 'enable_load')); 
    2971        $from_wp = stats_get_csv('views', array('days'=>$num_days, 'limit'=>$num_days, 'summarize'=>false)); 
     72        remove_filter('update_option_stats_cache', array(&$this, 'enable_load')); 
     73 
    3074        $data = array(); 
    3175        $max = $min = $from_wp[0]['views']; 
    32         foreach( $from_wp as $day ) { 
    33             if( $max<$day['views'] ) $max=$day['views']; 
    34             if( $min>$day['views'] ) $min=$day['views']; 
    35             $data []= $day['views']; 
     76 
     77        if( $this->do_load ) { 
     78            foreach( $from_wp as $day ) { 
     79                if( $max<$day['views'] ) $max=$day['views']; 
     80                if( $min>$day['views'] ) $min=$day['views']; 
     81                $data []= $day['views']; 
     82            } 
     83 
     84            $stats = array('data'=>implode($data, ','), 'min'=>$min, 'max'=>$max, 'days'=>$num_days, 'current'=>$data[count($data)-1]); 
     85            update_option('immerstat_data', $stats); 
    3686        } 
    37  
    38         $stats = array('data'=>implode($data, ','), 'min'=>$min, 'max'=>$max, 'days'=>$num_days, 'current'=>$data[count($data)-1]); 
    39         update_option('immerstat_data', $stats); 
    4087 
    4188        add_action('admin_footer', array(&$this, 'footer'));