Exemplo n.º 1
0
 /**
  * Init server / add handlers
  */
 public function init()
 {
     $callback_obj = new ilRestFileStorage();
     $this->get('/fileStorage/:name', array($callback_obj, 'getFile'));
     $this->post('/fileStorage', array($callback_obj, 'createFile'));
     $callback_obj->deleteDeprecated();
 }
Exemplo n.º 2
0
 function start()
 {
     $this->__buildHeader();
     $attribs = array("obj_id" => "il_" . IL_INST_ID . "_file_" . $this->file->getId(), "version" => $this->file->getVersion(), "size" => $this->file->getFileSize(), "type" => $this->file->getFileType());
     $this->xmlStartTag("File", $attribs);
     $this->xmlElement("Filename", null, $this->file->getFileName());
     $this->xmlElement("Title", null, $this->file->getTitle());
     $this->xmlElement("Description", null, $this->file->getDescription());
     $this->xmlElement("Rating", null, (int) $this->file->hasRating());
     if ($this->attachFileContents) {
         $filename = $this->file->getDirectory($this->file->getVersion()) . "/" . $this->file->getFileName();
         if (@is_file($filename)) {
             if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY) {
                 $attribs = array("mode" => "COPY");
                 copy($filename, $this->target_dir_absolute . "/" . $this->file->getFileName());
                 $content = $this->target_dir_relative . "/" . $this->file->getFileName();
                 $this->xmlElement("Content", $attribs, $content);
             } elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_REST) {
                 $attribs = array('mode' => "REST");
                 include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
                 $fs = new ilRestFileStorage();
                 $tmpname = $fs->storeFileForRest(base64_encode(@file_get_contents($filename)));
                 $this->xmlElement("Content", $attribs, $tmpname);
             } else {
                 $content = @file_get_contents($filename);
                 $attribs = array("mode" => "PLAIN");
                 if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
                     $attribs["mode"] = "ZLIB";
                     $content = @gzcompress($content, 9);
                 } elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
                     $attribs["mode"] = "GZIP";
                     $content = @gzencode($content, 9);
                 }
                 $content = base64_encode($content);
                 $this->xmlElement("Content", $attribs, $content);
             }
         }
     }
     include_once "./Services/History/classes/class.ilHistory.php";
     $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
     if (count($versions)) {
         $this->xmlStartTag("Versions");
         foreach ($versions as $version) {
             $info_params = $version["info_params"];
             list($filename, $history_id) = split(",", $info_params);
             $attribs = array("id" => $history_id, "date" => ilUtil::date_mysql2time($version["date"]), "usr_id" => "il_" . IL_INST_ID . "_usr_" . $version["user_id"]);
             $this->xmlElement("Version", $attribs);
         }
         $this->xmlEndTag("Versions");
     }
     $this->xmlEndTag("File");
     $this->__buildFooter();
     return true;
 }
 /**
  * handler for end of element
  *
  * @param	resource	$a_xml_parser		xml parser
  * @param	string		$a_name				element name
  */
 function handlerEndTag($a_xml_parser, $a_name)
 {
     $this->cdata = trim($this->cdata);
     $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->cdata);
     switch ($a_name) {
         case 'File':
             $this->result = true;
             break;
         case 'Filename':
             if (strlen($this->cdata) == 0) {
                 throw new ilFileException("Filename ist missing!");
             }
             $this->file->setFilename($this->cdata);
             $this->file->setTitle($this->cdata);
             break;
         case 'Title':
             $this->file->setTitle(trim($this->cdata));
             break;
         case 'Description':
             $this->file->setDescription(trim($this->cdata));
             break;
         case 'Content':
             $GLOBALS['ilLog']->write($this->mode);
             $this->isReadingFile = false;
             $baseDecodedFilename = ilUtil::ilTempnam();
             if ($this->mode == ilFileXMLParser::$CONTENT_COPY) {
                 $this->tmpFilename = $this->getImportDirectory() . "/" . $this->cdata;
             } elseif ($this->mode == ilFileXMLParser::$CONTENT_REST) {
                 include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
                 $storage = new ilRestFileStorage();
                 $this->tmpFilename = $storage->getStoredFilePath($this->cdata);
                 if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) {
                     throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
                 }
                 $this->tmpFilename = $baseDecodedFilename;
             } else {
                 if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) {
                     throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
                 }
                 if ($this->mode == ilFileXMLParser::$CONTENT_GZ_COMPRESSED) {
                     if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
                         throw new ilFileException("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED);
                     }
                     unlink($baseDecodedFilename);
                 } elseif ($this->mode == ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED) {
                     if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
                         throw new ilFileException("Deflating with fastDecompress failed", ilFileException::$DECOMPRESSION_FAILED);
                     }
                     unlink($baseDecodedFilename);
                 } else {
                     $this->tmpFilename = $baseDecodedFilename;
                 }
             }
             //$this->content = $content;
             $this->file->setFileSize(filesize($this->tmpFilename));
             // strlen($this->content));
             // if no file type is given => lookup mime type
             if (!$this->file->getFileType()) {
                 global $ilLog;
                 #$ilLog->write(__METHOD__.': Trying to detect mime type...');
                 include_once './Services/Utilities/classes/class.ilFileUtils.php';
                 $this->file->setFileType(ilFileUtils::_lookupMimeType($this->tmpFilename));
             }
             break;
     }
     $this->cdata = '';
     return;
 }