Skip to content

Commit

Permalink
Adding getDirStats() utility. See: wpsharks/comet-cache#83
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswsinc committed Aug 7, 2015
1 parent 976f82e commit fcb6d39
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 40 deletions.
132 changes: 94 additions & 38 deletions src/client-s/css/admin-bar.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*[pro strip-from="lite"]*/

/*
Admin Bar.
*/
Expand All @@ -9,11 +8,9 @@ Admin Bar.
content: ' ';
width: 16px;
height: 16px;

border: 0;
padding: 0;
margin: -3px 0 0 5px;

vertical-align: middle;
display: inline-block;
}
Expand All @@ -26,12 +23,11 @@ Admin Bar.
#wp-admin-bar-zencache-wipe.zencache-wiping > a:after,
#wp-admin-bar-zencache-clear.zencache-clearing > a:after {
background: url('../images/spinner.png');
-webkit-animation: zencache_animation_spin 1s infinite linear;
animation: zencache_animation_spin 1s infinite linear;
-webkit-animation: zencache-animation-spin 1s infinite linear;
animation: zencache-animation-spin 1s infinite linear;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

/*
AJAX Responses.
*/
Expand All @@ -41,24 +37,18 @@ AJAX Responses.
left: 50%;
z-index: 10000;
position: fixed;

color: #FFFFFF;
text-align: center;

width: 600px;
padding: 15px;
margin: 0 0 0 -300px;

border-radius: 5px;
box-shadow: 0 0 5px 0 #23282D;

outline: none;
cursor: pointer;

-webkit-user-select: none;
-moz-user-select: none;
user-select: none;

display: none;
}
#zencache-ajax-response.zencache-ajax-response-wipe {
Expand All @@ -71,7 +61,6 @@ AJAX Responses.
top: 5px;
right: 8px;
position: absolute;

font: 18px/1em sans-serif;
content: '\00d7';
opacity: 0.5;
Expand All @@ -95,20 +84,19 @@ AJAX Responses.
background: #EEEEEE;
padding: 1px 3px 1px 3px;
}

/*
Animation :: spin.
*/

@keyframes zencache_animation_spin {
@keyframes zencache-animation-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@-webkit-keyframes zencache_animation_spin {
@-webkit-keyframes zencache-animation-spin {
0% {
-webkit-transform: rotate(0deg);
}
Expand All @@ -117,17 +105,91 @@ Animation :: spin.
}
}
.zencache-animation-spin {
-webkit-animation: zencache_animation_spin 1s infinite linear;
animation: zencache_animation_spin 1s infinite linear;
-webkit-animation: zencache-animation-spin 1s infinite linear;
animation: zencache-animation-spin 1s infinite linear;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
/*
Animation :: zoomInDown.
Markup: `<div class="zencache-animation-disk-bars"><div></div><div></div><div></div><div></div><div></div></div>`
*/

.zencache-animation-disk-bars {
width: 100%;
box-sizing: border-box;
}
.zencache-animation-disk-bars > div {
width: 19%;
height: 5em;
margin: 0 .5%;
display: inline-block;
box-sizing: border-box;
background-color: currentColor;
-webkit-animation: zencache-animation-disk-bars .9s infinite cubic-bezier(.11, .49, .38, .78);
-moz-animation: zencache-animation-disk-bars .9s infinite cubic-bezier(.11, .49, .38, .78);
-o-animation: zencache-animation-disk-bars .9s infinite cubic-bezier(.11, .49, .38, .78);
animation: zencache-animation-disk-bars .9s infinite cubic-bezier(.11, .49, .38, .78);
}
.zencache-animation-disk-bars > div:nth-child(3) {
-webkit-animation-delay: -.9s;
-moz-animation-delay: -.9s;
-o-animation-delay: -.9s;
animation-delay: -.9s;
}
.zencache-animation-disk-bars > div:nth-child(2),
.zencache-animation-disk-bars > div:nth-child(4) {
-webkit-animation-delay: -.65s;
-moz-animation-delay: -.65s;
-o-animation-delay: -.65s;
animation-delay: -.65s;
}
.zencache-animation-disk-bars > div:nth-child(1),
.zencache-animation-disk-bars > div:nth-child(5) {
-webkit-animation-delay: -.4s;
-moz-animation-delay: -.4s;
-o-animation-delay: -.4s;
animation-delay: -.4s;
}
@-webkit-keyframes zencache-animation-disk-bars {
0% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
80% {
-webkit-transform: scaley(.3);
transform: scaley(.3);
}
90% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
}
@keyframes zencache-animation-disk-bars {
0% {
-webkit-transform: scaley(1);
-moz-transform: scaley(1);
-o-transform: scaley(1);
transform: scaley(1);
}
80% {
-webkit-transform: scaley(.3);
-moz-transform: scaley(.3);
-o-transform: scaley(.3);
transform: scaley(.3);
}
90% {
-webkit-transform: scaley(1);
-moz-transform: scaley(1);
-o-transform: scaley(1);
transform: scaley(1);
}
}
/*
Animation :: zoomInDown.
*/

@-webkit-keyframes zencache_animation_zoomInDown {
@-webkit-keyframes zencache-animation-zoom-in-down {
from {
opacity: 0;
-webkit-transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0);
Expand All @@ -143,7 +205,7 @@ Animation :: zoomInDown.
animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
}
}
@keyframes zencache_animation_zoomInDown {
@keyframes zencache-animation-zoom-in-down {
from {
opacity: 0;
-webkit-transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0);
Expand All @@ -159,64 +221,58 @@ Animation :: zoomInDown.
animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
}
}
.zencache-animation-zoomInDown {
-webkit-animation-name: zencache_animation_zoomInDown;
animation-name: zencache_animation_zoomInDown;
.zencache-animation-zoom-in-down {
-webkit-animation-name: zencache-animation-zoom-in-down;
animation-name: zencache-animation-zoom-in-down;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: .75s;
animation-duration: .75s;
}

/*
Animation :: bounceOutUp.
*/

@-webkit-keyframes zencache_animation_bounceOutUp {
@-webkit-keyframes zencache-animation_bounce-out-up {
20% {
-webkit-transform: translate3d(0, -10px, 0);
transform: translate3d(0, -10px, 0);
}

40%, 45% {
40%,
45% {
opacity: 1;
-webkit-transform: translate3d(0, 20px, 0);
transform: translate3d(0, 20px, 0);
}

100% {
opacity: 0;
-webkit-transform: translate3d(0, -2000px, 0);
transform: translate3d(0, -2000px, 0);
}
}

@keyframes zencache_animation_bounceOutUp {
@keyframes zencache-animation_bounce-out-up {
20% {
-webkit-transform: translate3d(0, -10px, 0);
transform: translate3d(0, -10px, 0);
}

40%, 45% {
40%,
45% {
opacity: 1;
-webkit-transform: translate3d(0, 20px, 0);
transform: translate3d(0, 20px, 0);
}

100% {
opacity: 0;
-webkit-transform: translate3d(0, -2000px, 0);
transform: translate3d(0, -2000px, 0);
}
}

.zencache-animation-bounceOutUp {
-webkit-animation-name: zencache_animation_bounceOutUp;
animation-name: zencache_animation_bounceOutUp;
.zencache-animation_bounce-out-up {
-webkit-animation-name: zencache-animation_bounce-out-up;
animation-name: zencache-animation_bounce-out-up;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: .75s;
animation-duration: .75s;
}

/*[/pro]*/
4 changes: 2 additions & 2 deletions src/client-s/js/admin-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@

$('#' + plugin.namespace + '-ajax-response').off(animationEnd).on(animationEnd, function () {
plugin.hideAJAXResponseTimeout = setTimeout(plugin.hideAJAXResponse, 2500);
}).show().addClass(plugin.namespace + '-animation-zoomInDown');
}).show().addClass(plugin.namespace + '-animation-zoom-in-down');
};

plugin.hideAJAXResponse = function (event, animate) {
clearTimeout(plugin.hideAJAXResponseTimeout);

$('#' + plugin.namespace + '-ajax-response').off(animationEnd).on(animationEnd, function () {
plugin.removeAJAXResponse();
}).addClass(plugin.namespace + '-animation-bounceOutUp');
}).addClass(plugin.namespace + '-animation-bounce-out-up');
};

plugin.removeAJAXResponse = function () {
Expand Down
68 changes: 68 additions & 0 deletions src/includes/closures/Shared/FsUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,74 @@
return $regex_iterator;
};

/*
* Recursive directory iterator.
*
* @since 15xxxx Adding a few statistics.
*
* @param string $dir An absolute server directory path.
*
* @return \RegexIterator Navigable with {@link \foreach()}; where each item
* is a {@link \RecursiveDirectoryIterator}.
*/
$self->dirIteration = function ($dir) use ($self) {
$dir = (string) $dir;

$dir_iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_SELF | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS);
return new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::CHILD_FIRST);
};

/*
* Directory stats.
*
* @since 15xxxx Adding a few statistics.
*
* @param string $dir An absolute server directory path.
* @param boolean $reconsider Bypass cached statistics?
*
* @return \stdClass `total_size`, `total_links`, `total_files`, `total_dirs`.
*/
$self->getDirStats = function ($dir, $reconsider = false) use ($self) {
if (!is_null($stats = &$self->staticKey('getDirStats', $dir)) && !$reconsider) {
return $stats; // Already cached this.
}
$stats = (object) array(
'total_size' => 0,
'total_resources' => 0,
'total_links' => 0,
'total_files' => 0,
'total_dirs' => 0,
'disk_free_space' => 0,
'disk_total_space' => 0,
);
if (!is_dir($dir = (string) $dir)) {
return $stats; // Not possible.
}
foreach ($self->dirIteration($dir) as $_resource) {
switch ($_resource->getType()) { // `link`, `file`, `dir`.

case 'link': // Symbolic links.
++$stats->total_links; // Counter.
break; // Break switch handler.

case 'file': // Regular files; i.e., not symlinks.
$stats->total_size += $_resource->getSize();
++$stats->total_files; // Counter.
break; // Break switch.

case 'dir': // Regular dirs; i.e., not symlinks.
++$stats->total_dirs; // Counter.
break; // Break switch.
}
}
unset($_resource); // Housekeeping.

$stats->disk_free_space = disk_free_space($dir);
$stats->disk_total_space = disk_total_space($dir);

return $stats;
};

/*
* Apache `.htaccess` rules that deny public access to the contents of a directory.
*
Expand Down

0 comments on commit fcb6d39

Please sign in to comment.