don't display binary data

This commit is contained in:
aina-esokia
2018-02-12 14:43:36 +04:00
parent 431ae31945
commit 9018254602
2 changed files with 53 additions and 13 deletions

View File

@@ -23,6 +23,9 @@ use Alchemy\Phrasea\Record\RecordWasRotated;
use DataURI\Parser;
use MediaAlchemyst\Alchemyst;
use MediaVorus\MediaVorus;
use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
use PHPExiftool\Driver\TagFactory;
use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException;
use PHPExiftool\Reader;
use Symfony\Component\HttpFoundation\Request;
@@ -82,12 +85,12 @@ class ToolsController extends Controller
);
}
}
if (!$record->isStory()) {
try {
$metadata = $this->getExifToolReader()
$metadatas = $this->getExifToolReader()
->files($record->get_subdef('document')->getRealPath())
->first()->getMetadatas();
$metadatas = $this->getNoBinaryMetadataValue($metadatas, $record);
} catch (PHPExiftoolException $e) {
// ignore
} catch (\Exception_Media_SubdefNotFound $e) {
@@ -102,7 +105,7 @@ class ToolsController extends Controller
'record' => $record,
'videoEditorConfig' => $conf->get(['video-editor']),
'recordSubdefs' => $recordAccessibleSubdefs,
'metadatas' => $metadata,
'metadatas' => $metadatas,
]);
}
@@ -433,4 +436,28 @@ class ToolsController extends Controller
unset($media);
$this->getFilesystem()->remove($fileName);
}
/**
* @param MetadataBag $metadatas
* @param $record
* @return MetadataBag
*/
private function getNoBinaryMetadataValue(MetadataBag $metadatas, $record)
{
$metadataBag = new MetadataBag();
$fileEntity = $this->getExifToolReader()
->files($record->get_subdef('document')->getRealPath())
->first();
foreach($metadatas as $metadata){
$valuedata = $fileEntity->executeQuery($metadata->getTag()->getTagname()."[not(@rdf:datatype = 'http://www.w3.org/2001/XMLSchema#base64Binary')]");
if(!empty($valuedata)){
$tag = TagFactory::getFromRDFTagname($metadata->getTag()->getTagname());
$metadataBagElement = new Metadata($tag, $valuedata);
$metadataBag->set($metadata->getTag()->getTagname(), $metadataBagElement);
}
}
return $metadataBag;
}
}