aboutsummaryrefslogtreecommitdiffstats
path: root/misc/tools.php
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2023-09-22 18:08:37 -0400
committerSquibid <me@zacharyscheiman.com>2023-09-22 18:08:37 -0400
commit472092fe43ad7da9feb4a8c0b4bf216b20c063b9 (patch)
tree6200ad064861b167684483c38e7db9ad05519e7e /misc/tools.php
downloadwallheaven-472092fe43ad7da9feb4a8c0b4bf216b20c063b9.tar.gz
wallheaven-472092fe43ad7da9feb4a8c0b4bf216b20c063b9.tar.bz2
wallheaven-472092fe43ad7da9feb4a8c0b4bf216b20c063b9.zip
inital commit
Diffstat (limited to '')
-rw-r--r--misc/tools.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/misc/tools.php b/misc/tools.php
new file mode 100644
index 0000000..7473953
--- /dev/null
+++ b/misc/tools.php
@@ -0,0 +1,41 @@
+<?php
+ function timesince($time) {
+ $time = time() - $time;
+ $timeunits = [
+ 31536000 => 'year',
+ 2592000 => 'month',
+ 604800 => 'week',
+ 86400 => 'day',
+ 3600 => 'hour',
+ 60 => 'minute',
+ ];
+
+ $numunits;
+ foreach ($timeunits as $unit => $text) {
+ if ($time < $unit)
+ continue;
+ $numunits = floor($time / $unit);
+ return ' '.$numunits.' '.$text.(($numunits > 1) ? 's' : '');
+ }
+ }
+
+ 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";
+ }
+
+ function toupperpurity($str) {
+ if ($str == "sfw")
+ return strtoupper($str);
+ if ($str == "sketchy")
+ return ucfirst($str);
+ if ($str == "nsfw")
+ return strtoupper($str);
+ return $str;
+ }
+?>