diff options
author | Minteck <contact@minteck.org> | 2022-09-21 22:42:33 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-09-21 22:42:33 +0200 |
commit | e95b208af90cc386a7d8d1bcab426727cf4f0121 (patch) | |
tree | b293e0c644513fbeb6e9ad29be97fa6347a55e9f /includes/keywords.php | |
parent | b5f589c323f415bb42ea7069cb4d1a8a2233dd69 (diff) | |
download | pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.tar.gz pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.tar.bz2 pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.zip |
Update time
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); } |