‪TYPO3CMS  ‪main
PlainTextExtractor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
31  public function ‪canExtractText(‪FileInterface $file)
32  {
33  $canExtract = false;
34 
35  if ($file->getMimeType() === 'text/plain') {
36  $canExtract = true;
37  }
38 
39  return $canExtract;
40  }
41 
47  public function ‪extractText(‪FileInterface $file)
48  {
49  $localTempFile = $file->getForLocalProcessing(false);
50 
51  // extract text
52  $content = (string)file_get_contents($localTempFile);
53 
54  // In case of remote storage, the temporary copy of the
55  // original file in typo3temp must be removed
56  // Simply compare the filenames, because the filename is so unique that
57  // it is nearly impossible to have a file with this name in a storage
58  if (‪PathUtility::basename($localTempFile) !== $file->‪getName()) {
59  unlink($localTempFile);
60  }
61 
62  return $content;
63  }
64 }
‪TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor\canExtractText
‪bool canExtractText(FileInterface $file)
Definition: PlainTextExtractor.php:31
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:26
‪TYPO3\CMS\Core\Resource\ResourceInterface\getName
‪getName()
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:24
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static basename(string $path)
Definition: PathUtility.php:219
‪TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor\extractText
‪string extractText(FileInterface $file)
Definition: PlainTextExtractor.php:47
‪TYPO3\CMS\Core\Resource\TextExtraction
Definition: PlainTextExtractor.php:16
‪TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor
Definition: PlainTextExtractor.php:25