summaryrefslogtreecommitdiff
path: root/includes/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/functions.php')
-rw-r--r--includes/functions.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/includes/functions.php b/includes/functions.php
new file mode 100644
index 0000000..637137c
--- /dev/null
+++ b/includes/functions.php
@@ -0,0 +1,70 @@
+<?php
+
+function version(): string {
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.version")) {
+ return substr(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/.version")), 0, 8);
+ } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.git/refs/heads/trunk")) {
+ return substr(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/.git/refs/heads/trunk")), 0, 8);
+ } else {
+ return "trunk";
+ }
+}
+
+function build(): string {
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.build")) {
+ $a = trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/.build"));
+ } else {
+ $a = "dev";
+ }
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.prjbuild")) {
+ $b = trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/.prjbuild"));
+ } else {
+ $b = "testing";
+ }
+ return "$a.$b";
+}
+
+function getLetters(string $project): string {
+ $words = explode(" ", preg_replace('/#+/m', "#", preg_replace('/[^a-z0-9 ]/m', "#", strtolower(trim(preg_replace('/[A-Z]/m', ' $0', $project))))));
+
+ $words = array_slice(array_filter($words, function ($v) {
+ return trim($v);
+ }), 0);
+
+ return substr($words[0], 0, 1);
+}
+
+function timeAgo($time): string {
+ global $lang;
+
+ if (!is_numeric($time)) {
+ $time = strtotime($time);
+ }
+
+ $periods = $lang['time']['periods'];
+ $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
+
+ $now = time();
+
+ $difference = $now - $time;
+ if ($difference <= 10 && $difference >= 0) {
+ return $tense = $lang['time']['now'];
+ } elseif ($difference > 0) {
+ $tense = $lang['time']['ago'];
+ } else {
+ $tense = $lang['time']['later'];
+ }
+
+ for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
+ $difference /= $lengths[$j];
+ }
+
+ $difference = round($difference);
+
+ $period = $periods[$j] . ($difference >1 ? $lang['time']['plural'] :'');
+ return "{$difference} {$period} {$tense} ";
+}
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/Parsedown.php";
+global $Parsedown;
+$Parsedown = new Parsedown(); \ No newline at end of file