Commit 0349d41a authored by dj3c1t's avatar dj3c1t

waveform generation: check if url is local file

parent dea4e098
......@@ -72,26 +72,36 @@ class SourceWaveform {
return;
}
foreach($documents as $document) {
if(
($media = $document->getMedia())
&& ($this->isAudioMimeType($media->getMimeType()))
) {
$localAudioFile = false;
if($media = $document->getMedia()) {
$localAudioFile = $mediasDir.$media->getName();
}
else {
$localAudioFile = $this->getLocalFile($document->getUrl());
}
if($localAudioFile) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$localAdioFileMimeType = finfo_file($finfo, $localAudioFile);
finfo_close($finfo);
if(!$this->isAudioMimeType($localAdioFileMimeType)) {
continue;
}
$this->makeWaveformsDir();
$pngFile = $this->waveformDir."/".$source->getId().".png";
$sw->audioToPng(
$mediasDir.$media->getName(),
$localAudioFile,
$mediasDir.$pngFile,
array(
"foreground" => "#555555"
)
);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $mediasDir.$pngFile);
$pngFileMimeType = finfo_file($finfo, $mediasDir.$pngFile);
finfo_close($finfo);
$media = new Media();
$media->setName($pngFile);
$media->setSize(filesize($mediasDir.$pngFile));
$media->setMimeType($mime_type ? $mime_type : "");
$media->setMimeType($pngFileMimeType ? $pngFileMimeType : "");
$em->persist($media);
$source->setWaveform($media);
return;
......@@ -118,4 +128,24 @@ class SourceWaveform {
}
}
public function getLocalFile($url) {
$v_url = explode("/", $url);
if(count($v_url) < 4 || !$v_url[2] || !$v_url[3]) {
return false;
}
$em = $this->container->get('doctrine')->getManager();
$configurationRepo = $em->getRepository("Dj3c1tAppBundle:Configuration");
if($v_url[2] != $configurationRepo->getConfigurationByName("install_domain")) {
return false;
}
$localFile = $_SERVER['DOCUMENT_ROOT'];
for($i = 3; $i < count($v_url); $i++) {
$localFile .= "/".$v_url[$i];
}
if(!file_exists($localFile)) {
return false;
}
return $localFile;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment