-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a filename cleaning for storage when uploading an image, media or…
… file Signed-off-by: daverner <[email protected]>
- Loading branch information
Showing
8 changed files
with
148 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace SQLI\EzToolboxBundle\Services\Core\FieldType; | ||
|
||
use eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage; | ||
use eZ\Publish\SPI\Persistence\Content\Field; | ||
use eZ\Publish\SPI\Persistence\Content\VersionInfo; | ||
|
||
/** | ||
* Description of BinaryFileStorage. | ||
*/ | ||
class BinaryFileStorage extends BinaryBaseStorage | ||
{ | ||
public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context) | ||
{ | ||
// Original filename, convert characters when it's possible (or remove them) | ||
$fileName = $field->value->externalData['fileName']; | ||
$fileName = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileName); | ||
// Replace spaces | ||
$fileName = preg_replace('/\s/', '_', $fileName); | ||
// Force lower case | ||
$fileName = mb_convert_case($fileName, MB_CASE_LOWER); | ||
// Cleaned filename can be used in original process | ||
$field->value->externalData['fileName'] = $fileName; | ||
|
||
return parent::storeFieldData($versionInfo, $field, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace SQLI\EzToolboxBundle\Services\Core\FieldType; | ||
|
||
use eZ\Publish\Core\FieldType\Image\ImageStorage as BaseImageStorage; | ||
use eZ\Publish\SPI\Persistence\Content\Field; | ||
use eZ\Publish\SPI\Persistence\Content\VersionInfo; | ||
|
||
class ImageStorage extends BaseImageStorage | ||
{ | ||
public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context) | ||
{ | ||
// Original filename, convert characters when it's possible (or remove them) | ||
$fileName = $field->value->externalData['fileName']; | ||
$fileName = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileName); | ||
// Replace spaces | ||
$fileName = preg_replace('/\s/', '_', $fileName); | ||
// Force lower case | ||
$fileName = mb_convert_case($fileName, MB_CASE_LOWER); | ||
// Cleaned filename can be used in original process | ||
$field->value->externalData['fileName'] = $fileName; | ||
|
||
return parent::storeFieldData($versionInfo, $field, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace SQLI\EzToolboxBundle\Services\Core\FieldType; | ||
|
||
use eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage; | ||
use eZ\Publish\SPI\Persistence\Content\Field; | ||
use eZ\Publish\SPI\Persistence\Content\VersionInfo; | ||
|
||
/** | ||
* Description of MediaStorage. | ||
*/ | ||
class MediaStorage extends BinaryBaseStorage | ||
{ | ||
public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context) | ||
{ | ||
// Original filename, convert characters when it's possible (or remove them) | ||
$fileName = $field->value->externalData['fileName']; | ||
$fileName = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileName); | ||
// Replace spaces | ||
$fileName = preg_replace('/\s/', '_', $fileName); | ||
// Force lower case | ||
$fileName = mb_convert_case($fileName, MB_CASE_LOWER); | ||
// Cleaned filename can be used in original process | ||
$field->value->externalData['fileName'] = $fileName; | ||
|
||
return parent::storeFieldData($versionInfo, $field, $context); | ||
} | ||
} |