/** * load text file * * @NoAdminRequired * * @param string $dir * @param string $filename * @return DataResponse */ public function load($dir, $filename) { try { if (!empty($filename)) { $path = $dir . '/' . $filename; $filecontents = $this->view->file_get_contents($path); if ($filecontents !== false) { $writable = $this->view->isUpdatable($path); $mime = $this->view->getMimeType($path); $mtime = $this->view->filemtime($path); $encoding = mb_detect_encoding($filecontents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true); if ($encoding == "") { // set default encoding if it couldn't be detected $encoding = 'ISO-8859-15'; } $filecontents = iconv($encoding, "UTF-8", $filecontents); return new DataResponse(['filecontents' => $filecontents, 'writeable' => $writable, 'mime' => $mime, 'mtime' => $mtime], Http::STATUS_OK); } else { return new DataResponse(['message' => (string) $this->l->t('Can not read the file.')], Http::STATUS_BAD_REQUEST); } } else { return new DataResponse(['message' => (string) $this->l->t('Invalid file path supplied.')], Http::STATUS_BAD_REQUEST); } } catch (\Exception $e) { $hint = method_exists($e, 'getHint') ? $e->getHint() : $e->getMessage(); return new DataResponse(['message' => (string) $hint], Http::STATUS_BAD_REQUEST); } }
/** * Gets all versions of a note * * @NoAdminRequired * @NoCSRFRequired * @CORS * * @return array */ public function getAllVersions() { $source = $this->request->getParam("file_name", ""); list($uid, $filename) = Storage::getUidAndFilename($source); $versions = Storage::getVersions($uid, $filename, $source); $versionsResults = array(); if (is_array($versions) && count($versions) > 0) { require_once __DIR__ . '/../3rdparty/finediff/finediff.php'; $users_view = new View('/' . $uid); $currentData = $users_view->file_get_contents('files/' . $filename); // $previousData = $currentData; // $versions = array_reverse( $versions, true ); foreach ($versions as $versionData) { // get timestamp of version $mtime = (int) $versionData["version"]; // get filename of note version $versionFileName = 'files_versions/' . $filename . '.v' . $mtime; // load the data from the file $data = $users_view->file_get_contents($versionFileName); // calculate diff between versions $opcodes = \FineDiff::getDiffOpcodes($currentData, $data); $html = \FineDiff::renderDiffToHTMLFromOpcodes($currentData, $opcodes); $versionsResults[] = array("timestamp" => $mtime, "humanReadableTimestamp" => $versionData["humanReadableTimestamp"], "diffHtml" => $html, "data" => $data); // $previousData = $data; } // $versionsResults = array_reverse( $versionsResults ); } return array("file_name" => $source, "versions" => $versionsResults); }
/** * get the users avatar * @param int $size size in px of the avatar, avatars are square, defaults to 64 * @return boolean|\OCP\IImage containing the avatar or false if there's no image */ public function get($size = 64) { if ($this->view->file_exists('avatar.jpg')) { $ext = 'jpg'; } elseif ($this->view->file_exists('avatar.png')) { $ext = 'png'; } else { return false; } $avatar = new OC_Image(); $avatar->loadFromData($this->view->file_get_contents('avatar.' . $ext)); $avatar->resize($size); return $avatar; }
/** * create the certificate bundle of all trusted certificated */ protected function createCertificateBundle() { $path = $this->getPathToCertificates(); $certs = $this->listCertificates(); $fh_certs = $this->view->fopen($path . '/rootcerts.crt', 'w'); foreach ($certs as $cert) { $file = $path . '/uploads/' . $cert->getName(); $data = $this->view->file_get_contents($file); if (strpos($data, 'BEGIN CERTIFICATE')) { fwrite($fh_certs, $data); fwrite($fh_certs, "\r\n"); } } fclose($fh_certs); }
/** * @medium * test if stream wrapper can read files outside from the data folder */ function testStreamFromLocalFile() { $filename = '/' . $this->userId . '/files/' . 'tmp-' . $this->getUniqueID() . '.txt'; $tmpFilename = "/tmp/" . $this->getUniqueID() . ".txt"; // write an encrypted file $cryptedFile = $this->view->file_put_contents($filename, $this->dataShort); // Test that data was successfully written $this->assertTrue(is_int($cryptedFile)); // create a copy outside of the data folder in /tmp $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $encryptedContent = $this->view->file_get_contents($filename); \OC_FileProxy::$enabled = $proxyStatus; file_put_contents($tmpFilename, $encryptedContent); \OCA\Files_Encryption\Helper::addTmpFileToMapper($tmpFilename, $filename); // try to read the file from /tmp $handle = fopen("crypt://" . $tmpFilename, "r"); $contentFromTmpFile = stream_get_contents($handle); // check if it was successful $this->assertEquals($this->dataShort, $contentFromTmpFile); fclose($handle); // clean up unlink($tmpFilename); $this->view->unlink($filename); }
/** * @medium * Test that data that is written by the crypto stream wrapper with AES 128 * @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read * @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual * reassembly of its data */ public function testStreamDecryptLongFileContentWithoutHeader() { // Generate a a random filename $filename = 'tmp-' . $this->getUniqueID() . '.test'; $this->config->setSystemValue('cipher', 'AES-128-CFB'); // Save long data as encrypted file using stream wrapper $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong); $this->config->deleteSystemValue('cipher'); // Test that data was successfully written $this->assertTrue(is_int($cryptedFile)); // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // Get file contents without using any wrapper to get it's actual contents on disk $retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename); // Check that the file was encrypted before being written to disk $this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile); // remove the header to check if we can also decrypt old files without a header, // this files should fall back to AES-128 $cryptedWithoutHeader = substr($retreivedCryptedFile, \OCA\Files_Encryption\Crypt::BLOCKSIZE); $this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader); // Re-enable proxy - our work is done \OC_FileProxy::$enabled = $proxyStatus; $decrypted = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename); $this->assertEquals($this->dataLong . $this->dataLong, $decrypted); // Teardown $this->view->unlink($this->userId . '/files/' . $filename); }
private function doTestRestore() { $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt'; $this->rootView->file_put_contents($filePath, 'test file'); $t0 = $this->rootView->filemtime($filePath); // not exactly the same timestamp as the file $t1 = time() - 60; // second version is two weeks older $t2 = $t1 - 60 * 60 * 24 * 14; // create some versions $v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1; $v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2; $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub'); $this->rootView->file_put_contents($v1, 'version1'); $this->rootView->file_put_contents($v2, 'version2'); $oldVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt'); $this->assertCount(2, $oldVersions); $this->assertEquals('test file', $this->rootView->file_get_contents($filePath)); $info1 = $this->rootView->getFileInfo($filePath); \OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2); $this->assertEquals('version2', $this->rootView->file_get_contents($filePath)); $info2 = $this->rootView->getFileInfo($filePath); $this->assertNotEquals($info2['etag'], $info1['etag'], 'Etag must change after rolling back version'); $this->assertEquals($info2['fileid'], $info1['fileid'], 'File id must not change after rolling back version'); $this->assertEquals($info2['mtime'], $t2, 'Restored file has mtime from version'); $newVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt'); $this->assertTrue($this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), 'A version file was created for the file before restoration'); $this->assertTrue($this->rootView->file_exists($v1), 'Untouched version file is still there'); $this->assertFalse($this->rootView->file_exists($v2), 'Restored version file gone from files_version folder'); $this->assertCount(2, $newVersions, 'Additional version created'); $this->assertTrue(isset($newVersions[$t0 . '#' . 'test.txt']), 'A version was created for the file before restoration'); $this->assertTrue(isset($newVersions[$t1 . '#' . 'test.txt']), 'Untouched version is still there'); $this->assertFalse(isset($newVersions[$t2 . '#' . 'test.txt']), 'Restored version is not in the list any more'); }
/** * create the certificate bundle of all trusted certificated */ public function createCertificateBundle() { $path = $this->getPathToCertificates(); $certs = $this->listCertificates(); if (!$this->view->file_exists($path)) { $this->view->mkdir($path); } $fhCerts = $this->view->fopen($path . '/rootcerts.crt', 'w'); // Write user certificates foreach ($certs as $cert) { $file = $path . '/uploads/' . $cert->getName(); $data = $this->view->file_get_contents($file); if (strpos($data, 'BEGIN CERTIFICATE')) { fwrite($fhCerts, $data); fwrite($fhCerts, "\r\n"); } } // Append the default certificates $defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); fwrite($fhCerts, $defaultCertificates); // Append the system certificate bundle $systemBundle = $this->getCertificateBundle(null); if ($this->view->file_exists($systemBundle)) { $systemCertificates = $this->view->file_get_contents($systemBundle); fwrite($fhCerts, $systemCertificates); } fclose($fhCerts); }
/** * Tests if a preview of max dimensions gets created * * @dataProvider dimensionsDataProvider * * @param int $sampleId * @param int $widthAdjustment * @param int $heightAdjustment * @param bool $keepAspect * @param bool $scalingUp */ public function testCreateMaxAndNormalPreviewsAtFirstRequest( $sampleId, $widthAdjustment, $heightAdjustment, $keepAspect = false, $scalingUp = false ) { //$this->markTestSkipped('Not testing this at this time'); // Get the right sample for the experiment $this->getSample($sampleId); $sampleWidth = $this->sampleWidth; $sampleHeight = $this->sampleHeight; $sampleFileId = $this->sampleFileId; // Adjust the requested size so that we trigger various test cases $previewWidth = $sampleWidth + $widthAdjustment; $previewHeight = $sampleHeight + $heightAdjustment; $this->keepAspect = $keepAspect; $this->scalingUp = $scalingUp; // Generates the max preview $preview = $this->createPreview($previewWidth, $previewHeight); // There should be no cached thumbnails $thumbnailFolder = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $sampleFileId; $this->assertSame(false, $this->rootView->is_dir($thumbnailFolder)); $image = $preview->getPreview(); $this->assertNotSame(false, $image); $maxThumbCacheFile = $this->buildCachePath( $sampleFileId, $this->maxPreviewWidth, $this->maxPreviewHeight, true, '-max' ); $this->assertSame( true, $this->rootView->file_exists($maxThumbCacheFile), "$maxThumbCacheFile \n" ); // We check the dimensions of the file we've just stored $maxPreview = imagecreatefromstring($this->rootView->file_get_contents($maxThumbCacheFile)); $this->assertEquals($this->maxPreviewWidth, imagesx($maxPreview)); $this->assertEquals($this->maxPreviewHeight, imagesy($maxPreview)); // A thumbnail of the asked dimensions should also have been created (within the constraints of the max preview) list($limitedPreviewWidth, $limitedPreviewHeight) = $this->simulatePreviewDimensions($previewWidth, $previewHeight); $actualWidth = $image->width(); $actualHeight = $image->height(); $this->assertEquals( (int)$limitedPreviewWidth, $image->width(), "$actualWidth x $actualHeight \n" ); $this->assertEquals((int)$limitedPreviewHeight, $image->height()); // And it should be cached $this->checkCache($sampleFileId, $limitedPreviewWidth, $limitedPreviewHeight); $preview->deleteAllPreviews(); }
/** * load text file * * @NoAdminRequired * * @param string $dir * @param string $filename * @return DataResponse */ public function load($dir, $filename) { try { if (!empty($filename)) { $path = $dir . '/' . $filename; // default of 4MB $maxSize = 4194304; if ($this->view->filesize($path) > $maxSize) { return new DataResponse(['message' => (string) $this->l->t('This file is too big to be opened. Please download the file instead.')], Http::STATUS_BAD_REQUEST); } $fileContents = $this->view->file_get_contents($path); if ($fileContents !== false) { $writable = $this->view->isUpdatable($path); $mime = $this->view->getMimeType($path); $mTime = $this->view->filemtime($path); $encoding = mb_detect_encoding($fileContents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true); if ($encoding == "") { // set default encoding if it couldn't be detected $encoding = 'ISO-8859-15'; } $fileContents = iconv($encoding, "UTF-8", $fileContents); return new DataResponse(['filecontents' => $fileContents, 'writeable' => $writable, 'mime' => $mime, 'mtime' => $mTime], Http::STATUS_OK); } else { return new DataResponse(['message' => (string) $this->l->t('Cannot read the file.')], Http::STATUS_BAD_REQUEST); } } else { return new DataResponse(['message' => (string) $this->l->t('Invalid file path supplied.')], Http::STATUS_BAD_REQUEST); } } catch (LockedException $e) { $message = (string) $this->l->t('The file is locked.'); return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); } catch (ForbiddenException $e) { return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } catch (HintException $e) { $message = (string) $e->getHint(); return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); } catch (\Exception $e) { $message = (string) $this->l->t('An internal server error occurred.'); return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); } }
/** * @brief retrieve the ENCRYPTED private key from a user * * @param \OC\Files\View $view * @param string $user * @return string private key or false (hopefully) * @note the key returned by this method must be decrypted before use */ public static function getPrivateKey($view, $user) { $path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key'; $key = false; $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; if ($view->file_exists($path)) { $key = $view->file_get_contents($path); } \OC_FileProxy::$enabled = $proxyStatus; return $key; }
/** * read key from hard disk * * @param string $path to key * @return string */ private function getKey($path) { $key = ''; if ($this->view->file_exists($path)) { if (isset($this->keyCache[$path])) { $key = $this->keyCache[$path]; } else { $key = $this->view->file_get_contents($path); $this->keyCache[$path] = $key; } } return $key; }
/** * Test that data that is read by the crypto stream wrapper */ function testGetFileSize() { self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1); $filename = 'tmp-' . $this->getUniqueID(); $externalFilename = '/' . $this->userId . '/files/' . $filename; // Test for 0 byte files $problematicFileSizeData = ""; $cryptedFile = $this->view->file_put_contents($externalFilename, $problematicFileSizeData); $this->assertTrue(is_int($cryptedFile)); $this->assertEquals($this->util->getFileSize($externalFilename), 0); $decrypt = $this->view->file_get_contents($externalFilename); $this->assertEquals($problematicFileSizeData, $decrypt); $this->view->unlink($this->userId . '/files/' . $filename); // Test a file with 18377 bytes as in https://github.com/owncloud/mirall/issues/1009 $problematicFileSizeData = str_pad("", 18377, "abc"); $cryptedFile = $this->view->file_put_contents($externalFilename, $problematicFileSizeData); $this->assertTrue(is_int($cryptedFile)); $this->assertEquals($this->util->getFileSize($externalFilename), 18377); $decrypt = $this->view->file_get_contents($externalFilename); $this->assertEquals($problematicFileSizeData, $decrypt); $this->view->unlink($this->userId . '/files/' . $filename); }
/** * test rename a shared file mount point */ function testRename() { // login as admin self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); // save file with content $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); // test that data was successfully written $this->assertInternalType('int', $cryptedFile); // get the file info from previous created file $fileInfo = $this->view->getFileInfo('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo); // share the file \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL); // check if share key for user1 and user2 exists $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // login as user2 self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2); $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename)); // get file contents $retrievedCryptedFile = $this->view->file_get_contents('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedCryptedFile); \OC\Files\Filesystem::mkdir($this->folder1); // move the file to a subfolder \OC\Files\Filesystem::rename($this->filename, $this->folder1 . $this->filename); // check if we can read the moved file $retrievedRenamedFile = $this->view->file_get_contents('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename); // check if data is the same as we previously written $this->assertEquals($this->dataShort, $retrievedRenamedFile); // check if share key for user2 and user1 still exists $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); // cleanup self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1); $this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); }
/** * test webdav put random file */ function testWebdavPUT() { // generate filename $filename = '/tmp-' . uniqid() . '.txt'; // set server vars $_SERVER['REQUEST_METHOD'] = 'OPTIONS'; $_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename; $_SERVER['HTTP_AUTHORIZATION'] = 'Basic dGVzdC13ZWJkYXYtdXNlcjE6dGVzdC13ZWJkYXYtdXNlcjE='; $_SERVER['CONTENT_TYPE'] = 'application/octet-stream'; $_SERVER['PATH_INFO'] = '/webdav' . $filename; $_SERVER['CONTENT_LENGTH'] = strlen($this->dataShort); // handle webdav request $this->handleWebdavRequest($this->dataShort); // check if file was created $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files' . $filename)); // check if key-file was created $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key')); // check if shareKey-file was created $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey')); // disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // get encrypted file content $encryptedContent = $this->view->file_get_contents('/' . $this->userId . '/files' . $filename); // restore proxy state \OC_FileProxy::$enabled = $proxyStatus; // check if encrypted content is valid $this->assertTrue(Encryption\Crypt::isCatfileContent($encryptedContent)); // get decrypted file contents $decrypt = file_get_contents('crypt:///' . $this->userId . '/files' . $filename); // check if file content match with the written content $this->assertEquals($this->dataShort, $decrypt); // return filename for next test return $filename; }
/** * retrieve shareKey for an encrypted file * @param \OC\Files\View $view * @param string $userId * @param \OCA\Encryption\Util $util * @param string $filePath * @return string file key or false * @note The sharekey returned is encrypted. Decryption * of the keyfile must be performed by client code */ public static function getShareKey(\OC\Files\View $view, $userId, $util, $filePath) { // try reusing key file if part file $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; list($owner, $filename) = $util->getUidAndFilename($filePath); $filename = Helper::stripPartialFileExtension($filename); // in case of system wide mount points the keys are stored directly in the data directory if ($util->isSystemWideMountPoint($filename)) { $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; } else { $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; } if ($view->file_exists($shareKeyPath)) { $result = $view->file_get_contents($shareKeyPath); } else { $result = false; } \OC_FileProxy::$enabled = $proxyStatus; return $result; }
/** * extract the metadata from a file * * uses getid3 to extract metadata. * if possible also adds content (currently only for plain text files) * hint: use OC\Files\Filesystem::getFileInfo($path) to get metadata for the last param * * @author Jörn Dreyer <*****@*****.**> * * @param Zend_Search_Lucene_Document $doc to add the metadata to * @param string $path path of the file to extract metadata from * @param string $mimetype depending on the mimetype different extractions are performed * * @return void */ private static function extractMetadata(\Zend_Search_Lucene_Document $doc, $path, \OC\Files\View $view, $mimetype) { $file = $view->getLocalFile($path); if (is_dir($file)) { // Don't lose time analizing a directory for file-specific metadata return; } $getID3 = new \getID3(); $getID3->encoding = 'UTF-8'; $data = $getID3->analyze($file); // TODO index meta information from media files? //show me what you got /*foreach ($data as $key => $value) { Util::writeLog('search_lucene', 'getid3 extracted '.$key.': '.$value, Util::DEBUG); if (is_array($value)) { foreach ($value as $k => $v) { Util::writeLog('search_lucene', ' ' . $value .'-' .$k.': '.$v, Util::DEBUG); } } }*/ if ('application/pdf' === $mimetype) { try { $zendpdf = \Zend_Pdf::parse($view->file_get_contents($path)); //we currently only display the filename, so we only index metadata here if (isset($zendpdf->properties['Title'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('title', $zendpdf->properties['Title'])); } if (isset($zendpdf->properties['Author'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('author', $zendpdf->properties['Author'])); } if (isset($zendpdf->properties['Subject'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('subject', $zendpdf->properties['Subject'])); } if (isset($zendpdf->properties['Keywords'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('keywords', $zendpdf->properties['Keywords'])); } //TODO handle PDF 1.6 metadata Zend_Pdf::getMetadata() //do the content extraction $pdfParse = new \App_Search_Helper_PdfParser(); $body = $pdfParse->pdf2txt($zendpdf->render()); } catch (Exception $e) { Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR); } } if ($body != '') { $doc->addField(\Zend_Search_Lucene_Field::UnStored('body', $body)); } if (isset($data['error'])) { Util::writeLog('search_lucene', 'failed to extract meta information for ' . $view->getAbsolutePath($path) . ': ' . $data['error']['0'], Util::WARN); return; } }
/** * @return string */ public static function file_get_contents($path) { return self::$defaultInstance->file_get_contents($path); }
protected function idtoDom($id) { $id = (int) $id; $view = new \OC\Files\View(''); //! need root ? $path = $view->getPath($id); $DOM = new GpxDOM(); $DOM->loadXML($view->file_get_contents($path)); return $DOM; }