Skip to content

Commit

Permalink
commit changes of user "ctrl-f5" for symfony3 compatibility and optio…
Browse files Browse the repository at this point in the history
…n to keep original file extension
  • Loading branch information
Maria Tzaneti committed Aug 1, 2016
1 parent 3743918 commit fa09e55
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Controller/FileManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function listFilesAction($dir_path = null)
$parameters = $this->container->getParameter('youwe_file_manager');
$fileManager = $service->createFileManager($parameters, $driver, $dir_path);

$form = $this->createForm(new FileManagerType);
$form = $this->createForm(FileManagerType::class);
$renderParameters = $service->getRenderOptions($form);

return $this->render($fileManager->getThemeTemplate(), $renderParameters);
Expand Down Expand Up @@ -73,7 +73,7 @@ public function uploadFileAction(Request $request, $dir_path)
$parameters = $this->container->getParameter('youwe_file_manager');
$fileManager = $service->createFileManager($parameters, $driver, $dir_path);

$form = $this->createForm(new FileManagerType);
$form = $this->createForm(FileManagerType::class);

if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function getConfigTreeBuilder()
->scalarNode('filter_images')
->defaultFalse()
->end()
->scalarNode('keep_original_extension')
->defaultFalse()
->end()
->scalarNode('usage_class')
->defaultFalse()
->end()
Expand Down
3 changes: 2 additions & 1 deletion Form/Type/FileManagerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Youwe\FileManagerBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;

/**
Expand All @@ -20,7 +21,7 @@ class FileManagerType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('file', 'file', array(
$builder->add('file', FileType::class, array(
'required' => false,
'attr' => array('class' => 'form-control file_manager_url', 'multiple' => 'multiple'),
'label' => 'Files'
Expand Down
2 changes: 1 addition & 1 deletion Model/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function checkPath($path = null)
}
$upload_path = realpath($this->getUploadPath());

if (strcasecmp($real_path, $upload_path) > 0) {
if (strcasecmp($real_path, $upload_path) >= 0) {
return true;
} else {
throw new \Exception("Directory is not in the upload path", 403);
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ youwe_file_manager_list:
prefix: /filemanager

youwe_uploads:
pattern: /uploads/{name}
path: /uploads/{name}
requirements:
name: .+
defaults:
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ services:
youwe.file_manager.service:
class: Youwe\FileManagerBundle\Services\FileManagerService
arguments: ["@service_container"]
call:
- [ 'setKeepOriginalFileExtensions', ['%youwe_file_manager.keep_original_extension%'] ]

youwe.file_manager.driver:
class: Youwe\FileManagerBundle\Driver\FileManagerDriver
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Set the route and the route parameters in the ckeditor config
$form = $this->createFormBuilder()
->add('content', 'ckeditor', array(
'config' => array(
'filebrowser_image_browse_url' => array(
'filebrowserImageBrowseUrl' => array(
'route' => 'youwe_file_manager_list',
'route_parameters' => array('popup'=>'1'),
),
Expand Down
2 changes: 1 addition & 1 deletion Resources/public/css/simple/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ div.block_row:hover {
div.block_row:hover,
#FileManagerContainer .FileManagerListItems .item_selected
#FileManagerContainer .FileManagerListItems .item_selected:hover,
div.block_row.item_selected:hover,
div.block_row.item_selected:hover
{
background-color: #e0e0e0;
}
Expand Down
38 changes: 32 additions & 6 deletions Services/FileManagerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class FileManagerService
/** @var FileManager */
private $file_manager;

/**
* @var bool
*/
private $keepOriginalFileExtensions = false;

/**
* Constructor
*
Expand Down Expand Up @@ -59,6 +64,22 @@ public function getFileManager()
return $this->file_manager;
}

/**
* @return boolean
*/
public function keepOriginalFileExtensions()
{
return $this->keepOriginalFileExtensions;
}

/**
* @param boolean $keepOriginalFileExtensions
*/
public function setKeepOriginalFileExtensions($keepOriginalFileExtensions)
{
$this->keepOriginalFileExtensions = $keepOriginalFileExtensions;
}

/**
* Create the file manager object
*
Expand Down Expand Up @@ -147,10 +168,14 @@ public function handleUploadFiles($files)
$driver = $this->container->get('youwe.file_manager.driver');

$this->getFileManager()->event(YouweFileManagerEvents::BEFORE_FILE_UPLOADED);

/** @var UploadedFile $file */
foreach ($files as $file) {
$extension = $file->guessExtension();
if ($this->keepOriginalFileExtensions()) {
$extension = $file->getClientOriginalExtension();
} else {
$extension = $file->guessExtension();
}
if (!$extension) {
$extension = 'bin';
}
Expand Down Expand Up @@ -190,7 +215,7 @@ public function getRenderOptions(Form $form)
$file_manager = $this->getFileManager();
$dir_files = scandir($file_manager->getDir());
$root_dirs = scandir($file_manager->getUploadPath());
$is_popup = $this->container->get('request')->get('popup') ? true : false;
$is_popup = $this->container->get('request_stack')->getCurrentRequest()->get('popup') ? true : false;

$options['files'] = $this->getFiles($dir_files);
$options['file_body_display'] = $file_manager->getDisplayType();
Expand Down Expand Up @@ -242,8 +267,9 @@ public function setDisplayType()
$session = $this->container->get('session');
$display_type = $session->get(self::DISPLAY_TYPE_SESSION);

if ($this->container->get('request')->get('display_type') != null) {
$display_type = $this->container->get('request')->get('display_type');
$request = $this->container->get('request_stack')->getCurrentRequest();
if ($request->get('display_type') != null) {
$display_type = $request->get('display_type');
$session->set(self::DISPLAY_TYPE_SESSION, $display_type);
} else {
if (is_null($display_type)) {
Expand Down Expand Up @@ -380,4 +406,4 @@ public function isAllowedGetAction($action)
);
return in_array($action, $allowed_get);
}
}
}
2 changes: 1 addition & 1 deletion Twig/FileManagerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(ContainerInterface $container)
public function getFilters()
{
return array(
'thumb' => new \Twig_Filter_Method($this, 'thumb'),
new \Twig_SimpleFilter('thumb', [$this, 'thumb']),
);
}

Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": "~2.0",
"symfony/finder": "*",
"symfony/filesystem": "*",
"friendsofsymfony/jsrouting-bundle": "@stable"
"symfony/framework-bundle": "^3.0",
"symfony/finder": "^3.0",
"symfony/filesystem": "^3.0",
"friendsofsymfony/jsrouting-bundle": "@stable",
"symfony/assetic-bundle": "^2.8"
},
"suggest": {
"liip/imagine-bundle": "Liip Imagine Bundle provides easy image manipulation support for Symfony2."
Expand All @@ -29,7 +30,7 @@
"target-dir": "Youwe/FileManagerBundle",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "2.x-dev"
}
}
}
}

0 comments on commit fa09e55

Please sign in to comment.