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

PHP get_file_packer函数代码示例

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

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



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

示例1: lightboxgallery_add_images

function lightboxgallery_add_images($stored_file, $context, $cm, $gallery, $resize = 0)
{
    require_once dirname(__FILE__) . '/imageclass.php';
    $fs = get_file_storage();
    $images = array();
    if ($stored_file->get_mimetype() == 'application/zip') {
        // Unpack.
        $packer = get_file_packer('application/zip');
        $fs->delete_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
        $stored_file->extract_to_storage($packer, $context->id, 'mod_lightboxgallery', 'unpacktemp', 0, '/');
        $images = $fs->get_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
        $stored_file->delete();
    } else {
        $images[] = $stored_file;
    }
    foreach ($images as $stored_file) {
        if ($stored_file->is_valid_image()) {
            $filename = $stored_file->get_filename();
            $fileinfo = array('contextid' => $context->id, 'component' => 'mod_lightboxgallery', 'filearea' => 'gallery_images', 'itemid' => 0, 'filepath' => '/', 'filename' => $filename);
            if (!$fs->get_file($context->id, 'mod_lightboxgallery', 'gallery_images', 0, '/', $filename)) {
                $stored_file = $fs->create_file_from_storedfile($fileinfo, $stored_file);
                $image = new lightboxgallery_image($stored_file, $gallery, $cm);
                if ($resize > 0) {
                    $resizeoptions = lightboxgallery_resize_options();
                    list($width, $height) = explode('x', $resizeoptions[$resize]);
                    $image->resize_image($width, $height);
                }
                $image->set_caption($filename);
            }
        }
    }
    $fs->delete_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
}
开发者ID:ndunand,项目名称:moodle-mod_lightboxgallery,代码行数:33,代码来源:locallib.php


示例2: process_attachments

 static function process_attachments($context, $email, $table, $id)
 {
     global $CFG, $USER;
     $base_path = "block_quickmail/{$USER->id}";
     $moodle_base = "{$CFG->tempdir}/{$base_path}";
     if (!file_exists($moodle_base)) {
         mkdir($moodle_base, $CFG->directorypermissions, true);
     }
     $zipname = $zip = $actual_zip = '';
     if (!empty($email->attachment)) {
         $zipname = "attachment.zip";
         $actual_zip = "{$moodle_base}/{$zipname}";
         $safe_path = preg_replace('/\\//', "\\/", $CFG->dataroot);
         $zip = preg_replace("/{$safe_path}\\//", '', $actual_zip);
         $packer = get_file_packer();
         $fs = get_file_storage();
         $files = $fs->get_area_files($context->id, 'block_quickmail', 'attachment_' . $table, $id, 'id');
         $stored_files = array();
         foreach ($files as $file) {
             if ($file->is_directory() and $file->get_filename() == '.') {
                 continue;
             }
             $stored_files[$file->get_filepath() . $file->get_filename()] = $file;
         }
         $packer->archive_to_pathname($stored_files, $actual_zip);
     }
     return array($zipname, $zip, $actual_zip);
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:28,代码来源:lib.php


示例3: booktool_exportimscp_build_package

/**
 * Export one book as IMSCP package
 *
 * @param stdClass $book book instance
 * @param context_module $context
 * @return bool|stored_file
 */
function booktool_exportimscp_build_package($book, $context)
{
    global $DB;
    $fs = get_file_storage();
    if ($packagefile = $fs->get_file($context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip')) {
        return $packagefile;
    }
    // fix structure and test if chapters present
    if (!book_preload_chapters($book)) {
        print_error('nochapters', 'booktool_exportimscp');
    }
    // prepare temp area with package contents
    booktool_exportimscp_prepare_files($book, $context);
    $packer = get_file_packer('application/zip');
    $areafiles = $fs->get_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision, "sortorder, itemid, filepath, filename", false);
    $files = array();
    foreach ($areafiles as $file) {
        $path = $file->get_filepath() . $file->get_filename();
        $path = ltrim($path, '/');
        $files[$path] = $file;
    }
    unset($areafiles);
    $packagefile = $packer->archive_to_storage($files, $context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip');
    // drop temp area
    $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision);
    // delete older versions
    $sql = "SELECT DISTINCT itemid\n              FROM {files}\n             WHERE contextid = :contextid AND component = 'booktool_exportimscp' AND itemid < :revision";
    $params = array('contextid' => $context->id, 'revision' => $book->revision);
    $revisions = $DB->get_records_sql($sql, $params);
    foreach ($revisions as $rev => $unused) {
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $rev);
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'package', $rev);
    }
    return $packagefile;
}
开发者ID:evltuma,项目名称:moodle,代码行数:42,代码来源:locallib.php


示例4: backup_course

 /**
  * Backup a course and return its backup ID.
  *
  * @param int $courseid The course ID.
  * @param int $userid The user doing the backup.
  * @return string
  */
 protected function backup_course($courseid, $userid = 2)
 {
     global $CFG;
     $packer = get_file_packer('application/vnd.moodle.backup');
     $bc = new backup_controller(backup::TYPE_1COURSE, $courseid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
     $bc->execute_plan();
     $results = $bc->get_results();
     $results['backup_destination']->extract_to_pathname($packer, "{$CFG->tempdir}/backup/core_course_testcase");
     $bc->destroy();
     unset($bc);
     return 'core_course_testcase';
 }
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:restore_test.php


示例5: test_archive_with_both_options

 public function test_archive_with_both_options()
 {
     global $CFG;
     $this->resetAfterTest();
     // Get backup packer.
     $packer = get_file_packer('application/vnd.moodle.backup');
     require_once $CFG->dirroot . '/lib/filestorage/tgz_packer.php';
     if (!tgz_packer::has_required_extension()) {
         $this->markTestSkipped('zlib not available');
         return;
     }
     // Set up basic archive contents.
     $files = array('1.txt' => array('frog'));
     // Create 2 archives (each with one file in) in default mode.
     $CFG->enabletgzbackups = false;
     $filefalse = $CFG->tempdir . '/false.mbz';
     $this->assertNotEmpty($packer->archive_to_pathname($files, $filefalse));
     $context = context_system::instance();
     $this->assertNotEmpty($storagefalse = $packer->archive_to_storage($files, $context->id, 'phpunit', 'data', 0, '/', 'false.mbz'));
     // Create 2 archives in tgz mode.
     $CFG->enabletgzbackups = true;
     $filetrue = $CFG->tempdir . '/true.mbz';
     $this->assertNotEmpty($packer->archive_to_pathname($files, $filetrue));
     $context = context_system::instance();
     $this->assertNotEmpty($storagetrue = $packer->archive_to_storage($files, $context->id, 'phpunit', 'data', 0, '/', 'false.mbz'));
     // Check the sizes are different (indicating different formats).
     $this->assertNotEquals(filesize($filefalse), filesize($filetrue));
     $this->assertNotEquals($storagefalse->get_filesize(), $storagetrue->get_filesize());
     // Extract files into storage and into filesystem from both formats.
     // (Note: the setting does not matter, but set to false just to check.)
     $CFG->enabletgzbackups = false;
     // Extract to path (zip).
     $packer->extract_to_pathname($filefalse, $CFG->tempdir);
     $onefile = $CFG->tempdir . '/1.txt';
     $this->assertEquals('frog', file_get_contents($onefile));
     unlink($onefile);
     // Extract to path (tgz).
     $packer->extract_to_pathname($filetrue, $CFG->tempdir);
     $onefile = $CFG->tempdir . '/1.txt';
     $this->assertEquals('frog', file_get_contents($onefile));
     unlink($onefile);
     // Extract to storage (zip).
     $packer->extract_to_storage($storagefalse, $context->id, 'phpunit', 'data', 1, '/');
     $fs = get_file_storage();
     $out = $fs->get_file($context->id, 'phpunit', 'data', 1, '/', '1.txt');
     $this->assertNotEmpty($out);
     $this->assertEquals('frog', $out->get_content());
     // Extract to storage (tgz).
     $packer->extract_to_storage($storagetrue, $context->id, 'phpunit', 'data', 2, '/');
     $out = $fs->get_file($context->id, 'phpunit', 'data', 2, '/', '1.txt');
     $this->assertNotEmpty($out);
     $this->assertEquals('frog', $out->get_content());
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:53,代码来源:mbz_packer_test.php


示例6: zip_attachments

 static function zip_attachments($context, $table, $id)
 {
     global $CFG, $USER;
     $base_path = "block_quickmail/{$USER->id}";
     $moodle_base = "{$CFG->tempdir}/{$base_path}";
     if (!file_exists($moodle_base)) {
         mkdir($moodle_base, $CFG->directorypermissions, true);
     }
     $zipname = "attachment.zip";
     $actual_zip = "{$moodle_base}/{$zipname}";
     $fs = get_file_storage();
     $packer = get_file_packer();
     $files = $fs->get_area_files($context->id, 'block_quickmail', 'attachment_' . $table, $id, 'id');
     $stored_files = array();
     foreach ($files as $file) {
         if ($file->is_directory() and $file->get_filename() == '.') {
             continue;
         }
         $stored_files[$file->get_filepath() . $file->get_filename()] = $file;
     }
     $packer->archive_to_pathname($stored_files, $actual_zip);
     return $actual_zip;
 }
开发者ID:nadavkav,项目名称:quickmail,代码行数:23,代码来源:lib.php


示例7: test_course_restored_event

 /**
  * Test that triggering a course_restored event works as expected.
  */
 public function test_course_restored_event()
 {
     global $CFG;
     // Get the necessary files to perform backup and restore.
     require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
     require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
     $this->resetAfterTest();
     // Set to admin user.
     $this->setAdminUser();
     // The user id is going to be 2 since we are the admin user.
     $userid = 2;
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Create backup file and save it to the backup location.
     $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
     $bc->execute_plan();
     $results = $bc->get_results();
     $file = $results['backup_destination'];
     $fp = get_file_packer('application/vnd.moodle.backup');
     $filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
     $file->extract_to_pathname($fp, $filepath);
     $bc->destroy();
     unset($bc);
     // Now we want to catch the restore course event.
     $sink = $this->redirectEvents();
     // Now restore the course to trigger the event.
     $rc = new restore_controller('test-restore-course-event', $course->id, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid, backup::TARGET_NEW_COURSE);
     $rc->execute_precheck();
     $rc->execute_plan();
     // Capture the event.
     $events = $sink->get_events();
     $sink->close();
     // Validate the event.
     $event = array_pop($events);
     $this->assertInstanceOf('\\core\\event\\course_restored', $event);
     $this->assertEquals('course', $event->objecttable);
     $this->assertEquals($rc->get_courseid(), $event->objectid);
     $this->assertEquals(context_course::instance($rc->get_courseid())->id, $event->contextid);
     $this->assertEquals('course_restored', $event->get_legacy_eventname());
     $legacydata = (object) array('courseid' => $rc->get_courseid(), 'userid' => $rc->get_userid(), 'type' => $rc->get_type(), 'target' => $rc->get_target(), 'mode' => $rc->get_mode(), 'operation' => $rc->get_operation(), 'samesite' => $rc->is_samesite());
     $url = new moodle_url('/course/view.php', array('id' => $event->objectid));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventLegacyData($legacydata, $event);
     $this->assertEventContextNotUsed($event);
     // Destroy the resource controller since we are done using it.
     $rc->destroy();
     unset($rc);
 }
开发者ID:uniedpa,项目名称:moodle,代码行数:51,代码来源:courselib_test.php


示例8: process_attachments

 /**
  * Process the attached file(s). If multiple files, create a zip file.
  */
 public static function process_attachments($context, $email, $table, $id)
 {
     global $CFG, $USER;
     $base_path = "block_clampmail/{$USER->id}";
     $moodle_base = "{$CFG->tempdir}/{$base_path}";
     if (!file_exists($moodle_base)) {
         mkdir($moodle_base, $CFG->directorypermissions, true);
     }
     $filename = $file = $actual_file = '';
     if (!empty($email->attachment)) {
         $fs = get_file_storage();
         $stored_files = array();
         $safe_path = preg_replace('/\\//', "\\/", $CFG->dataroot);
         $base_file_path = preg_replace("/{$safe_path}\\//", '', $moodle_base);
         $files = $fs->get_area_files($context->id, 'block_clampmail', 'attachment_' . $table, $id, 'id');
         // Cycle through files.
         foreach ($files as $item) {
             if ($item->is_directory() && $item->get_filename() == '.') {
                 continue;
             }
             $stored_files[$item->get_filepath() . $item->get_filename()] = $item;
         }
         // Create a zip archive if more than one file.
         if (count($stored_files) == 1) {
             $obj = current($stored_files);
             $filename = $obj->get_filename();
             $file = $base_file_path . '/' . $filename;
             $actual_file = $moodle_base . '/' . $filename;
             $obj->copy_content_to($actual_file);
         } else {
             $filename = 'attachment.zip';
             $file = $base_file_path . '/' . $filename;
             $actual_file = $moodle_base . '/' . $filename;
             $packer = get_file_packer();
             $packer->archive_to_pathname($stored_files, $actual_file);
         }
     }
     return array($filename, $file, $actual_file);
 }
开发者ID:jasonalley,项目名称:clampmail,代码行数:42,代码来源:lib.php


示例9: define_execution

 protected function define_execution()
 {
     // Get basepath
     $basepath = $this->get_basepath();
     // Get the list of files in directory
     $filestemp = get_directory_list($basepath, '', false, true, true);
     $files = array();
     foreach ($filestemp as $file) {
         // Add zip paths and fs paths to all them
         $files[$file] = $basepath . '/' . $file;
     }
     // Calculate the zip fullpath (in OS temp area it's always backup.mbz)
     $zipfile = $basepath . '/backup.imscc';
     // Get the zip packer
     $zippacker = get_file_packer('application/zip');
     // Zip files
     $zippacker->archive_to_pathname($files, $zipfile);
 }
开发者ID:nickread,项目名称:moodle,代码行数:18,代码来源:backuplib.php


示例10: validation

 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $type = $data['scormtype'];
     if ($type === SCORM_TYPE_LOCAL) {
         if (!empty($data['update'])) {
             //ok, not required
         } else {
             if (empty($files['packagefile'])) {
                 $errors['packagefile'] = get_string('required');
             } else {
                 $packer = get_file_packer('application/zip');
                 $filelist = $packer->list_files($files['packagefile']);
                 if (!is_array($filelist)) {
                     $errors['packagefile'] = 'Incorrect file package - not an archive';
                     //TODO: localise
                 } else {
                     $manifestpresent = false;
                     $aiccfound = false;
                     foreach ($filelist as $info) {
                         if ($info->pathname == 'imsmanifest.xml') {
                             $manifestpresent = true;
                             break;
                         }
                         if (preg_match('/\\.cst$/', $info->pathname)) {
                             $aiccfound = true;
                             break;
                         }
                     }
                     if (!$manifestpresent and !$aiccfound) {
                         $errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure';
                         //TODO: localise
                     }
                 }
             }
         }
     } else {
         if ($type === SCORM_TYPE_EXTERNAL) {
             $reference = $data['packageurl'];
             if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*\\/imsmanifest.xml$/i', $reference)) {
                 $errors['packageurl'] = get_string('required');
                 // TODO: improve help
             }
         } else {
             if ($type === 'packageurl') {
                 $reference = $data['reference'];
                 if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*(\\.zip|\\.pif)$/i', $reference)) {
                     $errors['packageurl'] = get_string('required');
                     // TODO: improve help
                 }
             } else {
                 if ($type === SCORM_TYPE_IMSREPOSITORY) {
                     $reference = $data['packageurl'];
                     if (stripos($reference, '#') !== 0) {
                         $errors['packageurl'] = get_string('required');
                     }
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:62,代码来源:mod_form.php


示例11: define_execution

 protected function define_execution()
 {
     // Get basepath
     $basepath = $this->get_basepath();
     // Get the list of files in directory
     $filestemp = get_directory_list($basepath, '', false, true, true);
     $files = array();
     foreach ($filestemp as $file) {
         // Add zip paths and fs paths to all them
         $files[$file] = $basepath . '/' . $file;
     }
     // Add the log file if exists
     $logfilepath = $basepath . '.log';
     if (file_exists($logfilepath)) {
         $files['moodle_backup.log'] = $logfilepath;
     }
     // Calculate the zip fullpath (in OS temp area it's always backup.mbz)
     $zipfile = $basepath . '/backup.mbz';
     // Get the zip packer
     $zippacker = get_file_packer('application/vnd.moodle.backup');
     // Track overall progress for the 2 long-running steps (archive to
     // pathname, get backup information).
     $reporter = $this->task->get_progress();
     $reporter->start_progress('backup_zip_contents', 2);
     // Zip files
     $result = $zippacker->archive_to_pathname($files, $zipfile, true, $this);
     // If any sub-progress happened, end it.
     if ($this->startedprogress) {
         $this->task->get_progress()->end_progress();
         $this->startedprogress = false;
     } else {
         // No progress was reported, manually move it on to the next overall task.
         $reporter->progress(1);
     }
     // Something went wrong.
     if ($result === false) {
         @unlink($zipfile);
         throw new backup_step_exception('error_zip_packing', '', 'An error was encountered while trying to generate backup zip');
     }
     // Read to make sure it is a valid backup. Refer MDL-37877 . Delete it, if found not to be valid.
     try {
         backup_general_helper::get_backup_information_from_mbz($zipfile, $this);
     } catch (backup_helper_exception $e) {
         @unlink($zipfile);
         throw new backup_step_exception('error_zip_packing', '', $e->debuginfo);
     }
     // If any sub-progress happened, end it.
     if ($this->startedprogress) {
         $this->task->get_progress()->end_progress();
         $this->startedprogress = false;
     } else {
         $reporter->progress(2);
     }
     $reporter->end_progress();
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:55,代码来源:backup_stepslib.php


示例12: lesson_importppt_form

$data = new stdClass;
$data->id = $cm->id;
$data->pageid = $pageid;
$mform = new lesson_importppt_form();
$mform->set_data($data);

if ($data = $mform->get_data()) {
    $manager = lesson_page_type_manager::get($lesson);
    if (!$filename = $mform->get_new_filename('pptzip')) {
        print_error('invalidfile', 'lesson');
    }
    if (!$package = $mform->save_stored_file('pptzip', $context->id, 'mod_lesson', 'ppt_imports', $lesson->id, '/', $filename, true)) {
        print_error('unabletosavefile', 'lesson');
    }
    // extract package content
    $packer = get_file_packer('application/zip');
    $package->extract_to_storage($packer, $context->id, 'mod_lesson', 'imported_files', $lesson->id, '/');

    $fs = get_file_storage();
    if ($files = $fs->get_area_files($context->id, 'mod_lesson', 'imported_files', $lesson->id)) {

        $pages = array();
        foreach ($files as $key=>$file) {
            if ($file->get_mimetype() != 'text/html') {
                continue;
            }
            $filenameinfo = pathinfo($file->get_filepath().$file->get_filename());

            $page = new stdClass;
            $page->title = '';
            $page->contents = array();
开发者ID:JP-Git,项目名称:moodle,代码行数:31,代码来源:importppt.php


示例13: report_ncccscensus_generate_bulk_zip

/**
 * Generates list of zip files in array.
 *
 * @param int $batch id of batch
 * @return array|bool False on no files to add to zip, array on success
 * @uses $CFG, $DB
 */
function report_ncccscensus_generate_bulk_zip($batch)
{
    global $DB, $USER;
    // Check if last report.
    $left = $DB->count_records('report_ncccscensus', array('batchid' => $batch, 'status' => 0));
    if ($left !== 0) {
        return false;
    }
    $files = report_ncccscensus_get_zip_files($batch);
    if (!is_array($files)) {
        return false;
    }
    $date = usergetdate(time(), get_user_timezone());
    $filename = date('MdY_Hi', mktime($date['hours'], $date['minutes'], 0, $date['mon'], $date['mday'], $date['year']));
    $filename = $filename . '-' . $batch . '.zip';
    $fs = get_file_storage();
    // Check to see if file exists.
    $contextid = context_system::instance()->id;
    $file = $fs->get_file($contextid, 'report_ncccscensus', 'archive', $batch, '/report_ncccscensus/', $filename);
    if (!$file) {
        // Prepare file record object.
        $fileinfo = array('contextid' => context_system::instance()->id, 'component' => 'report_ncccscensus', 'filearea' => 'archive', 'itemid' => $batch, 'filepath' => '/report_ncccscensus/', 'filename' => $filename);
        $file = $fs->create_file_from_string($fileinfo, '');
    }
    $parentpath = $file->get_parent_directory()->get_filepath();
    $filepath = explode('/', trim($file->get_filepath(), '/'));
    $filepath = array_pop($filepath);
    // Generate zip.
    $zipper = get_file_packer('application/zip');
    $record = $DB->get_record('report_ncccscensus_batch', array('id' => $batch));
    $contextid = context_system::instance()->id;
    $path = 'report_ncccscensus';
    $newfile = $zipper->archive_to_storage($files, $contextid, $path, 'archive', $batch, $parentpath, $filename, $USER->id);
    if ($newfile) {
        // Mark batch as complete.
        $record->zipfile = $filename;
    }
    $record->status = 1;
    $DB->update_record('report_ncccscensus_batch', $record);
    $info = array();
    // Delete pdf files.
    foreach ($files as $filename => $fullfilename) {
        @unlink($fullfilename);
        $info = pathinfo($fullfilename);
    }
    if (!empty($info['dirname'])) {
        @rmdir($info['dirname']);
    }
}
开发者ID:cbmegahan,项目名称:report_ncccscensus,代码行数:56,代码来源:lib.php


示例14: validation

    function validation($data, $files) {
        global $CFG;
        $errors = parent::validation($data, $files);

        $type = $data['scormtype'];

        if ($type === SCORM_TYPE_LOCAL) {
            if (!empty($data['update'])) {
                //ok, not required

            } else if (empty($data['packagefile'])) {
                $errors['packagefile'] = get_string('required');

            } else {
                $files = $this->get_draft_files('packagefile');
                if (count($files)<1) {
                    $errors['packagefile'] = get_string('required');
                    return $errors;
                }
                $file = reset($files);
                $filename = $CFG->tempdir.'/scormimport/scrom_'.time();
                make_temp_directory('scormimport');
                $file->copy_content_to($filename);

                $packer = get_file_packer('application/zip');

                $filelist = $packer->list_files($filename);
                if (!is_array($filelist)) {
                    $errors['packagefile'] = 'Incorrect file package - not an archive'; //TODO: localise
                } else {
                    $manifestpresent = false;
                    $aiccfound       = false;
                    foreach ($filelist as $info) {
                        if ($info->pathname == 'imsmanifest.xml') {
                            $manifestpresent = true;
                            break;
                        }
                        if (preg_match('/\.cst$/', $info->pathname)) {
                            $aiccfound = true;
                            break;
                        }
                    }
                    if (!$manifestpresent and !$aiccfound) {
                        $errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure'; //TODO: localise
                    }
                }
                unlink($filename);
            }

        } else if ($type === SCORM_TYPE_EXTERNAL) {
            $reference = $data['packageurl'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        } else if ($type === 'packageurl') {
            $reference = $data['reference'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        } else if ($type === SCORM_TYPE_IMSREPOSITORY) {
            $reference = $data['packageurl'];
            if (stripos($reference, '#') !== 0) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            }

        } else if ($type === SCORM_TYPE_AICCURL) {
            $reference = $data['packageurl'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        }

        return $errors;
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:98,代码来源:mod_form.php


示例15: extract_file_to_dir

 protected function extract_file_to_dir()
 {
     global $CFG, $USER;
     $this->filepath = restore_controller::get_tempdir_name($this->contextid, $USER->id);
     $fb = get_file_packer();
     return $fb->extract_to_pathname("{$CFG->tempdir}/backup/" . $this->filename, "{$CFG->tempdir}/backup/{$this->filepath}/");
 }
开发者ID:raymondAntonio,项目名称:moodle,代码行数:7,代码来源:restore_ui_stage.class.php


示例16: get_packer_for_read_operation

 /**
  * Selects appropriate packer for existing archive depending on file contents.
  *
  * @param string|stored_file $archivefile full pathname of zip file or stored_file instance
  * @return file_packer Suitable packer
  */
 protected function get_packer_for_read_operation($archivefile)
 {
     global $CFG;
     require_once $CFG->dirroot . '/lib/filestorage/tgz_packer.php';
     if (tgz_packer::is_tgz_file($archivefile)) {
         return get_file_packer('application/x-gzip');
     } else {
         return get_file_packer('application/zip');
     }
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:16,代码来源:mbz_packer.php


示例17: scorm_validate_package

/**
 * Check that a Zip file contains a valid SCORM package
 *
 * @param $file stored_file a Zip file.
 * @return array empty if no issue is found. Array of error message otherwise
 */
function scorm_validate_package($file) {
    $packer = get_file_packer('application/zip');
    $errors = array();
    if ($file->is_external_file()) { // Get zip file so we can check it is correct.
        $file->import_external_file_contents();
    }
    $filelist = $file->list_files($packer);

    if (!is_array($filelist)) {
        $errors['packagefile'] = get_string('badarchive', 'scorm');
    } else {
        $aiccfound = false;
        $badmanifestpresent = false;
        foreach ($filelist as $info) {
            if ($info->pathname == 'imsmanifest.xml') {
                return array();
            } else if (strpos($info->pathname, 'imsmanifest.xml') !== false) {
                // This package has an imsmanifest file inside a folder of the package.
                $badmanifestpresent = true;
            }
            if (preg_match('/\.cst$/', $info->pathname)) {
                return array();
            }
        }
        if (!$aiccfound) {
            if ($badmanifestpresent) {
                $errors['packagefile'] = get_string('badimsmanifestlocation', 'scorm');
            } else {
                $errors['packagefile'] = get_string('nomanifest', 'scorm');
            }
        }
    }
    return $errors;
}
开发者ID:ruddj,项目名称:moodle,代码行数:40,代码来源:lib.php


示例18: execute

 public function execute()
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . "/backup/util/includes/backup_includes.php";
     require_once $CFG->dirroot . "/backup/util/includes/restore_includes.php";
     $arguments = $this->arguments;
     $options = $this->expandedOptions;
     if (empty($CFG->tempdir)) {
         $CFG->tempdir = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
     }
     // Check if category is OK.
     if (!$options['existing']) {
         $category = $DB->get_record('course_categories', array('id' => $this->arguments[1]), '*', MUST_EXIST);
     } else {
         $course = $DB->get_record('course', array('id' => $this->arguments[1]), '*', MUST_EXIST);
         $category = $DB->get_record('course_categories', array('id' => $course->category), '*', MUST_EXIST);
     }
     if (!$options['directory']) {
         if ($arguments[0][0] != '/') {
             $arguments[0] = $this->cwd . DIRECTORY_SEPARATOR . $arguments[0];
         }
         if (!file_exists($arguments[0])) {
             cli_error("Backup file '" . $arguments[0] . "' does not exist.");
         }
         if (!is_readable($arguments[0])) {
             cli_error("Backup file '" . $arguments[0] . "' is not readable.");
         }
     } else {
         $path = $CFG->tempdir . DIRECTORY_SEPARATOR . "backup" . DIRECTORY_SEPARATOR . $arguments[0];
         if (!file_exists($path) || !is_dir($path) || !is_readable($path)) {
             cli_error("Directory '{$path}' does not exist, not a directory or not readable.");
         }
     }
     if (!$options['directory']) {
         //unzip into $CFG->tempdir / "backup" / "auto_restore_" . $split[1];
         $backupdir = "moosh_restore_" . uniqid();
         $path = $CFG->tempdir . DIRECTORY_SEPARATOR . "backup" . DIRECTORY_SEPARATOR . $backupdir;
         if ($this->verbose) {
             echo "Extracting Moode backup file to: '" . $path . "'\n";
         }
         /** @var $fp file_packer */
         $fp = get_file_packer('application/vnd.moodle.backup');
         $fp->extract_to_pathname($arguments[0], $path);
     } else {
         $backupdir = $arguments[0];
     }
     //extract original full & short names
     $xmlfile = $path . DIRECTORY_SEPARATOR . "course" . DIRECTORY_SEPARATOR . "course.xml";
     // Different XML file in Moodle 1.9 backup
     if (!file_exists($xmlfile)) {
         $xmlfile = $path . DIRECTORY_SEPARATOR . "moodle.xml";
     }
     $xml = simplexml_load_file($xmlfile);
     $fullname = $xml->xpath('/course/fullname');
     if (!$fullname) {
         $fullname = $xml->xpath('/MOODLE_BACKUP/COURSE/HEADER/FULLNAME');
     }
     $shortname = $xml->xpath('/course/shortname');
     if (!$shortname) {
         $shortname = $xml->xpath('/MOODLE_BACKUP/COURSE/HEADER/SHORTNAME');
     }
     $fullname = (string) $fullname[0];
     $shortname = (string) $shortname[0];
     if (!$shortname) {
         cli_error('No shortname in the backup file.');
     }
     if (!$fullname) {
         $fullname = $shortname;
     }
     // Get unique shortname if creating new course.
     if (!$options['existing'] && $DB->get_record('course', array('category' => $category->id, 'shortname' => $shortname))) {
         $matches = NULL;
         preg_match('/(.*)_(\\d+)$/', $shortname, $matches);
         if ($matches) {
             $base = $matches[1];
             $number = $matches[2];
         } else {
             $base = $shortname;
             $number = 1;
         }
         $shortname = $base . '_' . $number;
         while ($DB->get_record('course', array('category' => $category->id, 'shortname' => $shortname))) {
             $number++;
             $shortname = $base . '_' . $number;
         }
     }
     if ($options['existing']) {
         $courseid = $arguments[1];
         $rc = new restore_controller($backupdir, $courseid, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, backup::TARGET_CURRENT_ADDING);
     } else {
         $courseid = restore_dbops::create_new_course($fullname, $shortname, $category->id);
         $rc = new restore_controller($backupdir, $courseid, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, backup::TARGET_NEW_COURSE);
     }
     echo "Restoring (new course id,shortname,destination category): {$courseid},{$shortname}," . $category->id . "\n";
     if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
         $rc->convert();
     }
     $plan = $rc->get_plan();
     $tasks = $plan->get_tasks();
     foreach ($tasks as &$task) {
//.........这里部分代码省略.........
开发者ID:dariogs,项目名称:moosh,代码行数:101,代码来源:CourseRestore.php


示例19: test_file_progress

 /**
  * Tests the progress reporting.
  */
 public function test_file_progress()
 {
     global $CFG;
     // Set up.
     $this->resetAfterTest(true);
     $packer = get_file_packer('application/zip');
     $archive = "{$CFG->tempdir}/archive.zip";
     $context = context_system::instance();
     // Archive to pathname.
     $this->progress = array();
     $result = $packer->archive_to_pathname($this->files, $archive, true, $this);
     $this->assertTrue($result);
     // Should send progress at least once per file.
     $this->assertTrue(count($this->progress) >= count($this->files));
     // Each progress will be indeterminate.
     $this->assertEquals(array(file_progress::INDETERMINATE, file_progress::INDETERMINATE), $this->progress[0]);
     // Archive to pathname using entire folder and subfolder instead of file list.
     unlink($archive);
     $folder = make_temp_directory('zip_packer_progress');
     file_put_contents($folder . '/test1.txt', 'hello');
     $subfolder = $folder . '/sub';
     check_dir_exists($subfolder);
     file_put_contents($subfolder . '/test2.txt', 'world');
     file_put_contents($subfolder . '/test3.txt', 'and');
     file_put_contents($subfolder . '/test4.txt', 'other');
     file_put_contents($subfolder . '/test5.txt', 'worlds');
     $this->progress = array();
     $result = $packer->archive_to_pathname(array('' => $folder), $archive, true, $this);
     $this->assertTrue($result);
     // Should send progress at least once per file.
     $this->assertTrue(count($this->progress) >= 5);
     // Archive to storage.
     $this->progress = array();
     $archivefile = $packer->archive_to_storage($this->files, $context->id, 'phpunit', 'test', 0, '/', 'archive.zip', null, true, $this);
     $this->assertInstanceOf('stored_file', $archivefile);
     $this->assertTrue(count($this->progress) >= count($this->files));
     $this->assertEquals(array(file_progress::INDETERMINATE, file_progress::INDETERMINATE), $this->progress[0]);
     // Extract to pathname.
     $this->progress = array();
     $target = "{$CFG->tempdir}/test/";
     check_dir_exists($target);
     $result = $packer->extract_to_pathname($archive, $target, null, $this);
     remove_dir($target);
     $this->assertEquals(count($this->files), count($result));
     $this->assertTrue(count($this->progress) >= count($this->files));
     $this->check_progress_toward_max();
     // Extract to storage (from storage).
     $this->progress = array();
     $result = $packer->extract_to_storage($archivefile, $context->id, 'phpunit', 'target', 0, '/', null, $this);
     $this->assertEquals(count($this->files), count($result));
     $this->assertTrue(count($this->progress) >= count($this->files));
     $this->check_progress_toward_max();
     // Extract to storage (from path).
     $this->progress = array();
     $result = $packer->extract_to_storage($archive, $context->id, 'phpunit', 'target', 0, '/', null, $this);
     $this->assertEquals(count($this->files), count($result));
     $this->assertTrue(count($this->progress) >= count($this->files));
     $this->check_progress_toward_max();
     // Wipe created 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP get_file_path函数代码示例发布时间:2022-05-15
下一篇:
PHP get_file_name函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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