ILIAS  release_8 Revision v8.24
StartUpMetaBarProvider.php
Go to the documentation of this file.
1<?php
2
4
8use Psr\Http\Message\UriInterface;
9
15{
19 public function getMetaBarItems(): array
20 {
21 $factory = $this->dic->ui()->factory();
22 $request = $this->dic->http()->request();
23 $languages = $this->dic->language()->getInstalledLanguages();
24
25 $if = function (string $id): IdentificationInterface {
26 return $this->if->identifier($id);
27 };
28
29 $txt = function (string $id): string {
30 return $this->dic->language()->txt($id);
31 };
32
33 // Login-Button
34 // Only visible, if not on login-page but not logged in
35 $target_str = '';
36 if (isset($request->getQueryParams()['ref_id']) && $ref_id = $request->getQueryParams()['ref_id']) {
38 if ($type != "root") { // see bug #30710
39 $target_str = 'target=' . \ilObject::_lookupType((int) $ref_id, true) . '_' . (int) $ref_id . '&';
40 }
41 } elseif (isset($request->getQueryParams()['target']) && $target = $request->getQueryParams()['target']) {
42 $target = rawurlencode($target); // see #32789
43 $target_str = 'target=' . $target . '&';
44 }
45
46 $login_glyph = $factory->symbol()->glyph()->login();
47 $login = $this->meta_bar->topLinkItem($if('login'))
48 ->withAction("login.php?" . $target_str . "client_id=" . rawurlencode(CLIENT_ID) . "&cmd=force_login&lang=" . $this->dic->user()->getCurrentLanguage())
49 ->withSymbol($login_glyph)
50 ->withPosition(2)
51 ->withTitle($txt('log_in'))
52 ->withAvailableCallable(function () {
53 return !$this->isUserLoggedIn();
54 })
55 ->withVisibilityCallable(function () use ($request) {
56 return !$this->isUserOnLoginPage($request->getUri());
57 });
58
59 // Language-Selection
60 $language_selection = $this->meta_bar->topParentItem($if('language_selection'))
61 ->withSymbol($factory->symbol()->glyph()->language())
62 ->withPosition(1)
63 ->withAvailableCallable(function () {
64 return !$this->isUserLoggedIn();
65 })
66 ->withVisibilityCallable(function () use ($languages) {
67 return count($languages) > 1;
68 })
69 ->withTitle($txt('language'));
70
71 $base = $this->getBaseURL($request->getUri());
72
73 foreach ($languages as $lang_key) {
74 $link = $this->appendUrlParameterString($base, "lang=" . $lang_key);
75 $language_name = $this->dic->language()->_lookupEntry($lang_key, "meta", "meta_l_" . $lang_key);
76
77 $language_icon = $factory->symbol()->icon()->standard("none", $language_name)
78 ->withAbbreviation($lang_key);
79
80 $s = $this->meta_bar->linkItem($if($lang_key))
81 ->withSymbol($language_icon)
82 ->withAction($link)
83 ->withTitle($language_name);
84
85 $language_selection->appendChild($s);
86 }
87
88 return [
89 $login,
90 $language_selection,
91 ];
92 }
93
94 private function isUserLoggedIn(): bool
95 {
96 return (!$this->dic->user()->isAnonymous() && $this->dic->user()->getId() != 0);
97 }
98
99 private function isUserOnLoginPage(UriInterface $uri): bool
100 {
101 $b = preg_match("%^.*/login.php$%", $uri->getPath()) === 1;
102
103 return $b;
104 }
105
106 private function appendUrlParameterString(string $existing_url, string $addition): string
107 {
108 $url = (is_int(strpos($existing_url, "?")))
109 ? $existing_url . "&" . $addition
110 : $existing_url . "?" . $addition;
111
112 $url = str_replace("?&", "?", $url);
113
114 return $url;
115 }
116
117 private function getBaseURL(UriInterface $uri): string
118 {
119 $base = substr($uri->__toString(), strrpos($uri->__toString(), "/") + 1);
120 return preg_replace("/&*lang=[a-z]{2}&*/", "", $base);
121 }
122}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
appendUrlParameterString(string $existing_url, string $addition)
static _lookupType(int $id, bool $reference=false)
const CLIENT_ID
Definition: constants.php:41
$txt
Definition: error.php:13
$ref_id
Definition: ltiauth.php:67
$factory
Definition: metadata.php:75
withSymbol(Symbol $symbol)
@inheritDoc
$base
Definition: index.php:4
$type
$url