/** * deploys the item into the given absolute directory * * @param core_kernel_classes_Resource $item * @param string $languageCode * @param string $compiledDirectory * @return common_report_Report */ protected function deployItem(core_kernel_classes_Resource $item, $languageCode, $compiledDirectory) { $itemService = taoItems_models_classes_ItemsService::singleton(); // copy local files $source = $itemService->getItemFolder($item, $languageCode); $success = taoItems_helpers_Deployment::copyResources($source, $compiledDirectory, array('index.html')); if (!$success) { return $this->fail(__('Unable to copy resources for language %s', $languageCode)); } // render item $xhtml = $itemService->render($item, $languageCode); // retrieve external resources $subReport = taoItems_helpers_Deployment::retrieveExternalResources($xhtml, $compiledDirectory); if ($subReport->getType() == common_report_Report::TYPE_SUCCESS) { $xhtml = $subReport->getData(); // write index.html file_put_contents($compiledDirectory . 'index.html', $xhtml); return new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published "%1$s" in language "%2$s"', $item->getLabel(), $languageCode)); } else { return $subReport; } }
/** * Copy all remote resource (absolute URLs to another host) contained in a rubricBlock into a dedicated directory. Remote resources * can be refereced by the following QTI classes/attributes: * * * a:href * * object:data * * img:src * * @param AssessmentTest $assessmentTest An AssessmentTest object. * @throws taoQtiTest_models_classes_QtiTestCompilationFailedException If a remote resource cannot be retrieved. */ protected function copyRemoteResources(RubricBlock $rubricBlock) { $ds = DIRECTORY_SEPARATOR; $tmpDir = tao_helpers_File::createTempDir(); $destPath = trim($this->getExtraPath(), $ds) . $ds . TAOQTITEST_REMOTE_FOLDER . $ds; // Search for all class-attributes in QTI-XML that might reference a remote file. $search = $rubricBlock->getComponentsByClassName(array('a', 'object', 'img')); foreach ($search as $component) { switch ($component->getQtiClassName()) { case 'object': $url = $component->getData(); break; case 'img': $url = $component->getSrc(); break; } if (isset($url) && !preg_match('@^' . ROOT_URL . '@', $url) && !Url::isRelative($url)) { $tmpFile = taoItems_helpers_Deployment::retrieveFile($url, $tmpDir); if ($tmpFile !== false) { $pathinfo = pathinfo($tmpFile); $handle = fopen($tmpFile, 'r'); $this->getPublicDirectory()->writeStream($destPath . $pathinfo['basename'], $handle); fclose($handle); unlink($tmpFile); $newUrl = TAOQTITEST_REMOTE_FOLDER . '/' . $pathinfo['basename']; switch ($component->getQtiClassName()) { case 'object': $component->setData($newUrl); break; case 'img': $component->setSrc($newUrl); break; } } else { $msg = "The remote resource referenced by '{$url}' could not be retrieved."; throw new taoQtiTest_models_classes_QtiTestCompilationFailedException($msg, $this->getResource(), taoQtiTest_models_classes_QtiTestCompilationFailedException::REMOTE_RESOURCE); } } } }
/** * Copy all remote resource (absolute URLs to another host) contained in a rubricBlock into a dedicated directory. Remote resources * can be refereced by the following QTI classes/attributes: * * * a:href * * object:data * * img:src * * @param AssessmentTest $assessmentTest An AssessmentTest object. * @throws taoQtiTest_models_classes_QtiTestCompilationFailedException If a remote resource cannot be retrieved. */ protected function copyRemoteResources(RubricBlock $rubricBlock) { $publicCompiledDocDir = $this->getPublicDirectory()->getPath(); $ds = DIRECTORY_SEPARATOR; $destination = $publicCompiledDocDir . trim($this->getExtraPath(), $ds) . $ds . TAOQTITEST_REMOTE_FOLDER . $ds; // If remote directory does not exist yet, create it. if (file_exists($destination) === false) { mkdir($destination, 0770, true); } // Search for all class-attributes in QTI-XML that might reference a remote file. $search = $rubricBlock->getComponentsByClassName(array('a', 'object', 'img')); foreach ($search as $component) { switch ($component->getQtiClassName()) { case 'object': $url = $component->getData(); break; case 'img': $url = $component->getSrc(); break; } if (isset($url) && !preg_match('@^' . ROOT_URL . '@', $url) && !Url::isRelative($url)) { $finalDestination = taoItems_helpers_Deployment::retrieveFile($url, $destination); $pathinfo = pathinfo($finalDestination); if ($finalDestination !== false) { $newUrl = TAOQTITEST_REMOTE_FOLDER . '/' . $pathinfo['basename']; switch ($component->getQtiClassName()) { case 'object': $component->setData($newUrl); break; case 'img': $component->setSrc($newUrl); break; } } else { $msg = "The remote resource referenced by '{$url}' could not be retrieved."; throw new taoQtiTest_models_classes_QtiTestCompilationFailedException($msg, $this->getResource(), taoQtiTest_models_classes_QtiTestCompilationFailedException::REMOTE_RESOURCE); } } } }