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

59 lines
1.4 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-02-10 00:52:25 +01:00
}
2020-04-04 01:15:59 +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-04-04 01:15:59 +02:00
if($request->execute()) {
$requestUri = $_SERVER["REQUEST_URI"];
$queryString = $_SERVER['QUERY_STRING'];
$params = explode("&", $queryString);
$query = array();
foreach($params as $param) {
$aParam = explode("=", $param);
$key = $aParam[0];
if($key == "s" && startsWith($requestUri, "/s/"))
continue;
$val = (isset($aParam[1]) ? $aParam[1] : "");
if(!empty($key)) {
$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-02-10 00:52:25 +01:00
foreach($request->getResult()['languages'] as $lang) {
$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-04-03 22:10:21 +02:00
"<img class=\"p-1\" src=\"/img/icons/lang/$langCode.gif\" alt=\"$langName\" title=\"$langName\">"
2020-02-10 00:52:25 +01:00
);
}
}
2020-04-04 01:15:59 +02:00
}
2020-02-10 00:52:25 +01:00
2020-04-04 01:15:59 +02:00
public function getCode() {
return implode('', $this->languageFlags);
2020-02-10 00:52:25 +01:00
}
2020-04-03 15:56:04 +02:00
}