‪TYPO3CMS  10.4
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 {
32  public function ‪canExtractText(‪FileInterface $file)
33  {
34  $canExtract = false;
35 
36  if ($file->‪getMimeType() === 'text/plain') {
37  $canExtract = true;
38  }
39 
40  return $canExtract;
41  }
42 
49  public function ‪extractText(‪FileInterface $file)
50  {
51  $localTempFile = $file->‪getForLocalProcessing(false);
52 
53  // extract text
54  $content = (string)file_get_contents($localTempFile);
55 
56  // In case of remote storage, the temporary copy of the
57  // original file in typo3temp must be removed
58  // Simply compare the filenames, because the filename is so unique that
59  // it is nearly impossible to have a file with this name in a storage
60  if (‪PathUtility::basename($localTempFile) !== $file->‪getName()) {
61  unlink($localTempFile);
62  }
63 
64  return $content;
65  }
66 }
‪TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor\canExtractText
‪bool canExtractText(FileInterface $file)
Definition: PlainTextExtractor.php:32
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:24
‪TYPO3\CMS\Core\Resource\FileInterface\getForLocalProcessing
‪string getForLocalProcessing($writable=true)
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static string basename($path)
Definition: PathUtility.php:165
‪TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor\extractText
‪string extractText(FileInterface $file)
Definition: PlainTextExtractor.php:49
‪TYPO3\CMS\Core\Resource\ResourceInterface\getName
‪string getName()
‪TYPO3\CMS\Core\Resource\TextExtraction
Definition: PlainTextExtractor.php:16
‪TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor
Definition: PlainTextExtractor.php:25
‪TYPO3\CMS\Core\Resource\FileInterface\getMimeType
‪string getMimeType()