ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWebDAVMountInstructions.php
Go to the documentation of this file.
1<?php
2
12{
13 protected $user_agent;
14 protected $request_uri;
15 protected $http_host;
16 protected $script_name;
17 protected $client_id;
19
20 protected $clientOSFlavor;
21 protected $clientOS;
22
23 protected $settings;
24 protected $lng;
25
26 protected $ref_id;
27 protected $obj_id;
28 protected $obj_title;
29
30 public function __construct($a_user_agent = '', $a_request_uri = '', $a_http_host = '', $a_script_name = '', $a_client_id = '')
31 {
32 global $DIC;
33
34 $this->settings = new ilSetting('file_access');
35 $this->lng = $DIC->language();
36
37 $this->user_agent = $a_user_agent == '' ? strtolower($_SERVER['HTTP_USER_AGENT']) : $a_user_agent;
38 $this->request_uri = $a_request_uri == '' ? $_SERVER['REQUEST_URI'] : $a_request_uri;
39 $this->http_host = $a_http_host == '' ? $_SERVER['HTTP_HOST'] : $a_http_host;
40 $this->script_name = $a_http_host == '' ? $_SERVER['SCRIPT_NAME'] : $a_script_name;
41 $this->client_id = $a_http_host == '' ? CLIENT_ID : $a_client_id;
42 $this->path_to_template = 'Customizing/clients/' . $this->client_id . '/webdavtemplate.htm';
43
44 $this->ref_id = 0;
45 foreach (explode('/', $this->request_uri) as $uri_part) {
46 if (strpos($uri_part, 'ref_') !== false && $this->ref_id == 0) {
47 $this->ref_id = (int) explode('_', $uri_part)[1];
48 }
49 }
50 if ($this->ref_id == 0) {
51 throw new Exception('Bad Request: No ref id given!');
52 } else {
53 $this->obj_id = ilObject::_lookupObjectId($this->ref_id);
54 $this->obj_title = ilObject::_lookupTitle($this->obj_id);
55 }
56
57 $this->base_uri = $this->http_host . $this->script_name . '/' . $this->client_id . '/ref_' . $this->ref_id . '/';
58
59 $this->protocol_prefixes = array(
60 'default' => 'https://',
61 'konqueror' => 'webdavs://',
62 'nautilus' => 'davs://'
63 );
64
65 $this->setValuesFromUserAgent($this->user_agent);
66 }
67
68 protected function setValuesFromUserAgent($a_user_agent)
69 {
70 // Guess operating system, operating system flavor and browser of the webdav client
71 //
72 // - We need to know the operating system in order to properly
73 // hide hidden resources in directory listings.
74 //
75 // - We need the operating system flavor and the browser to
76 // properly support mounting of a webdav folder.
77 //
78 if (strpos($a_user_agent, 'windows') !== false
79 || strpos($a_user_agent, 'microsoft') !== false) {
80 $this->clientOS = 'windows';
81 if (strpos($a_user_agent, 'nt 5.1') !== false) {
82 $this->clientOSFlavor = 'xp';
83 } else {
84 $this->clientOSFlavor = 'nichtxp';
85 }
86 } elseif (strpos($this->user_agent, 'darwin') !== false
87 || strpos($a_user_agent, 'macintosh') !== false
88 || strpos($a_user_agent, 'linux') !== false
89 || strpos($a_user_agent, 'solaris') !== false
90 || strpos($a_user_agent, 'aix') !== false
91 || strpos($a_user_agent, 'unix') !== false
92 || strpos($a_user_agent, 'gvfs') !== false // nautilus browser uses this ID
93 ) {
94 $this->clientOS = 'unix';
95 if (strpos($a_user_agent, 'linux') !== false) {
96 $this->clientOSFlavor = 'linux';
97 } elseif (strpos($a_user_agent, 'macintosh') !== false) {
98 $this->clientOSFlavor = 'osx';
99 }
100 }
101 }
102
104 {
105 return is_file($this->path_to_template);
106 }
107
109 {
110 return fread(fopen($this->path_to_template, "rb"), filesize($this->path_to_template));
111 }
112
113 public function getCustomInstruction()
114 {
115 return $this->settings->get('custom_webfolder_instructions');
116 }
117
118 public function getDefaultInstruction()
119 {
120 return $this->lng->txt('webfolder_instructions_text');
121 }
122
123 public function getWebfolderTitle()
124 {
125 return $this->obj_title;
126 }
127
128 public function getDefaultUri()
129 {
130 return $this->protocol_prefixes['default'] . $this->base_uri;
131 }
132
133 public function getIEUri()
134 {
135 // Was in the old webdav the same like default uri and is now still the same
136 return $this->protocol_prefixes['default'] . $this->base_uri;
137 }
138
139 public function getKonquerorUri()
140 {
141 return $this->protocol_prefixes['konqueror'] . $this->base_uri;
142 }
143
144 public function getNautilusUri()
145 {
146 return $this->protocol_prefixes['nautilus'] . $this->base_uri;
147 }
148
168 public function setInstructionPlaceholders($a_instruction_tpl)
169 {
170 $a_instruction_tpl = str_replace("[WEBFOLDER_ID]", $this->ref_id, $a_instruction_tpl);
171 $a_instruction_tpl = str_replace("[WEBFOLDER_TITLE]", $this->obj_title, $a_instruction_tpl);
172 $a_instruction_tpl = str_replace("[WEBFOLDER_URI]", $this->getDefaultUri(), $a_instruction_tpl);
173 $a_instruction_tpl = str_replace("[WEBFOLDER_URI_IE]", $this->getIEUri(), $a_instruction_tpl);
174 $a_instruction_tpl = str_replace("[WEBFOLDER_URI_KONQUEROR]", $this->getKonquerorUri(), $a_instruction_tpl);
175 $a_instruction_tpl = str_replace("[WEBFOLDER_URI_NAUTILUS]", $this->getNautilusUri(), $a_instruction_tpl);
176 $a_instruction_tpl = str_replace("[ADMIN_MAIL]", $this->settings->get("admin_email"), $a_instruction_tpl);
177
178 if (strpos($this->user_agent, 'MSIE') !== false) {
179 $a_instruction_tpl = preg_replace('/\[IF_IEXPLORE\](?:(.*))\[\/IF_IEXPLORE\]/s', '\1', $a_instruction_tpl);
180 } else {
181 $a_instruction_tpl = preg_replace('/\[IF_NOTIEXPLORE\](?:(.*))\[\/IF_NOTIEXPLORE\]/s', '\1', $a_instruction_tpl);
182 }
183
184 switch ($this->clientOS) {
185 case 'windows':
186 $operatingSystem = 'WINDOWS';
187 break;
188 case 'unix':
189 switch ($this->clientOSFlavor) {
190 case 'osx':
191 $operatingSystem = 'MAC';
192 break;
193 case 'linux':
194 $operatingSystem = 'LINUX';
195 break;
196 default:
197 $operatingSystem = 'LINUX';
198 break;
199 }
200 break;
201 default:
202 $operatingSystem = 'UNKNOWN';
203 break;
204 }
205 if ($operatingSystem != 'UNKNOWN') {
206 $a_instruction_tpl = preg_replace('/\[IF_' . $operatingSystem . '\](?:(.*))\[\/IF_' . $operatingSystem . '\]/s', '\1', $a_instruction_tpl);
207 $a_instruction_tpl = preg_replace('/\[IF_([A-Z_]+)\](?:(.*))\[\/IF_\1\]/s', '', $a_instruction_tpl);
208 } else {
209 $a_instruction_tpl = preg_replace('/\[IF_([A-Z_]+)\](?:(.*))\[\/IF_\1\]/s', '\2', $a_instruction_tpl);
210 }
211
212 return $a_instruction_tpl;
213 }
214}
An exception for terminatinating execution or to throw for unit testing.
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
ILIAS Setting Class.
Class ilWebDAVMountInstructions.
setInstructionPlaceholders($a_instruction_tpl)
Gets Webfolder mount instructions for the specified webfolder.
__construct($a_user_agent='', $a_request_uri='', $a_http_host='', $a_script_name='', $a_client_id='')
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']