From 108525534c28013cfe1897c30e4565f9893f3766 Mon Sep 17 00:00:00 2001 From: Minteck Date: Mon, 10 Oct 2022 20:51:39 +0200 Subject: Update --- includes/keywords.inc | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 includes/keywords.inc (limited to 'includes/keywords.inc') diff --git a/includes/keywords.inc b/includes/keywords.inc new file mode 100644 index 0000000..9bea167 --- /dev/null +++ b/includes/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