diff --git a/.travis.yml b/.travis.yml index a93fc0c..1d00e86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,14 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm matrix: allow_failures: - php: - - 5.6 - hhvm + - 7.0 fast_finish: true install: diff --git a/Bridge/ElFinderBridge.php b/Bridge/ElFinderBridge.php index 33da06b..ae3bf31 100644 --- a/Bridge/ElFinderBridge.php +++ b/Bridge/ElFinderBridge.php @@ -6,10 +6,9 @@ use FM\ElFinderPHP\Driver\ElFinderVolumeDriver; /** - * Class ElFinderBridge + * Class ElFinderBridge. * * Use Symfony services as regular VolumeDrivers. - * */ class ElFinderBridge extends ElFinder { diff --git a/Configuration/ElFinderConfigurationReader.php b/Configuration/ElFinderConfigurationReader.php index 5638231..955c449 100644 --- a/Configuration/ElFinderConfigurationReader.php +++ b/Configuration/ElFinderConfigurationReader.php @@ -21,18 +21,17 @@ use Barracuda\Copy\API; /** - * Class ElFinderConfigurationReader - * @package FM\ElfinderBundle\Configuration + * Class ElFinderConfigurationReader. */ class ElFinderConfigurationReader implements ElFinderConfigurationProviderInterface { /** - * @var array $options + * @var array */ protected $options = array(); /** - * @var array $parameters + * @var array */ protected $parameters; @@ -49,7 +48,7 @@ class ElFinderConfigurationReader implements ElFinderConfigurationProviderInterf /** * @param $parameters * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack - * @param ContainerInterface $container + * @param ContainerInterface $container */ public function __construct($parameters, RequestStack $requestStack, ContainerInterface $container) { @@ -60,29 +59,30 @@ public function __construct($parameters, RequestStack $requestStack, ContainerIn /** * @param $instance + * * @return array */ public function getConfiguration($instance) { - $request = $this->requestStack->getCurrentRequest(); - $efParameters = $this->parameters; - $parameters = $efParameters['instances'][$instance]; - $options = array(); + $request = $this->requestStack->getCurrentRequest(); + $efParameters = $this->parameters; + $parameters = $efParameters['instances'][$instance]; + $options = array(); $options['corsSupport'] = $parameters['cors_support']; - $options['debug'] = $parameters['connector']['debug']; - $options['bind'] = $parameters['connector']['binds']; - $options['plugins'] = $parameters['connector']['plugins']; - $options['roots'] = array(); + $options['debug'] = $parameters['connector']['debug']; + $options['bind'] = $parameters['connector']['binds']; + $options['plugins'] = $parameters['connector']['plugins']; + $options['roots'] = array(); foreach ($parameters['connector']['roots'] as $parameter) { - $path = $parameter['path']; + $path = $parameter['path']; $homeFolder = $request->attributes->get('homeFolder'); if ($homeFolder !== '') { $homeFolder = '/'.$homeFolder.'/'; } - if($parameter['flysystem']['enabled']) { - $adapter = $parameter['flysystem']['type']; // ftp ex. - $opt = $parameter['flysystem']['options']; + if ($parameter['flysystem']['enabled']) { + $adapter = $parameter['flysystem']['type']; // ftp ex. + $opt = $parameter['flysystem']['options']; $filesystem = $this->configureFlysystem($opt, $adapter); } $driver = $this->container->has($parameter['driver']) ? $this->container->get($parameter['driver']) : null; @@ -93,7 +93,7 @@ public function getConfiguration($instance) 'glideURL' => $parameter['glide_url'], 'glideKey' => $parameter['glide_key'], 'plugin' => $parameter['plugins'], - 'path' => $path . $homeFolder, //removed slash for Flysystem compatibility + 'path' => $path.$homeFolder, //removed slash for Flysystem compatibility 'startPath' => $parameter['start_path'], 'URL' => $this->getURL($parameter, $request, $homeFolder, $path), 'alias' => $parameter['alias'], @@ -123,18 +123,18 @@ public function getConfiguration($instance) 'separator' => $parameter['separator'], 'timeFormat' => $parameter['time_format'], 'archiveMimes' => $parameter['archive_mimes'], - 'archivers' => $parameter['archivers'] + 'archivers' => $parameter['archivers'], ); if ($parameter['volume_id'] > 0) { $driverOptions['id'] = $parameter['volume_id']; } - if(!$parameter['show_hidden']) { + if (!$parameter['show_hidden']) { $driverOptions['accessControl'] = array($this, 'access'); }; - if($parameter['driver'] == 'Flysystem') { + if ($parameter['driver'] == 'Flysystem') { $driverOptions['filesystem'] = $filesystem; } $options['roots'][] = array_merge($driverOptions, $this->configureDriver($parameter)); @@ -148,6 +148,7 @@ public function getConfiguration($instance) * @param $request * @param $homeFolder * @param $path + * * @return string */ private function getURL($parameter, $request, $homeFolder, $path) @@ -162,6 +163,7 @@ private function getURL($parameter, $request, $homeFolder, $path) /** * @param $opt * @param $adapter + * * @return Filesystem */ private function configureFlysystem($opt, $adapter) @@ -176,21 +178,21 @@ private function configureFlysystem($opt, $adapter) 'username' => $opt['ftp']['username'], 'password' => $opt['ftp']['password'], - /** optional config settings */ + /* optional config settings */ 'port' => $opt['ftp']['port'], 'root' => $opt['ftp']['root'], 'passive' => $opt['ftp']['passive'], 'ssl' => $opt['ftp']['ssl'], 'timeout' => $opt['ftp']['timeout'], - 'directoryPerm' => $opt['ftp']['directoryPerm'] + 'directoryPerm' => $opt['ftp']['directoryPerm'], ); - $filesystem = (!$opt['ftp']['sftp']) ? new Filesystem(new Ftp($settings)): new Filesystem(new SftpAdapter($settings)); + $filesystem = (!$opt['ftp']['sftp']) ? new Filesystem(new Ftp($settings)) : new Filesystem(new SftpAdapter($settings)); break; case 'aws_s3_v2': $client = S3Client::factory(array( 'key' => $opt['aws_s3_v2']['key'], 'secret' => $opt['aws_s3_v2']['secret'], - 'region' => $opt['aws_s3_v2']['region'] + 'region' => $opt['aws_s3_v2']['region'], )); $filesystem = new Filesystem(new AwsS3v2($client, $opt['aws_s3_v2']['bucket_name'], $opt['aws_s3_v2']['optional_prefix'])); break; @@ -199,7 +201,7 @@ private function configureFlysystem($opt, $adapter) 'key' => $opt['aws_s3_v3']['key'], 'secret' => $opt['aws_s3_v3']['secret'], 'region' => $opt['aws_s3_v3']['region'], - 'version' => $opt['aws_s3_v3']['version'] + 'version' => $opt['aws_s3_v3']['version'], )); $filesystem = new Filesystem(new AwsS3v3($client, $opt['aws_s3_v3']['bucket_name'], $opt['aws_s3_v3']['optional_prefix'])); break; @@ -214,21 +216,23 @@ private function configureFlysystem($opt, $adapter) break; case 'gridfs': $mongoClient = new MongoClient(); - $gridFs = $mongoClient->selectDB($opt['gridfs']['db_name'])->getGridFS(); - $filesystem = new Filesystem(new GridFSAdapter($gridFs)); + $gridFs = $mongoClient->selectDB($opt['gridfs']['db_name'])->getGridFS(); + $filesystem = new Filesystem(new GridFSAdapter($gridFs)); break; case 'zip': $filesystem = new Filesystem(new ZipArchiveAdapter($opt['zip']['path'])); break; case 'dropbox': - $filesystem = new Filesystem(new DropboxAdapter(new Client($opt['dropbox']['token'],$opt['dropbox']['app']))); + $filesystem = new Filesystem(new DropboxAdapter(new Client($opt['dropbox']['token'], $opt['dropbox']['app']))); break; } + return $filesystem; } /** - * @param array $parameter + * @param array $parameter + * * @return array */ private function configureDriver(array $parameter) @@ -236,19 +240,19 @@ private function configureDriver(array $parameter) $settings = array(); switch (strtolower($parameter['driver'])) { - case "ftp": + case 'ftp': $settings['host'] = $parameter['ftp_settings']['host']; $settings['user'] = $parameter['ftp_settings']['user']; $settings['pass'] = $parameter['ftp_settings']['password']; $settings['path'] = $parameter['ftp_settings']['path']; break; - case "ftpiis": + case 'ftpiis': $settings['host'] = $parameter['ftp_settings']['host']; $settings['user'] = $parameter['ftp_settings']['user']; $settings['pass'] = $parameter['ftp_settings']['password']; $settings['path'] = $parameter['ftp_settings']['path']; break; - case "dropbox": + case 'dropbox': $settings['consumerKey'] = $parameter['dropbox_settings']['consumer_key']; $settings['consumerSecret'] = $parameter['dropbox_settings']['consumer_secret']; $settings['accessToken'] = $parameter['dropbox_settings']['access_token']; @@ -256,13 +260,13 @@ private function configureDriver(array $parameter) $settings['dropboxUid'] = $parameter['dropbox_settings']['dropbox_uid']; $settings['metaCachePath'] = $parameter['dropbox_settings']['meta_cache_path']; break; - case "s3": - $settings['accesskey'] = $parameter['s3_settings']['access_key']; - $settings['secretkey'] = $parameter['s3_settings']['secret_key']; - $settings['bucket'] = $parameter['s3_settings']['bucket']; - $settings['tmpPath'] = $parameter['s3_settings']['tmp_path']; + case 's3': + $settings['accesskey'] = $parameter['s3_settings']['access_key']; + $settings['secretkey'] = $parameter['s3_settings']['secret_key']; + $settings['bucket'] = $parameter['s3_settings']['bucket']; + $settings['tmpPath'] = $parameter['s3_settings']['tmp_path']; $settings['signature'] = $parameter['s3_settings']['signature']; - $settings['region'] = $parameter['s3_settings']['region']; + $settings['region'] = $parameter['s3_settings']['region']; break; default: break; @@ -273,12 +277,13 @@ private function configureDriver(array $parameter) /** * Simple function to demonstrate how to control file access using "accessControl" callback. - * This method will disable accessing files/folders starting from '.' (dot) + * This method will disable accessing files/folders starting from '.' (dot). * - * @param string $attr attribute name (read|write|locked|hidden) - * @param string $path file path relative to volume root directory started with directory separator + * @param string $attr attribute name (read|write|locked|hidden) + * @param string $path file path relative to volume root directory started with directory separator * @param $data * @param $volume + * * @return bool|null */ public function access($attr, $path, $data, $volume) diff --git a/Controller/ElFinderController.php b/Controller/ElFinderController.php index 207c944..4133789 100644 --- a/Controller/ElFinderController.php +++ b/Controller/ElFinderController.php @@ -13,38 +13,42 @@ /** * Loader service for Elfinder backend - * displays Elfinder + * displays Elfinder. + * * @author Al Ganiev * @copyright 2012-2015 Al Ganiev * @license http://www.opensource.org/licenses/mit-license.php MIT License */ class ElFinderController extends Controller { - /** - * Renders Elfinder + * Renders Elfinder. + * * @param Request $request - * @param string $instance - * @param string $homeFolder + * @param string $instance + * @param string $homeFolder + * * @return Response */ public function showAction(Request $request, $instance, $homeFolder) { $efParameters = $this->container->getParameter('fm_elfinder'); - $parameters = $efParameters['instances'][$instance]; - $assetsPath = $efParameters['assets_path']; - $result = $this->selectEditor($parameters, $instance, $homeFolder, $assetsPath, $request->get("id")); + $parameters = $efParameters['instances'][$instance]; + $assetsPath = $efParameters['assets_path']; + $result = $this->selectEditor($parameters, $instance, $homeFolder, $assetsPath, $request->get('id')); return $this->render($result['template'], $result['params']); } /** - * @param array $parameters + * @param array $parameters * @param string $instance * @param string $homeFolder * @param $assetsPath * @param null $formTypeId + * * @return array + * * @throws Exception */ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, $formTypeId = null) @@ -65,7 +69,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, } $result['template'] = $parameters['editor_template']; - $result['params'] = array( + $result['params'] = array( 'locale' => $locale, 'fullscreen' => $fullScreen, 'includeAssets' => $includeAssets, @@ -74,12 +78,28 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'relative_path' => $relativePath, 'prefix' => $assetsPath, 'theme' => $theme, - 'pathPrefix' => $pathPrefix + 'pathPrefix' => $pathPrefix, ); + return $result; case 'ckeditor': $result['template'] = 'FMElfinderBundle:Elfinder:ckeditor.html.twig'; - $result['params'] = array( + $result['params'] = array( + 'locale' => $locale, + 'fullscreen' => $fullScreen, + 'includeAssets' => $includeAssets, + 'instance' => $instance, + 'homeFolder' => $homeFolder, + 'relative_path' => $relativePath, + 'prefix' => $assetsPath, + 'theme' => $theme, + 'pathPrefix' => $pathPrefix, + ); + + return $result; + case 'summernote': + $result['template'] = 'FMElfinderBundle:Elfinder:summernote.html.twig'; + $result['params'] = array( 'locale' => $locale, 'fullscreen' => $fullScreen, 'includeAssets' => $includeAssets, @@ -88,12 +108,13 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'relative_path' => $relativePath, 'prefix' => $assetsPath, 'theme' => $theme, - 'pathPrefix' => $pathPrefix + 'pathPrefix' => $pathPrefix, ); + return $result; case 'tinymce': $result['template'] = 'FMElfinderBundle:Elfinder:tinymce.html.twig'; - $result['params'] = array( + $result['params'] = array( 'locale' => $locale, 'tinymce_popup_path' => $this->getAssetsUrl($parameters['tinymce_popup_path']), 'includeAssets' => $includeAssets, @@ -101,12 +122,13 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'homeFolder' => $homeFolder, 'prefix' => $assetsPath, 'theme' => $theme, - 'pathPrefix' => $pathPrefix + 'pathPrefix' => $pathPrefix, ); + return $result; case 'tinymce4': $result['template'] = 'FMElfinderBundle:Elfinder:tinymce4.html.twig'; - $result['params'] = array( + $result['params'] = array( 'locale' => $locale, 'includeAssets' => $includeAssets, 'instance' => $instance, @@ -114,12 +136,13 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'relative_path' => $relativePath, 'prefix' => $assetsPath, 'theme' => $theme, - 'pathPrefix' => $pathPrefix + 'pathPrefix' => $pathPrefix, ); + return $result; case 'form': $result['template'] = 'FMElfinderBundle:Elfinder:elfinder_type.html.twig'; - $result['params'] = array( + $result['params'] = array( 'locale' => $locale, 'fullscreen' => $fullScreen, 'includeAssets' => $includeAssets, @@ -129,28 +152,32 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath, 'relative_path' => $relativePath, 'prefix' => $assetsPath, 'theme' => $theme, - 'pathPrefix' => $pathPrefix + 'pathPrefix' => $pathPrefix, ); + return $result; default: $result['template'] = 'FMElfinderBundle:Elfinder:simple.html.twig'; - $result['params'] = array( + $result['params'] = array( 'locale' => $locale, 'fullscreen' => $fullScreen, 'includeAssets' => $includeAssets, 'instance' => $instance, 'homeFolder' => $homeFolder, - 'prefix' => $assetsPath + 'prefix' => $assetsPath, ); + return $result; } } /** - * Loader service init + * Loader service init. + * * @param Request $request - * @param string $instance - * @param string $homeFolder + * @param string $instance + * @param string $homeFolder + * * @return JsonResponse/void */ public function loadAction(Request $request, $instance, $homeFolder) @@ -171,7 +198,7 @@ public function loadAction(Request $request, $instance, $homeFolder) } /** - * Get url from config string + * Get url from config string. * * @param string $inputUrl * @@ -190,5 +217,4 @@ protected function getAssetsUrl($inputUrl) return $inputUrl; } - } diff --git a/DependencyInjection/Compiler/TwigFormPass.php b/DependencyInjection/Compiler/TwigFormPass.php index 9438028..172bde6 100644 --- a/DependencyInjection/Compiler/TwigFormPass.php +++ b/DependencyInjection/Compiler/TwigFormPass.php @@ -6,8 +6,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; /** - * Class TwigFormPass - * @package FM\ElfinderBundle\DependencyInjection\Compiler + * Class TwigFormPass. */ class TwigFormPass implements CompilerPassInterface { @@ -23,4 +22,3 @@ public function process(ContainerBuilder $container) )); } } - diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6d75414..a64b209 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -6,10 +6,11 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * This class contains the configuration information for the bundle + * This class contains the configuration information for the bundle. * * This information is solely responsible for how the different configuration * sections are normalized, and merged. + * * @author Al Ganiev * @copyright 2012-2015 Al Ganiev * @license http://www.opensource.org/licenses/mit-license.php MIT License @@ -17,12 +18,12 @@ class Configuration implements ConfigurationInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('fm_elfinder'); + $rootNode = $treeBuilder->root('fm_elfinder'); $rootNode ->fixXmlConfig('instance') @@ -347,4 +348,3 @@ private function createTreeBuilder() return new TreeBuilder(); } } - diff --git a/DependencyInjection/FMElfinderExtension.php b/DependencyInjection/FMElfinderExtension.php index 5ed6fe9..8c49a76 100644 --- a/DependencyInjection/FMElfinderExtension.php +++ b/DependencyInjection/FMElfinderExtension.php @@ -17,7 +17,7 @@ class FMElfinderExtension extends Extension { /** - * {@inheritDoc} + * {@inheritdoc} */ public function load(array $configs, ContainerBuilder $container) { diff --git a/Event/ElFinderEvents.php b/Event/ElFinderEvents.php index 7b18bd2..4f9a139 100644 --- a/Event/ElFinderEvents.php +++ b/Event/ElFinderEvents.php @@ -8,12 +8,14 @@ abstract class ElFinderEvents extends Event { /** * Event name to identify pre execution event. + * * @var string */ const PRE_EXECUTION = 'fm_elfinder.event.pre_execution'; /** * Event name to identify post execution event. + * * @var string */ const POST_EXECUTION = 'fm_elfinder.event.post_execution'; diff --git a/Event/ElFinderPostExecutionEvent.php b/Event/ElFinderPostExecutionEvent.php index 2f4e1ac..5fa6cae 100644 --- a/Event/ElFinderPostExecutionEvent.php +++ b/Event/ElFinderPostExecutionEvent.php @@ -9,13 +9,14 @@ class ElFinderPostExecutionEvent extends ElFinderPreExecutionEvent { /** * Command execution result. + * * @var array */ protected $result; - /** * Constructor. + * * @param Request $request * @param HttpKernelInterface $httpKernel * @param string $instance @@ -31,7 +32,8 @@ public function __construct(Request $request, HttpKernelInterface $httpKernel, $ /** * Tells if execution has encountered errors. - * @return boolean + * + * @return bool */ public function hasErrors() { diff --git a/Event/ElFinderPreExecutionEvent.php b/Event/ElFinderPreExecutionEvent.php index a5f7fe3..59016fa 100644 --- a/Event/ElFinderPreExecutionEvent.php +++ b/Event/ElFinderPreExecutionEvent.php @@ -9,31 +9,35 @@ class ElFinderPreExecutionEvent extends ElFinderEvents { /** * Request object containing ElFinder command and parameters. + * * @var Request */ protected $request; /** * Used to make sub requests. + * * @var HttpKernelInterface */ private $httpKernel; /** * ElFinder instance. + * * @var string */ protected $instance; /** * Home folder. + * * @var string */ protected $homeFolder; - /** * Constructor. + * * @param Request $request * @param HttpKernelInterface $httpKernel * @param string $instance @@ -41,9 +45,9 @@ class ElFinderPreExecutionEvent extends ElFinderEvents */ public function __construct(Request $request, HttpKernelInterface $httpKernel, $instance, $homeFolder) { - $this->request = $request; + $this->request = $request; $this->httpKernel = $httpKernel; - $this->instance = $instance; + $this->instance = $instance; $this->homeFolder = $homeFolder; } @@ -53,7 +57,7 @@ public function __construct(Request $request, HttpKernelInterface $httpKernel, $ * * @see https://github.com/symfony/symfony/blob/2.5/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php * - * @param array $path An array of path parameters + * @param array $path An array of path parameters * @param array $query An array of query parameters * * @return Symfony\Component\HttpFoundation\Response A Response instance @@ -61,13 +65,14 @@ public function __construct(Request $request, HttpKernelInterface $httpKernel, $ public function subRequest(array $path, array $query) { $path['_controller'] = 'FMElfinderBundle:ElFinder:load'; - $subRequest = $this->request->duplicate($query, null, $path); - + $subRequest = $this->request->duplicate($query, null, $path); + return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); } /** * Returns executed command. + * * @return string */ public function getCommand() diff --git a/FMElfinderBundle.php b/FMElfinderBundle.php index e65af4c..cd121cd 100644 --- a/FMElfinderBundle.php +++ b/FMElfinderBundle.php @@ -8,8 +8,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * Class FMElfinderBundle - * @package FM\ElfinderBundle + * Class FMElfinderBundle. */ class FMElfinderBundle extends Bundle { diff --git a/Form/Type/ElFinderType.php b/Form/Type/ElFinderType.php index edf59c8..9f2a38a 100644 --- a/Form/Type/ElFinderType.php +++ b/Form/Type/ElFinderType.php @@ -9,39 +9,38 @@ use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** - * Class ElFinderType - * @package FM\ElfinderBundle\Form\Type + * Class ElFinderType. */ class ElFinderType extends AbstractType { - /** - * @inheritdoc + * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setAttribute('enable', $options['enable']); - if($builder->getAttribute('enable')) + if ($builder->getAttribute('enable')) { $builder->setAttribute('instance', $options['instance']); - $builder->setAttribute('homeFolder', $options['homeFolder']); + } + $builder->setAttribute('homeFolder', $options['homeFolder']); } /** - * @inheritdoc + * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['enable'] = $form->getConfig()->getAttribute('enable'); - if($form->getConfig()->getAttribute('enable')) { - $view->vars['instance'] = $form->getConfig()->getAttribute('instance'); + if ($form->getConfig()->getAttribute('enable')) { + $view->vars['instance'] = $form->getConfig()->getAttribute('instance'); $view->vars['homeFolder'] = $form->getConfig()->getAttribute('homeFolder'); } } /** - * @inheritdoc + * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { @@ -57,19 +56,20 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'homeFolder' => array('string', 'null'), )); } + /** - * @inheritdoc + * {@inheritdoc} */ public function getParent() { return 'text'; } + /** - * @inheritdoc + * {@inheritdoc} */ public function getName() { return 'elfinder'; } } - diff --git a/Loader/ElFinderLoader.php b/Loader/ElFinderLoader.php index d9d5558..dd4bac4 100644 --- a/Loader/ElFinderLoader.php +++ b/Loader/ElFinderLoader.php @@ -9,8 +9,7 @@ use Symfony\Component\HttpFoundation\Request; /** - * Class ElFinderLoader - * @package FM\ElfinderBundle\Loader + * Class ElFinderLoader. */ class ElFinderLoader { @@ -21,7 +20,7 @@ class ElFinderLoader /** * @var ElFinderConfigurationProviderInterface - * Configurator service name + * Configurator service name */ protected $configurator; @@ -35,13 +34,14 @@ public function __construct(ElFinderConfigurationProviderInterface $configurator /** * @throws \Exception + * * @return array */ public function configure() { $configurator = $this->configurator; if (!($configurator instanceof ElFinderConfigurationProviderInterface)) { - throw new Exception("Configurator class must implement ElFinderConfigurationProviderInterface"); + throw new Exception('Configurator class must implement ElFinderConfigurationProviderInterface'); } $parameters = $configurator->getConfiguration($this->instance); @@ -49,15 +49,15 @@ public function configure() } /** - * Starts ElFinder - * @var Request $request + * Starts ElFinder. + * + * @var Request * @var string $instance - * @return void/array */ public function load(Request $request, $instance) { $this->setInstance($instance); - $config = $this->configure(); + $config = $this->configure(); $connector = new ElFinderConnector(new ElFinderBridge($config)); if ($config['corsSupport']) { return $connector->execute($request->query->all()); diff --git a/Model/ElFinderConfigurationProviderInterface.php b/Model/ElFinderConfigurationProviderInterface.php index 7cf1336..1f77d56 100644 --- a/Model/ElFinderConfigurationProviderInterface.php +++ b/Model/ElFinderConfigurationProviderInterface.php @@ -3,13 +3,13 @@ namespace FM\ElfinderBundle\Model; /** - * Interface ElFinderConfigurationProviderInterface - * @package FM\ElfinderBundle\Model + * Interface ElFinderConfigurationProviderInterface. */ interface ElFinderConfigurationProviderInterface { /** * @param $instance + * * @return array */ public function getConfiguration($instance); diff --git a/Model/ElFinderPermissionsInterface.php b/Model/ElFinderPermissionsInterface.php deleted file mode 100644 index f1d725b..0000000 --- a/Model/ElFinderPermissionsInterface.php +++ /dev/null @@ -1,28 +0,0 @@ - @@ -50,6 +51,8 @@ Recommended bundles to use with: - [TinyMCE integration](#tinymce-integration) - [Integration with TinyMCE 3](#tinymce-3x) - [Integration with TinyMCE 4](#tinymce-4x) +- [Summernote integration](#summernote-integration) + - [Advanced configuration](#advanced-configuration) - [Custom configuration provider](#custom-configuration-provider) - [Custom loader](#custom-loader) @@ -522,6 +525,26 @@ as shown below instance_name is instance of elfinder configuration +## Summernote integration + +Update the editor property in your app/config.yml +Set Summernote editor type: + +```yaml +fm_elfinder: + editor: summernote +``` + +Edit template that contains summernote instance (the same way as for tinymce) + +```jinja + {{ elfinder_summernote_init('instance_name') }} + {{ summernote_init() }} +``` + +Don't forget to enable elfinder plugin in summernote configuration. + + # Advanced configuration ## Custom configuration provider diff --git a/Resources/config/elfinder.xml b/Resources/config/elfinder.xml index b80dcd3..afc83e9 100644 --- a/Resources/config/elfinder.xml +++ b/Resources/config/elfinder.xml @@ -17,10 +17,9 @@ - + - + - diff --git a/Entity/ElFinderFile.php b/Resources/entity/ElFinderFile.php.dst similarity index 100% rename from Entity/ElFinderFile.php rename to Resources/entity/ElFinderFile.php.dst diff --git a/DataFixtures/ORM/LoadRootElement.php b/Resources/fixtures/LoadRootElement.php.dst similarity index 100% rename from DataFixtures/ORM/LoadRootElement.php rename to Resources/fixtures/LoadRootElement.php.dst diff --git a/Resources/views/Elfinder/helper/_summernote.html.twig b/Resources/views/Elfinder/helper/_summernote.html.twig new file mode 100644 index 0000000..abe8b3b --- /dev/null +++ b/Resources/views/Elfinder/helper/_summernote.html.twig @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/Resources/views/Elfinder/summernote.html.twig b/Resources/views/Elfinder/summernote.html.twig new file mode 100644 index 0000000..d573092 --- /dev/null +++ b/Resources/views/Elfinder/summernote.html.twig @@ -0,0 +1,27 @@ + + + + {% if includeAssets %} + {% include "FMElfinderBundle:Elfinder:helper/assets_css.html.twig" %} + {% endif %} + + +{% if includeAssets %} + {% include "FMElfinderBundle:Elfinder:helper/assets_js.html.twig" %} +{% endif %} + +
+ + diff --git a/Tests/Configuration/ElFinderConfigurationReaderTest.php b/Tests/Configuration/ElFinderConfigurationReaderTest.php index dc04b43..39b2d79 100644 --- a/Tests/Configuration/ElFinderConfigurationReaderTest.php +++ b/Tests/Configuration/ElFinderConfigurationReaderTest.php @@ -1,15 +1,13 @@ -assertTrue($rc->isSubclassOf('FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface')); - } -} \ No newline at end of file +assertTrue($rc->isSubclassOf('FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface')); + } +} diff --git a/Tests/Controller/ElFinderControllerTest.php b/Tests/Controller/ElFinderControllerTest.php index f85e838..4c1efd1 100644 --- a/Tests/Controller/ElFinderControllerTest.php +++ b/Tests/Controller/ElFinderControllerTest.php @@ -18,18 +18,18 @@ public function setUp() public function testDispatchedPrePostExecutionEvents() { - $preExecCount = 0; + $preExecCount = 0; $postExecCount = 0; // storing the real event dispatcher $eventDispatcher = $this->container->get('event_dispatcher'); // creating a container with mocked services for this test $container = $this->getContainer($eventDispatcher); - // adding listeners + // adding listeners $eventDispatcher->addListener(ElFinderEvents::PRE_EXECUTION, $preExecListener = function (ElFinderEvents $e) use (&$preExecCount) { - $preExecCount++; + ++$preExecCount; }); $eventDispatcher->addListener(ElFinderEvents::POST_EXECUTION, $postExecListener = function (ElFinderEvents $e) use (&$postExecCount) { - $postExecCount++; + ++$postExecCount; }); $controller = new ElFinderController(); @@ -46,6 +46,7 @@ private function getContainer($eventDispatcher) $container->set('fm_elfinder.loader', $this->getElFinderLoaderMock()); $container->set('http_kernel', $this->getHttpKernelMock()); $container->set('event_dispatcher', $eventDispatcher); + return $container; } @@ -57,6 +58,7 @@ private function getElFinderLoaderMock() $stub->expects($this->once()) ->method('load') ->willReturn(array()); + return $stub; } @@ -65,6 +67,7 @@ private function getHttpKernelMock() $stub = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') ->disableOriginalConstructor() ->getMock(); + return $stub; } } diff --git a/Tests/DependencyInjection/ConfigurationLoadTest.php b/Tests/DependencyInjection/ConfigurationLoadTest.php index 3930435..225da38 100644 --- a/Tests/DependencyInjection/ConfigurationLoadTest.php +++ b/Tests/DependencyInjection/ConfigurationLoadTest.php @@ -1,131 +1,130 @@ - 'app.configurator.custom', - 'assets_path' => '/assets', - 'loader' => 'fm_elfinder.loader.default', - 'instances' => array( - 'default' => array( - 'locale' => 'en', - 'editor' => 'tinymce', - 'theme' => 'smoothness', - 'editor_template' => 'Elfinder/editor.html.twig', - 'fullscreen' => false, - 'include_assets' => false, - 'cors_support' => false, - 'tinymce_popup_path' => '/pop-up', - 'relative_path' => false, - 'path_prefix' => '/', - 'connector' => array( - 'debug' => true, - 'binds' => array(), - 'plugins' => array(), - 'roots' => array( - 'uploads' => array( - 'driver' => 'LocalFileSystem', - 'volume_id' => 0, - 'disabled_commands' => array(), - 'plugins' => array(), - 'path' => 'uploads', - 'show_hidden' => true, - 'flysystem' => array( - 'enabled' => false, - 'type' => '' - ), - 'start_path' => '', - 'url' => '', - 'mime_detect' => 'auto', - 'mimefile' => '', - 'img_lib' => 'auto', - 'tmb_path' => '.tmb', - 'tmb_url' => '', - 'tmb_size' => 48, - 'tmb_crop' => true, - 'tmb_bg_color' => '#ffffff', - 'tmb_path_mode' => 511, - 'copy_overwrite' => true, - 'copy_join' => true, - 'copy_from' => true, - 'copy_to' => true, - 'upload_overwrite' => true, - 'attributes' => array( - 'some_pattern' => array( - 'pattern' => '/^some_pattern$/', - 'read' => true, - 'write' => true, - 'locked' => false, - 'hidden' => false, - ) - ), - 'accepted_name' => '/^\w[\w\s\.\%\-]*$/u', - 'check_subfolders' => true, - 'separator' => DIRECTORY_SEPARATOR, - 'date_format' => 'j M Y H:i', - 'time_format' => 'H:i', - 'archive_mimes' => array(), - 'archivers' => array(), - 'glide_url' => '', - 'glide_key' => '', - 'alias' => 'foo', - 'tree_deep' => 1, - 'upload_allow' => array('image/png', 'image/jpg', 'image/jpeg'), - 'upload_order' => array('deny', 'allow'), - 'defaults' => array('read' => true, 'write' => true), - 'upload_deny' => array('all'), - 'upload_max_size' => 0, - 'dropbox_settings' => array( - 'consumer_key' => 'some_consumer', - 'consumer_secret' => 'con$umer', - 'enabled' => true, - ), - 'ftp_settings' => array( - 'host' => '127.0.0.1', - 'user' => 'root', - 'enabled' => true, - ), - 's3_settings' => array( - 'enabled' => false, - ), - ), - ), - ), - ), - ), - ); - - - $this->assertProcessedConfigurationEquals($expectedConfiguration, array(__DIR__.'/../Fixtures/'.$path)); - } - - public function getSupportsAllConfigFormatsData() - { - return array( - 'yml' => array('config/config.yml'), - 'php' => array('config/config.php'), - 'xml' => array('config/config.xml') - ); - } -} + 'app.configurator.custom', + 'assets_path' => '/assets', + 'loader' => 'fm_elfinder.loader.default', + 'instances' => array( + 'default' => array( + 'locale' => 'en', + 'editor' => 'tinymce', + 'theme' => 'smoothness', + 'editor_template' => 'Elfinder/editor.html.twig', + 'fullscreen' => false, + 'include_assets' => false, + 'cors_support' => false, + 'tinymce_popup_path' => '/pop-up', + 'relative_path' => false, + 'path_prefix' => '/', + 'connector' => array( + 'debug' => true, + 'binds' => array(), + 'plugins' => array(), + 'roots' => array( + 'uploads' => array( + 'driver' => 'LocalFileSystem', + 'volume_id' => 0, + 'disabled_commands' => array(), + 'plugins' => array(), + 'path' => 'uploads', + 'show_hidden' => true, + 'flysystem' => array( + 'enabled' => false, + 'type' => '', + ), + 'start_path' => '', + 'url' => '', + 'mime_detect' => 'auto', + 'mimefile' => '', + 'img_lib' => 'auto', + 'tmb_path' => '.tmb', + 'tmb_url' => '', + 'tmb_size' => 48, + 'tmb_crop' => true, + 'tmb_bg_color' => '#ffffff', + 'tmb_path_mode' => 511, + 'copy_overwrite' => true, + 'copy_join' => true, + 'copy_from' => true, + 'copy_to' => true, + 'upload_overwrite' => true, + 'attributes' => array( + 'some_pattern' => array( + 'pattern' => '/^some_pattern$/', + 'read' => true, + 'write' => true, + 'locked' => false, + 'hidden' => false, + ), + ), + 'accepted_name' => '/^\w[\w\s\.\%\-]*$/u', + 'check_subfolders' => true, + 'separator' => DIRECTORY_SEPARATOR, + 'date_format' => 'j M Y H:i', + 'time_format' => 'H:i', + 'archive_mimes' => array(), + 'archivers' => array(), + 'glide_url' => '', + 'glide_key' => '', + 'alias' => 'foo', + 'tree_deep' => 1, + 'upload_allow' => array('image/png', 'image/jpg', 'image/jpeg'), + 'upload_order' => array('deny', 'allow'), + 'defaults' => array('read' => true, 'write' => true), + 'upload_deny' => array('all'), + 'upload_max_size' => 0, + 'dropbox_settings' => array( + 'consumer_key' => 'some_consumer', + 'consumer_secret' => 'con$umer', + 'enabled' => true, + ), + 'ftp_settings' => array( + 'host' => '127.0.0.1', + 'user' => 'root', + 'enabled' => true, + ), + 's3_settings' => array( + 'enabled' => false, + ), + ), + ), + ), + ), + ), + ); + + $this->assertProcessedConfigurationEquals($expectedConfiguration, array(__DIR__.'/../Fixtures/'.$path)); + } + + public function getSupportsAllConfigFormatsData() + { + return array( + 'yml' => array('config/config.yml'), + 'php' => array('config/config.php'), + 'xml' => array('config/config.xml'), + ); + } +} diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 0387921..7743733 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -1,28 +1,26 @@ -assertConfigurationIsInvalid( - array( - array() - ) - ); - } - -} - +assertConfigurationIsInvalid( + array( + array(), + ) + ); + } +} diff --git a/Tests/DependencyInjection/FMElfinderExtensionTest.php b/Tests/DependencyInjection/FMElfinderExtensionTest.php index 0207f17..2552723 100644 --- a/Tests/DependencyInjection/FMElfinderExtensionTest.php +++ b/Tests/DependencyInjection/FMElfinderExtensionTest.php @@ -12,7 +12,7 @@ class FMElfinderExtensionTest extends AbstractExtensionTestCase protected function getContainerExtensions() { return array( - new FMElfinderExtension() + new FMElfinderExtension(), ); } @@ -22,23 +22,21 @@ public function testServices() $this->assertContainerBuilderHasAlias('fm_elfinder.configurator'); $this->assertContainerBuilderHasService('fm_elfinder.loader'); $this->assertContainerBuilderHasService('fm_elfinder.configurator.default'); - $this->assertContainerBuilderHasService('twig.extension.fm_tinymce_init'); + $this->assertContainerBuilderHasService('twig.extension.fm_elfinder_init'); } /** - * @return void */ public function testMinimumConfiguration() { $this->container = new ContainerBuilder(); - $loader = new FMElfinderExtension(); + $loader = new FMElfinderExtension(); $loader->load(array($this->getMinimalConfiguration()), $this->container); $this->assertTrue($this->container instanceof ContainerBuilder); } protected function getMinimalConfiguration() { - $yaml = <<parse($yaml); } - } diff --git a/Tests/Event/ElFinderPostExecutionEventTest.php b/Tests/Event/ElFinderPostExecutionEventTest.php index 7db47f4..ea08d47 100644 --- a/Tests/Event/ElFinderPostExecutionEventTest.php +++ b/Tests/Event/ElFinderPostExecutionEventTest.php @@ -10,9 +10,9 @@ class ElFinderPostExecutionEventTest extends TestCase { public function testHasErrors() { - $request = new Request(); + $request = new Request(); $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); - $event = new ElFinderPostExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder', array()); + $event = new ElFinderPostExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder', array()); $this->assertEquals(false, $event->hasErrors()); $event = new ElFinderPostExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder', array('error' => true)); diff --git a/Tests/Event/ElFinderPreExecutionEventTest.php b/Tests/Event/ElFinderPreExecutionEventTest.php index dabd6e3..8471546 100644 --- a/Tests/Event/ElFinderPreExecutionEventTest.php +++ b/Tests/Event/ElFinderPreExecutionEventTest.php @@ -10,25 +10,25 @@ class ElFinderPreExecutionEventTest extends TestCase { public function testGetCommand() { - $command = 'rm'; - $request = new Request(array('cmd' => $command)); + $command = 'rm'; + $request = new Request(array('cmd' => $command)); $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); - $event = new ElFinderPreExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder'); + $event = new ElFinderPreExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder'); $this->assertEquals($command, $event->getCommand()); } public function testSubRequest() { - $request = new Request(array('cmd' => 'info')); + $request = new Request(array('cmd' => 'info')); $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $httpKernel ->expects($this->once()) ->method('handle'); $event = new ElFinderPreExecutionEvent($request, $httpKernel, 'testInstance', 'testHomeFolder'); - + $jsonResponse = $event->subRequest(array( - 'instance' => $event->getInstance(), - 'homeFolder' => $event->getHomeFolder() + 'instance' => $event->getInstance(), + 'homeFolder' => $event->getHomeFolder(), ), $request->query->all()); } } diff --git a/Tests/Fixtures/config/config.php b/Tests/Fixtures/config/config.php index 64ff2b6..c581b57 100644 --- a/Tests/Fixtures/config/config.php +++ b/Tests/Fixtures/config/config.php @@ -1,49 +1,49 @@ -loadFromExtension('fm_elfinder', array( - 'configuration_provider' => 'app.configurator.custom', - 'instances' => array( - 'default' => array( - 'locale' => 'en', - 'cors_support' => false, - 'editor' => 'tinymce', - 'editor_template' => 'Elfinder/editor.html.twig', - 'fullscreen' => false, - 'include_assets' => false, - 'tinymce_popup_path' => '/pop-up', - 'relative_path' => false, - 'connector' => array( - 'debug' => true, - 'roots' => array( - 'uploads' => array( - 'driver' => 'LocalFileSystem', - 'path' => 'uploads', - 'show_hidden' => true, - 'alias' => 'foo', - 'tree_deep' => 1, - 'upload_allow' => array('image/png', 'image/jpg', 'image/jpeg'), - 'upload_deny' => array('all'), - 'upload_max_size' => 0, - 'dropbox_settings' => array( - 'consumer_key' => 'some_consumer', - 'consumer_secret' => 'con$umer', - ), - 'ftp_settings' => array( - 'host' => '127.0.0.1', - 'user' => 'root', - ), - 'attributes' => array( - 'some_pattern' => array( - 'pattern' => '/^some_pattern$/', - 'read' => true, - 'write' => true, - 'locked' => false, - 'hidden' => false, - ) - ), - ), - ), - ), - ), - ), -)); +loadFromExtension('fm_elfinder', array( + 'configuration_provider' => 'app.configurator.custom', + 'instances' => array( + 'default' => array( + 'locale' => 'en', + 'cors_support' => false, + 'editor' => 'tinymce', + 'editor_template' => 'Elfinder/editor.html.twig', + 'fullscreen' => false, + 'include_assets' => false, + 'tinymce_popup_path' => '/pop-up', + 'relative_path' => false, + 'connector' => array( + 'debug' => true, + 'roots' => array( + 'uploads' => array( + 'driver' => 'LocalFileSystem', + 'path' => 'uploads', + 'show_hidden' => true, + 'alias' => 'foo', + 'tree_deep' => 1, + 'upload_allow' => array('image/png', 'image/jpg', 'image/jpeg'), + 'upload_deny' => array('all'), + 'upload_max_size' => 0, + 'dropbox_settings' => array( + 'consumer_key' => 'some_consumer', + 'consumer_secret' => 'con$umer', + ), + 'ftp_settings' => array( + 'host' => '127.0.0.1', + 'user' => 'root', + ), + 'attributes' => array( + 'some_pattern' => array( + 'pattern' => '/^some_pattern$/', + 'read' => true, + 'write' => true, + 'locked' => false, + 'hidden' => false, + ), + ), + ), + ), + ), + ), + ), +)); diff --git a/Tests/Loader/ElFinderLoaderTest.php b/Tests/Loader/ElFinderLoaderTest.php index 71ae83c..b2b51c8 100644 --- a/Tests/Loader/ElFinderLoaderTest.php +++ b/Tests/Loader/ElFinderLoaderTest.php @@ -1,37 +1,34 @@ -configuratorMock = $this->getMock('FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface'); - $this->configuratorMock->expects($this->any()) - ->method('getConfiguration') - ->will($this->returnValue(array('parameters'=>array()))); - $this->loader = new ElFinderLoader($this->configuratorMock); - $this->loader->setInstance('minimal'); - } - - public function testConfigure() - { - $this->loader->configure(); - $this->assertEquals(array('parameters'=>array()), $this->configuratorMock->getConfiguration('minimal')); - } -} \ No newline at end of file +configuratorMock = $this->getMock('FM\ElfinderBundle\Model\ElFinderConfigurationProviderInterface'); + $this->configuratorMock->expects($this->any()) + ->method('getConfiguration') + ->will($this->returnValue(array('parameters' => array()))); + $this->loader = new ElFinderLoader($this->configuratorMock); + $this->loader->setInstance('minimal'); + } + + public function testConfigure() + { + $this->loader->configure(); + $this->assertEquals(array('parameters' => array()), $this->configuratorMock->getConfiguration('minimal')); + } +} diff --git a/Tests/Twig/Extension/FMElfinderTinymceExtensionTest.php b/Tests/Twig/Extension/FMElfinderExtensionTest.php similarity index 77% rename from Tests/Twig/Extension/FMElfinderTinymceExtensionTest.php rename to Tests/Twig/Extension/FMElfinderExtensionTest.php index df6c737..009cbf3 100644 --- a/Tests/Twig/Extension/FMElfinderTinymceExtensionTest.php +++ b/Tests/Twig/Extension/FMElfinderExtensionTest.php @@ -1,154 +1,151 @@ -twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array(__DIR__.'/../../../Resources/views/Elfinder/helper'))); - $this->extension = new FMElfinderTinymceExtension($this->twig); - $this->twig->addExtension($this->extension); - $loader = new YamlFileLoader(new FileLocator(__DIR__ . '/../../../Resources/config')); - $routes = new RouteCollection(); - $collection = $loader->load('routing.yml'); - $routes->addCollection($collection); - $this->twig->addExtension(new RoutingExtension(new UrlGenerator($routes, new RequestContext()))); - } - - - public function testRenderTinyMCE3() - { - $this->template = $this->twig->loadTemplate('_tinymce.html.twig'); - $testData = $this->renderTemplate(array('instance' => 'minimal')); - - $expected = << - // - -EOF; - - $this->assertSame($this->normalizeOutput($expected), $this->normalizeOutput($testData)); - } - - public function testRenderTinyMCE4() - { - $this->template = $this->twig->loadTemplate('_tinymce4.html.twig'); - $testData = $this->renderTemplate(array('instance' => 'minimal')); - - $expected = << - function elFinderBrowser (field_name, url, type, win) { - tinymce.activeEditor.windowManager.open({ - file:"http://localhost/elfinder/minimal", - title:"", - width:, - height:, - resizable: 'yes' - }, { - setUrl: function (url) { - win.document.getElementById(field_name).value = url; - } - }); - return false; - } - -EOF; - - $this->assertSame($this->normalizeOutput($expected), $this->normalizeOutput($testData)); - } - - /** - * - */ - public function testName() - { - $this->assertEquals('fm_tinymce_init', $this->extension->getName()); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->template); - unset($this->twig); - } - - /** - * {@inheritdoc} - */ - protected function renderTemplate(array $context = array()) - { - return $this->template->render($context); - } - - /** - * Normalizes the output by removing the heading whitespaces. - * - * @param string $output The output. - * - * @return string The normalized output. - */ - protected function normalizeOutput($output) - { - return preg_replace( "/\r|\n/", "", str_replace(PHP_EOL, '', str_replace(' ', '', $output))); - } - - /** - * - */ - public function testSubClassOfTwigExtension() - { - $rc = new \ReflectionClass('FM\ElfinderBundle\Twig\Extension\FMElfinderTinymceExtension'); - - $this->assertTrue($rc->isSubclassOf('Twig_Extension')); - } -} - +twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array(__DIR__.'/../../../Resources/views/Elfinder/helper'))); + $this->extension = new FMElfinderExtension($this->twig); + $this->twig->addExtension($this->extension); + $loader = new YamlFileLoader(new FileLocator(__DIR__.'/../../../Resources/config')); + $routes = new RouteCollection(); + $collection = $loader->load('routing.yml'); + $routes->addCollection($collection); + $this->twig->addExtension(new RoutingExtension(new UrlGenerator($routes, new RequestContext()))); + } + + public function testRenderTinyMCE3() + { + $this->template = $this->twig->loadTemplate('_tinymce.html.twig'); + $testData = $this->renderTemplate(array('instance' => 'minimal')); + + $expected = << + // + +EOF; + + $this->assertSame($this->normalizeOutput($expected), $this->normalizeOutput($testData)); + } + + public function testRenderTinyMCE4() + { + $this->template = $this->twig->loadTemplate('_tinymce4.html.twig'); + $testData = $this->renderTemplate(array('instance' => 'minimal')); + + $expected = << + function elFinderBrowser (field_name, url, type, win) { + tinymce.activeEditor.windowManager.open({ + file:"http://localhost/elfinder/minimal", + title:"", + width:, + height:, + resizable: 'yes' + }, { + setUrl: function (url) { + win.document.getElementById(field_name).value = url; + } + }); + return false; + } + +EOF; + + $this->assertSame($this->normalizeOutput($expected), $this->normalizeOutput($testData)); + } + + /** + * + */ + public function testName() + { + $this->assertEquals('fm_elfinder_init', $this->extension->getName()); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->template); + unset($this->twig); + } + + /** + * {@inheritdoc} + */ + protected function renderTemplate(array $context = array()) + { + return $this->template->render($context); + } + + /** + * Normalizes the output by removing the heading whitespaces. + * + * @param string $output The output. + * + * @return string The normalized output. + */ + protected function normalizeOutput($output) + { + return preg_replace("/\r|\n/", '', str_replace(PHP_EOL, '', str_replace(' ', '', $output))); + } + + /** + * + */ + public function testSubClassOfTwigExtension() + { + $rc = new \ReflectionClass('FM\ElfinderBundle\Twig\Extension\FMElfinderExtension'); + + $this->assertTrue($rc->isSubclassOf('Twig_Extension')); + } +} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 1209aaf..faa5eea 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,6 +1,7 @@ twig = $twig; + } + + /** + * {@inheritdoc} + * + * @return array + */ + public function getFunctions() + { + $options = array('is_safe' => array('html')); + + return array( + new \Twig_SimpleFunction('elfinder_tinymce_init', array($this, 'tinymce'), $options), + new \Twig_SimpleFunction('elfinder_tinymce_init4', array($this, 'tinymce4'), $options), + new \Twig_SimpleFunction('elfinder_summernote_init', array($this, 'summernote'), $options), + ); + } + + /** + * @param string $instance + * @param array $parameters + * + * @throws \Twig_Error_Runtime + * + * @return mixed + */ + public function tinymce($instance = 'default', $parameters = array('width' => 900, 'height' => 450, 'title' => 'elFinder 2.0')) + { + if (!is_string($instance)) { + throw new \Twig_Error_Runtime('The function can be applied to strings only.'); + } + + return $this->twig->render('FMElfinderBundle:Elfinder/helper:_tinymce.html.twig', + array( + 'instance' => $instance, + 'width' => $parameters['width'], + 'height' => $parameters['height'], + 'title' => $parameters['title'], + )); + } + + /** + * @param string $instance + * @param array $parameters + * + * @throws \Twig_Error_Runtime + * + * @return mixed + */ + public function tinymce4($instance = 'default', $parameters = array('width' => 900, 'height' => 450, 'title' => 'elFinder 2.0')) + { + if (!is_string($instance)) { + throw new \Twig_Error_Runtime('The function can be applied to strings only.'); + } + + return $this->twig->render('FMElfinderBundle:Elfinder/helper:_tinymce4.html.twig', + array( + 'instance' => $instance, + 'width' => $parameters['width'], + 'height' => $parameters['height'], + 'title' => $parameters['title'], + )); + } + + /** + * @param string $instance + * @param array $parameters + * + * @throws \Twig_Error_Runtime + * + * @return mixed + */ + public function summernote($instance = 'default', $selector = '.summenote', $parameters = array('width' => 900, 'height' => 450, 'title' => 'elFinder 2.0')) + { + if (!is_string($instance)) { + throw new Twig_Error_Runtime('The function can be applied to strings only.'); + } + + return $this->twig->render('FMElfinderBundle:Elfinder/helper:_summernote.html.twig', + array( + 'instance' => $instance, + 'selector' => $selector, + 'width' => $parameters['width'], + 'height' => $parameters['height'], + 'title' => $parameters['title'], + )); + } + + /** + * (non-PHPdoc). + * + * @see Twig_ExtensionInterface::getName() + */ + public function getName() + { + return 'fm_elfinder_init'; + } +} diff --git a/Twig/Extension/FMElfinderTinymceExtension.php b/Twig/Extension/FMElfinderTinymceExtension.php deleted file mode 100644 index 38eace2..0000000 --- a/Twig/Extension/FMElfinderTinymceExtension.php +++ /dev/null @@ -1,93 +0,0 @@ -twig = $twig; - } - - /** - * (non-PHPdoc) - * @see Twig_Extension::getFilters() - * @return array - */ - public function getFunctions() - { - return array( - 'elfinder_tinymce_init' => new \Twig_Function_Method($this, 'tinymce', array('is_safe' => array('html'))), - 'elfinder_tinymce_init4' => new \Twig_Function_Method($this, 'tinymce4', array('is_safe' => array('html'))) - ); - } - - /** - * @param string $instance - * @param array $parameters - * @throws \Twig_Error_Runtime - * @return mixed - */ - public function tinymce($instance = 'default', $parameters = array('width' => 900, 'height' => 450, 'title' => 'elFinder 2.0')) - { - if (!is_string($instance)) { - throw new Twig_Error_Runtime('The filter can be applied to strings only.'); - } - - return $this->twig->render('FMElfinderBundle:Elfinder/helper:_tinymce.html.twig', - array( - 'instance' => $instance, - 'width' => $parameters['width'], - 'height' => $parameters['height'], - 'title' => $parameters['title'] - )); - } - - /** - * @param string $instance - * @param array $parameters - * @throws \Twig_Error_Runtime - * @return mixed - */ - public function tinymce4($instance = 'default', $parameters = array('width' => 900, 'height' => 450, 'title' => 'elFinder 2.0')) - { - if (!is_string($instance)) { - throw new Twig_Error_Runtime('The filter can be applied to strings only.'); - } - - return $this->twig->render('FMElfinderBundle:Elfinder/helper:_tinymce4.html.twig', - array( - 'instance' => $instance, - 'width' => $parameters['width'], - 'height' => $parameters['height'], - 'title' => $parameters['title'] - )); - } - - /** - * (non-PHPdoc) - * @see Twig_ExtensionInterface::getName() - */ - public function getName() - { - return 'fm_tinymce_init'; - } - -} - diff --git a/composer.json b/composer.json index 261c667..827929b 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "suggest": { "stfalcon/tinymce-bundle": "TinyMCE Bundle by Stfalcon", "egeloen/ckeditor-bundle": "CKEditor Bundle by Egeloen", - "trsteel/ckeditor-bundle": "CKEditor Bundle by trsteel" + "trsteel/ckeditor-bundle": "CKEditor Bundle by trsteel", + "helios-ag/fm-summernote-bundle": "Summernote Bundle by me" }, "autoload": { "psr-4": { "FM\\ElfinderBundle\\": "" }