web-base/core/Views/LanguageFlags.class.php

62 lines
1.5 KiB
PHP
Raw Normal View History

2020-02-10 00:52:25 +01:00
<?php
namespace Views;
2020-04-04 01:15:59 +02:00
use Elements\View;
2020-04-03 22:10:21 +02:00
2020-04-04 01:15:59 +02:00
class LanguageFlags extends View {
private array $languageFlags;
2020-02-10 00:52:25 +01:00
public function __construct($document) {
parent::__construct($document);
2020-04-04 01:15:59 +02:00
$this->languageFlags = array();
2020-06-22 19:09:02 +02:00
$this->searchable = false;
2020-02-10 00:52:25 +01:00
}
2020-06-22 19:09:02 +02:00
public function loadView() {
parent::loadView();
2020-02-10 00:52:25 +01:00
2020-06-20 20:13:51 +02:00
$request = new \Api\Language\Get($this->getDocument()->getUser());
2020-06-22 01:06:54 +02:00
if ($request->execute()) {
2020-04-04 01:15:59 +02:00
$requestUri = $_SERVER["REQUEST_URI"];
$queryString = $_SERVER['QUERY_STRING'];
$params = explode("&", $queryString);
$query = array();
2020-06-22 01:06:54 +02:00
foreach ($params as $param) {
2020-04-04 01:15:59 +02:00
$aParam = explode("=", $param);
$key = $aParam[0];
2020-06-22 01:06:54 +02:00
if ($key === "site" &&
(!startsWith($_SERVER["REQUEST_URI"], "/index.php") || $_SERVER["REQUEST_URI"] === "/")) {
2020-04-04 01:15:59 +02:00
continue;
2020-06-22 01:06:54 +02:00
}
2020-04-04 01:15:59 +02:00
$val = (isset($aParam[1]) ? $aParam[1] : "");
2020-06-22 01:06:54 +02:00
if (!empty($key)) {
2020-04-04 01:15:59 +02:00
$query[$key] = $val;
}
2020-02-10 00:52:25 +01:00
}
2020-04-04 01:15:59 +02:00
$url = parse_url($requestUri, PHP_URL_PATH) . "?";
2020-06-22 01:06:54 +02:00
foreach ($request->getResult()['languages'] as $lang) {
2020-02-10 00:52:25 +01:00
$langCode = $lang['code'];
$langName = $lang['name'];
$query['lang'] = $langCode;
$queryString = http_build_query($query);
2020-04-04 01:15:59 +02:00
$this->languageFlags[] = $this->createLink(
2020-02-10 00:52:25 +01:00
"$url$queryString",
2020-06-22 01:06:54 +02:00
"<img class=\"p-1 clickable\" src=\"/img/icons/lang/$langCode.gif\" alt=\"$langName\" title=\"$langName\">"
2020-02-10 00:52:25 +01:00
);
}
2020-06-22 01:06:54 +02:00
}
2020-02-10 00:52:25 +01:00
}
2020-06-22 19:09:02 +02:00
2021-04-02 21:58:06 +02:00
public function getCode(): string {
2020-06-22 19:09:02 +02:00
return implode('', $this->languageFlags);
}
2020-04-03 15:56:04 +02:00
}