TYPO3 CMS  TYPO3_8-7
PlainTextExtractor.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
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 
48  public function extractText(FileInterface $file)
49  {
50  $localTempFile = $file->getForLocalProcessing(false);
51 
52  // extract text
53  $content = file_get_contents($localTempFile);
54 
55  // In case of remote storage, the temporary copy of the
56  // original file in typo3temp must be removed
57  // Simply compare the filenames, because the filename is so unique that
58  // it is nearly impossible to have a file with this name in a storage
59  if (PathUtility::basename($localTempFile) !== $file->getName()) {
60  unlink($localTempFile);
61  }
62 
63  return $content;
64  }
65 }