-version 2.2alpha - Guardian of Ice - (tba)
+version 2.2 - Guardian of Ice - (tba)
* email import
* code cleanups
* authentication with an extra url now (index.php?m=auth)
* management actions shown only if authenticated
* small stats overview
- * links can now be deleted...
+ * links can now be deleted
* awaiting moderation links can new be moderated
* Fixed an error in create sql file
+ * clean up the local storage via stats page (if authenticated)
version 2.1alpha - Guardian of Fire - (2019-09-29)
return $ret;
}
+ /**
+ * get the used disk space for local image storage
+ * @return false|int
+ */
public function storageAmount() {
$ret = 0;
$_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE;
if(file_exists($_storageFolder) && is_readable($_storageFolder)) {
- $ret = Summoner::folderSize();
+ $ret = Summoner::folderSize($_storageFolder);
}
return $ret;
}
+ /**
+ * empties the local storage directory
+ * @return bool
+ */
+ public function clearLocalStorage() {
+ $ret = false;
+
+ $_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE;
+ if(file_exists($_storageFolder) && is_writable($_storageFolder)) {
+ $ret = Summoner::recursive_remove_directory($_storageFolder,true);
+ }
+
+ return $ret;
+ }
+
/**
* Load link by given hash. Do not use Link class directly.
}
/**
- * get as much as possible solcial meta infos from given string
+ * get as much as possible social meta infos from given string
* the string is usually a HTML source
* @param string $string
* @return array
return $ret;
}
+ /**
+ * retrieve the folder size with its children of given folder path
+ * @param $folder
+ * @return false|int
+ */
static function folderSize($folder) {
$ret = 0;
return $ret;
}
+ /**
+ * Calculate the given byte size in more human readable format.
+ * @param $size
+ * @param string $unit
+ * @return string
+ */
static function humanFileSize($size,$unit="") {
- if( (!$unit && $size >= 1<<30) || $unit == "GB")
- return number_format($size/(1<<30),2)."GB";
- if( (!$unit && $size >= 1<<20) || $unit == "MB")
- return number_format($size/(1<<20),2)."MB";
- if( (!$unit && $size >= 1<<10) || $unit == "KB")
- return number_format($size/(1<<10),2)."KB";
- return number_format($size)." bytes";
+ $ret = number_format($size)." bytes";
+
+ if((!$unit && $size >= 1<<30) || $unit == "GB") {
+ $ret = number_format($size / (1 << 30), 2)."GB";
+ }
+ elseif((!$unit && $size >= 1<<20) || $unit == "MB") {
+ $ret = number_format($size / (1 << 20), 2) . "MB";
+ }
+ elseif( (!$unit && $size >= 1<<10) || $unit == "KB") {
+ $ret = number_format($size / (1 << 10), 2) . "KB";
+ }
+
+ return $ret;
}
+
+ /**
+ * delete and/or empty a directory
+ *
+ * $empty = true => empty the directory but do not delete it
+ *
+ * @param string $directory
+ * @param boolean $empty
+ * @param int $fTime If not false remove files older then this value in sec.
+ * @return boolean
+ */
+ static function recursive_remove_directory($directory,$empty=false,$fTime=0) {
+ if(substr($directory,-1) == '/') {
+ $directory = substr($directory,0,-1);
+ }
+
+ if(!file_exists($directory) || !is_dir($directory)) {
+ return false;
+ }
+ elseif(!is_readable($directory)) {
+ return false;
+ }
+ else {
+ $handle = opendir($directory);
+
+ // and scan through the items inside
+ while (false !== ($item = readdir($handle))) {
+ if($item[0] != '.') {
+ $path = $directory.'/'.$item;
+
+ if(is_dir($path)) {
+ recursive_remove_directory($path);
+ }
+ else {
+ if($fTime !== false && is_int($fTime)) {
+ $ft = filemtime($path);
+ $offset = time()-$fTime;
+ if($ft <= $offset) {
+ unlink($path);
+ }
+ }
+ else {
+ unlink($path);
+ }
+ }
+ }
+ }
+ closedir($handle);
+
+ if($empty === false) {
+ if(!rmdir($directory)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
}
$moderationAmount = $Management->moderationAmount();
}
+if(isset($_POST['statsDeleteLocalStorage'])) {
+
+ if($Management->clearLocalStorage() === true) {
+
+ $TemplateData['refresh'] = 'index.php?p=stats';
+ }
+ else {
+ $submitFeedback['message'] = 'Something went wrong while storage cleaning';
+ $submitFeedback['status'] = 'error';
+ }
+}
+
$linkAmount = $Management->linkAmount();
$tagAmount = $Management->tagAmount();
$categoryAmount = $Management->categoryAmount();
$localStorageAmount = $Management->storageAmount();
+$localStorageAmount = Summoner::humanFileSize($localStorageAmount);
<section class="section">
<div class="columns is-multiline">
<div class="column is-one-quarter">
- <h3 class="is-size-3">Links</h3>
+ <h4 class="is-size-4">Links</h4>
<p># of Links: <?php echo $linkAmount; ?></p>
<p><a href="index.php?p=overview&m=all">View all</a></p>
</div>
<div class="column is-one-quarter">
- <h3 class="is-size-3">Tags</h3>
+ <h4 class="is-size-4">Tags</h4>
<p># of Tags: <?php echo $tagAmount; ?></p>
<p><a href="index.php?p=overview&m=tag">View all</a></p>
</div>
<div class="column is-one-quarter">
- <h3 class="is-size-3">Categories</h3>
+ <h4 class="is-size-4">Categories</h4>
<p># of Categories: <?php echo $categoryAmount; ?></p>
<p><a href="index.php?p=overview&m=category">View all</a></p>
</div>
<?php if($_displayEditButton === true) { ?>
<div class="column is-one-quarter">
- <h3 class="is-size-3">Moderation</h3>
+ <h4 class="is-size-4">Moderation</h4>
<p># Moderation needed: <?php echo $moderationAmount; ?></p>
<p><a href="index.php?p=overview&m=awm">View all</a></p>
</div>
<div class="column is-one-quarter">
- <h3 class="is-size-3">Local image storage</h3>
- <p>Diskspace used: <?php echo $moderationAmount; ?></p>
- <p><a href="index.php?p=overview&m=category">Delete all</a></p>
+ <h4 class="is-size-4">Local image storage</h4>
+ <p>Diskspace used: <?php echo $localStorageAmount; ?></p>
+ <form method="post">
+ <input type="submit" class="button is-info is-small" value="Delete all" name="statsDeleteLocalStorage">
+ </form>
</div>
<?php } ?>
</div>