~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to repository/boxnet/lib.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
263
263
            }
264
264
        }
265
265
 
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'));
270
270
 
330
330
        $mform->addRule('clientsecret', $strrequired, 'required', null, 'client');
331
331
        $mform->setType('clientsecret', PARAM_RAW_TRIMMED);
332
332
 
333
 
        $mform->addElement('static', null, '',  get_string('informationapiv2', 'repository_boxnet'));
 
333
        $mform->addElement('static', null, '',  get_string('information', 'repository_boxnet'));
334
334
 
335
335
        if (strpos($CFG->wwwroot, 'https') !== 0) {
336
336
            $mform->addElement('static', null, '',  get_string('warninghttps', 'repository_boxnet'));
414
414
        return $shareinfo->url;
415
415
    }
416
416
 
417
 
     /**
418
 
     * Returns information about file in this repository by reference
419
 
     * {@link repository::get_file_reference()}
420
 
     * {@link repository::get_file()}
421
 
     *
422
 
     * Returns null if file not found or is not readable
423
 
     *
424
 
     * @param stdClass $reference file reference db record
425
 
     * @return null|stdClass with attribute 'filepath'
 
417
    /**
 
418
     * Synchronize the references.
 
419
     *
 
420
     * @param stored_file $file Stored file.
 
421
     * @return boolean
426
422
     */
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.
 
426
            return false;
 
427
        }
 
428
        $c = new curl();
 
429
        $reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
429
430
        $url = $reference->downloadurl;
430
 
        $c = new curl();
 
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);
 
439
                return true;
 
440
            }
 
441
        }
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);
 
449
            return true;
438
450
        }
439
 
        return null;
 
451
        $file->set_missingsource();
 
452
        return true;
440
453
    }
441
454
 
442
455
    /**
473
486
     * Repository method to serve the referenced file
474
487
     *
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
480
493
     */
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);
484
497
    }