From 475c5731bf3362b6ac8d2dc5d5b43e4b4a6117bd Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Tue, 21 Mar 2023 16:21:21 +0100 Subject: Updated 26 files and added 1074 files (automated) --- includes/util/functions.inc | 57 ++++++++++++++++------- includes/util/keywords.inc | 110 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 includes/util/keywords.inc (limited to 'includes/util') diff --git a/includes/util/functions.inc b/includes/util/functions.inc index 24b059a..1bfd341 100644 --- a/includes/util/functions.inc +++ b/includes/util/functions.inc @@ -389,18 +389,26 @@ if (!function_exists("getMember")) { } if (!function_exists("timeAgo")) { - function timeAgo($time, $french = false): string { - if (!is_numeric($time)) { - $time = strtotime($time); + function timeAgo($time, $french = false, $isDifference = false, $long = false, $showTense = true): string { + $lengths = array("60", "60", "24", "7", "4.35", "12", "100"); + + if ($long) { + $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"]; + } else { + $periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"]; } - $periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"]; - $periods_fr = $periods; - $lengths = array("60", "60", "24", "7", "4.35", "12", "100"); + if ($isDifference) { + $difference = $time; + } else { + if (!is_numeric($time)) { + $time = strtotime($time); + } - $now = time(); + $now = time(); + $difference = $now - $time; + } - $difference = $now - $time; if ($difference <= 10 && $difference >= 0) { return $tense = "now"; } elseif ($difference > 0) { @@ -416,22 +424,39 @@ if (!function_exists("timeAgo")) { $difference = round($difference); $period = $periods[$j]; - return "{$difference} {$period} {$tense}"; + + if ($showTense) { + if ($long) { + return "{$difference} {$period}" . ($difference > 1 ? "s" : "") . " {$tense}"; + } else { + return "{$difference} {$period} {$tense}"; + } + } else { + if ($long) { + return "{$difference} {$period}" . ($difference > 1 ? "s" : ""); + } else { + return "{$difference} {$period}"; + } + } } } if (!function_exists("timeIn")) { - function timeIn($time): string { - if (!is_numeric($time)) { - $time = strtotime($time); - } - + function timeIn($time, $isDifference = false): string { $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"]; $lengths = array("60", "60", "24", "7", "4.35", "12", "100"); - $now = time(); + if ($isDifference) { + $difference = $time; + } else { + if (!is_numeric($time)) { + $time = strtotime($time); + } + + $now = time(); + $difference = $time - $now; + } - $difference = $time - $now; if ($difference <= 10 && $difference >= 0) { return $tense = "now"; } elseif ($difference > 0) { diff --git a/includes/util/keywords.inc b/includes/util/keywords.inc new file mode 100644 index 0000000..d5bb8c8 --- /dev/null +++ b/includes/util/keywords.inc @@ -0,0 +1,110 @@ + array_unique($keywords), + "link" => "/-/actions/$action[id]" + ]; + }*/ + + foreach ($toys as $toy) { + $base = strtolower($toy["name"]); + $addKeywords = $toy["keywords"] ?? []; + $keywords = [ + $base, + ucfirst($base), + ucwords($base) + ]; + + for ($i = 0; $i < strlen($base); $i++) { + $keywords[] = substr($base, 0, $i) . strtoupper(substr($base, $i, 1)) . substr($base, $i + 1, strlen($base) - $i - 1); + + for ($j = 0; $j < strlen($base); $j++) { + $keywords[] = substr($base, 0, $i) . strtoupper(substr($base, $i, $j)) . substr($base, $i + $j, strlen($base) - $i - $j); + } + } + + foreach ($addKeywords as $keyword) { + $keywords[] = $keyword; + $keywords[] = ucfirst($keyword); + $keywords[] = ucwords($keyword); + + for ($i = 0; $i < strlen($keyword); $i++) { + $keywords[] = substr($keyword, 0, $i) . strtoupper(substr($keyword, $i, 1)) . substr($keyword, $i + 1, strlen($keyword) - $i - 1); + + for ($j = 0; $j < strlen($keyword); $j++) { + $keywords[] = substr($keyword, 0, $i) . strtoupper(substr($keyword, $i, $j)) . substr($keyword, $i + $j, strlen($keyword) - $i - $j); + } + } + } + + $pages[$toy["id"]] = [ + "keywords" => array_unique($keywords), + "link" => "/-/toys/$toy[id]" + ]; + } + + $keywords = []; + foreach ($pages as $page) { + foreach ($page["keywords"] as $keyword) { + $keywords[] = [ + "keyword" => $keyword, + "link" => $page["link"] + ]; + } + } + + uasort($keywords, function ($a, $b) { + return strlen($b["keyword"]) - strlen($a["keyword"]); + }); + + return $keywords; +} + +function replaceKeyWords(string $input): string { + $keywords = getKeyWords(); + + foreach ($keywords as $data) { + $keyword = $data["keyword"]; + $url = $data["link"]; + + $input = str_replace($keyword, "$keyword", $input); + } + + return $input; +} \ No newline at end of file -- cgit