Page URL from title, UUID for pages files

This commit is contained in:
Diego Najar 2022-02-23 14:15:10 +01:00
parent 347bc6fbbb
commit 1d6e1d8fc0
3 changed files with 36 additions and 30 deletions

View file

@ -38,7 +38,7 @@
// Set the global variable with the page key // Set the global variable with the page key
_pageKey = response.data.key; _pageKey = response.data.key;
// Set Friendly URL // Set Friendly URL
$('#friendlyURL').val(response.data.key); //$('#friendlyURL').val(response.data.key);
// Get current files // Get current files
fmGetFiles(); fmGetFiles();
} else { } else {
@ -76,7 +76,7 @@
// The page key can change after save the page so you need to set again the variable // The page key can change after save the page so you need to set again the variable
_pageKey = response.data.key; _pageKey = response.data.key;
// Set friendly URL with the key // Set friendly URL with the key
$('#friendlyURL').val(response.data.key); //$('#friendlyURL').val(response.data.key);
} else { } else {
logs('An error occurred while trying to save the current page.'); logs('An error occurred while trying to save the current page.');
showAlertError(response.message); showAlertError(response.message);
@ -138,6 +138,7 @@
customFields[field] = value customFields[field] = value
}); });
var args = { var args = {
slug: $('#friendlyURL').val(),
title: $('#title').val(), title: $('#title').val(),
content: editorGetContent(), content: editorGetContent(),
custom: customFields, custom: customFields,
@ -191,8 +192,8 @@
var value = $(this).val() var value = $(this).val()
customFields[field] = value customFields[field] = value
}); });
var args = { var args = {
slug: $('#friendlyURL').val(),
title: $('#title').val(), title: $('#title').val(),
content: editorGetContent(), content: editorGetContent(),
custom: customFields, custom: customFields,
@ -215,6 +216,7 @@
}); });
$('#coverImagePreview').dblclick(function() { $('#coverImagePreview').dblclick(function() {
logs('Removing cover image.');
$('#coverImage').val(''); $('#coverImage').val('');
$(this).attr('src', HTML_PATH_CORE_IMG + 'default.svg'); $(this).attr('src', HTML_PATH_CORE_IMG + 'default.svg');
var args = { coverImage: '' } var args = { coverImage: '' }
@ -389,6 +391,7 @@
}); });
var args = { var args = {
slug: $('#friendlyURL').val(),
title: $('#title').val(), title: $('#title').val(),
content: content, content: content,
custom: customFields, custom: customFields,

View file

@ -153,8 +153,14 @@ class Pages extends dbJSON {
} }
// Create the upload directory for the page // Create the upload directory for the page
if (Filesystem::mkdir(PATH_UPLOADS_PAGES.$key, true) === false) { if (Filesystem::mkdir(PATH_UPLOADS_PAGES.$row['uuid'], true) === false) {
Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to create the directory: '.PATH_UPLOADS_PAGES.$key, LOG_TYPE_ERROR); Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to create the directory: '.PATH_UPLOADS_PAGES.$row['uuid'], LOG_TYPE_ERROR);
return false;
}
// Create symlink for the upload directory
if (symlink(PATH_UPLOADS_PAGES.$row['uuid'], PATH_UPLOADS_PAGES.$key) === false) {
Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to create the symlink: '.PATH_UPLOADS_PAGES.$key, LOG_TYPE_ERROR);
return false; return false;
} }
@ -238,8 +244,12 @@ class Pages extends dbJSON {
// If the user send an empty slug the page key doesn't change // If the user send an empty slug the page key doesn't change
// This variable is not belong to the database so is not defined in $row // This variable is not belong to the database so is not defined in $row
if (empty($args['slug'])) { if (empty($args['slug'])) {
$explode = explode('/', $key); if (!empty($args['title'])) {
$slug = end($explode); $slug = $args['title'];
} else {
$explode = explode('/', $key);
$slug = end($explode);
}
} else { } else {
$slug = $args['slug']; $slug = $args['slug'];
} }
@ -271,7 +281,9 @@ class Pages extends dbJSON {
return false; return false;
} }
if (Filesystem::mv(PATH_UPLOADS_PAGES.$key, PATH_UPLOADS_PAGES.$newKey) === false) { // Regenerate the symlink to a proper directory
unlink(PATH_UPLOADS_PAGES.$key);
if (symlink(PATH_UPLOADS_PAGES.$row['uuid'], PATH_UPLOADS_PAGES.$newKey) === false) {
Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to move the directory: '.PATH_UPLOADS_PAGES.$newKey, LOG_TYPE_ERROR); Log::set(__METHOD__.LOG_SEP.'An error occurred while trying to move the directory: '.PATH_UPLOADS_PAGES.$newKey, LOG_TYPE_ERROR);
return false; return false;
} }

View file

@ -954,26 +954,17 @@ class pluginAPI extends Plugin {
); );
} }
/* /**
Returns all files uploaded for a specific page. * Returns all files uploaded for a specific page.
Includes all files types. * @param string $pageKey Page's key
* @return array List of files in return['data'], status in return['status']
@pageKey string The page's key */
@return['data'] array The list of files
*/
private function getFiles($pageKey) private function getFiles($pageKey)
{ {
$chunk = false; $chunk = false;
$sortByDate = true; $sortByDate = true;
$path = PATH_UPLOADS_PAGES.$pageKey.DS; $page = new Page($pageKey);
$path = PATH_UPLOADS_PAGES.$page->uuid().DS;
if (Sanitize::pathFile($path) === false) {
return array(
'status'=>'1',
'message'=>'Invalid path.'
);
}
$files = array(); $files = array();
$listFiles = Filesystem::listFiles($path, '*', '*', $sortByDate, $chunk); $listFiles = Filesystem::listFiles($path, '*', '*', $sortByDate, $chunk);
@ -984,17 +975,17 @@ class pluginAPI extends Plugin {
$filename = Filesystem::filename($file); $filename = Filesystem::filename($file);
$fileExtension = Filesystem::extension($file); $fileExtension = Filesystem::extension($file);
$absoluteURL = DOMAIN_UPLOADS_PAGES.$pageKey.DS.$filename.'.'.$fileExtension; $absoluteURL = DOMAIN_UPLOADS_PAGES.$page->uuid().DS.$filename.'.'.$fileExtension;
$absolutePath = PATH_UPLOADS_PAGES.$pageKey.DS.$filename.'.'.$fileExtension; $absolutePath = PATH_UPLOADS_PAGES.$page->uuid().DS.$filename.'.'.$fileExtension;
$thumbnailSmall = ''; $thumbnailSmall = '';
if (Filesystem::fileExists(PATH_UPLOADS_PAGES.$pageKey.DS.$filename.'-thumbnail-s.'.$fileExtension)) { if (Filesystem::fileExists(PATH_UPLOADS_PAGES.$page->uuid().DS.$filename.'-thumbnail-s.'.$fileExtension)) {
$thumbnailSmall = DOMAIN_UPLOADS_PAGES.$pageKey.DS.$filename.'-thumbnail-s.'.$fileExtension; $thumbnailSmall = DOMAIN_UPLOADS_PAGES.$page->uuid().DS.$filename.'-thumbnail-s.'.$fileExtension;
} }
$thumbnailMedium = ''; $thumbnailMedium = '';
if (Filesystem::fileExists(PATH_UPLOADS_PAGES.$pageKey.DS.$filename.'-thumbnail-m.'.$fileExtension)) { if (Filesystem::fileExists(PATH_UPLOADS_PAGES.$page->uuid().DS.$filename.'-thumbnail-m.'.$fileExtension)) {
$thumbnailMedium = DOMAIN_UPLOADS_PAGES.$pageKey.DS.$filename.'-thumbnail-m.'.$fileExtension; $thumbnailMedium = DOMAIN_UPLOADS_PAGES.$page->uuid().DS.$filename.'-thumbnail-m.'.$fileExtension;
} }
$data = array( $data = array(