Add a core feature to rename new image and thumbnail with his MD5 hash

This commit is contained in:
grz 2021-01-07 15:03:45 +01:00
parent 17ddd0343d
commit cd242e8d3f
6 changed files with 25 additions and 4 deletions

View file

@ -443,6 +443,15 @@
<!-- Images tab -->
<div class="tab-pane fade" id="images" role="tabpanel" aria-labelledby="images-tab">
<?php
echo Bootstrap::formCheckbox(array(
'name'=>'renameImageWithHash',
'label'=>'',
'labelForCheckbox'=>$L->g('rename-new-images-and-thumbnails-with-hash'),
'checked'=>$site->renameImageWithHash(),
'placeholder'=>'',
'tip'=>$L->g('Activate').' / '.$L->g('Deactivate')
));
echo Bootstrap::formTitle(array('title'=>$L->g('Thumbnails')));
echo Bootstrap::formInputText(array(

View file

@ -879,7 +879,7 @@ function transformImage($file, $imageDir, $thumbnailDir=false) {
// Generate a filename to not overwrite current image if exists
$filename = Filesystem::filename($file);
$nextFilename = Filesystem::nextFilename($imageDir, $filename);
$nextFilename = Filesystem::nextFilename($imageDir, $filename, $site->renameImageWithHash());
// Move the image to a proper place and rename
$image = $imageDir.$nextFilename;

View file

@ -217,7 +217,7 @@ class Filesystem {
|
| @return string
*/
public static function nextFilename($path=PATH_UPLOADS, $filename) {
public static function nextFilename($path=PATH_UPLOADS, $filename, $hash=false) {
// Clean filename and get extension
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
$fileExtension = Text::lowercase($fileExtension);
@ -225,6 +225,10 @@ class Filesystem {
$filename = Text::removeSpaces($filename);
$filename = Text::removeQuotes($filename);
if ($hash) {
$filename = md5($filename);
}
// Search for the next filename
$tmpName = $filename.'.'.$fileExtension;
if (Sanitize::pathFile($path.$tmpName)) {

View file

@ -43,6 +43,7 @@ class Site extends dbJSON {
'titleFormatTag'=> '{{tag-name}} | {{site-title}}',
'imageRestrict'=> true,
'imageRelativeToAbsolute'=> false,
'renameImageWithHash' => false,
'thumbnailWidth'=> 400, // px
'thumbnailHeight'=> 400, // px
'thumbnailQuality'=> 100,
@ -119,6 +120,11 @@ class Site extends dbJSON {
return DOMAIN_BASE.'sitemap.xml';
}
public function renameImageWithHash()
{
return $this->getField('renameImageWithHash');
}
public function thumbnailWidth()
{
return $this->getField('thumbnailWidth');
@ -420,4 +426,4 @@ class Site extends dbJSON {
return json_decode($customFields, true);
}
}
}

View file

@ -376,6 +376,7 @@
"thumbnail-width-in-pixels": "Thumbnail width in pixels (px).",
"thumbnail-height-in-pixels": "Thumbnail height in pixels (px).",
"thumbnail-quality-in-percentage": "Thumbnail quality in percentage (%).",
"rename-new-images-and-thumbnails-with-hash": "Rename new images and thumbnails with hash",
"maximum-load-file-size-allowed:": "Maximum load file size allowed:",
"file-type-is-not-supported": "File type is not supported. Allowed types:",
"page-content": "Page content",

View file

@ -376,6 +376,7 @@
"thumbnail-width-in-pixels": "Largeur de la miniature en pixels (px).",
"thumbnail-height-in-pixels": "Hauteur de la miniature en pixels (px).",
"thumbnail-quality-in-percentage": "Qualité des miniatures en pourcentage (%).",
"rename-new-images-and-thumbnails-with-hash": "Renommer les nouvelles images et miniatures avec un hash",
"maximum-load-file-size-allowed:": "Taille maximale des fichiers autorisée :",
"file-type-is-not-supported": "Le type de fichier nest pas supporté. Liste des extensions autorisées :",
"page-content": "Contenu de la page",
@ -392,4 +393,4 @@
"define-custom-fields-for-the-content": "Define custom fields for the content. Learn more about custom fields in the <a href='https:\/\/docs.bludit.com\/en\/content\/custom-fields'>documentation<\/a>.",
"start-typing-to-see-a-list-of-suggestions": "Start typing to see a list of suggestions.",
"view": "View"
}
}