diff options
Diffstat (limited to 'includes/keywords.php')
-rw-r--r-- | includes/keywords.php | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/includes/keywords.php b/includes/keywords.php index 4d6afaf..270d905 100644 --- a/includes/keywords.php +++ b/includes/keywords.php @@ -7,7 +7,7 @@ function getKeyWords() { foreach ($actions as $action) { $base = strtolower($action["name"]); - $addKeywords = $action["keywords"]; + $addKeywords = $action["keywords"] ?? []; $keywords = [ $base, ucfirst($base), @@ -44,7 +44,7 @@ function getKeyWords() { foreach ($toys as $toy) { $base = strtolower($toy["name"]); - $addKeywords = $toy["keywords"]; + $addKeywords = $toy["keywords"] ?? []; $keywords = [ $base, ucfirst($base), @@ -82,17 +82,27 @@ function getKeyWords() { $keywords = []; foreach ($pages as $page) { foreach ($page["keywords"] as $keyword) { - $keywords[$keyword] = $page["link"]; + $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 $keyword => $url) { + foreach ($keywords as $data) { + $keyword = $data["keyword"]; + $url = $data["link"]; + $input = str_replace($keyword, "<a href='$url'>$keyword</a>", $input); } |