ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWebDAVMountInstructionsGUI.php
Go to the documentation of this file.
1<?php
2
12{
13
19 protected $base_url;
20 protected $ref_id;
22 protected $il_lang;
23 protected $ui;
24 protected $http;
25
26 public function __construct(ilWebDAVBaseMountInstructions $a_mount_instruction)
27 {
28 global $DIC;
29
30 $this->uri_builder = new ilWebDAVUriBuilder($DIC->http()->request());
31 $this->mount_instruction = $a_mount_instruction;
32 $this->il_lang = $DIC->language();
33 $this->ui = $DIC->ui();
34 $this->http = $DIC->http();
35 }
36
37 public function buildGUIFromGivenMountInstructions($a_mount_instructions, $a_render_async = false)
38 {
39 $os = $this->determineOSfromUserAgent();
40
41 $f = $this->ui->factory();
42 $r = $this->ui->renderer();
43
44 // List of all components to render
45 $comps = array();
46
47 // This is an additional legacy component. It contains the java script function to substitute the shown instructions
48 $js_function_legacy = $f->legacy('<script>'
49 . 'il.UI.showMountInstructions = function (e, id){'
50 // e['target'] is the id for the button which was clicked (e.g. 'button#il_ui_fw_1234')
51 . "obj = $(e['target']);"
52 // Sets all buttons to the "unclicked" state
53 . "obj.siblings().removeClass('engaged disabled ilSubmitInactive').attr('aria-pressed', 'false');"
54 . "obj.siblings().removeAttr('disabled');"
55 // Sets the clicked button into the "clicked" state
56 . "obj.addClass('engaged disabled ilSubmitInactive').attr('aria-pressed', 'true');"
57 . "obj.attr('disabled', 'disabled');"
58 // Hide all instruction divs at first
59 . '$(".instructions").hide();'
60 // Show the div which is given as an argument
61 . '$("#"+id).show();}</script>');
62
63 /*
64 * The document might just contain a single entry, then we don't need a view control and just return it.
65 */
66 if (count($a_mount_instructions) === 1) {
67 $content = $f->legacy("<div class='instructions'>" . array_shift($a_mount_instructions) . "</div>");
68
69 return $a_render_async ? $r->renderAsync($content) : $r->render($content);
70 }
71
72 /*
73 * This is an associative array. The key is the title of the button, the value the used signal. E.g.:
74 * array(
75 * "WINDOWS" => signal_for_windows_legacy_component,
76 * "MAC" => signal_for_mac_legacy_component,
77 * "LINUX" => signal_for_linux_legacy_component);
78 */
79 $view_control_actions = array();
80
81 /*
82 * If we can determine the os and we find a corresponding string in the
83 * title of the instructions we automatically set it.
84 */
85
86 foreach ($a_mount_instructions as $key => $value) {
87 $selected = $a_mount_instructions[$key];
88 break;
89 }
90
91
92 foreach ($a_mount_instructions as $title => $text) {
93 foreach ($os as $os_string) {
94 if (stristr($title, $os_string) !== false) {
95 $selected = $title;
96 break 2;
97 }
98 }
99 }
100
101 foreach ($a_mount_instructions as $title => $text) {
102 if ($title == $selected) {
103 $hidden = '';
104 } else {
105 $hidden = 'style="display: none;"';
106 }
107
108 // Create legacy component for mount instructions. Mount instructions text is wrapped in a <div>-tag
109 $legacy = $f->legacy("<div id='$title' class='instructions' $hidden>$text</div>")
110 ->withCustomSignal($title, "il.UI.showMountInstructions(event, '$title');");
111
112 // Add to the list of components to render
113 $comps[] = $legacy;
114
115 // Add signal to the list for the view control
116 $view_control_actions[$title] = $legacy->getCustomSignal($title);
117 }
118
119 $view_control = $f->viewControl()->mode($view_control_actions, "mount-instruction-buttons")->withActive($selected);
120
121 // Add view control and legacy add the beginning of the array (so they will be rendered first)
122 $header_comps = array(
123 $f->legacy("<div style='text-align: center'>"),
124 $view_control,
125 $f->legacy("</div>"),
126 $js_function_legacy);
127
128 $comps = array_merge($header_comps, $comps);
129
130 return $a_render_async ? $r->renderAsync($comps) : $r->render($comps);
131 }
132
134 {
135 try {
136 $instructions = $this->mount_instruction->getMountInstructionsAsArray();
137 } catch (InvalidArgumentException $e) {
139 $instructions = $document_processor->processMountInstructions($this->il_lang->txt('webfolder_instructions_text'));
140 $instructions = $this->mount_instruction->getMountInstructionsAsArray($instructions);
141 if ($instructions == '' || $instructions == '-webfolder_instructions_text-') {
142 $instructions = ["<div class='alert alert-danger'>" . $this->il_lang->txt('error') . ": " . $this->il_lang->txt('webdav_missing_lang') . "</div>"];
143 }
144 }
145
146 echo $this->buildGUIFromGivenMountInstructions($instructions, true);
147 exit;
148 }
149
150 private function determineOSfromUserAgent() : array
151 {
152 $ua = $this->http->request()->getHeader('User-Agent')[0];
153
154 if (stristr($ua, 'windows') !== false
155 || strpos($ua, 'microsoft') !== false) {
156 return ['win'];
157 }
158
159 if (stristr($this->user_agent, 'darwin') !== false
160 || stristr($ua, 'macintosh') !== false) {
161 return ['mac', 'osx'];
162 }
163
164 if (stristr($ua, 'linux') !== false
165 || stristr($ua, 'solaris') !== false
166 || stristr($ua, 'aix') !== false
167 || stristr($ua, 'unix') !== false
168 || stristr($ua, 'gvfs') !== false // nautilus browser uses this ID
169 ) {
170 return ['linux'];
171 }
172
173 return ['unknown'];
174 }
175}
An exception for terminatinating execution or to throw for unit testing.
Class ilWebDAVMountInstructionsGUI.
__construct(ilWebDAVBaseMountInstructions $a_mount_instruction)
buildGUIFromGivenMountInstructions($a_mount_instructions, $a_render_async=false)
exit
Definition: login.php:29
static http()
Fetches the global http state from ILIAS.
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46