当前位置: 首页>>代码示例>>PHP>>正文


PHP resourcelib_try_file_migration函数代码示例

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


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

示例1: resource_pluginfile

/**
 * Serves the resource files.
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
    global $CFG, $DB;
    require_once("$CFG->libdir/resourcelib.php");

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_course_login($course, true, $cm);
    if (!has_capability('mod/resource:view', $context)) {
        return false;
    }

    if ($filearea !== 'content') {
        // intro is handled automatically in pluginfile.php
        return false;
    }

    array_shift($args); // ignore revision - designed to prevent caching problems only

    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = rtrim("/$context->id/mod_resource/$filearea/0/$relativepath", '/');
    do {
        if (!$file = $fs->get_file_by_hash(sha1($fullpath))) {
            if ($fs->get_file_by_hash(sha1("$fullpath/."))) {
                if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.htm"))) {
                    break;
                }
                if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.html"))) {
                    break;
                }
                if ($file = $fs->get_file_by_hash(sha1("$fullpath/Default.htm"))) {
                    break;
                }
            }
            $resource = $DB->get_record('resource', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST);
            if ($resource->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
                return false;
            }
            if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_resource', 'content', 0)) {
                return false;
            }
            // file migrate - update flag
            $resource->legacyfileslast = time();
            $DB->update_record('resource', $resource);
        }
    } while (false);

    // should we apply filters?
    $mimetype = $file->get_mimetype();
    if ($mimetype === 'text/html' or $mimetype === 'text/plain') {
        $filter = $DB->get_field('resource', 'filterfiles', array('id'=>$cm->instance));
        $CFG->embeddedsoforcelinktarget = true;
    } else {
        $filter = 0;
    }

    // finally send the file
    send_stored_file($file, 86400, $filter, $forcedownload);
}
开发者ID:nfreear,项目名称:moodle,代码行数:71,代码来源:lib.php

示例2: resource_20_migrate

/**
 * Migrate resource module data from 1.9 resource_old table to new resource table
 * @return void
 */
function resource_20_migrate()
{
    global $CFG, $DB;
    require_once "{$CFG->libdir}/filelib.php";
    require_once "{$CFG->libdir}/resourcelib.php";
    require_once "{$CFG->dirroot}/course/lib.php";
    $fs = get_file_storage();
    $withrelativelinks = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/x-shockwave-flash');
    // note: pdf doc and other types may contain links too, but we do not support relative links there
    $candidates = $DB->get_recordset('resource_old', array('type' => 'file', 'migrated' => 0));
    if (!$candidates->valid()) {
        $candidates->close();
        // Not going to iterate (but exit), close rs
        return;
    }
    foreach ($candidates as $candidate) {
        upgrade_set_timeout();
        $path = $candidate->reference;
        $siteid = get_site()->id;
        $fs = get_file_storage();
        if (empty($candidate->cmid)) {
            // skip borked records
            continue;
        } else {
            if (strpos($path, 'LOCALPATH') === 0) {
                // ignore not maintained local files - sorry
                continue;
            } else {
                if (preg_match("|{$CFG->wwwroot}/file.php(\\?file=)?/{$siteid}(/[^\\s'\"&\\?#]+)|", $path, $matches)) {
                    // public site files
                    $path = $matches[2];
                    $resource = new stdClass();
                    $resource->id = $candidate->oldid;
                    $resource->tobemigrated = 0;
                    $resource->mainfile = $path;
                    $resource->filterfiles = $CFG->filteruploadedfiles;
                    $resource->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
                    // on-demand-migration not possible for site files, sorry
                    $context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
                    $sitecontext = get_context_instance(CONTEXT_COURSE, $siteid);
                    $file_record = array('contextid' => $context->id, 'component' => 'mod_resourse', 'filearea' => 'content', 'itemid' => 0);
                    if ($file = $fs->get_file_by_hash(sha1("/{$sitecontext->id}/course/legacy/content/0" . $path))) {
                        try {
                            $fs->create_file_from_storedfile($file_record, $file);
                        } catch (Exception $x) {
                        }
                        $resource->mainfile = $file->get_filepath() . $file->get_filename();
                    }
                } else {
                    if (preg_match("|{$CFG->wwwroot}/file.php(\\?file=)?/{$candidate->course}(/[^\\s'\"&\\?#]+)|", $path, $matches)) {
                        // current course files
                        $path = $matches[2];
                        $resource = new stdClass();
                        $resource->id = $candidate->oldid;
                        $resource->tobemigrated = 0;
                        $resource->mainfile = $path;
                        $resource->filterfiles = $CFG->filteruploadedfiles;
                        $mimetype = mimeinfo('type', $resource->mainfile);
                        if (in_array($mimetype, $withrelativelinks)) {
                            $resource->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
                        } else {
                            $resource->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
                        }
                        // try migration of main file - ignore if does not exist
                        if ($file = resourcelib_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'mod_resource', 'content', 0)) {
                            $resource->mainfile = $file->get_filepath() . $file->get_filename();
                        }
                    } else {
                        if (strpos($path, '://') or strpos($path, '/') === 0) {
                            // http:// https:// ftp:// OR starts with slash - to be converted to link resource
                            continue;
                        } else {
                            // current course files
                            // cleanup old path first
                            $path = '/' . trim(trim($path), '/');
                            if (strpos($path, '?forcedownload=1') !== false) {
                                // eliminate old force download tricks
                                $candidate->options = 'forcedownload';
                                $path = str_replace('?forcedownload=1', '', $path);
                            }
                            // get rid of any extra url parameters, sorry we can not support these
                            preg_match("/^[^?#]+/", $path, $matches);
                            $parts = $matches[0];
                            $resource = new stdClass();
                            $resource->id = $candidate->oldid;
                            $resource->tobemigrated = 0;
                            $resource->mainfile = $path;
                            $resource->filterfiles = $CFG->filteruploadedfiles;
                            $mimetype = mimeinfo('type', $resource->mainfile);
                            if (in_array($mimetype, $withrelativelinks)) {
                                $resource->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
                            } else {
                                $resource->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
                            }
                            // try migration of main file - ignore if does not exist
                            if ($file = resourcelib_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'mod_resource', 'content', 0)) {
//.........这里部分代码省略.........
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:101,代码来源:upgradelib.php

示例3: page_pluginfile

/**
 * Serves the page files.
 *
 * @package  mod_page
 * @category files
 * @param stdClass $course course object
 * @param stdClass $cm course module object
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool false if file not found, does not return if found - just send the file
 */
function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
    global $CFG, $DB;
    require_once("$CFG->libdir/resourcelib.php");

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_course_login($course, true, $cm);
    if (!has_capability('mod/page:view', $context)) {
        return false;
    }

    if ($filearea !== 'content') {
        // intro is handled automatically in pluginfile.php
        return false;
    }

    // $arg could be revision number or index.html
    $arg = array_shift($args);
    if ($arg == 'index.html' || $arg == 'index.htm') {
        // serve page content
        $filename = $arg;

        if (!$page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST)) {
            return false;
        }

        // remove @@PLUGINFILE@@/
        $content = str_replace('@@PLUGINFILE@@/', '', $page->content);

        $formatoptions = new stdClass;
        $formatoptions->noclean = true;
        $formatoptions->overflowdiv = true;
        $formatoptions->context = $context;
        $content = format_text($content, $page->contentformat, $formatoptions);

        send_file($content, $filename, 0, 0, true, true);
    } else {
        $fs = get_file_storage();
        $relativepath = implode('/', $args);
        $fullpath = "/$context->id/mod_page/$filearea/0/$relativepath";
        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
            $page = $DB->get_record('page', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST);
            if ($page->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
                return false;
            }
            if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_page', 'content', 0)) {
                return false;
            }
            //file migrate - update flag
            $page->legacyfileslast = time();
            $DB->update_record('page', $page);
        }

        // finally send the file
        send_stored_file($file, 86400, 0, $forcedownload, $options);
    }
}
开发者ID:JP-Git,项目名称:moodle,代码行数:73,代码来源:lib.php

示例4: page_pluginfile

/**
 * Serves the page files.
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
    global $CFG, $DB;
    require_once("$CFG->libdir/resourcelib.php");

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_course_login($course, true, $cm);
    if (!has_capability('mod/page:view', $context)) {
        return false;
    }

    if ($filearea !== 'content') {
        // intro is handled automatically in pluginfile.php
        return false;
    }

    array_shift($args); // ignore revision - designed to prevent caching problems only

    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/$context->id/mod_page/$filearea/0/$relativepath";
    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
        $page = $DB->get_record('page', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST);
        if ($page->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
            return false;
        }
        if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_page', 'content', 0)) {
            return false;
        }
        //file migrate - update flag
        $page->legacyfileslast = time();
        $DB->update_record('page', $page);
    }

    // finally send the file
    send_stored_file($file, 86400, 0, $forcedownload);
}
开发者ID:nottmoo,项目名称:moodle,代码行数:49,代码来源:lib.php


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