+
+ /**
+ * This function converts a file size string written in PHP's shorthand notation to an integer number of total bytes.
+ * For example: The string for shorthand notation of '2M' (which is 2,097,152 Bytes) is converted to 2097152
+ * @see https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
+ * @param string $shorthand
+ * @return int
+ */
+ public static function getBytesFromShorthand(string $shorthand): int
+ {
+ $shorthand = trim($shorthand);
+
+ if (is_numeric($shorthand)) {
+ return $shorthand;
+ }
+
+ $last = strtolower($shorthand[strlen($shorthand)-1]);
+ $shorthand = substr($shorthand, 0, -1);
+
+ switch($last) {
+ case 'g':
+ $shorthand *= 1024;
+ case 'm':
+ $shorthand *= 1024;
+ case 'k':
+ $shorthand *= 1024;
+ }
+
+ return $shorthand;
+ }
+
+ /**
+ * Converts an URL in a nicer format (without the scheme and possibly shortened)
+ *
+ * @param string $url URL that is about to be reformatted
+ * @return string reformatted link
+ */
+ public static function getStyledURL(string $url): string
+ {
+ $parts = parse_url($url);
+ $scheme = [$parts['scheme'] . '://www.', $parts['scheme'] . '://'];
+ $styled_url = str_replace($scheme, '', $url);
+
+ if (strlen($styled_url) > 30) {
+ $styled_url = substr($styled_url, 0, 30) . "…";
+ }
+
+ return $styled_url;
+ }