Plugin Directory

Changeset 422897


Ignore:
Timestamp:
08/13/2011 12:07:36 PM (15 years ago)
Author:
Denis Buka
Message:
 
Location:
generate-cache
Files:
8 added
6 edited

Legend:

Unmodified
Added
Removed
  • generate-cache/tags/0.2/generate-cache.php

    r420326 r422897  
    161161function gen_cache_validate_options($input) {
    162162    if( ( trim( $input['gen_cache_time_hr'] ) != "" ) && ( trim( $input['gen_cache_time_min'] ) != "" ) ) {
    163         $now = time() + get_option('gmt_offset') * 3600;
     163        $offset = get_option('gmt_offset') * 3600;
     164        $now = time();
    164165        $midnight = $now - ( $now%86400 );
    165166        $converted = strtotime( trim( $input['gen_cache_time_hr'] ) . ":" . trim( $input['gen_cache_time_min'] ) );
    166         if( $converted > $now ) {
     167        //$converted = $converted%86400 + $midnight;
     168        if( $converted%86400 == 0 ) {
     169            $start = $midnight + ( $converted%86400 ) + 86400;
     170        } elseif( ( $converted - $offset ) > $now ) {
    167171            $start = $converted;
    168172        } else {
    169173            $start = $midnight + ( $converted%86400 ) + 86400;
    170174        }
    171         $start = $start - get_option('gmt_offset') * 3600;
    172         //$start = $now;
     175        $start = $start - $offset;
    173176
    174177        $timestamp = wp_next_scheduled( 'gen_cache_hook' );
     
    176179       
    177180        if (!wp_next_scheduled('gen_cache_hook')) {
    178             wp_schedule_event( $start/* - get_option('gmt_offset') * 3600*/, $input['gen_cache_freq'], 'gen_cache_hook' );
     181            wp_schedule_event( $start, $input['gen_cache_freq'], 'gen_cache_hook' );
    179182        }
    180183    } else {
  • generate-cache/trunk/functions.php

    r420299 r422897  
    1111    $asynchronous_call = curl_post_async( $url, $params );
    1212}
    13 
     13function slaap($seconds) {
     14    $seconds = abs($seconds);
     15    if ($seconds < 1):
     16        usleep($seconds*1000000);
     17    else:
     18        sleep($seconds);
     19    endif;   
     20}
    1421function get_data($url) {
    1522    $ch = curl_init();
  • generate-cache/trunk/generate-cache.php

    r420326 r422897  
    44Plugin URI: http://www.denisbuka.ru/generate-cache/
    55Description: When your cache is emptied (say, upon a new post or comment publication), the plugin loops through selected items (posts, categories, tags or pages) and makes sure you have them all freshly cached for quicker access.
    6 Version: 0.2
     6Version: 0.3
    77Author: Denis Buka
    88Author URI: http://www.denisbuka.ru
     
    3939                        "gen_cache_tags" => "1",
    4040                        "gen_cache_pages" => "1",
     41                        "gen_cache_speed" => "1",
    4142                        "gen_cache_dir" => "",
    42                         "gen_cache_cur_cache_dir" => "",
    4343                        "gen_cache_final_dir" => "",
    4444                        "gen_cache_user_dir" => "",
     
    123123               
    124124                <tr>
     125                    <th scope="row" style="width:270px;"><strong>Caching speed:</strong><br /><em>(interval between subsequent page calls)</em></th>
     126                    <td>
     127                        <label><input style="text-align:right;" type="text" size="4" name="gen_cache_options[gen_cache_speed]" value="<?php echo $options['gen_cache_speed']; ?>" /> seconds&nbsp;&nbsp;&nbsp;<em>&ndash; <strong>Warning:</strong> setting this to less than a second may impede your server's performance!</em></label>
     128                    </td>
     129                </tr>
     130
     131                <tr>
    125132                    <th scope="row" style="width:270px;"><strong>Schedule cache generation:</strong><br /><em>(you can optionally schedule cache generation to be run periodically even if cache folder size is above limit)</em></th>
    126133                    <td>
     
    149156            </p>
    150157        </form>
     158                       
     159        <?php
     160        if( isset( $_POST['gen_cache_now'] ) ) initCache();
     161
     162        $genflag = WP_PLUGIN_DIR . '/generate-cache/generation_running';
     163        if( isset( $_POST['gen_cache_abort'] ) ) unlink( $genflag );;
     164        if( file_exists( $genflag ) ) {
     165            echo '  <form method="post">
     166                        <p class="submit"><strong>Cache generation is now in progress...</strong>&nbsp;&nbsp;&nbsp;
     167                        <input type="submit" name="gen_cache_abort" value="Abort" />
     168                        </p>
     169                    </form>';
     170        } else {
     171            echo '  <form method="post">
     172                        <p class="submit">You can start cache generation manually by hitting this button:&nbsp;&nbsp;&nbsp;
     173                        <input type="submit" name="gen_cache_now" value="Generate cache now!" />
     174                        </p>
     175                    </form>';
     176        }
     177        ?>
    151178
    152179    </div>
     
    161188function gen_cache_validate_options($input) {
    162189    if( ( trim( $input['gen_cache_time_hr'] ) != "" ) && ( trim( $input['gen_cache_time_min'] ) != "" ) ) {
    163         $now = time() + get_option('gmt_offset') * 3600;
     190        $offset = get_option('gmt_offset') * 3600;
     191        $now = time();
    164192        $midnight = $now - ( $now%86400 );
    165193        $converted = strtotime( trim( $input['gen_cache_time_hr'] ) . ":" . trim( $input['gen_cache_time_min'] ) );
     194        $converted = ($converted - $offset)%86400 + $midnight;
    166195        if( $converted > $now ) {
    167196            $start = $converted;
     
    169198            $start = $midnight + ( $converted%86400 ) + 86400;
    170199        }
    171         $start = $start - get_option('gmt_offset') * 3600;
    172         //$start = $now;
    173200
    174201        $timestamp = wp_next_scheduled( 'gen_cache_hook' );
     
    176203       
    177204        if (!wp_next_scheduled('gen_cache_hook')) {
    178             wp_schedule_event( $start/* - get_option('gmt_offset') * 3600*/, $input['gen_cache_freq'], 'gen_cache_hook' );
     205            wp_schedule_event( $start, $input['gen_cache_freq'], 'gen_cache_hook' );
    179206        }
    180207    } else {
  • generate-cache/trunk/readme.txt

    r420299 r422897  
    55Requires at least: 3.2
    66Tested up to: 3.2
    7 Stable tag: 0.2
     7Stable tag: 0.3
    88
    99Makes sure your entire website is fully cached at all times. Can be used when performing website maintenance/construction.
     
    2929* Tries to guess your cache folder location, or you can specify it manually.   
    3030* Choose for which blog items (posts, categories, tags, pages) cache should be regenerated.
     31* Set cache generation interval.   
    3132* Schedule automatic cache generation to be run at a specific time even if cache folder size is not below limit (in case your caching plugin doesn't emply cache upon content changes).   
     33* Manually start/abort cache generation from the admin page.   
    3234
    3335
     
    5456== Screenshots ==
    5557
     581. Settings admin page   
     59
    5660== Changelog ==
     61
     62= 0.3 =
     63* Minor code fixes
     64* Added manual cache generate/abort
     65
     66= 0.2 =
     67* Added scheduling feature
    5768
    5869= 0.1 =
    5970* Initial release
    60 
    61 = 0.2 =
    62 * Added scheduling feature
  • generate-cache/trunk/run1.php

    r418947 r422897  
    1212
    1313$links = getCacheLinks();
     14$options = get_option('gen_cache_options');
     15
    1416
    1517$contents = get_data( $links[$count] );
    16 sleep(1);
     18slaap( $options['gen_cache_speed'] );
    1719unset( $contents );
    1820
  • generate-cache/trunk/run2.php

    r418947 r422897  
    1212
    1313$links = getCacheLinks();
     14$options = get_option('gen_cache_options');
     15
    1416
    1517$contents = get_data( $links[$count] );
    16 sleep(1);
     18slaap( $options['gen_cache_speed'] );
    1719unset( $contents );
    1820
Note: See TracChangeset for help on using the changeset viewer.