| Línea 162... |
Línea 162... |
| 162 |
}
|
162 |
}
|
| 163 |
return ($countfailures[$sess] < 3);
|
163 |
return ($countfailures[$sess] < 3);
|
| 164 |
}
|
164 |
}
|
| Línea 165... |
Línea 165... |
| 165 |
|
165 |
|
| - |
|
166 |
/**
|
| - |
|
167 |
* Returned unserialized object from base64 encoded file reference data
|
| - |
|
168 |
*
|
| - |
|
169 |
* @param string $reference
|
| - |
|
170 |
* @return stdClass
|
| - |
|
171 |
*/
|
| - |
|
172 |
private function unserialize_reference(string $reference): stdClass {
|
| - |
|
173 |
$decoded = base64_decode($reference);
|
| - |
|
174 |
return unserialize_object($decoded);
|
| - |
|
175 |
}
|
| - |
|
176 |
|
| 166 |
/**
|
177 |
/**
|
| 167 |
* Download a file, this function can be overridden by subclass. {@link curl}
|
178 |
* Download a file, this function can be overridden by subclass. {@link curl}
|
| 168 |
*
|
179 |
*
|
| 169 |
* @param string $reference the source of the file
|
180 |
* @param string $reference the source of the file
|
| 170 |
* @param string $filename filename (without path) to save the downloaded file in the
|
181 |
* @param string $filename filename (without path) to save the downloaded file in the
|
| Línea 173... |
Línea 184... |
| 173 |
* path: internal location of the file
|
184 |
* path: internal location of the file
|
| 174 |
* url: URL to the source (from parameters)
|
185 |
* url: URL to the source (from parameters)
|
| 175 |
*/
|
186 |
*/
|
| 176 |
public function get_file($reference, $filename = '') {
|
187 |
public function get_file($reference, $filename = '') {
|
| 177 |
global $USER, $CFG;
|
188 |
global $USER, $CFG;
|
| 178 |
$ref = @unserialize(base64_decode($reference));
|
189 |
$ref = $this->unserialize_reference($reference);
|
| 179 |
if (!isset($ref->url) || !($url = $this->appendtoken($ref->url))) {
|
190 |
if (!isset($ref->url) || !($url = $this->appendtoken($ref->url))) {
|
| 180 |
// Occurs when the user isn't known..
|
191 |
// Occurs when the user isn't known..
|
| 181 |
return null;
|
192 |
return null;
|
| 182 |
}
|
193 |
}
|
| 183 |
$path = $this->prepare_file($filename);
|
194 |
$path = $this->prepare_file($filename);
|
| Línea 199... |
Línea 210... |
| 199 |
if ($file->get_referencelastsync() + DAYSECS > time() || !$this->connection_result()) {
|
210 |
if ($file->get_referencelastsync() + DAYSECS > time() || !$this->connection_result()) {
|
| 200 |
// Synchronise not more often than once a day.
|
211 |
// Synchronise not more often than once a day.
|
| 201 |
// if we had several unsuccessfull attempts to connect to server - do not try any more.
|
212 |
// if we had several unsuccessfull attempts to connect to server - do not try any more.
|
| 202 |
return false;
|
213 |
return false;
|
| 203 |
}
|
214 |
}
|
| 204 |
$ref = @unserialize(base64_decode($file->get_reference()));
|
215 |
$ref = $this->unserialize_reference($file->get_reference());
|
| 205 |
if (!isset($ref->url) || !($url = $this->appendtoken($ref->url))) {
|
216 |
if (!isset($ref->url) || !($url = $this->appendtoken($ref->url))) {
|
| 206 |
// Occurs when the user isn't known..
|
217 |
// Occurs when the user isn't known..
|
| 207 |
$file->set_missingsource();
|
218 |
$file->set_missingsource();
|
| 208 |
return true;
|
219 |
return true;
|
| 209 |
}
|
220 |
}
|
| Línea 245... |
Línea 256... |
| 245 |
* @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
|
256 |
* @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
|
| 246 |
* @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
|
257 |
* @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
|
| 247 |
* @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
|
258 |
* @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
|
| 248 |
* @param array $options additional options affecting the file serving
|
259 |
* @param array $options additional options affecting the file serving
|
| 249 |
*/
|
260 |
*/
|
| 250 |
public function send_file($stored_file, $lifetime=null , $filter=0, $forcedownload=false, array $options = null) {
|
261 |
public function send_file($stored_file, $lifetime=null , $filter=0, $forcedownload=false, ?array $options = null) {
|
| 251 |
$reference = unserialize(base64_decode($stored_file->get_reference()));
|
262 |
$ref = $this->unserialize_reference($stored_file->get_reference());
|
| 252 |
$url = $this->appendtoken($reference->url);
|
263 |
if (isset($ref->url) && $url = $this->appendtoken($ref->url)) {
|
| 253 |
if ($url) {
|
- |
|
| 254 |
header('Location: ' . $url);
|
264 |
header('Location: ' . $url);
|
| 255 |
} else {
|
265 |
} else {
|
| 256 |
send_file_not_found();
|
266 |
send_file_not_found();
|
| 257 |
}
|
267 |
}
|
| 258 |
}
|
268 |
}
|
| Línea 433... |
Línea 443... |
| 433 |
* @param int $filestatus status of the file, 0 - ok, 666 - source missing
|
443 |
* @param int $filestatus status of the file, 0 - ok, 666 - source missing
|
| 434 |
* @return string
|
444 |
* @return string
|
| 435 |
*/
|
445 |
*/
|
| 436 |
public function get_reference_details($reference, $filestatus = 0) {
|
446 |
public function get_reference_details($reference, $filestatus = 0) {
|
| 437 |
if (!$filestatus) {
|
447 |
if (!$filestatus) {
|
| 438 |
$ref = unserialize(base64_decode($reference));
|
448 |
$ref = $this->unserialize_reference($reference);
|
| 439 |
return $this->get_name(). ': '. $ref->filename;
|
449 |
return $this->get_name(). ': '. ($ref->filename ?? '');
|
| 440 |
} else {
|
450 |
} else {
|
| 441 |
return get_string('lostsource', 'repository', '');
|
451 |
return get_string('lostsource', 'repository', '');
|
| 442 |
}
|
452 |
}
|
| 443 |
}
|
453 |
}
|