mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 21:43:18 +00:00
Merge branch '3.8'
This commit is contained in:
@@ -81,6 +81,7 @@ main:
|
|||||||
client_secret: null
|
client_secret: null
|
||||||
border-manager:
|
border-manager:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
extension-mapping: { }
|
||||||
checkers:
|
checkers:
|
||||||
-
|
-
|
||||||
type: Checker\Sha256
|
type: Checker\Sha256
|
||||||
|
@@ -121,10 +121,6 @@ use Monolog\Logger;
|
|||||||
use Monolog\Processor\IntrospectionProcessor;
|
use Monolog\Processor\IntrospectionProcessor;
|
||||||
use Neutron\Silex\Provider\ImagineServiceProvider;
|
use Neutron\Silex\Provider\ImagineServiceProvider;
|
||||||
use MediaVorus\MediaVorusServiceProvider;
|
use MediaVorus\MediaVorusServiceProvider;
|
||||||
use MediaVorus\Utils\RawImageMimeTypeGuesser;
|
|
||||||
use MediaVorus\Utils\PostScriptMimeTypeGuesser;
|
|
||||||
use MediaVorus\Utils\AudioMimeTypeGuesser;
|
|
||||||
use MediaVorus\Utils\VideoMimeTypeGuesser;
|
|
||||||
use MediaAlchemyst\MediaAlchemystServiceProvider;
|
use MediaAlchemyst\MediaAlchemystServiceProvider;
|
||||||
use Monolog\Handler\NullHandler;
|
use Monolog\Handler\NullHandler;
|
||||||
use MP4Box\MP4BoxServiceProvider;
|
use MP4Box\MP4BoxServiceProvider;
|
||||||
@@ -151,8 +147,6 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
|||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
|
||||||
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
use Symfony\Component\Routing\Generator\UrlGenerator;
|
||||||
use Symfony\Component\Form\FormFactory;
|
use Symfony\Component\Form\FormFactory;
|
||||||
@@ -476,14 +470,6 @@ class Application extends SilexApplication
|
|||||||
$this->mount('/permalink/', new Permalink());
|
$this->mount('/permalink/', new Permalink());
|
||||||
$this->mount('/lightbox/', new Lightbox());
|
$this->mount('/lightbox/', new Lightbox());
|
||||||
|
|
||||||
$guesser = MimeTypeGuesser::getInstance();
|
|
||||||
|
|
||||||
$guesser->register(new FileBinaryMimeTypeGuesser());
|
|
||||||
$guesser->register(new RawImageMimeTypeGuesser());
|
|
||||||
$guesser->register(new PostScriptMimeTypeGuesser());
|
|
||||||
$guesser->register(new AudioMimeTypeGuesser());
|
|
||||||
$guesser->register(new VideoMimeTypeGuesser());
|
|
||||||
|
|
||||||
$app['plugins.directory'] = $app->share(function () {
|
$app['plugins.directory'] = $app->share(function () {
|
||||||
$dir = __DIR__ . '/../../../plugins';
|
$dir = __DIR__ . '/../../../plugins';
|
||||||
|
|
||||||
|
36
lib/Alchemy/Phrasea/Border/CustomExtensionGuesser.php
Normal file
36
lib/Alchemy/Phrasea/Border/CustomExtensionGuesser.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2014 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Border;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
|
||||||
|
|
||||||
|
class CustomExtensionGuesser implements MimeTypeGuesserInterface
|
||||||
|
{
|
||||||
|
private $mapping;
|
||||||
|
|
||||||
|
public function __construct(array $mapping)
|
||||||
|
{
|
||||||
|
$this->mapping = $mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function guess($path)
|
||||||
|
{
|
||||||
|
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
if (isset($this->mapping[$extension])) {
|
||||||
|
return $this->mapping[$extension];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
lib/Alchemy/Phrasea/Border/MimeGuesserConfiguration.php
Normal file
52
lib/Alchemy/Phrasea/Border/MimeGuesserConfiguration.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2014 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Border;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\Configuration\Configuration;
|
||||||
|
use MediaVorus\Utils\AudioMimeTypeGuesser;
|
||||||
|
use MediaVorus\Utils\PostScriptMimeTypeGuesser;
|
||||||
|
use MediaVorus\Utils\RawImageMimeTypeGuesser;
|
||||||
|
use MediaVorus\Utils\VideoMimeTypeGuesser;
|
||||||
|
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
||||||
|
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||||
|
|
||||||
|
class MimeGuesserConfiguration
|
||||||
|
{
|
||||||
|
private $conf;
|
||||||
|
|
||||||
|
public function __construct(Configuration $conf)
|
||||||
|
{
|
||||||
|
$this->conf = $conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers mime type guessers given the configuration
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$guesser = MimeTypeGuesser::getInstance();
|
||||||
|
|
||||||
|
$guesser->register(new FileBinaryMimeTypeGuesser());
|
||||||
|
$guesser->register(new RawImageMimeTypeGuesser());
|
||||||
|
$guesser->register(new PostScriptMimeTypeGuesser());
|
||||||
|
$guesser->register(new AudioMimeTypeGuesser());
|
||||||
|
$guesser->register(new VideoMimeTypeGuesser());
|
||||||
|
|
||||||
|
if ($this->conf->isSetup()) {
|
||||||
|
$conf = $this->conf->getConfig();
|
||||||
|
|
||||||
|
if (isset($conf['border-manager']['extension-mapping']) && is_array($conf['border-manager']['extension-mapping'])) {
|
||||||
|
$guesser->register(new CustomExtensionGuesser($conf['border-manager']['extension-mapping']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -12,6 +12,7 @@
|
|||||||
namespace Alchemy\Phrasea\Core\Provider;
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Border\Manager;
|
use Alchemy\Phrasea\Border\Manager;
|
||||||
|
use Alchemy\Phrasea\Border\MimeGuesserConfiguration;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
use XPDF\Exception\BinaryNotFoundException;
|
use XPDF\Exception\BinaryNotFoundException;
|
||||||
@@ -97,9 +98,14 @@ class BorderManagerServiceProvider implements ServiceProviderInterface
|
|||||||
|
|
||||||
return $borderManager;
|
return $borderManager;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app['border-manager.mime-guesser-configuration'] = $app->share(function (Application $app) {
|
||||||
|
return new MimeGuesserConfiguration($app['phraseanet.configuration']);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(Application $app)
|
public function boot(Application $app)
|
||||||
{
|
{
|
||||||
|
$app['border-manager.mime-guesser-configuration']->register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -84,6 +84,7 @@ debugger:
|
|||||||
allowed-ips: []
|
allowed-ips: []
|
||||||
border-manager:
|
border-manager:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
extension-mapping: { }
|
||||||
checkers:
|
checkers:
|
||||||
-
|
-
|
||||||
type: Checker\Sha256
|
type: Checker\Sha256
|
||||||
|
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Tests\Phrasea\Border;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Border\CustomExtensionGuesser;
|
||||||
|
|
||||||
|
class CustomExtensionGuesserTest extends \PhraseanetPHPUnitAbstract
|
||||||
|
{
|
||||||
|
public function testGuess()
|
||||||
|
{
|
||||||
|
$conf = array(
|
||||||
|
'mpeg' => 'video/x-romain-neutron',
|
||||||
|
);
|
||||||
|
|
||||||
|
$guesser = new CustomExtensionGuesser($conf);
|
||||||
|
$this->assertNull($guesser->guess(__FILE__));
|
||||||
|
$this->assertEquals('video/x-romain-neutron', $guesser->guess('/path/to/video.mpeg'));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user