ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
InstructionsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Mount;
22
25use ilLanguage;
26use InvalidArgumentException;
27
29{
30 public function __construct(
31 protected BaseInstructions $mount_instruction,
32 protected ilLanguage $lang,
33 protected UIServices $ui,
34 protected Services $http
35 ) {
36 }
37
41 public function buildGUIFromGivenMountInstructions(array $mount_instructions, bool $render_async = false): string
42 {
43 $os = $this->determineOSfromUserAgent();
44
45 $f = $this->ui->factory();
46 $r = $this->ui->renderer();
47
48 $components = [];
49
50 $js_function_legacy = $f->legacy()->content(
51 '<script>'
52 . 'il.UI.showMountInstructions = function (e, id){'
53 . "obj = $(e['target']);"
54 . "obj.siblings().removeClass('engaged disabled ilSubmitInactive').attr('aria-pressed', 'false');"
55 . "obj.siblings().removeAttr('disabled');"
56 . "obj.addClass('engaged ilSubmitInactive').attr('aria-pressed', 'true');"
57 . '$(".instructions").hide();'
58 . '$("#"+id).show();}</script>'
59 );
60
61 if (count($mount_instructions) === 1) {
62 $content = $f->legacy()->content("<div class='instructions'>" . array_shift($mount_instructions) . "</div>");
63
64 return $render_async ? $r->renderAsync($content) : $r->render($content);
65 }
66
67 $view_control_actions = [];
68
69 $selected = array_key_first($mount_instructions);
70
71 foreach ($mount_instructions as $title => $text) {
72 foreach ($os as $os_string) {
73 if (stripos((string) $title, (string) $os_string) !== false) {
74 $selected = $title;
75 break 2;
76 }
77 }
78 }
79
80 foreach ($mount_instructions as $title => $text) {
81 $hidden = $title === $selected ? '' : 'style="display: none;"';
82
83 $legacy = $f->legacy()->content("<div id='$title' class='instructions' $hidden>$text</div>")
84 ->withCustomSignal($title, "il.UI.showMountInstructions(event, '$title');");
85
86 $view_control_actions[$title] = $legacy->getCustomSignal($title);
87
88 $components[] = $legacy;
89 }
90
91 $view_control = $f->viewControl()->mode($view_control_actions, 'mount-instruction-buttons')->withActive(
92 $selected
93 );
94
95 $header_components = [
96 $f->legacy()->content("<div class='webdav-view-control'>"),
97 $view_control,
98 $f->legacy()->content('</div>'),
99 $js_function_legacy,
100 ];
101
102 $components = array_merge($header_components, $components);
103
104 return $render_async ? $r->renderAsync($components) : $r->render($components);
105 }
106
107 public function renderMountInstructionsContent(): void
108 {
109 try {
110 $instructions = $this->mount_instruction->getMountInstructionsAsArray();
111 } catch (InvalidArgumentException) {
112 $document_processor = new HtmlDocumentProcessor(
113 new DocumentPurifier()
114 );
115 $instructions = $document_processor->processMountInstructions(
116 $this->lang->txt('webfolder_instructions_text')
117 );
118 $instructions = $this->mount_instruction->getMountInstructionsAsArray($instructions);
119 if ($instructions === '-webfolder_instructions_text-') {
120 $instructions = [
121 "<div class='alert alert-danger'>" . $this->lang->txt('error')
122 . ': ' . $this->lang->txt('webdav_missing_lang') . '</div>',
123 ];
124 }
125 }
126
127 echo $this->buildGUIFromGivenMountInstructions($instructions, true);
128 exit;
129 }
130
131 private function determineOSfromUserAgent(): array
132 {
133 $ua = $this->http->request()->getHeader('User-Agent')[0] ?? '';
134
135 if (stripos($ua, 'windows') !== false || str_contains($ua, 'microsoft')) {
136 return ['win'];
137 }
138
139 if (stripos($ua, 'darwin') !== false || stripos($ua, 'macintosh') !== false) {
140 return ['mac', 'osx'];
141 }
142
143 if (stripos($ua, 'linux') !== false
144 || stripos($ua, 'solaris') !== false
145 || stripos($ua, 'aix') !== false
146 || stripos($ua, 'unix') !== false
147 || stripos($ua, 'gvfs') !== false // nautilus browser uses this ID
148 ) {
149 return ['linux'];
150 }
151
152 return ['unknown'];
153 }
154}
$components
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Class Services.
Definition: Services.php:38
buildGUIFromGivenMountInstructions(array $mount_instructions, bool $render_async=false)
__construct(protected BaseInstructions $mount_instruction, protected ilLanguage $lang, protected UIServices $ui, protected Services $http)
language handling
$http
Definition: deliver.php:30
exit
static http()
Fetches the global http state from ILIAS.
$text
Definition: xapiexit.php:21