Beispiel #1
0
function wp_cache_files()
{
    global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled;
    if ('/' != substr($cache_path, -1)) {
        $cache_path .= '/';
    }
    if ($valid_nonce) {
        if (isset($_REQUEST['wp_delete_cache'])) {
            wp_cache_clean_cache($file_prefix);
        }
        if (isset($_REQUEST['wp_delete_cache_file'])) {
            wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']);
        }
        if (isset($_REQUEST['wp_delete_expired'])) {
            wp_cache_clean_expired($file_prefix);
        }
    }
    if (isset($_REQUEST['wp_list_cache'])) {
        $list_files = true;
        $list_mess = "Update list";
    } else {
        $list_mess = "List files";
    }
    echo '<br /><a name="list"></a><fieldset class="options"><h3>Cache Contents</h3>';
    /*
    echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
    echo '<input type="hidden" name="wp_list_cache" />';
    echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
    echo "</form>\n";
    */
    $list_files = false;
    // it doesn't list supercached files, and removing single pages is buggy
    $count = 0;
    $expired = 0;
    $now = time();
    if ($handle = @opendir($cache_path . 'meta/')) {
        if ($list_files) {
            echo "<table cellspacing=\"0\" cellpadding=\"5\">";
        }
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) {
                $this_expired = false;
                $content_file = preg_replace("/meta\$/", "html", $file);
                $mtime = filemtime($cache_path . 'meta/' . $file);
                if (!($fsize = @filesize($cache_path . $content_file))) {
                    continue;
                }
                // .meta does not exists
                $fsize = intval($fsize / 1024);
                $age = $now - $mtime;
                if ($age > $cache_max_time) {
                    $expired++;
                    $this_expired = true;
                }
                $count++;
                if ($list_files) {
                    $meta = new CacheMeta();
                    $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file));
                    echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>';
                    $flip = !$flip;
                    echo '<td><a href="http://' . $meta->uri . '" target="_blank" >';
                    echo $meta->uri . "</a></td>";
                    if ($this_expired) {
                        echo "<td><span style='color:red'>{$age} secs</span></td>";
                    } else {
                        echo "<td>{$age} secs</td>";
                    }
                    echo "<td>{$fsize} KB</td>";
                    echo '<td><form name="wp_delete_cache_file" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
                    echo '<input type="hidden" name="wp_list_cache" />';
                    echo '<input type="hidden" name="wp_delete_cache_file" value="' . preg_replace("/^(.*)\\.meta\$/", "\$1", $file) . '" />';
                    echo '<div><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
                    wp_nonce_field('wp-cache');
                    echo "</form></td></tr>\n";
                }
            }
        }
        closedir($handle);
        if ($list_files) {
            echo "</table>";
        }
    }
    if ($cache_enabled == true && $super_cache_enabled == true) {
        $now = time();
        $sizes = array('expired' => 0, 'cached' => 0, 'ts' => 0);
        if (is_dir($supercachedir)) {
            $entries = glob($supercachedir . '/*');
            foreach ((array) $entries as $entry) {
                if ($entry != '.' && $entry != '..') {
                    $sizes = wpsc_dirsize($entry, $sizes);
                }
            }
        } else {
            if (is_file($supercachedir) && filemtime($supercachedir) + $cache_max_time <= $now) {
                $sizes['expired']++;
            }
        }
        $sizes['ts'] = time();
    }
    echo "<p><h4>WP-Cache</h4></p>";
    echo "<ul><li>{$count} cached pages</li>";
    echo "<li>{$expired} expired pages</li></ul>";
    if ($cache_enabled == true && $super_cache_enabled == true) {
        echo "<p><h4>WP-Super-Cache</h4></p>";
        echo "<ul><li>" . intval($sizes['cached'] / 2) . " cached pages</li>";
        $age = intval(($now - $sizes['ts']) / 60);
        echo "<li>" . intval($sizes['expired'] / 2) . " expired pages.</li></ul>";
    }
    echo '<form name="wp_cache_content_expired" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
    echo '<input type="hidden" name="wp_delete_expired" />';
    echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Delete expired &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '<form name="wp_cache_content_delete" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
    echo '<input type="hidden" name="wp_delete_cache" />';
    echo '<div><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete cache &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '</fieldset>';
}
Beispiel #2
0
function wp_cache_files()
{
    global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
    if ('/' != substr($cache_path, -1)) {
        $cache_path .= '/';
    }
    if ($valid_nonce) {
        if (isset($_REQUEST['wp_delete_cache'])) {
            wp_cache_clean_cache($file_prefix);
        }
        if (isset($_REQUEST['wp_delete_expired'])) {
            wp_cache_clean_expired($file_prefix);
        }
    }
    echo "<a name='listfiles'></a>";
    echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __('Cache Contents', 'wp-super-cache') . '</h3>';
    $list_files = false;
    // it doesn't list supercached files, and removing single pages is buggy
    $count = 0;
    $expired = 0;
    $now = time();
    if ($handle = @opendir($blog_cache_dir . 'meta/')) {
        if ($list_files) {
            echo "<table cellspacing=\"0\" cellpadding=\"5\">";
        }
        $wp_cache_fsize = 0;
        if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletewpcache') {
            $deleteuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri'])))));
            $deleteuri = str_replace('\\', '', $deleteuri);
        } else {
            $deleteuri = '';
        }
        if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletesupercache') {
            $supercacheuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri'])))));
            $supercacheuri = trailingslashit(str_replace('\\', '', $supercacheuri));
            printf(__("Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache'), $supercacheuri);
            @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html');
            @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html.gz');
            prune_super_cache($cache_path . 'supercache/' . $supercacheuri . 'page', true);
            @rmdir($cache_path . 'supercache/' . $supercacheuri);
        }
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) {
                $content_file = preg_replace("/meta\$/", "html", $file);
                $mtime = filemtime($blog_cache_dir . 'meta/' . $file);
                if (!($fsize = @filesize($blog_cache_dir . $content_file))) {
                    continue;
                }
                // .meta does not exists
                $age = $now - $mtime;
                if ($valid_nonce && $_GET['listfiles']) {
                    $meta = unserialize(file_get_contents($blog_cache_dir . 'meta/' . $file));
                    if ($deleteuri != '' && $meta['uri'] == $deleteuri) {
                        printf(__("Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache'), $deleteuri);
                        @unlink($blog_cache_dir . 'meta/' . $file);
                        @unlink($blog_cache_dir . $content_file);
                        continue;
                    }
                    $meta['age'] = $age;
                    if ($age > $cache_max_time) {
                        $expired_list[$age][] = $meta;
                    } else {
                        $cached_list[$age][] = $meta;
                    }
                }
                if ($age > $cache_max_time) {
                    $expired++;
                } else {
                    $count++;
                }
                $wp_cache_fsize += $fsize;
                $fsize = intval($fsize / 1024);
            }
        }
        closedir($handle);
        if ($list_files) {
            echo "</table>";
        }
    }
    if ($wp_cache_fsize != 0) {
        $wp_cache_fsize = $wp_cache_fsize / 1024;
    } else {
        $wp_cache_fsize = 0;
    }
    if ($wp_cache_fsize > 1024) {
        $wp_cache_fsize = number_format($wp_cache_fsize / 1024, 2) . "MB";
    } elseif ($wp_cache_fsize != 0) {
        $wp_cache_fsize = number_format($wp_cache_fsize, 2) . "KB";
    } else {
        $wp_cache_fsize = '0KB';
    }
    if ($cache_enabled == true && $super_cache_enabled == true) {
        $now = time();
        $sizes = array('expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0);
        if (is_dir($supercachedir)) {
            if ($dh = opendir($supercachedir)) {
                while (($entry = readdir($dh)) !== false) {
                    if ($entry != '.' && $entry != '..') {
                        $sizes = wpsc_dirsize(trailingslashit($supercachedir) . $entry, $sizes);
                    }
                }
                closedir($dh);
            }
        } else {
            $filem = @filemtime($supercachedir);
            if (is_file($supercachedir) && $filem + $cache_max_time <= $now) {
                $sizes['expired']++;
                if ($valid_nonce && $_GET['listfiles']) {
                    $sizes['expired_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem;
                }
            } else {
                if ($valid_nonce && $_GET['listfiles'] && $filem) {
                    $sizes['cached_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem;
                }
            }
        }
        $sizes['ts'] = time();
    }
    echo "<p><strong>" . __('WP-Cache', 'wp-super-cache') . " ({$wp_cache_fsize})</strong></p>";
    echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), $count) . "</li>";
    echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), $expired) . "</li></ul>";
    if ($cache_enabled == true && $super_cache_enabled == true) {
        $fsize = $sizes['fsize'] / 1024;
        if ($fsize > 1024) {
            $fsize = number_format($fsize / 1024, 2) . "MB";
        } elseif ($fsize != 0) {
            $fsize = number_format($fsize, 2) . "KB";
        } else {
            $fsize = "0KB";
        }
        $divisor = $cache_compression == 1 ? 2 : 1;
        echo "<p><strong>" . __('WP-Super-Cache', 'wp-super-cache') . " ({$fsize})</strong></p>";
        echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), intval($sizes['cached'] / $divisor)) . "</li>";
        $age = intval(($now - $sizes['ts']) / 60);
        echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), intval($sizes['expired'] / $divisor)) . "</li></ul>";
    }
    if ($valid_nonce && $_GET['listfiles']) {
        echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 70%; overflow: auto'>";
        if (is_array($cached_list) && !empty($cached_list)) {
            echo "<h4>" . __('Fresh WP-Cached Files', 'wp-super-cache') . "</h4>";
            echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
            $c = 1;
            $flip = 1;
            ksort($cached_list);
            foreach ($cached_list as $age => $d) {
                foreach ($d as $details) {
                    $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                    echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                    $flip = !$flip;
                    $c++;
                }
            }
            echo "</table>";
        }
        if (is_array($expired_list) && !empty($expired_list)) {
            echo "<h4>" . __('Stale WP-Cached Files', 'wp-super-cache') . "</h4>";
            echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
            $c = 1;
            $flip = 1;
            ksort($expired_list);
            foreach ($expired_list as $age => $d) {
                foreach ($d as $details) {
                    $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                    echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                    $flip = !$flip;
                    $c++;
                }
            }
            echo "</table>";
        }
        if (is_array($sizes['cached_list']) & !empty($sizes['cached_list'])) {
            echo "<h4>" . __('Fresh Super Cached Files', 'wp-super-cache') . "</h4>";
            echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
            $c = 1;
            $flip = 1;
            ksort($sizes['cached_list']);
            foreach ($sizes['cached_list'] as $age => $d) {
                foreach ($d as $uri => $n) {
                    $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                    echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                    $flip = !$flip;
                    $c++;
                }
            }
            echo "</table>";
        }
        if (is_array($sizes['expired_list']) && !empty($sizes['expired_list'])) {
            echo "<h4>" . __('Stale Super Cached Files', 'wp-super-cache') . "</h4>";
            echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
            $c = 1;
            $flip = 1;
            ksort($sizes['expired_list']);
            foreach ($sizes['expired_list'] as $age => $d) {
                foreach ($d as $uri => $n) {
                    $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                    echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                    $flip = !$flip;
                    $c++;
                }
            }
            echo "</table>";
        }
        echo "</div>";
        echo "<p><a href='?page=wpsupercache#top'>" . __('Hide file list', 'wp-super-cache') . "</a></p>";
    } else {
        echo "<p><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'listfiles' => '1')), 'wp-cache') . "#listfiles'>" . __('List all cached files', 'wp-super-cache') . "</a></p>";
    }
    $last_gc = get_option("wpsupercache_gc_time");
    if ($last_gc) {
        $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
        $next_gc_mins = time() - $last_gc;
        echo "<p>" . sprintf(__('<strong>Garbage Collection</strong><br />Last GC was <strong>%s</strong> minutes ago<br />', 'wp-super-cache'), date('i:s', $next_gc_mins));
        printf(__("Next GC in <strong>%s</strong> minutes", 'wp-super-cache'), date('i:s', $next_gc - $next_gc_mins)) . "</p>";
    }
    echo "<p>" . sprintf(__('Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache'), $cache_max_time) . "</p>";
    echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">';
    echo '<input type="hidden" name="wp_delete_expired" />';
    echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="' . __('Delete Expired', 'wp-super-cache') . ' &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
    echo '<input type="hidden" name="wp_delete_cache" />';
    echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __('Delete Cache', 'wp-super-cache') . ' &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '</fieldset>';
}
Beispiel #3
0
function wp_cache_files()
{
    global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir;
    if ('/' != substr($cache_path, -1)) {
        $cache_path .= '/';
    }
    if ($valid_nonce) {
        if (isset($_REQUEST['wp_delete_cache'])) {
            wp_cache_clean_cache($file_prefix);
        }
        if (isset($_REQUEST['wp_delete_cache_file'])) {
            wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']);
        }
        if (isset($_REQUEST['wp_delete_expired'])) {
            wp_cache_clean_expired($file_prefix);
        }
    }
    if (isset($_REQUEST['wp_list_cache'])) {
        $list_files = true;
        $list_mess = "Update list";
    } else {
        $list_mess = "List files";
    }
    echo '<fieldset class="options" id="show-this-fieldset"><h3>Cache Contents</h3>';
    /*
    echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
    echo '<input type="hidden" name="wp_list_cache" />';
    echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
    echo "</form>\n";
    */
    $list_files = false;
    // it doesn't list supercached files, and removing single pages is buggy
    $count = 0;
    $expired = 0;
    $now = time();
    if ($handle = @opendir($blog_cache_dir . 'meta/')) {
        if ($list_files) {
            echo "<table cellspacing=\"0\" cellpadding=\"5\">";
        }
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) {
                $this_expired = false;
                $content_file = preg_replace("/meta\$/", "html", $file);
                $mtime = filemtime($blog_cache_dir . 'meta/' . $file);
                if (!($fsize = @filesize($blog_cache_dir . $content_file))) {
                    continue;
                }
                // .meta does not exists
                $fsize = intval($fsize / 1024);
                $age = $now - $mtime;
                if ($age > $cache_max_time) {
                    $expired++;
                    $this_expired = true;
                }
                $count++;
                /*
                if ($list_files) {
                	$meta = new CacheMeta;
                	$meta = unserialize(file_get_contents($cache_path . 'meta/' . $file));
                	echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>';
                	$flip = !$flip;
                	echo '<td><a href="http://' . $meta->uri . '" target="_blank" >';
                	echo $meta->uri . "</a></td>";
                	if ($this_expired) echo "<td><span style='color:red'>$age secs</span></td>";
                	else echo "<td>$age secs</td>";
                	echo "<td>$fsize KB</td>";
                	echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
                	echo '<input type="hidden" name="wp_list_cache" />';
                	echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />';
                	echo '<div class="submit"><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
                	wp_nonce_field('wp-cache');
                	echo "</form></td></tr>\n";
                }
                */
            }
        }
        closedir($handle);
        if ($list_files) {
            echo "</table>";
        }
    }
    if ($cache_enabled == true && $super_cache_enabled == true) {
        $now = time();
        $sizes = array('expired' => 0, 'cached' => 0, 'ts' => 0);
        if (is_dir($supercachedir)) {
            if ($dh = opendir($supercachedir)) {
                while (($entry = readdir($dh)) !== false) {
                    if ($entry != '.' && $entry != '..') {
                        $sizes = wpsc_dirsize(trailingslashit($supercachedir) . $entry, $sizes);
                    }
                }
                closedir($dh);
            }
        } else {
            if (is_file($supercachedir) && filemtime($supercachedir) + $cache_max_time <= $now) {
                $sizes['expired']++;
            }
        }
        $sizes['ts'] = time();
    }
    echo "<p><strong>WP-Cache</strong></p>";
    echo "<ul><li>{$count} Cached Pages</li>";
    echo "<li>{$expired} Expired Pages</li></ul>";
    if ($cache_enabled == true && $super_cache_enabled == true) {
        echo "<p><strong>WP-Super-Cache</strong></p>";
        echo "<ul><li>" . intval($sizes['cached'] / 2) . " Cached Pages</li>";
        $age = intval(($now - $sizes['ts']) / 60);
        echo "<li>" . intval($sizes['expired'] / 2) . " Expired Pages</li></ul>";
    }
    $last_gc = get_option("wpsupercache_gc_time");
    if ($last_gc) {
        $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
        echo "<p><strong>Garbage Collection</strong><br />Last: " . date("Y-m-d H:i:s", $last_gc + get_option('gmt_offset') * 3600) . "<br />";
        echo "Next: " . date("Y-m-d H:i:s", $next_gc + $last_gc + get_option('gmt_offset') * 3600) . "</p>";
    }
    echo "<p>Expired files are files older than {$cache_max_time} seconds. They are still used by the plugin and are deleted periodically.</p>";
    echo '<form name="wp_cache_content_expired" action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
    echo '<input type="hidden" name="wp_delete_expired" />';
    echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="Delete Expired &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '<form name="wp_cache_content_delete" action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
    echo '<input type="hidden" name="wp_delete_cache" />';
    echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete Cache &raquo;" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '</fieldset>';
}
Beispiel #4
0
function wp_cache_files()
{
    global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
    global $wp_cache_object_cache, $wp_cache_preload_on;
    if ('/' != substr($cache_path, -1)) {
        $cache_path .= '/';
    }
    if ($valid_nonce) {
        if (isset($_REQUEST['wp_delete_cache'])) {
            wp_cache_clean_cache($file_prefix);
            $_GET['action'] = 'regenerate_cache_stats';
        }
        if (isset($_REQUEST['wp_delete_all_cache'])) {
            wp_cache_clean_cache($file_prefix, true);
            $_GET['action'] = 'regenerate_cache_stats';
        }
        if (isset($_REQUEST['wp_delete_expired'])) {
            wp_cache_clean_expired($file_prefix);
            $_GET['action'] = 'regenerate_cache_stats';
        }
    }
    echo "<a name='listfiles'></a>";
    echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __('Cache Contents', 'wp-super-cache') . '</h3>';
    if ($wp_cache_object_cache) {
        echo "<p>" . __("Object cache in use. No cache listing available.", 'wp-super-cache') . "</p>";
        wp_cache_delete_buttons();
        echo "</fieldset>";
        return false;
    }
    $cache_stats = get_option('supercache_stats');
    if (!is_array($cache_stats) || isset($_GET['listfiles']) || $valid_nonce && array_key_exists('action', $_GET) && $_GET['action'] == 'regenerate_cache_stats') {
        $list_files = false;
        // it doesn't list supercached files, and removing single pages is buggy
        $count = 0;
        $expired = 0;
        $now = time();
        if ($handle = @opendir($blog_cache_dir . 'meta/')) {
            $wp_cache_fsize = 0;
            if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletewpcache') {
                $deleteuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri'])))));
                $deleteuri = str_replace('\\', '', $deleteuri);
            } else {
                $deleteuri = '';
            }
            if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'deletesupercache') {
                $supercacheuri = preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', str_replace('/index.php', '/', str_replace('..', '', preg_replace("/(\\?.*)?\$/", '', base64_decode($_GET['uri'])))));
                $supercacheuri = trailingslashit(str_replace('\\', '', $supercacheuri));
                printf(__("Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache'), $supercacheuri);
                @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html');
                @unlink($cache_path . 'supercache/' . $supercacheuri . 'index.html.gz');
                prune_super_cache($cache_path . 'supercache/' . $supercacheuri . 'page', true);
                @rmdir($cache_path . 'supercache/' . $supercacheuri);
            }
            while (false !== ($file = readdir($handle))) {
                if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) {
                    $content_file = preg_replace("/meta\$/", "html", $file);
                    $mtime = filemtime($blog_cache_dir . 'meta/' . $file);
                    if (!($fsize = @filesize($blog_cache_dir . $content_file))) {
                        continue;
                    }
                    // .meta does not exists
                    $age = $now - $mtime;
                    if ($valid_nonce && $_GET['listfiles']) {
                        $meta = unserialize(file_get_contents($blog_cache_dir . 'meta/' . $file));
                        if ($deleteuri != '' && $meta['uri'] == $deleteuri) {
                            printf(__("Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache'), $deleteuri);
                            @unlink($blog_cache_dir . 'meta/' . $file);
                            @unlink($blog_cache_dir . $content_file);
                            continue;
                        }
                        $meta['age'] = $age;
                        if ($cache_max_time > 0 && $age > $cache_max_time) {
                            $expired_list[$age][] = $meta;
                        } else {
                            $cached_list[$age][] = $meta;
                        }
                    }
                    if ($cache_max_time > 0 && $age > $cache_max_time) {
                        $expired++;
                    } else {
                        $count++;
                    }
                    $wp_cache_fsize += $fsize;
                    $fsize = intval($fsize / 1024);
                }
            }
            closedir($handle);
        }
        if ($wp_cache_fsize != 0) {
            $wp_cache_fsize = $wp_cache_fsize / 1024;
        } else {
            $wp_cache_fsize = 0;
        }
        if ($wp_cache_fsize > 1024) {
            $wp_cache_fsize = number_format($wp_cache_fsize / 1024, 2) . "MB";
        } elseif ($wp_cache_fsize != 0) {
            $wp_cache_fsize = number_format($wp_cache_fsize, 2) . "KB";
        } else {
            $wp_cache_fsize = '0KB';
        }
        // Supercache files
        $now = time();
        $sizes = array('expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0);
        if (is_dir($supercachedir)) {
            if ($dh = opendir($supercachedir)) {
                while (($entry = readdir($dh)) !== false) {
                    if ($entry != '.' && $entry != '..') {
                        $sizes = wpsc_dirsize(trailingslashit($supercachedir) . $entry, $sizes);
                    }
                }
                closedir($dh);
            }
        } else {
            $filem = @filemtime($supercachedir);
            if (false == $wp_cache_preload_on && is_file($supercachedir) && $cache_max_time > 0 && $filem + $cache_max_time <= $now) {
                $sizes['expired']++;
                if ($valid_nonce && $_GET['listfiles']) {
                    $sizes['expired_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem;
                }
            } else {
                if ($valid_nonce && $_GET['listfiles'] && $filem) {
                    $sizes['cached_list'][str_replace($cache_path . 'supercache/', '', $supercachedir)] = $now - $filem;
                }
            }
        }
        $sizes['ts'] = time();
        $cache_stats = array('generated' => time(), 'supercache' => $sizes, 'wpcache' => array('cached' => $count, 'expired' => $expired, 'fsize' => $wp_cache_fsize));
        update_option('supercache_stats', $cache_stats);
    } else {
        echo "<p>" . __('Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache') . "</p>";
        echo "<a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats')), 'wp-cache') . "'>" . __('Regenerate cache stats', 'wp-super-cache') . "</a>";
        if (is_array($cache_stats)) {
            echo "<p>" . sprintf(__('Cache stats last generated: %s minutes ago.', 'wp-super-cache'), number_format((time() - $cache_stats['generated']) / 60)) . "</p>";
        }
        $cache_stats = get_option('supercache_stats');
    }
    // regerate stats cache
    if (is_array($cache_stats)) {
        echo "<p><strong>" . __('WP-Cache', 'wp-super-cache') . " ({$cache_stats['wpcache']['fsize']})</strong></p>";
        echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), $cache_stats['wpcache']['cached']) . "</li>";
        echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), $cache_stats['wpcache']['expired']) . "</li></ul>";
        $divisor = $cache_compression == 1 ? 2 : 1;
        if (array_key_exists('fsize', (array) $cache_stats['supercache'])) {
            $fsize = $cache_stats['supercache']['fsize'] / 1024;
        } else {
            $fsize = 0;
        }
        if ($fsize > 1024) {
            $fsize = number_format($fsize / 1024, 2) . "MB";
        } elseif ($fsize != 0) {
            $fsize = number_format($fsize, 2) . "KB";
        } else {
            $fsize = "0KB";
        }
        echo "<p><strong>" . __('WP-Super-Cache', 'wp-super-cache') . " ({$fsize})</strong></p>";
        echo "<ul><li>" . sprintf(__('%s Cached Pages', 'wp-super-cache'), intval($cache_stats['supercache']['cached'] / $divisor)) . "</li>";
        if (isset($now) && isset($sizes)) {
            $age = intval(($now - $sizes['ts']) / 60);
        } else {
            $age = 0;
        }
        echo "<li>" . sprintf(__('%s Expired Pages', 'wp-super-cache'), intval($cache_stats['supercache']['expired'] / $divisor)) . "</li></ul>";
        if ($valid_nonce && array_key_exists('listfiles', $_GET) && $_GET['listfiles']) {
            echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>";
            if (is_array($cached_list) && !empty($cached_list)) {
                echo "<h4>" . __('Fresh WP-Cached Files', 'wp-super-cache') . "</h4>";
                echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
                $c = 1;
                $flip = 1;
                ksort($cached_list);
                foreach ($cached_list as $age => $d) {
                    foreach ($d as $details) {
                        $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                        echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                        $flip = !$flip;
                        $c++;
                    }
                }
                echo "</table>";
            }
            if (is_array($expired_list) && !empty($expired_list)) {
                echo "<h4>" . __('Stale WP-Cached Files', 'wp-super-cache') . "</h4>";
                echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Key', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
                $c = 1;
                $flip = 1;
                ksort($expired_list);
                foreach ($expired_list as $age => $d) {
                    foreach ($d as $details) {
                        $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                        echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$details['uri']}'>" . $details['uri'] . "</a></td><td> " . str_replace($details['uri'], '', $details['key']) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode($details['uri']))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                        $flip = !$flip;
                        $c++;
                    }
                }
                echo "</table>";
            }
            if (is_array($sizes['cached_list']) & !empty($sizes['cached_list'])) {
                echo "<h4>" . __('Fresh Super Cached Files', 'wp-super-cache') . "</h4>";
                echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
                $c = 1;
                $flip = 1;
                ksort($sizes['cached_list']);
                foreach ($sizes['cached_list'] as $age => $d) {
                    foreach ($d as $uri => $n) {
                        $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                        echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                        $flip = !$flip;
                        $c++;
                    }
                }
                echo "</table>";
            }
            if (is_array($sizes['expired_list']) && !empty($sizes['expired_list'])) {
                echo "<h4>" . __('Stale Super Cached Files', 'wp-super-cache') . "</h4>";
                echo "<table class='widefat'><tr><th>#</th><th>" . __('URI', 'wp-super-cache') . "</th><th>" . __('Age', 'wp-super-cache') . "</th><th>" . __('Delete', 'wp-super-cache') . "</th></tr>";
                $c = 1;
                $flip = 1;
                ksort($sizes['expired_list']);
                foreach ($sizes['expired_list'] as $age => $d) {
                    foreach ($d as $uri => $n) {
                        $bg = $flip ? 'style="background: #EAEAEA;"' : '';
                        echo "<tr {$bg}><td>{$c}</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>{$age}</td><td><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode($uri))), 'wp-cache') . "#listfiles'>X</a></td></tr>\n";
                        $flip = !$flip;
                        $c++;
                    }
                }
                echo "</table>";
            }
            echo "</div>";
            echo "<p><a href='?page=wpsupercache&tab=contents#top'>" . __('Hide file list', 'wp-super-cache') . "</a></p>";
        } elseif ($cache_stats['supercache']['cached'] > 300 || $cache_stats['supercache']['expired'] > 300 || $cache_stats['wpcache']['cached'] / $divisor > 300 || $cache_stats['wpcache']['expired'] / $divisor > 300) {
            echo "<p><em>" . __('Too many cached files, no listing possible.', 'wp-super-cache') . "</em></p>";
        } else {
            echo "<p><a href='" . wp_nonce_url(add_query_arg(array('page' => 'wpsupercache', 'listfiles' => '1')), 'wp-cache') . "#listfiles'>" . __('List all cached files', 'wp-super-cache') . "</a></p>";
        }
        $last_gc = get_option("wpsupercache_gc_time");
        if ($cache_max_time > 0 && $last_gc) {
            $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
            $next_gc_mins = time() - $last_gc;
            echo "<p>" . sprintf(__('<strong>Garbage Collection</strong><br />Last GC was <strong>%s</strong> minutes ago<br />', 'wp-super-cache'), date('i:s', $next_gc_mins));
            printf(__("Next GC in <strong>%s</strong> minutes", 'wp-super-cache'), date('i:s', $next_gc - $next_gc_mins)) . "</p>";
        }
        if ($cache_max_time > 0) {
            echo "<p>" . sprintf(__('Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache'), $cache_max_time) . "</p>";
        }
    }
    // cache_stats
    wp_cache_delete_buttons();
    echo '</fieldset>';
}
function wp_cache_files()
{
    global $cache_path, $file_prefix, $cache_max_time, $valid_nonce;
    if ('/' != substr($cache_path, -1)) {
        $cache_path .= '/';
    }
    if ($valid_nonce) {
        if (isset($_REQUEST['wp_delete_cache'])) {
            wp_cache_clean_cache($file_prefix);
        }
        if (isset($_REQUEST['wp_delete_cache_file'])) {
            wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']);
        }
        if (isset($_REQUEST['wp_delete_expired'])) {
            wp_cache_clean_expired($file_prefix);
        }
    }
    if (isset($_REQUEST['wp_list_cache'])) {
        $list_files = true;
        $list_mess = "Update list";
    } else {
        $list_mess = "List files";
    }
    echo '<a name="list"></a><fieldset class="options"><legend>Cache contents</legend>';
    echo '<form name="wp_cache_content_list" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
    echo '<input type="hidden" name="wp_list_cache" />';
    echo '<div class="submit"><input type="submit" value="' . $list_mess . '" /></div>';
    echo "</form>\n";
    $count = 0;
    $expired = 0;
    $now = time();
    if ($handle = opendir($cache_path)) {
        if ($list_files) {
            echo "<table cellspacing=\"0\" cellpadding=\"5\">";
        }
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/^{$file_prefix}.*\\.meta/", $file)) {
                $this_expired = false;
                $content_file = preg_replace("/meta\$/", "html", $file);
                $mtime = filemtime($cache_path . $file);
                if (!($fsize = @filesize($cache_path . $content_file))) {
                    continue;
                }
                // .meta does not exists
                $fsize = intval($fsize / 1024);
                $age = $now - $mtime;
                if ($age > $cache_max_time) {
                    $expired++;
                    $this_expired = true;
                }
                $count++;
                if ($list_files) {
                    $meta = new CacheMeta();
                    $meta = unserialize(file_get_contents($cache_path . $file));
                    echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>';
                    $flip = !$flip;
                    echo '<td><a href="http://' . $meta->uri . '" target="_blank" >';
                    echo $meta->uri . "</a></td>";
                    if ($this_expired) {
                        echo "<td><span style='color:red'>{$age} secs</span></td>";
                    } else {
                        echo "<td>{$age} secs</td>";
                    }
                    echo "<td>{$fsize} KB</td>";
                    echo '<td><form name="wp_delete_cache_file" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
                    echo '<input type="hidden" name="wp_list_cache" />';
                    echo '<input type="hidden" name="wp_delete_cache_file" value="' . preg_replace("/^(.*)\\.meta\$/", "\$1", $file) . '" />';
                    echo '<div class="submit"><input id="deletepost" type="submit" value="Remove" /></div>';
                    wp_nonce_field('wp-cache');
                    echo "</form></td></tr>\n";
                }
            }
        }
        closedir($handle);
        if ($list_files) {
            echo "</table>";
        }
    }
    echo "<P><b>{$count} cached pages</b></p>";
    echo "<P><b>{$expired} expired pages</b></p>";
    echo '<form name="wp_cache_content_expired" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
    echo '<input type="hidden" name="wp_delete_expired" />';
    echo '<input type="hidden" name="wp_list_cache" />';
    echo '<div class="submit"><input type="submit" value="Delete expired" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '<form name="wp_cache_content_delete" action="' . $_SERVER["REQUEST_URI"] . '#list" method="post">';
    echo '<input type="hidden" name="wp_delete_cache" />';
    echo '<div class="submit"><input id="deletepost" type="submit" value="Delete cache" /></div>';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    echo '</fieldset>';
}