コード例 #1
0
 public function send(Message $message)
 {
     $receiver = $message->getTo();
     $path = $this->getOption(self::CONFIG_FILEPATH) . \tao_helpers_File::getSafeFileName($receiver->getIdentifier()) . DIRECTORY_SEPARATOR;
     if (!file_exists($path)) {
         mkdir($path);
     }
     $messageFile = $path . \tao_helpers_File::getSafeFileName('message.html', $path);
     \common_Logger::d($messageFile);
     $written = file_put_contents($messageFile, $message->getBody());
     return $written !== false;
 }
コード例 #2
0
ファイル: FileSink.php プロジェクト: nagyist/tao-core
 /**
  * Get file path to save message
  * @param User $receiver
  * @param boolean $refresh whether the file path must be regenerated.
  */
 public function getFilePath(User $receiver)
 {
     $basePath = $this->getOption(self::CONFIG_FILEPATH);
     if (is_null($basePath) || !file_exists($basePath)) {
         throw new \common_exception_InconsistentData('Missing path ' . self::CONFIG_FILEPATH . ' for ' . __CLASS__);
     }
     $path = $basePath . \tao_helpers_File::getSafeFileName($receiver->getIdentifier()) . DIRECTORY_SEPARATOR;
     if (!file_exists($path)) {
         mkdir($path);
     }
     return $path . \tao_helpers_File::getSafeFileName('message.html', $path);
 }
コード例 #3
0
 private static function migrateFrom09To091()
 {
     // Get all items...
     $itemService = \taoItems_models_classes_ItemsService::singleton();
     $itemClass = $itemService->getRootClass();
     foreach ($itemClass->getInstances(true) as $item) {
         if ($itemService->hasItemModel($item, array(TAO_ITEM_MODEL_QTI))) {
             $path = $itemService->getDefaultItemFolder($item);
             $qtiXml = $itemService->getItemContent($item);
             if (empty($qtiXml) === false) {
                 $qtiDom = new \DOMDocument('1.0', 'UTF-8');
                 $qtiDom->loadXML($qtiXml);
                 // Get all stylesheet hrefs.
                 $hrefs = Utils::getStylesheetHrefs($qtiDom);
                 // Make sure the hrefs are refering existing files.
                 for ($i = 0; $i < count($hrefs); $i++) {
                     $href = $hrefs[$i];
                     if (is_readable($path . $href) === false) {
                         \common_Logger::i("The stylesheet->href '{$path}.{$href}' does not reference an existing file. Trying to repair...");
                         // Let's try with another name...
                         $pathinfo = pathinfo($href);
                         $altFileName = \tao_helpers_File::getSafeFileName($pathinfo['basename']);
                         $dirSep = $pathinfo['dirname'] !== '.' ? $pathInfo['dirname'] . DIRECTORY_SEPARATOR : '';
                         $altPath = $path . $dirSep . $altFileName;
                         if (is_readable($altPath)) {
                             // Bingo! We rebind.
                             $hrefs[$i] = $dirSep . $altFileName;
                             \common_Logger::i("Repaired with new href '{$dirSep}.{$altFileName}}'.");
                         } else {
                             // It's definitely broken...
                             unset($hrefs[$i]);
                             \common_Logger::i("Could not be repaired! QTI stylesheet component removed from item.");
                         }
                     }
                 }
                 // Reput them in the item with cleanup enabled
                 // to solve the XMLSchema validation issue.
                 if (count($hrefs) > 0) {
                     $href = array_shift($hrefs);
                     Utils::appendStylesheet($qtiDom, $href, true);
                 }
                 // Append the rest of the stylesheets.
                 foreach ($hrefs as $href) {
                     Utils::appendStylesheet($qtiDom, $href);
                 }
                 $itemService->setItemContent($item, $qtiDom->saveXML());
             }
         }
     }
 }
コード例 #4
0
 /**
  * (non-PHPdoc)
  * @see \oat\oatbox\action\Action::__invoke()
  */
 public function __invoke($params)
 {
     \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf');
     if (count($params) != 2) {
         return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s DELIVERY_CLASS_URI OUTPUT_DIRECTORY', __CLASS__));
     }
     $deliveryClassUri = array_shift($params);
     $deliveryClass = new \core_kernel_classes_Class($deliveryClassUri);
     $dir = array_shift($params);
     if (!file_exists($dir) && !mkdir($dir)) {
         return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Directory %s doesn\'t exist', $dir));
     }
     $dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exporting %s', $deliveryClass->getLabel()));
     foreach ($deliveryClass->getInstances(true) as $delivery) {
         $destFile = $dir . \tao_helpers_File::getSafeFileName($delivery->getLabel()) . '.zip';
         $tmpFile = Assembler::exportCompiledDelivery($delivery);
         \tao_helpers_File::move($tmpFile, $destFile);
         $report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exported %1$s to %2$s', $delivery->getLabel(), $destFile)));
     }
     return $report;
 }
コード例 #5
0
 /**
  * 
  * @param core_kernel_classes_Resource $item
  * @param string $lang
  * @param string $destination
  * @return \oat\taoQtiItem\model\qti\Item
  */
 protected function retrieveAssets(core_kernel_classes_Resource $item, $lang, $destination)
 {
     $xml = taoItems_models_classes_ItemsService::singleton()->getItemContent($item);
     $qtiParser = new Parser($xml);
     $qtiItem = $qtiParser->load();
     $assetParser = new AssetParser($qtiItem);
     $assetParser->setGetSharedLibraries(false);
     $assetParser->setGetXinclude(false);
     $resolver = new ItemMediaResolver($item, $lang);
     foreach ($assetParser->extract() as $type => $assets) {
         foreach ($assets as $assetUrl) {
             foreach (self::$BLACKLIST as $blacklist) {
                 if (preg_match($blacklist, $assetUrl) === 1) {
                     continue 2;
                 }
             }
             $mediaAsset = $resolver->resolve($assetUrl);
             $mediaSource = $mediaAsset->getMediaSource();
             $srcPath = $mediaSource->download($mediaAsset->getMediaIdentifier());
             $filename = \tao_helpers_File::getSafeFileName(ltrim($mediaAsset->getMediaIdentifier(), '/'), $destination);
             $replacement = $mediaAsset->getMediaIdentifier();
             if (get_class($mediaSource) !== 'oat\\tao\\model\\media\\sourceStrategy\\HttpSource') {
                 $fileInfo = $mediaSource->getFileInfo($mediaAsset->getMediaIdentifier());
                 $filename = $fileInfo['filePath'];
                 if ($mediaAsset->getMediaIdentifier() !== $fileInfo['uri']) {
                     $replacement = $filename;
                 }
             }
             $destPath = ltrim($filename, '/');
             tao_helpers_File::copy($srcPath, $destination . $destPath, false);
             $xml = str_replace($assetUrl, $replacement, $xml);
         }
     }
     $qtiParser = new Parser($xml);
     $assetRetrievedQtiItem = $qtiParser->load();
     //loadxinclude
     $xincludeLoader = new XIncludeLoader($assetRetrievedQtiItem, $resolver);
     $xincludeLoader->load(true);
     return $assetRetrievedQtiItem;
 }