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


PHP tao_helpers_File::getMimeType方法代码示例

本文整理汇总了PHP中tao_helpers_File::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP tao_helpers_File::getMimeType方法的具体用法?PHP tao_helpers_File::getMimeType怎么用?PHP tao_helpers_File::getMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tao_helpers_File的用法示例。


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

示例1: outputFile

 public static function outputFile($relPath, $filename = null)
 {
     $fullpath = self::getExportPath() . DIRECTORY_SEPARATOR . $relPath;
     if (tao_helpers_File::securityCheck($fullpath, true) && file_exists($fullpath)) {
         Context::getInstance()->getResponse()->setContentHeader(tao_helpers_File::getMimeType($fullpath));
         $fileName = empty($filename) ? basename($fullpath) : $filename;
         header('Content-Disposition: attachment; fileName="' . $fileName . '"');
         header("Content-Length: " . filesize($fullpath));
         //Clean all levels of output buffering
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         flush();
         $fp = fopen($fullpath, "r");
         if ($fp !== false) {
             while (!feof($fp)) {
                 echo fread($fp, 65536);
                 flush();
             }
             fclose($fp);
             @unlink($fullpath);
         } else {
             common_Logger::e('Unable to open File to export' . $fullpath);
         }
     } else {
         common_Logger::e('Could not find File to export: ' . $fullpath);
     }
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:28,代码来源:class.Export.php

示例2: import

 /**
  * Import file entry point by using $this->service
  * Check POST method & get valid uploaded file
  */
 public function import()
 {
     $fileUploadName = "qtiPackage";
     if ($this->getRequestMethod() != Request::HTTP_POST) {
         throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.');
     }
     if (tao_helpers_Http::hasUploadedFile($fileUploadName)) {
         $file = tao_helpers_Http::getUploadedFile($fileUploadName);
         $mimeType = tao_helpers_File::getMimeType($file['tmp_name']);
         if (!in_array($mimeType, self::$accepted_types)) {
             $this->returnFailure(new common_exception_BadRequest());
         } else {
             $report = $this->service->importQtiTest($file['tmp_name']);
             if ($report->getType() === common_report_Report::TYPE_SUCCESS) {
                 $data = array();
                 foreach ($report as $r) {
                     $values = $r->getData();
                     $testid = $values->rdfsResource->getUri();
                     foreach ($values->items as $item) {
                         $itemsid[] = $item->getUri();
                     }
                     $data[] = array('testId' => $testid, 'testItems' => $itemsid);
                 }
                 return $this->returnSuccess($data);
             } else {
                 return $this->returnFailure(new common_exception_InconsistentData($report->getMessage()));
             }
         }
     } else {
         return $this->returnFailure(new common_exception_BadRequest());
     }
 }
开发者ID:oat-sa,项目名称:extension-tao-testqti,代码行数:36,代码来源:class.RestQtiTests.php

示例3: getAsset

 public function getAsset()
 {
     $item = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     $assetPath = $this->getRequestParameter('asset');
     $mimeType = \tao_helpers_File::getMimeType($assetPath, true);
     header('Content-Type: ' . $mimeType);
     $loader = new Loader($item);
     $content = $loader->getAssetContent($assetPath);
     echo $content;
 }
开发者ID:oat-sa,项目名称:extension-tao-devtools,代码行数:10,代码来源:ItemTools.php

示例4: buildFile

 public static function buildFile(core_kernel_classes_Resource $test, $lang, $relPath, $filters = array())
 {
     $file = null;
     $baseDir = self::getBaseDir($test);
     $path = $baseDir . ltrim($relPath, '/');
     $mime = tao_helpers_File::getMimeType($path);
     if (count($filters) == 0 || in_array($mime, $filters)) {
         $file = array('name' => basename($path), 'mime' => $mime, 'size' => filesize($path), 'url' => _url('download', 'TestContent', 'taoQtiTest', array('uri' => $test->getUri(), 'lang' => $lang, 'path' => $relPath)));
     }
     return $file;
 }
开发者ID:nagyist,项目名称:extension-tao-testqti,代码行数:11,代码来源:class.ResourceManager.php

示例5: getFileInfo

 /**
  * (non-PHPdoc)
  * @see \oat\tao\model\media\MediaBrowser::getFileInfo
  */
 public function getFileInfo($link)
 {
     $file = null;
     $filename = basename($link);
     $dir = ltrim(dirname($link), '/');
     $sysPath = $this->getSysPath($dir . '/' . $filename);
     $mime = tao_helpers_File::getMimeType($sysPath);
     if (file_exists($sysPath)) {
         $file = array('name' => basename($sysPath), 'mime' => $mime, 'size' => filesize($sysPath));
     }
     return $file;
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:16,代码来源:class.ResourceManager.php

示例6: createMediaInstance

 /**
  * Create a media instance from a file, and define its class and language
  *
  * @param string $fileSource path to the file to create instance from
  * @param string $classUri parent to add the instance to
  * @param string $language language of the content
  * @param string $label label of the instance
  * @param string $mimeType mimeType of the file
  * @return string | bool $instanceUri or false on error
  */
 public function createMediaInstance($fileSource, $classUri, $language, $label = null, $mimeType = null)
 {
     $clazz = new \core_kernel_classes_Class($classUri);
     //get the file MD5
     $md5 = md5_file($fileSource);
     //create media instance
     $label = is_null($label) ? basename($fileSource) : $label;
     $fileManager = FileManager::getFileManagementModel();
     $link = $fileManager->storeFile($fileSource, $label);
     if ($link !== false) {
         $mimeType = is_null($mimeType) ? \tao_helpers_File::getMimeType($fileSource) : $mimeType;
         $instance = $clazz->createInstanceWithProperties(array(RDFS_LABEL => $label, MEDIA_LINK => $link, MEDIA_LANGUAGE => $language, MEDIA_MD5 => $md5, MEDIA_MIME_TYPE => $mimeType, MEDIA_ALT_TEXT => $label));
         if (common_ext_ExtensionsManager::singleton()->isEnabled('taoRevision')) {
             \common_Logger::i('Auto generating initial revision');
             RevisionService::commit($instance, __('Initial import'));
         }
         return $instance->getUri();
     }
     return false;
 }
开发者ID:oat-sa,项目名称:extension-tao-mediamanager,代码行数:30,代码来源:MediaService.php

示例7: evaluate

 /**
  * Short description of method evaluate
  *
  * @access public
  * @author Joel Bout, <joel.bout@tudor.lu>
  * @param  values
  * @return boolean
  */
 public function evaluate($values)
 {
     $returnValue = (bool) false;
     $mimetype = '';
     if (is_array($values)) {
         if (file_exists($values['uploaded_file'])) {
             $mimetype = tao_helpers_File::getMimeType($values['uploaded_file']);
             common_Logger::i($mimetype);
         }
         if (!empty($mimetype)) {
             if (in_array($mimetype, $this->options['mimetype'])) {
                 $returnValue = true;
             } else {
                 $this->message .= " " . implode(', ', $this->options['mimetype']) . " are expected but {$mimetype} detected";
             }
         } else {
             common_Logger::i('mimetype empty');
         }
     }
     return (bool) $returnValue;
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:29,代码来源:class.FileMimeType.php

示例8: evaluate

 /**
  * Short description of method evaluate
  *
  * @access public
  * @author Joel Bout, <joel.bout@tudor.lu>
  * @param  values
  * @return boolean
  */
 public function evaluate($values)
 {
     $returnValue = (bool) false;
     $mimetype = '';
     if (is_array($values)) {
         if (file_exists($values['uploaded_file'])) {
             $mimetype = tao_helpers_File::getMimeType($values['uploaded_file']);
             common_Logger::d($mimetype);
         }
         if (!empty($mimetype)) {
             if (in_array($mimetype, $this->getOption('mimetype'))) {
                 $returnValue = true;
             } else {
                 $this->setMessage(__('%1$s expected but %2$s detected', implode(', ', $this->getOption('mimetype')), $mimetype));
             }
         } else {
             common_Logger::i('mimetype empty');
         }
     }
     return (bool) $returnValue;
 }
开发者ID:oat-sa,项目名称:tao-core,代码行数:29,代码来源:class.FileMimeType.php

示例9: upload

 /**
  * Upload a file to the item directory
  * 
  * @throws common_exception_MissingParameter
  */
 public function upload()
 {
     //as upload may be called multiple times, we remove the session lock as soon as possible
     try {
         session_write_close();
         if ($this->hasRequestParameter('uri')) {
             $itemUri = $this->getRequestParameter('uri');
             $item = new core_kernel_classes_Resource($itemUri);
         }
         if ($this->hasRequestParameter('lang')) {
             $itemLang = $this->getRequestParameter('lang');
         }
         if (!$this->hasRequestParameter('path')) {
             throw new common_exception_MissingParameter('path', __METHOD__);
         }
         if (!$this->hasRequestParameter('filters')) {
             throw new common_exception_MissingParameter('filters', __METHOD__);
         }
         $filters = explode(',', $this->getRequestParameter('filters'));
         $resolver = new ItemMediaResolver($item, $itemLang);
         $asset = $resolver->resolve($this->getRequestParameter('relPath'));
         $file = tao_helpers_Http::getUploadedFile('content');
         $fileTmpName = $file['tmp_name'] . '_' . $file['name'];
         if (!tao_helpers_File::copy($file['tmp_name'], $fileTmpName)) {
             throw new common_exception_Error('impossible to copy ' . $file['tmp_name'] . ' to ' . $fileTmpName);
         }
         $mime = \tao_helpers_File::getMimeType($fileTmpName);
         if (in_array($mime, $filters)) {
             $filedata = $asset->getMediaSource()->add($fileTmpName, $file['name'], $asset->getMediaIdentifier());
         } else {
             throw new \oat\tao\helpers\FileUploadException('The file you tried to upload is not valid');
         }
         $this->returnJson($filedata);
         return;
     } catch (\oat\tao\model\accessControl\data\PermissionException $e) {
         $message = $e->getMessage();
     } catch (\oat\tao\helpers\FileUploadException $e) {
         $message = $e->getMessage();
     } catch (common_Exception $e) {
         common_Logger::w($e->getMessage());
         $message = _('Unable to upload file');
     }
     $this->returnJson(array('error' => $message));
 }
开发者ID:nagyist,项目名称:tao-extension-tao-item,代码行数:49,代码来源:class.ItemContent.php

示例10: returnFile

 /**
  * Sends file content to the client(browser or video/audio player in the browser), it serves images, video/audio files and any other type of file.<br />
  * If the client asks for partial contents, then partial contents are served, if not, the whole file is send.<br />
  * Works well with big files, without eating up memory.
  * @author "Martin for OAT <code@taotesting.com>"
  * @param string $filename the file name
  * @param boolean $contenttype whether to add content type header or not
  * @param boolean $svgzSupport whether to add content encoding header or not
  * @throws common_exception_Error
  */
 public static function returnFile($filename, $contenttype = true, $svgzSupport = false)
 {
     if (tao_helpers_File::securityCheck($filename, true)) {
         if (file_exists($filename)) {
             $mimeType = tao_helpers_File::getMimeType($filename, true);
             if ($contenttype) {
                 header('Content-Type: ' . $mimeType);
             }
             $fp = fopen($filename, 'rb');
             if ($fp === false) {
                 header("HTTP/1.0 404 Not Found");
             } else {
                 $pathinfo = pathinfo($filename);
                 if (isset($pathinfo['extension']) && $pathinfo['extension'] === 'svgz' && !$svgzSupport) {
                     header('Content-Encoding: gzip');
                 }
                 // session must be closed because, for example, video files might take a while to be sent to the client
                 //  and we need the client to be able to make other calls to the server during that time
                 session_write_close();
                 $http416RequestRangeNotSatisfiable = 'HTTP/1.1 416 Requested Range Not Satisfiable';
                 $http206PartialContent = 'HTTP/1.1 206 Partial Content';
                 $http200OK = 'HTTP/1.1 200 OK';
                 $filesize = filesize($filename);
                 $offset = 0;
                 $length = $filesize;
                 $useFpassthru = false;
                 $partialContent = false;
                 header('Accept-Ranges: bytes');
                 if (isset($_SERVER['HTTP_RANGE'])) {
                     $partialContent = true;
                     preg_match('/bytes=(\\d+)-(\\d+)?/', $_SERVER['HTTP_RANGE'], $matches);
                     $offset = intval($matches[1]);
                     if (!isset($matches[2])) {
                         // no end position is given, so we serve the file from the start position to the end
                         $useFpassthru = true;
                     } else {
                         $length = intval($matches[2]) - $offset;
                     }
                 }
                 fseek($fp, $offset);
                 if ($partialContent) {
                     if ($offset < 0 || $offset > $filesize) {
                         header($http416RequestRangeNotSatisfiable);
                     } else {
                         if ($useFpassthru) {
                             // only a starting position is given
                             header($http206PartialContent);
                             header("Content-Length: " . ($filesize - $offset));
                             header('Content-Range: bytes ' . $offset . '-' . ($filesize - 1) . '/' . $filesize);
                             if (ob_get_level() > 0) {
                                 ob_end_flush();
                             }
                             fpassthru($fp);
                         } else {
                             // we are given a starting position and how many bytes the client asks for
                             $endPosition = $offset + $length;
                             if ($endPosition > $filesize) {
                                 header($http416RequestRangeNotSatisfiable);
                             } else {
                                 header($http206PartialContent);
                                 header("Content-Length: " . $length);
                                 header('Content-Range: bytes ' . $offset . '-' . ($offset + $length - 1) . '/' . $filesize);
                                 // send 500KB per cycle
                                 $bytesPerCycle = 1024 * 1024 * 0.5;
                                 $currentPosition = $offset;
                                 if (ob_get_level() > 0) {
                                     ob_end_flush();
                                 }
                                 // because the client might ask for the whole file, we split the serving into little pieces
                                 // this is also good in case someone with bad intentions tries to get the whole file many times
                                 //  and eat up the server memory, we are not loading the whole file into the memory.
                                 while (!feof($fp)) {
                                     if ($currentPosition + $bytesPerCycle <= $endPosition) {
                                         $data = fread($fp, $bytesPerCycle);
                                         $currentPosition = $currentPosition + $bytesPerCycle;
                                         echo $data;
                                     } else {
                                         $data = fread($fp, $endPosition - $currentPosition);
                                         echo $data;
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     // client does not want partial contents so we just serve the whole file
                     header($http200OK);
                     header("Content-Length: " . $filesize);
                     if (ob_get_level() > 0) {
                         ob_end_flush();
//.........这里部分代码省略.........
开发者ID:oat-sa,项目名称:tao-core,代码行数:101,代码来源:class.Http.php

示例11: uploadFile

 /**
  * Get, check and move the file uploaded (described in the posetedFile parameter)
  * 
  * @param array $postedFile
  * @param string $folder
  * @return array $data
  */
 protected function uploadFile($postedFile, $folder)
 {
     $returnValue = array();
     if (isset($postedFile['tmp_name']) && isset($postedFile['name'])) {
         $tempFile = $postedFile['tmp_name'];
         $targetPath = tao_helpers_File::concat(array($this->rootFolder, $folder));
         if (tao_helpers_File::securityCheck($targetPath)) {
             if (!file_exists($targetPath)) {
                 mkdir($targetPath);
             }
             $targetFile = tao_helpers_File::concat(array($targetPath, uniqid() . '_' . $postedFile['name']));
             if (move_uploaded_file($tempFile, $targetFile)) {
                 $returnValue['uploaded'] = true;
                 $data = $postedFile;
                 $data['type'] = tao_helpers_File::getMimeType($targetFile);
                 $data['uploaded_file'] = $targetFile;
                 $returnValue['name'] = $postedFile['name'];
                 $returnValue['uploaded_file'] = $targetFile;
                 $returnValue['data'] = json_encode($data);
             }
         }
     }
     return $returnValue;
 }
开发者ID:oat-sa,项目名称:tao-core,代码行数:31,代码来源:class.File.php

示例12: downloadFile

 /**
  * Download a resource file content
  * @param {String} uri Uri of the resource file
  */
 public function downloadFile()
 {
     if ($this->hasRequestParameter('uri')) {
         $uri = tao_helpers_Uri::decode($this->getRequestParameter('uri'));
         $resource = new core_kernel_classes_Resource($uri);
         if (core_kernel_versioning_File::isVersionedFile($resource) || core_kernel_file_File::isFile($resource)) {
             $file = new core_kernel_file_File($uri);
             $fileName = $file->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FILE_FILENAME));
             $content = $file->getFileContent();
             $size = strlen($content);
             $mimeType = tao_helpers_File::getMimeType($file->getAbsolutePath(), true);
             $this->setContentHeader($mimeType);
             header("Content-Length: {$size}");
             header("Content-Disposition: attachment; filename=\"{$fileName}\"");
             header("Expires: 0");
             header("Cache-Control: no-cache, must-revalidate");
             header("Pragma: no-cache");
             print $content;
             return;
         } else {
             throw new Exception('The resource (' . $uri . ') is not a valid file resource');
         }
     }
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:28,代码来源:class.File.php

示例13: getFileInfo

 /**
  * Get details about file
  *
  * @param $path
  * @param $relPath
  * @return array
  * @throws \tao_models_classes_FileNotFoundException
  */
 public function getFileInfo($path, $relPath)
 {
     if (file_exists($path)) {
         return array('name' => basename($path), 'uri' => $relPath, 'mime' => \tao_helpers_File::getMimeType($path), 'filePath' => $path, 'size' => filesize($path));
     }
     throw new \tao_models_classes_FileNotFoundException($path);
 }
开发者ID:oat-sa,项目名称:extension-tao-itemqti,代码行数:15,代码来源:PortableElementItemParser.php

示例14: update


//.........这里部分代码省略.........
         //modify links in item content
         $service = \taoItems_models_classes_ItemsService::singleton();
         $items = $service->getAllByModel('http://www.tao.lu/Ontologies/TAOItem.rdf#QTI');
         foreach ($items as $item) {
             $itemContent = $service->getItemContent($item);
             $itemContent = preg_replace_callback('/src="mediamanager\\/([^"]+)"/', function ($matches) {
                 $mediaClass = MediaService::singleton()->getRootClass();
                 $medias = $mediaClass->searchInstances(array(MEDIA_LINK => $matches[1]), array('recursive' => true));
                 $media = array_pop($medias);
                 $uri = '';
                 if (!is_null($media) && $media->exists()) {
                     $uri = \tao_helpers_Uri::encode($media->getUri());
                 }
                 return 'src="taomedia://mediamanager/' . $uri . '"';
             }, $itemContent);
             $itemContent = preg_replace_callback('/src="local\\/([^"]+)"/', function ($matches) {
                 return 'src="' . $matches[1] . '"';
             }, $itemContent);
             $service->setItemContent($item, $itemContent);
         }
         $currentVersion = '0.2.0';
     }
     if ($currentVersion === '0.2.0') {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         //revoke access right to back office
         $backOffice = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#BackOfficeRole');
         $accessService->revokeExtensionAccess($backOffice, 'taoMediaManager');
         //grant access right to media manager
         $mediaManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOMedia.rdf#MediaManagerRole');
         $accessService->grantExtensionAccess($mediaManager, 'taoMediaManager');
         $currentVersion = '0.2.1';
     }
     if ($currentVersion === '0.2.1') {
         //include mediamanager into globalmanager
         $mediaManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOMedia.rdf#MediaManagerRole');
         $globalManager = new \core_kernel_Classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#GlobalManagerRole');
         \tao_models_classes_RoleService::singleton()->includeRole($globalManager, $mediaManager);
         $currentVersion = '0.2.2';
     }
     if ($currentVersion === '0.2.2') {
         //copy file from /media to data/taoMediaManager/media and delete /media
         $dataPath = FILES_PATH . 'taoMediaManager' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR;
         $dir = dirname(dirname(__DIR__)) . '/media';
         if (file_exists($dir)) {
             if (\tao_helpers_File::copy($dir, $dataPath)) {
                 $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
                 $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
                 foreach ($files as $file) {
                     if ($file->isDir()) {
                         rmdir($file->getRealPath());
                     } else {
                         unlink($file->getRealPath());
                     }
                 }
                 rmdir($dir);
                 $currentVersion = '0.2.3';
             }
         } else {
             $currentVersion = '0.2.3';
         }
     }
     if ($currentVersion === '0.2.3') {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         //grant access to item author
         $itemAuthor = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemAuthor');
         $accessService->grantExtensionAccess($itemAuthor, 'taoMediaManager');
         $currentVersion = '0.2.4';
     }
     if ($currentVersion === '0.2.4') {
         $mediaClass = MediaService::singleton()->getRootClass();
         $fileManager = FileManager::getFileManagementModel();
         foreach ($mediaClass->getInstances(true) as $media) {
             $fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
             $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink;
             $filePath = $fileManager->retrieveFile($fileLink);
             $mimeType = \tao_helpers_File::getMimeType($filePath);
             $mimeType = $mimeType === 'application/xhtml+xml' ? 'application/qti+xml' : $mimeType;
             $media->setPropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
         }
         $currentVersion = '0.2.5';
     }
     if ($currentVersion === '0.2.5') {
         $fileManager = FileManager::getFileManagementModel();
         $iterator = new \core_kernel_classes_ResourceIterator(array(MediaService::singleton()->getRootClass()));
         foreach ($iterator as $media) {
             $fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
             $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink;
             $filePath = $fileManager->retrieveFile($fileLink);
             try {
                 SharedStimulusImporter::isValidSharedStimulus($filePath);
                 $media->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), 'application/qti+xml');
             } catch (\Exception $e) {
                 $mimeType = \tao_helpers_File::getMimeType($filePath);
                 $media->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
             }
         }
         $currentVersion = '0.3.0';
     }
     $this->skip('0.3.0', '0.5.1');
 }
开发者ID:oat-sa,项目名称:extension-tao-mediamanager,代码行数:101,代码来源:Updater.php

示例15: exportPortableAssets

 /**
  * Reconstruct PortableElement XML from PortableElementStorage data
  *
  * @param DOMDocument $dom
  * @param $nodeName
  * @param $typeIdentifierAttributeName
  * @param $ns
  * @param $portableElementsToExport
  * @param $portableAssetsToExport
  * @throws \common_Exception
  */
 private function exportPortableAssets(DOMDocument $dom, $nodeName, $typeIdentifierAttributeName, $ns, $portableElementsToExport, $portableAssetsToExport)
 {
     $xpath = new DOMXPath($dom);
     // Get all portable element from qti.xml
     $portableElementNodes = $dom->getElementsByTagName($nodeName);
     for ($i = 0; $i < $portableElementNodes->length; $i++) {
         /** @var \DOMElement $currentPortableNode */
         $currentPortableNode = $portableElementNodes->item($i);
         $identifier = $currentPortableNode->getAttribute($typeIdentifierAttributeName);
         if (!isset($portableElementsToExport[$identifier])) {
             throw new \common_Exception('Unable to find loaded portable element.');
         }
         /** @var PortableElementObject $portableElement */
         $portableElement = $portableElementsToExport[$identifier];
         // Add hook and version as attributes
         if ($portableElement->hasRuntimeKey('hook')) {
             $currentPortableNode->setAttribute('hook', preg_replace('/^(.\\/)(.*)/', $portableElement->getTypeIdentifier() . "/\$2", $portableElement->getRuntimeKey('hook')));
         }
         $currentPortableNode->setAttribute('version', $portableElement->getVersion());
         // If asset files list is empty for current identifier skip
         if (!isset($portableAssetsToExport) || !isset($portableAssetsToExport[$portableElement->getTypeIdentifier()])) {
             continue;
         }
         /** @var \DOMElement $resourcesNode */
         $resourcesNode = $currentPortableNode->getElementsByTagName('resources')->item(0);
         // Portable libraries
         $librariesNode = $dom->createElement($ns . ':libraries');
         foreach ($portableElement->getRuntimeKey('libraries') as $library) {
             $libraryNode = $dom->createElement($ns . ':lib');
             //the exported lib id must be adapted from a href mode to an amd name mode
             $libraryNode->setAttribute('id', preg_replace('/\\.js$/', '', $portableAssetsToExport[$portableElement->getTypeIdentifier()][$library]));
             $librariesNode->appendChild($libraryNode);
         }
         $oldLibrariesNode = $xpath->query('.//' . $ns . ':libraries', $resourcesNode);
         if ($oldLibrariesNode->length > 0) {
             $resourcesNode->removeChild($oldLibrariesNode->item(0));
         }
         if ($librariesNode->hasChildNodes()) {
             $resourcesNode->appendChild($librariesNode);
         }
         // Portable stylesheets
         $stylesheetsNode = $dom->createElement($ns . ':stylesheets');
         foreach ($portableElement->getRuntimeKey('stylesheets') as $stylesheet) {
             $stylesheetNode = $dom->createElement($ns . ':link');
             $stylesheetNode->setAttribute('href', $portableAssetsToExport[$portableElement->getTypeIdentifier()][$stylesheet]);
             $stylesheetNode->setAttribute('type', 'text/css');
             $info = pathinfo($stylesheet);
             $stylesheetNode->setAttribute('title', basename($stylesheet, '.' . $info['extension']));
             $stylesheetsNode->appendChild($stylesheetNode);
         }
         $oldStylesheetsNode = $xpath->query('.//' . $ns . ':stylesheets', $resourcesNode);
         if ($oldStylesheetsNode->length > 0) {
             $resourcesNode->removeChild($oldStylesheetsNode->item(0));
         }
         if ($stylesheetsNode->hasChildNodes()) {
             $resourcesNode->appendChild($stylesheetsNode);
         }
         // Portable mediaFiles
         $mediaFilesNode = $dom->createElement($ns . ':mediaFiles');
         foreach ($portableElement->getRuntimeKey('mediaFiles') as $mediaFile) {
             $mediaFileNode = $dom->createElement($ns . ':file');
             $mediaFileNode->setAttribute('src', $portableAssetsToExport[$portableElement->getTypeIdentifier()][$mediaFile]);
             $mediaFileNode->setAttribute('type', \tao_helpers_File::getMimeType($portableAssetsToExport[$portableElement->getTypeIdentifier()][$mediaFile]));
             $mediaFilesNode->appendChild($mediaFileNode);
         }
         $oldMediaFilesNode = $xpath->query('.//' . $ns . ':mediaFiles', $resourcesNode);
         if ($oldMediaFilesNode->length > 0) {
             $resourcesNode->removeChild($oldMediaFilesNode->item(0));
         }
         if ($mediaFilesNode->hasChildNodes()) {
             $resourcesNode->appendChild($mediaFilesNode);
         }
     }
     unset($xpath);
 }
开发者ID:oat-sa,项目名称:extension-tao-itemqti,代码行数:86,代码来源:AbstractQTIItemExporter.php


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