• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP stored_file类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中stored_file的典型用法代码示例。如果您正苦于以下问题:PHP stored_file类的具体用法?PHP stored_file怎么用?PHP stored_file使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了stored_file类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: can_import_file

 /**
  * Check if the given file is capable of being imported by this plugin.
  * As {@link file_storage::mimetype()} now uses finfo PHP extension if available,
  * the value returned by $file->get_mimetype for a .dat file is not the same on all servers.
  * So we must made 2 checks to verify if the plugin can import the file.
  * @param stored_file $file the file to check
  * @return bool whether this plugin can import the file
  */
 public function can_import_file($file) {
     $mimetypes = array(
         mimeinfo('type', '.dat'),
         mimeinfo('type', '.zip')
     );
     return in_array($file->get_mimetype(), $mimetypes) || in_array(mimeinfo('type', $file->get_filename()), $mimetypes);
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:15,代码来源:formatbase.php


示例2: send_file

 /**
  * Repository method to serve the referenced file
  *
  * @param stored_file $storedfile the file that contains the reference
  * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
  * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
  * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
  * @param array $options additional options affecting the file serving
  */
 public function send_file($storedfile, $lifetime = null, $filter = 0, $forcedownload = false, array $options = null)
 {
     $ref = unserialize(self::convert_to_valid_reference($storedfile->get_reference()));
     header('Location: ' . $ref->downloadurl);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:14,代码来源:lib.php


示例3: scorm_parse_scorm

/**
 * Sets up SCORM 1.2/2004 packages using the manifest file.
 * Called whenever SCORM changes
 * @param object $scorm instance - fields are updated and changes saved into database
 * @param stored_file|string $manifest - path to manifest file or stored_file.
 * @return bool
 */
function scorm_parse_scorm(&$scorm, $manifest)
{
    global $CFG, $DB;
    // load manifest into string
    if ($manifest instanceof stored_file) {
        $xmltext = $manifest->get_content();
    } else {
        require_once "{$CFG->libdir}/filelib.php";
        $xmltext = download_file_content($manifest);
    }
    $defaultorgid = 0;
    $firstinorg = 0;
    $pattern = '/&(?!\\w{2,6};)/';
    $replacement = '&';
    $xmltext = preg_replace($pattern, $replacement, $xmltext);
    $objXML = new xml2Array();
    $manifests = $objXML->parse($xmltext);
    $scoes = new stdClass();
    $scoes->version = '';
    $scoes = scorm_get_manifest($manifests, $scoes);
    $newscoes = array();
    $sortorder = 0;
    if (count($scoes->elements) > 0) {
        $olditems = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id));
        foreach ($scoes->elements as $manifest => $organizations) {
            foreach ($organizations as $organization => $items) {
                foreach ($items as $identifier => $item) {
                    $sortorder++;
                    // This new db mngt will support all SCORM future extensions
                    $newitem = new stdClass();
                    $newitem->scorm = $scorm->id;
                    $newitem->manifest = $manifest;
                    $newitem->organization = $organization;
                    $newitem->sortorder = $sortorder;
                    $standarddatas = array('parent', 'identifier', 'launch', 'scormtype', 'title');
                    foreach ($standarddatas as $standarddata) {
                        if (isset($item->{$standarddata})) {
                            $newitem->{$standarddata} = $item->{$standarddata};
                        } else {
                            $newitem->{$standarddata} = '';
                        }
                    }
                    if (!empty($defaultorgid) && !empty($scoes->defaultorg) && empty($firstinorg) && $newitem->parent == $scoes->defaultorg) {
                        $firstinorg = $sortorder;
                    }
                    if (!empty($olditems) && ($olditemid = scorm_array_search('identifier', $newitem->identifier, $olditems))) {
                        $newitem->id = $olditemid;
                        // Update the Sco sortorder but keep id so that user tracks are kept against the same ids.
                        $DB->update_record('scorm_scoes', $newitem);
                        $id = $olditemid;
                        // Remove all old data so we don't duplicate it.
                        $DB->delete_records('scorm_scoes_data', array('scoid' => $olditemid));
                        $DB->delete_records('scorm_seq_objective', array('scoid' => $olditemid));
                        $DB->delete_records('scorm_seq_mapinfo', array('scoid' => $olditemid));
                        $DB->delete_records('scorm_seq_ruleconds', array('scoid' => $olditemid));
                        $DB->delete_records('scorm_seq_rulecond', array('scoid' => $olditemid));
                        $DB->delete_records('scorm_seq_rolluprule', array('scoid' => $olditemid));
                        $DB->delete_records('scorm_seq_rolluprulecond', array('scoid' => $olditemid));
                        // Now remove this SCO from the olditems object as we have dealt with it.
                        unset($olditems[$olditemid]);
                    } else {
                        // Insert the new SCO, and retain the link between the old and new for later adjustment
                        $id = $DB->insert_record('scorm_scoes', $newitem);
                    }
                    $newscoes[$id] = $newitem;
                    // Save this sco in memory so we can use it later.
                    if ($optionaldatas = scorm_optionals_data($item, $standarddatas)) {
                        $data = new stdClass();
                        $data->scoid = $id;
                        foreach ($optionaldatas as $optionaldata) {
                            if (isset($item->{$optionaldata})) {
                                $data->name = $optionaldata;
                                $data->value = $item->{$optionaldata};
                                $dataid = $DB->insert_record('scorm_scoes_data', $data);
                            }
                        }
                    }
                    if (isset($item->sequencingrules)) {
                        foreach ($item->sequencingrules as $sequencingrule) {
                            $rule = new stdClass();
                            $rule->scoid = $id;
                            $rule->ruletype = $sequencingrule->type;
                            $rule->conditioncombination = $sequencingrule->conditioncombination;
                            $rule->action = $sequencingrule->action;
                            $ruleid = $DB->insert_record('scorm_seq_ruleconds', $rule);
                            if (isset($sequencingrule->ruleconditions)) {
                                foreach ($sequencingrule->ruleconditions as $rulecondition) {
                                    $rulecond = new stdClass();
                                    $rulecond->scoid = $id;
                                    $rulecond->ruleconditionsid = $ruleid;
                                    $rulecond->referencedobjective = $rulecondition->referencedobjective;
                                    $rulecond->measurethreshold = $rulecondition->measurethreshold;
                                    $rulecond->operator = $rulecondition->operator;
//.........这里部分代码省略.........
开发者ID:educacionbe,项目名称:cursos,代码行数:101,代码来源:scormlib.php


示例4: sync_reference

 /**
  * Performs synchronisation of an external file if the previous one has expired.
  *
  * This function must be implemented for external repositories supporting
  * FILE_REFERENCE, it is called for existing aliases when their filesize,
  * contenthash or timemodified are requested. It is not called for internal
  * repositories (see {@link repository::has_moodle_files()}), references to
  * internal files are updated immediately when source is modified.
  *
  * Referenced files may optionally keep their content in Moodle filepool (for
  * thumbnail generation or to be able to serve cached copy). In this
  * case both contenthash and filesize need to be synchronized. Otherwise repositories
  * should use contenthash of empty file and correct filesize in bytes.
  *
  * Note that this function may be run for EACH file that needs to be synchronised at the
  * moment. If anything is being downloaded or requested from external sources there
  * should be a small timeout. The synchronisation is performed to update the size of
  * the file and/or to update image and re-generated image preview. There is nothing
  * fatal if syncronisation fails but it is fatal if syncronisation takes too long
  * and hangs the script generating a page.
  *
  * Note: If you wish to call $file->get_filesize(), $file->get_contenthash() or
  * $file->get_timemodified() make sure that recursion does not happen.
  *
  * Called from {@link stored_file::sync_external_file()}
  *
  * @uses stored_file::set_missingsource()
  * @uses stored_file::set_synchronized()
  * @param stored_file $file
  * @return bool false when file does not need synchronisation, true if it was synchronised
  */
 public function sync_reference(stored_file $file)
 {
     if ($file->get_repository_id() != $this->id) {
         // This should not really happen because the function can be called from stored_file only.
         return false;
     }
     if ($this->has_moodle_files()) {
         // References to local files need to be synchronised only once.
         // Later they will be synchronised automatically when the source is changed.
         if ($file->get_referencelastsync()) {
             return false;
         }
         $fs = get_file_storage();
         $params = file_storage::unpack_reference($file->get_reference(), true);
         if (!is_array($params) || !($storedfile = $fs->get_file($params['contextid'], $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']))) {
             $file->set_missingsource();
         } else {
             $file->set_synchronized($storedfile->get_contenthash(), $storedfile->get_filesize(), 0, $storedfile->get_timemodified());
         }
         return true;
     }
     return false;
 }
开发者ID:isuruAb,项目名称:moodle,代码行数:54,代码来源:lib.php


示例5: data_preset_get_file_contents

    /**
     * Retreive the contents of a file. That file may either be in a conventional directory of the Moodle file storage
     * @param file_storage $filestorage. should be null if using a conventional directory
     * @param stored_file $fileobj the directory to look in. null if using a conventional directory
     * @param string $dir the directory to look in. null if using the Moodle file storage
     * @param string $filename the name of the file we want
     * @return string the contents of the file
     */
    public function data_preset_get_file_contents(&$filestorage, &$fileobj, $dir, $filename) {
        if(empty($filestorage) || empty($fileobj)) {
            if (substr($dir, -1)!='/') {
                $dir .= '/';
            }
            return file_get_contents($dir.$filename);
        } else {
            $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename);
            return $file->get_content();
        }

    }
开发者ID:nottmoo,项目名称:moodle,代码行数:20,代码来源:lib.php


示例6: file_restore_source_field_from_draft_file

/**
 * Restore the original source field from draft files
 *
 * Do not use this function because it makes field files.source inconsistent
 * for draft area files. This function will be deprecated in 2.6
 *
 * @param stored_file $storedfile This only works with draft files
 * @return stored_file
 */
function file_restore_source_field_from_draft_file($storedfile)
{
    $source = @unserialize($storedfile->get_source());
    if (!empty($source)) {
        if (is_object($source)) {
            $restoredsource = $source->source;
            $storedfile->set_source($restoredsource);
        } else {
            throw new moodle_exception('invalidsourcefield', 'error');
        }
    }
    return $storedfile;
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:22,代码来源:filelib.php


示例7: get_response_file_url

 /**
  * Get the URL of a file that belongs to a response variable of this
  * question_attempt.
  * @param stored_file $file the file to link to.
  * @return string the URL of that file.
  */
 public function get_response_file_url(stored_file $file)
 {
     return file_encode_url(new moodle_url('/pluginfile.php'), '/' . implode('/', array($file->get_contextid(), $file->get_component(), $file->get_filearea(), $this->usageid, $this->slot, $file->get_itemid())) . $file->get_filepath() . $file->get_filename(), true);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:10,代码来源:questionattempt.php


示例8: get_pretected_pathname

 public static function get_pretected_pathname(stored_file $file)
 {
     return $file->get_pathname_by_contenthash();
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:4,代码来源:file_storage_test.php


示例9: replace_file_with

 /**
  * Replaces the fields that might have changed when file was overriden in filepicker:
  * reference, contenthash, filesize, userid
  *
  * Note that field 'source' must be updated separately because
  * it has different format for draft and non-draft areas and
  * this function will usually be used to replace non-draft area
  * file with draft area file.
  *
  * @param stored_file $newfile
  * @throws coding_exception
  */
 public function replace_file_with(stored_file $newfile)
 {
     if ($newfile->get_referencefileid() && $this->fs->get_references_count_by_storedfile($this)) {
         // The new file is a reference.
         // The current file has other local files referencing to it.
         // Double reference is not allowed.
         throw new moodle_exception('errordoublereference', 'repository');
     }
     $filerecord = new stdClass();
     $contenthash = $newfile->get_contenthash();
     if ($this->fs->content_exists($contenthash)) {
         $filerecord->contenthash = $contenthash;
     } else {
         throw new file_exception('storedfileproblem', 'Invalid contenthash, content must be already in filepool', $contenthash);
     }
     $filerecord->filesize = $newfile->get_filesize();
     $filerecord->referencefileid = $newfile->get_referencefileid();
     $filerecord->userid = $newfile->get_userid();
     $this->update($filerecord);
 }
开发者ID:qanuj,项目名称:moodle,代码行数:32,代码来源:stored_file.php


示例10: file_overwrite_existing_draftfile

/**
 * Overwrite an existing file in a draft area.
 *
 * @param  stored_file $newfile      the new file with the new content and meta-data
 * @param  stored_file $existingfile the file that will be overwritten
 * @throws moodle_exception
 * @since Moodle 3.2
 */
function file_overwrite_existing_draftfile(stored_file $newfile, stored_file $existingfile)
{
    if ($existingfile->get_component() != 'user' or $existingfile->get_filearea() != 'draft') {
        throw new coding_exception('The file to overwrite is not in a draft area.');
    }
    $fs = get_file_storage();
    // Remember original file source field.
    $source = @unserialize($existingfile->get_source());
    // Remember the original sortorder.
    $sortorder = $existingfile->get_sortorder();
    if ($newfile->is_external_file()) {
        // New file is a reference. Check that existing file does not have any other files referencing to it
        if (isset($source->original) && $fs->search_references_count($source->original)) {
            throw new moodle_exception('errordoublereference', 'repository');
        }
    }
    // Delete existing file to release filename.
    $newfilerecord = array('contextid' => $existingfile->get_contextid(), 'component' => 'user', 'filearea' => 'draft', 'itemid' => $existingfile->get_itemid(), 'timemodified' => time());
    $existingfile->delete();
    // Create new file.
    $newfile = $fs->create_file_from_storedfile($newfilerecord, $newfile);
    // Preserve original file location (stored in source field) for handling references.
    if (isset($source->original)) {
        if (!($newfilesource = @unserialize($newfile->get_source()))) {
            $newfilesource = new stdClass();
        }
        $newfilesource->original = $source->original;
        $newfile->set_source(serialize($newfilesource));
    }
    $newfile->set_sortorder($sortorder);
}
开发者ID:gabrielrosset,项目名称:moodle,代码行数:39,代码来源:filelib.php


示例11: copy_existing_file

 /**
  * Copies a file from somewhere else in moodle
  * to the portfolio temporary working directory
  * associated with this export
  *
  * @param stored_file $oldfile existing stored file object
  * @return stored_file|bool new file object
  */
 public function copy_existing_file($oldfile)
 {
     if (array_key_exists($oldfile->get_contenthash(), $this->newfilehashes)) {
         return $this->newfilehashes[$oldfile->get_contenthash()];
     }
     $fs = get_file_storage();
     $file_record = $this->new_file_record_base($oldfile->get_filename());
     if ($dir = $this->get('format')->get_file_directory()) {
         $file_record->filepath = '/' . $dir . '/';
     }
     try {
         $newfile = $fs->create_file_from_storedfile($file_record, $oldfile->get_id());
         $this->newfilehashes[$newfile->get_contenthash()] = $newfile;
         return $newfile;
     } catch (file_exception $e) {
         return false;
     }
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:26,代码来源:exporter.php


示例12: export_file_for_engine

 /**
  * Export the data for the given file in relation to this document.
  *
  * @param \stored_file $file The stored file we are talking about.
  * @return array
  */
 public function export_file_for_engine($file)
 {
     $data = $this->export_for_engine();
     // Content is index in the main document.
     unset($data['content']);
     unset($data['description1']);
     unset($data['description2']);
     // Going to append the fileid to give it a unique id.
     $data['id'] = $data['id'] . '-solrfile' . $file->get_id();
     $data['type'] = \core_search\manager::TYPE_FILE;
     $data['solr_fileid'] = $file->get_id();
     $data['solr_filecontenthash'] = $file->get_contenthash();
     $data['solr_fileindexstatus'] = self::INDEXED_FILE_TRUE;
     $data['title'] = $file->get_filename();
     $data['modified'] = self::format_time_for_engine($file->get_timemodified());
     return $data;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:23,代码来源:document.php


示例13: send_file

 /**
  * Repository method to serve the referenced file
  *
  * @param stored_file $storedfile the file that contains the reference
  * @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
  * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
  * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
  * @param array $options additional options affecting the file serving
  */
 public function send_file($storedfile, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) {
     $ref = $storedfile->get_reference();
     // Let box.net serve the file. It will return 'no such file' content if file not found
     // also if file has the different name than alias, it will be returned with the box.net filename
     header('Location: ' . $ref);
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:15,代码来源:lib.php


示例14: get_references_count_by_storedfile

 /**
  * Returns the number of aliases that link to the given stored_file
  *
  * Aliases in user draft areas are not counted.
  *
  * @param stored_file $storedfile
  * @return int
  */
 public function get_references_count_by_storedfile(stored_file $storedfile)
 {
     global $DB;
     $params = array();
     $params['contextid'] = $storedfile->get_contextid();
     $params['component'] = $storedfile->get_component();
     $params['filearea'] = $storedfile->get_filearea();
     $params['itemid'] = $storedfile->get_itemid();
     $params['filename'] = $storedfile->get_filename();
     $params['filepath'] = $storedfile->get_filepath();
     return $this->search_references_count(self::pack_reference($params));
 }
开发者ID:nigeli,项目名称:moodle,代码行数:20,代码来源:file_storage.php


示例15: send_file

 /**
  * Repository method to serve the referenced file
  *
  * @see send_stored_file
  *
  * @param stored_file $storedfile the file that contains the reference
  * @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
  * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
  * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
  * @param array $options additional options affecting the file serving
  */
 public function send_file($storedfile, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) {
     $reference = $storedfile->get_reference();
     if ($reference{0} == '/') {
         $file = $this->root_path.substr($reference, 1, strlen($reference)-1);
     } else {
         $file = $this->root_path.$reference;
     }
     if (is_readable($file)) {
         $filename = $storedfile->get_filename();
         if ($options && isset($options['filename'])) {
             $filename = $options['filename'];
         }
         $dontdie = ($options && isset($options['dontdie']));
         send_file($file, $filename, $lifetime , $filter, false, $forcedownload, '', $dontdie);
     } else {
         send_file_not_found();
     }
 }
开发者ID:nigeli,项目名称:moodle,代码行数:29,代码来源:lib.php


示例16: can_import_file

 /**
  * Check if the given file is capable of being imported by this plugin.
  *
  * Note that expensive or detailed integrity checks on the file should
  * not be performed by this method. Simple file type or magic-number tests
  * would be suitable.
  *
  * @param stored_file $file the file to check
  * @return bool whether this plugin can import the file
  */
 public function can_import_file($file)
 {
     return $file->get_mimetype() == $this->mime_type();
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:14,代码来源:format.php


示例17: import_external_file

 /**
  * Convert file alias to local file
  *
  * @throws moodle_exception if file could not be downloaded
  *
  * @param stored_file $storedfile a stored_file instances
  * @param int $maxbytes throw an exception if file size is bigger than $maxbytes (0 means no limit)
  * @return stored_file stored_file
  */
 public function import_external_file(stored_file $storedfile, $maxbytes = 0)
 {
     global $CFG;
     $storedfile->import_external_file_contents($maxbytes);
     $storedfile->delete_reference();
     return $storedfile;
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:16,代码来源:file_storage.php


示例18: label_generate_resized_image

/**
 * Resize the image, if required, then generate an img tag and, if required, a link to the full-size image
 * @param stored_file $file the image file to process
 * @param int $maxwidth the maximum width allowed for the image
 * @param int $maxheight the maximum height allowed for the image
 * @return string HTML fragment to add to the label
 */
function label_generate_resized_image(stored_file $file, $maxwidth, $maxheight)
{
    global $CFG;
    $fullurl = moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename());
    $link = null;
    $attrib = array('alt' => $file->get_filename(), 'src' => $fullurl);
    if ($imginfo = $file->get_imageinfo()) {
        // Work out the new width / height, bounded by maxwidth / maxheight
        $width = $imginfo['width'];
        $height = $imginfo['height'];
        if (!empty($maxwidth) && $width > $maxwidth) {
            $height *= (double) $maxwidth / $width;
            $width = $maxwidth;
        }
        if (!empty($maxheight) && $height > $maxheight) {
            $width *= (double) $maxheight / $height;
            $height = $maxheight;
        }
        $attrib['width'] = $width;
        $attrib['height'] = $height;
        // If the size has changed and the image is of a suitable mime type, generate a smaller version
        if ($width != $imginfo['width']) {
            $mimetype = $file->get_mimetype();
            if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
                require_once $CFG->libdir . '/gdlib.php';
                $tmproot = make_temp_directory('mod_label');
                $tmpfilepath = $tmproot . '/' . $file->get_contenthash();
                $file->copy_content_to($tmpfilepath);
                $data = generate_image_thumbnail($tmpfilepath, $width, $height);
                unlink($tmpfilepath);
                if (!empty($data)) {
                    $fs = get_file_storage();
                    $record = array('contextid' => $file->get_contextid(), 'component' => $file->get_component(), 'filearea' => $file->get_filearea(), 'itemid' => $file->get_itemid(), 'filepath' => '/', 'filename' => 's_' . $file->get_filename());
                    $smallfile = $fs->create_file_from_string($record, $data);
                    // Replace the image 'src' with the resized file and link to the original
                    $attrib['src'] = moodle_url::make_draftfile_url($smallfile->get_itemid(), $smallfile->get_filepath(), $smallfile->get_filename());
                    $link = $fullurl;
                }
            }
        }
    } else {
        // Assume this is an image type that get_imageinfo cannot handle (e.g. SVG)
        $attrib['width'] = $maxwidth;
    }
    $img = html_writer::empty_tag('img', $attrib);
    if ($link) {
        return html_writer::link($link, $img);
    } else {
        return $img;
    }
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:58,代码来源:lib.php


示例19: sync_external_file

 /**
  * Performs synchronisation of reference to an external file if the previous one has expired.
  *
  * @param stored_file $file
  * @param bool $resetsynchistory whether to reset all history of sync (used by phpunit)
  * @return bool success
  */
 public static function sync_external_file($file, $resetsynchistory = false)
 {
     global $DB;
     // TODO MDL-25290 static should be replaced with MUC code.
     static $synchronized = array();
     if ($resetsynchistory) {
         $synchronized = array();
     }
     $fs = get_file_storage();
     if (!$file || !$file->get_referencefileid()) {
         return false;
     }
     if (array_key_exists($file->get_id(), $synchronized)) {
         return $synchronized[$file->get_id()];
     }
     // remember that we already cached in current request to prevent from querying again
     $synchronized[$file->get_id()] = false;
     if (!($reference = $DB->get_record('files_reference', array('id' => $file->get_referencefileid())))) {
         return false;
     }
     if (!empty($reference->lastsync) and $reference->lastsync + $reference->lifetime > time()) {
         $synchronized[$file->get_id()] = true;
         return true;
     }
     if (!($repository = self::get_repository_by_id($reference->repositoryid, SYSCONTEXTID))) {
         return false;
     }
     if (!$repository->sync_individual_file($file)) {
         return false;
     }
     $lifetime = $repository->get_reference_file_lifetime($reference);
     $fileinfo = $repository->get_file_by_reference($reference);
     if ($fileinfo === null) {
         // does not exist any more - set status to missing
         $file->set_missingsource($lifetime);
         $synchronized[$file->get_id()] = true;
         return true;
     }
     $contenthash = null;
     $filesize = null;
     if (!empty($fileinfo->filesize)) {
         // filesize returned
         if (!empty($fileinfo->contenthash) && $fs->content_exists($fileinfo->contenthash)) {
             // contenthash is specified and valid
             $contenthash = $fileinfo->contenthash;
         } else {
             if ($fileinfo->filesize == $file->get_filesize()) {
                 // we don't know the new contenthash but the filesize did not change,
                 // assume the contenthash did not change either
                 $contenthash = $file->get_contenthash();
             } else {
                 // we can't save empty contenthash so generate contenthash from empty string
                 $fs->add_string_to_pool('');
                 $contenthash = sha1('');
             }
         }
         $filesize = $fileinfo->filesize;
     } else {
         if (!empty($fileinfo->filepath)) {
             // File path returned
             list($contenthash, $filesize, $newfile) = $fs->add_file_to_pool($fileinfo->filepath);
         } else {
             if (!empty($fileinfo->handle) && is_resource($fileinfo->handle)) {
                 // File handle returned
                 $contents = '';
                 while (!feof($fileinfo->handle)) {
                     $contents .= fread($handle, 8192);
                 }
                 fclose($fileinfo->handle);
                 list($contenthash, $filesize, $newfile) = $fs->add_string_to_pool($content);
             } else {
                 if (isset($fileinfo->content)) {
                     // File content returned
                     list($contenthash, $filesize, $newfile) = $fs->add_string_to_pool($fileinfo->content);
                 }
             }
         }
     }
     if (!isset($contenthash) or !isset($filesize)) {
         return false;
     }
     // update files table
     $file->set_synchronized($contenthash, $filesize, 0, $lifetime);
     $synchronized[$file->get_id()] = true;
     return true;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:93,代码来源:lib.php


示例20: resource_print_workaround

/**
 * Print resource info and workaround link when JS not available.
 * @param object $resource
 * @param object $cm
 * @param object $course
 * @param stored_file $file main file
 * @return does not return
 */
function resource_print_workaround($resource, $cm, $course, $file)
{
    global $CFG, $OUTPUT;
    resource_print_header($resource, $cm, $course);
    resource_print_heading($resource, $cm, $course, true);
    resource_print_intro($resource, $cm, $course, true);
    $resource->mainfile = $file->get_filename();
    echo '<div class="resourceworkaround">';
    switch (resource_get_final_display_type($resource)) {
        case RESOURCELIB_DISPLAY_POPUP:
            $path = '/' . $file->get_contextid() . '/mod_resource/content/' . $resource->revision . $file->get_filepath() . $file->get_filename();
            $fullurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', $path, false);
            $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions);
            $width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
            $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
            $wh = "width={$width},height={$height},toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
            $extra = "onclick=\"window.open('{$fullurl}', '', '{$wh}'); return false;\"";
            echo resource_get_clicktoopen($file, $resource->revision, $extra);
            break;
        case RESOURCELIB_DISPLAY_NEW:
            $extra = 'onclick="this.target=\'_blank\'"';
            echo resource_get_clicktoopen($file, $resource->revision, $extra);
            break;
        case RESOURCELIB_DISPLAY_DOWNLOAD:
            echo resource_get_clicktodownload($file, $resource->revision);
            break;
        case RESOURCELIB_DISPLAY_OPEN:
        default:
            echo resource_get_clicktoopen($file, $resource->revision);
            break;
    }
    echo '</div>';
    echo $OUTPUT->footer();
    die;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:43,代码来源:locallib.php



注:本文中的stored_file类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP str类代码示例发布时间:2022-05-23
下一篇:
PHP storage类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap