ILIAS  release_8 Revision v8.24
class.ilWebDAVMountInstructionsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23
29{
32 protected ilLanguage$lang;
33 protected UIServices $ui;
34 protected Services $http;
35
37 {
38 $this->uri_builder = new ilWebDAVUriBuilder($http->request());
39 $this->mount_instruction = $mount_instruction;
40 $this->lang = $lang;
41 $this->ui = $ui;
42 $this->http = $http;
43 }
44
48 public function buildGUIFromGivenMountInstructions(array $mount_instructions, bool $render_async = false): string
49 {
50 $os = $this->determineOSfromUserAgent();
51
52 $f = $this->ui->factory();
53 $r = $this->ui->renderer();
54
55 $components = [];
56
57 $js_function_legacy = $f->legacy('<script>'
58 . 'il.UI.showMountInstructions = function (e, id){'
59 . "obj = $(e['target']);"
60 . "obj.siblings().removeClass('engaged disabled ilSubmitInactive').attr('aria-pressed', 'false');"
61 . "obj.siblings().removeAttr('disabled');"
62 . "obj.addClass('engaged ilSubmitInactive').attr('aria-pressed', 'true');"
63 . '$(".instructions").hide();'
64 . '$("#"+id).show();}</script>');
65
66 if (count($mount_instructions) === 1) {
67 $content = $f->legacy("<div class='instructions'>" . array_shift($mount_instructions) . "</div>");
68
69 return $render_async ? $r->renderAsync($content) : $r->render($content);
70 }
71
72 $view_control_actions = [];
73
74 $selected = array_key_first($mount_instructions);
75
76 foreach ($mount_instructions as $title => $text) {
77 foreach ($os as $os_string) {
78 if (stristr($title, $os_string) !== false) {
79 $selected = $title;
80 break 2;
81 }
82 }
83 }
84
85 foreach ($mount_instructions as $title => $text) {
86 if ($title == $selected) {
87 $hidden = '';
88 } else {
89 $hidden = 'style="display: none;"';
90 }
91
92 $legacy = $f->legacy("<div id='$title' class='instructions' $hidden>$text</div>")
93 ->withCustomSignal($title, "il.UI.showMountInstructions(event, '$title');");
94
95 $view_control_actions[$title] = $legacy->getCustomSignal($title);
96
97 $components[] = $legacy;
98 }
99
100 $view_control = $f->viewControl()->mode($view_control_actions, "mount-instruction-buttons")->withActive($selected);
101
102 // Add view control and legacy add the beginning of the array (so they will be rendered first)
103 $header_components = [
104 $f->legacy("<div class='webdav-view-control'>"),
105 $view_control,
106 $f->legacy("</div>"),
107 $js_function_legacy];
108
109 $components = array_merge($header_components, $components);
110
111 return $render_async ? $r->renderAsync($components) : $r->render($components);
112 }
113
114 public function renderMountInstructionsContent(): void
115 {
116 try {
117 $instructions = $this->mount_instruction->getMountInstructionsAsArray();
118 } catch (InvalidArgumentException $e) {
120 $instructions = $document_processor->processMountInstructions($this->lang->txt('webfolder_instructions_text'));
121 $instructions = $this->mount_instruction->getMountInstructionsAsArray($instructions);
122 if ($instructions == '' || $instructions == '-webfolder_instructions_text-') {
123 $instructions = ["<div class='alert alert-danger'>" . $this->lang->txt('error') . ": " . $this->lang->txt('webdav_missing_lang') . "</div>"];
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 (stristr($ua, 'windows') !== false
136 || strpos($ua, 'microsoft') !== false) {
137 return ['win'];
138 }
139
140 if (stristr($ua, 'darwin') !== false
141 || stristr($ua, 'macintosh') !== false) {
142 return ['mac', 'osx'];
143 }
144
145 if (stristr($ua, 'linux') !== false
146 || stristr($ua, 'solaris') !== false
147 || stristr($ua, 'aix') !== false
148 || stristr($ua, 'unix') !== false
149 || stristr($ua, 'gvfs') !== false // nautilus browser uses this ID
150 ) {
151 return ['linux'];
152 }
153
154 return ['unknown'];
155 }
156}
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
Class Services.
Definition: Services.php:38
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilWebDAVBaseMountInstructions $mount_instruction
buildGUIFromGivenMountInstructions(array $mount_instructions, bool $render_async=false)
__construct(ilWebDAVBaseMountInstructions $mount_instruction, ilLanguage $lang, UIServices $ui, Services $http)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:28
static http()
Fetches the global http state from ILIAS.
$lang
Definition: xapiexit.php:26