Plugin Directory

Changeset 399351


Ignore:
Timestamp:
06/20/2011 07:35:35 PM (15 years ago)
Author:
Rontu
Message:
  • added update interval option
  • PiwikCounter now just updates the amount of visits before today if they are greater than the old value.
Location:
piwikcounter/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • piwikcounter/trunk/class.PiwikCounterAdministration.php

    r386209 r399351  
    3131            update_option( 'piwikcounter_start_date', $_POST[ 'start_date' ] );
    3232            update_option( 'piwikcounter_unique_visitors', $_POST[ 'unique_visitors' ] );
     33           
     34            if ( $this->validateInt( $_POST[ 'update_interval' ], 0, 60 ) == $_POST[ 'update_interval' ] )
     35            {
     36                update_option( 'piwikcounter_update_every', $_POST[ 'update_interval' ] );
     37            }
    3338           
    3439            if (isset($_POST[ 'visits_today_visible' ]) &&  ($_POST[ 'visits_today_visible' ] == 1)) {
     
    95100                    </td>
    96101                </tr>
     102               
     103                <tr valign="top">
     104                    <th scope="row"><?php _e("Update interval", 'piwikcounter'); ?></th>
     105                    <td>
     106                        <input type="text" size="4" name="update_interval" value="<?php echo get_option('piwikcounter_update_every') ?>" /> (time in minutes between 0 and 60)
     107                    </td>
     108                </tr>
    97109       
    98110                <tr valign="top">
     
    113125        <?php
    114126    }
     127   
     128    private function validateInt($value, $min_range = null, $max_range = null) {
     129       
     130        if ($min_range != null AND $max_range != null) {
     131            $int_options = array("options"=>array("min_range"=>$min_range, "max_range"=>$max_range));
     132        }
     133        else if ($min_range == null AND $max_range != null) {
     134            $int_options = array("options"=>array("max_range"=>$max_range));
     135        }
     136        else if ($min_range != null AND $max_range == null) {
     137            $int_options = array("options"=>array("min_range"=>$min_range));
     138        }
     139
     140        return filter_var($value, FILTER_VALIDATE_INT, $int_options);
     141    }
    115142
    116143}
  • piwikcounter/trunk/class.Visitors.php

    r386209 r399351  
    5858       
    5959        // Update
    60         update_option( 'piwikcounter_visitors_yesterday', $visitors_yesterday );   
    61         update_option( 'piwikcounter_visitors_last_change', date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y"))) );
    62    
     60        if ( get_option( 'piwikcounter_visitors_yesterday' ) < $visitors_yesterday )
     61        {
     62            update_option( 'piwikcounter_visitors_yesterday', $visitors_yesterday );   
     63            update_option( 'piwikcounter_visitors_last_change', date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y"))) );
     64        }
    6365    }
    6466   
    6567    public function getTodaysVisitors() {
    6668       
    67         return $this->getVisitors( null, get_option('piwikcounter_piwik_url'), get_option('piwikcounter_site_id'), get_option('piwikcounter_auth_key'), get_option('piwikcounter_unique_visitors') );
     69        if ( ($this->minTimeDiffReached( get_option('piwikcounter_todays_visitors_last_change'), get_option('piwikcounter_update_every')) ) )
     70        {
     71            update_option( 'piwikcounter_todays_visitors_last_change', time() );
     72            update_option( 'piwikcounter_todays_visitors', $this->getVisitors( null, get_option('piwikcounter_piwik_url'), get_option('piwikcounter_site_id'), get_option('piwikcounter_auth_key'), get_option('piwikcounter_unique_visitors')) );
     73        }
     74   
     75        return (int) get_option('piwikcounter_todays_visitors');
    6876   
    6977    }
    70 
     78   
     79    // check the minimum time between two timestamps
     80    private function minTimeDiffReached($timestamp, $timedifference)
     81    {
     82        if ( time()-((int) $timedifference * 60) > (int) $timestamp )
     83        {
     84            return true;
     85        }   
     86        return false;
     87    }
     88   
    7189}
    7290
  • piwikcounter/trunk/piwikcounter.php

    r386217 r399351  
    99Plugin URI: http://piwikcounter.rontu.de
    1010Description: PiwikCounter allows you to show the summary of (unique) visitors as a widget on your blog.
    11 Version: 0.2.0
     11Version: 0.3.0
    1212Author: Tobias Etzold
    1313Email: tobias.etzold@googlemail.com
     
    3333add_option( 'piwikcounter_visitors_last_change', '2000-01-01', '', 'yes' ); // last modification date of piwikcounter_visitors_yesterday (date YYYY-MM-DD)
    3434add_option( 'piwikcounter_visits_today_visible', '1', '', 'yes' );  // enables visability of visits for today
     35add_option( 'piwikcounter_todays_visitors', '', '', 'yes' );        // cached amount of visitors for today
     36add_option( 'piwikcounter_todays_visitors_last_change', '0000000001', '', 'yes' ); // last modification of piwikcounter_todays_visitors (timestamp)
     37add_option( 'piwikcounter_update_every', '5', '', 'yes' );          // time in minutes between updates of todays visitors
    3538
    3639$pca = new PiwikCounterAdministration();
Note: See TracChangeset for help on using the changeset viewer.