Example #1
0
 /**
  * @param File $file
  * @return static
  */
 public static function fromFile(File $file)
 {
     $note = new static();
     $note->setId($file->getId());
     $note->setContent($file->getContent());
     $note->setModified($file->getMTime());
     $note->setTitle(substr($file->getName(), 0, -4));
     // remove trailing .txt
     $note->resetUpdatedFields();
     return $note;
 }
Example #2
0
 /**
  * @param File $file
  * @return static
  */
 public static function fromFile(File $file)
 {
     $note = new static();
     $note->setId($file->getId());
     $note->setContent($file->getContent());
     $note->setModified($file->getMTime());
     $note->setTitle(pathinfo($file->getName(), PATHINFO_FILENAME));
     // remove extension
     $note->resetUpdatedFields();
     return $note;
 }
Example #3
0
 /**
  * Downloads the requested file
  *
  * @param File $file
  * @param bool $base64Encode
  *
  * @return false|array
  */
 public function downloadFile($file, $base64Encode = false)
 {
     try {
         $this->logger->debug("[DownloadService] File to Download: {name}", ['name' => $file->getName()]);
         $download = ['preview' => $file->getContent(), 'mimetype' => $file->getMimeType()];
         if ($base64Encode) {
             $download['preview'] = $this->encode($download['preview']);
         }
     } catch (\Exception $exception) {
         $download = false;
     }
     return $download;
 }
 /**
  * Downloads the requested file
  *
  * @param File $file
  * @param bool $base64Encode
  *
  * @return array|false
  * @throws NotFoundServiceException
  */
 public function downloadFile($file, $base64Encode = false)
 {
     try {
         $this->logger->debug("[DownloadService] File to Download: {name}", ['name' => $file->getName()]);
         $download = ['preview' => $file->getContent(), 'mimetype' => $file->getMimeType()];
         if ($base64Encode) {
             $download['preview'] = $this->encode($download['preview']);
         }
         return $download;
     } catch (\Exception $exception) {
         throw new NotFoundServiceException('There was a problem accessing the file');
     }
 }
 /**
  * Runs before each test (public method)
  *
  * It's important to recreate the app for every test, as if the user had just logged in
  *
  * @fixme Or just create the app once for each type of env and run all tests. For that to work,
  *     I think I would need to switch to Cepts
  */
 protected function _before()
 {
     $this->coreTestCase->setUp();
     $app = new Gallery();
     $this->container = $app->getContainer();
     $this->server = $this->container->getServer();
     $setupData = $this->getModule('\\Helper\\DataSetup');
     $this->userId = $setupData->userId;
     $this->sharerUserId = $setupData->sharerUserId;
     $this->sharedFolder = $setupData->sharedFolder;
     $this->sharedFolderName = $this->sharedFolder->getName();
     $this->sharedFile = $setupData->sharedFile;
     $this->sharedFileName = $this->sharedFile->getName();
     $this->sharedFolderToken = $setupData->sharedFolderToken;
     $this->sharedFileToken = $setupData->sharedFileToken;
     $this->passwordForFolderShare = $setupData->passwordForFolderShare;
 }
Example #6
0
 /**
  * test if file is a note
  *
  * @param \OCP\Files\File $file
  * @return bool
  */
 private function isNote($file)
 {
     $allowedExtensions = ['txt', 'org', 'markdown', 'md', 'note'];
     if ($file->getType() !== 'file') {
         return false;
     }
     if (!in_array(pathinfo($file->getName(), PATHINFO_EXTENSION), $allowedExtensions)) {
         return false;
     }
     return true;
 }
Example #7
0
 /**
  * index a file
  *
  * @param File $file the file to be indexed
  * @param bool $commit
  *
  * @return bool true when something was stored in the index, false otherwise (eg, folders are not indexed)
  * @throws NotIndexedException when an unsupported file type is encountered
  */
 public function indexFile(File $file, $commit = true)
 {
     // we decide how to index on mime type or file extension
     $mimeType = $file->getMimeType();
     $fileExtension = strtolower(pathinfo($file->getName(), PATHINFO_EXTENSION));
     // initialize plain lucene document
     $doc = new Document();
     // index content for local files only
     $storage = $file->getStorage();
     if ($storage->isLocal()) {
         $path = $storage->getLocalFile($file->getInternalPath());
         //try to use special lucene document types
         if ('text/html' === $mimeType) {
             //TODO could be indexed, even if not local
             $doc = HTML::loadHTML($file->getContent());
         } else {
             if ('text/' === substr($mimeType, 0, 5) || 'application/x-tex' === $mimeType) {
                 $body = $file->getContent();
                 if ($body != '') {
                     $doc->addField(Document\Field::UnStored('body', $body));
                 }
             } else {
                 if ('application/pdf' === $mimeType) {
                     $doc = Pdf::loadPdf($file->getContent());
                     // the zend classes only understand docx and not doc files
                 } else {
                     if ($fileExtension === 'docx') {
                         $doc = Document\Docx::loadDocxFile($path);
                         //} else if ('application/msexcel' === $mimeType) {
                     } else {
                         if ($fileExtension === 'xlsx') {
                             $doc = Document\Xlsx::loadXlsxFile($path);
                             //} else if ('application/mspowerpoint' === $mimeType) {
                         } else {
                             if ($fileExtension === 'pptx') {
                                 $doc = Document\Pptx::loadPptxFile($path);
                             } else {
                                 if ($fileExtension === 'odt') {
                                     $doc = Odt::loadOdtFile($path);
                                 } else {
                                     if ($fileExtension === 'ods') {
                                         $doc = Ods::loadOdsFile($path);
                                     } else {
                                         throw new NotIndexedException();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Store filecache id as unique id to lookup by when deleting
     $doc->addField(Document\Field::Keyword('fileId', $file->getId()));
     // Store document path for the search results
     $doc->addField(Document\Field::Text('path', $file->getPath(), 'UTF-8'));
     $doc->addField(Document\Field::unIndexed('mtime', $file->getMTime()));
     $doc->addField(Document\Field::unIndexed('size', $file->getSize()));
     $doc->addField(Document\Field::unIndexed('mimetype', $mimeType));
     $this->index->updateFile($doc, $file->getId(), $commit);
     return true;
 }
Example #8
0
 /**
  * @param File $file
  */
 public function addAttachmentFromFiles(File $file)
 {
     $part = new Horde_Mime_Part();
     $part->setCharset('us-ascii');
     $part->setDisposition('attachment');
     $part->setName($file->getName());
     $part->setContents($file->getContent());
     $part->setType($file->getMimeType());
     $this->attachments[] = $part;
 }