summaryrefslogtreecommitdiff
path: root/includes/keywords.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
committerMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
commit108525534c28013cfe1897c30e4565f9893f3766 (patch)
treedd3e5132971f96ab5f05e7f3f8f6dbbf379a19bd /includes/keywords.php
parent2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (diff)
downloadpluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.gz
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.bz2
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.zip
Update
Diffstat (limited to 'includes/keywords.php')
-rw-r--r--includes/keywords.php110
1 files changed, 0 insertions, 110 deletions
diff --git a/includes/keywords.php b/includes/keywords.php
deleted file mode 100644
index 270d905..0000000
--- a/includes/keywords.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-function getKeyWords() {
- $actions = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/actions.json"), true);
- $toys = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys.json"), true);
- $pages = [];
-
- foreach ($actions as $action) {
- $base = strtolower($action["name"]);
- $addKeywords = $action["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[$action["id"]] = [
- "keywords" => 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, "<a href='$url'>$keyword</a>", $input);
- }
-
- return $input;
-} \ No newline at end of file