266
collatorlib::ksort($folders, collatorlib::SORT_NATURAL);
267
collatorlib::ksort($files, collatorlib::SORT_NATURAL);
266
collatorlib::ksort($folders, core_collator::SORT_NATURAL);
267
collatorlib::ksort($files, core_collator::SORT_NATURAL);
268
268
$ret['list'] = array_merge($folders, $files);
269
269
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
330
330
$mform->addRule('clientsecret', $strrequired, 'required', null, 'client');
331
331
$mform->setType('clientsecret', PARAM_RAW_TRIMMED);
333
$mform->addElement('static', null, '', get_string('informationapiv2', 'repository_boxnet'));
333
$mform->addElement('static', null, '', get_string('information', 'repository_boxnet'));
335
335
if (strpos($CFG->wwwroot, 'https') !== 0) {
336
336
$mform->addElement('static', null, '', get_string('warninghttps', 'repository_boxnet'));
414
414
return $shareinfo->url;
418
* Returns information about file in this repository by reference
419
* {@link repository::get_file_reference()}
420
* {@link repository::get_file()}
422
* Returns null if file not found or is not readable
424
* @param stdClass $reference file reference db record
425
* @return null|stdClass with attribute 'filepath'
418
* Synchronize the references.
420
* @param stored_file $file Stored file.
427
public function get_file_by_reference($reference) {
428
$reference = unserialize(self::convert_to_valid_reference($reference->reference));
423
public function sync_reference(stored_file $file) {
424
if ($file->get_referencelastsync() + DAYSECS > time()) {
425
// Synchronise not more often than once a day.
429
$reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
429
430
$url = $reference->downloadurl;
431
if (file_extension_in_typegroup($file->get_filename(), 'web_image')) {
432
$path = $this->prepare_file('');
433
$result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => self::SYNCIMAGE_TIMEOUT));
434
$info = $c->get_info();
435
if ($result === true && isset($info['http_code']) && $info['http_code'] == 200) {
436
$fs = get_file_storage();
437
list($contenthash, $filesize, $newfile) = $fs->add_file_to_pool($path);
438
$file->set_synchronized($contenthash, $filesize);
431
442
$c->get($url, null, array('timeout' => self::SYNCIMAGE_TIMEOUT, 'followlocation' => true, 'nobody' => true));
432
443
$info = $c->get_info();
433
444
if (isset($info['http_code']) && $info['http_code'] == 200 &&
434
445
array_key_exists('download_content_length', $info) &&
435
446
$info['download_content_length'] >= 0) {
436
447
$filesize = (int)$info['download_content_length'];
437
return (object) array('filesize' => $filesize);
448
$file->set_synchronized(null, $filesize);
451
$file->set_missingsource();
473
486
* Repository method to serve the referenced file
475
488
* @param stored_file $storedfile the file that contains the reference
476
* @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
489
* @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
477
490
* @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
478
491
* @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
479
492
* @param array $options additional options affecting the file serving
481
public function send_file($storedfile, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) {
494
public function send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, array $options = null) {
482
495
$ref = unserialize(self::convert_to_valid_reference($storedfile->get_reference()));
483
496
header('Location: ' . $ref->downloadurl);