bug fix when insert image and cover images

This commit is contained in:
Diego Najar 2018-10-07 23:11:49 +02:00
parent eb81472081
commit 23ea0fe6e4
8 changed files with 58 additions and 26 deletions

View File

@ -2,12 +2,16 @@
// Preload the first 10 files to not call via AJAX when the user open the first time the media manager // Preload the first 10 files to not call via AJAX when the user open the first time the media manager
if (IMAGE_RESTRICT) { if (IMAGE_RESTRICT) {
$imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS_PAGES.$uuid.'/'); $imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS_PAGES.$uuid.'/');
$imagesURL = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS_PAGES.$uuid.'/');
$thumbnailDirectory = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS; $thumbnailDirectory = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS;
$thumbnailHTML = HTML_PATH_UPLOADS_PAGES.$uuid.'/thumbnails/'; $thumbnailHTML = HTML_PATH_UPLOADS_PAGES.$uuid.'/thumbnails/';
$thumbnailURL = DOMAIN_UPLOADS_PAGES.$uuid.'/thumbnails/';
} else { } else {
$imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS); $imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS);
$imagesURL = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS);
$thumbnailDirectory = PATH_UPLOADS_THUMBNAILS; $thumbnailDirectory = PATH_UPLOADS_THUMBNAILS;
$thumbnailHTML = HTML_PATH_UPLOADS_THUMBNAILS; $thumbnailHTML = HTML_PATH_UPLOADS_THUMBNAILS;
$thumbnailURL = DOMAIN_UPLOADS_THUMBNAILS;
} }
$listOfFilesByPage = Filesystem::listFiles($thumbnailDirectory, '*', '*', $GLOBALS['MEDIA_MANAGER_SORT_BY_DATE'], $GLOBALS['MEDIA_MANAGER_NUMBER_OF_FILES']); $listOfFilesByPage = Filesystem::listFiles($thumbnailDirectory, '*', '*', $GLOBALS['MEDIA_MANAGER_SORT_BY_DATE'], $GLOBALS['MEDIA_MANAGER_NUMBER_OF_FILES']);
$preLoadFiles = array(); $preLoadFiles = array();
@ -99,15 +103,15 @@ function displayFiles(files) {
cleanFiles(); cleanFiles();
// Regenerate the table // Regenerate the table
$.each(files, function(key, filename) { $.each(files, function(key, filename) {
var thumbnail = "<?php echo $thumbnailHTML; ?>"+filename; var thumbnail = "<?php echo $thumbnailURL; ?>"+filename;
var path = "<?php echo $imagesDirectory; ?>"; var image = "<?php echo $imagesURL; ?>"+filename;
tableRow = '<tr id="js'+filename+'">'+ tableRow = '<tr id="js'+filename+'">'+
'<td style="width:80px"><img class="img-thumbnail" alt="200x200" src="'+thumbnail+'" style="width: 50px; height: 50px;"><\/td>'+ '<td style="width:80px"><img class="img-thumbnail" alt="200x200" src="'+thumbnail+'" style="width: 50px; height: 50px;"><\/td>'+
'<td class="information">'+ '<td class="information">'+
'<div class="pb-2">'+filename+'<\/div>'+ '<div class="pb-2">'+filename+'<\/div>'+
'<div>'+ '<div>'+
'<button type="button" class="btn btn-primary btn-sm mr-2" onClick="editorInsertMedia(\''+path+filename+'\'); closeMediaManager();"><?php $L->p('Insert') ?><\/button>'+ '<button type="button" class="btn btn-primary btn-sm mr-2" onClick="editorInsertMedia(\''+image+'\'); closeMediaManager();"><?php $L->p('Insert') ?><\/button>'+
'<button type="button" class="btn btn-primary btn-sm" onClick="setCoverImage(\''+filename+'\'); closeMediaManager();"><?php $L->p('Set as cover image') ?><\/button>'+ '<button type="button" class="btn btn-primary btn-sm" onClick="setCoverImage(\''+filename+'\'); closeMediaManager();"><?php $L->p('Set as cover image') ?><\/button>'+
'<button type="button" class="btn btn-secondary btn-sm float-right" onClick="deleteMedia(\''+filename+'\')"><?php $L->p('Delete') ?><\/button>'+ '<button type="button" class="btn btn-secondary btn-sm float-right" onClick="deleteMedia(\''+filename+'\')"><?php $L->p('Delete') ?><\/button>'+
'<\/div>'+ '<\/div>'+
@ -133,9 +137,10 @@ function getFiles(pageNumber) {
// Delete the file and the thumbnail if exist // Delete the file and the thumbnail if exist
function deleteMedia(filename) { function deleteMedia(filename) {
$.post(HTML_PATH_ADMIN_ROOT+"ajax/delete-file", $.post(HTML_PATH_ADMIN_ROOT+"ajax/delete-image",
{ tokenCSRF: tokenCSRF, { tokenCSRF: tokenCSRF,
filename: filename filename: filename,
uuid: "<?php echo $uuid; ?>"
}, },
function(data) { function(data) {
getFiles(1); getFiles(1);
@ -144,9 +149,9 @@ function deleteMedia(filename) {
} }
function setCoverImage(filename) { function setCoverImage(filename) {
var thumbnail = "<?php echo $thumbnailHTML; ?>"+filename; var image = "<?php echo $imagesURL; ?>"+filename;
$("#jscoverImage").val(filename); $("#jscoverImage").val(filename);
$("#jscoverImagePreview").attr("src", thumbnail); $("#jscoverImagePreview").attr("src", image);
} }
$(document).ready(function() { $(document).ready(function() {

View File

@ -5,6 +5,9 @@ header('Content-Type: application/json');
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// (string) $_POST['path'] Name of file to delete, just the filename // (string) $_POST['path'] Name of file to delete, just the filename
$filename = isset($_POST['filename']) ? $_POST['filename'] : false; $filename = isset($_POST['filename']) ? $_POST['filename'] : false;
// (string) $_POST['uuid']
$uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
if ($filename==false) { if ($filename==false) {
@ -14,19 +17,27 @@ if ($filename==false) {
))); )));
} }
// Check if the filename exist if ($uuid && IMAGE_RESTRICT) {
if (Sanitize::pathFile(PATH_UPLOADS.$filename)) { $imagePath = PATH_UPLOADS_PAGES.$uuid.DS;
Filesystem::rmfile(PATH_UPLOADS.$filename); $thumbnailPath = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS;
} else {
$imagePath = PATH_UPLOADS;
$thumbnailPath = PATH_UPLOADS_THUMBNAILS;
} }
// Check if the file has a thumbnail // Delete image
if (Sanitize::pathFile(PATH_UPLOADS_THUMBNAILS.$filename)) { if (Sanitize::pathFile($imagePath.$filename)) {
Filesystem::rmfile(PATH_UPLOADS_THUMBNAILS.$filename); Filesystem::rmfile($imagePath.$filename);
}
// Delete thumbnail
if (Sanitize::pathFile($thumbnailPath.$filename)) {
Filesystem::rmfile($thumbnailPath.$filename);
} }
exit (json_encode(array( exit (json_encode(array(
'status'=>0, 'status'=>0,
'message'=>'File deleted.' 'message'=>'Image deleted.'
))); )));
?> ?>

View File

@ -13,12 +13,21 @@ if ($query===false) {
))); )));
} }
$tmp = array(); $list = array();
$parents = buildParentPages(); $published = $pages->getPublishedDB();
foreach ($parents as $parent) { $statics = $pages->getStaticDB();
$lowerTitle = Text::lowercase($parent->title()); $pagesKey = array_merge($published, $statics);
if (Text::stringContains($lowerTitle, $query)) { foreach ($pagesKey as $pageKey) {
$tmp[$parent->title()] = $parent->key(); try {
$page = new Page($pageKey);
if ($page->isParent()) {
$lowerTitle = Text::lowercase($page->title());
if (Text::stringContains($lowerTitle, $query)) {
$tmp[$page->title()] = $page->key();
}
}
} catch (Exception $e) {
// continue
} }
} }

View File

@ -2,6 +2,6 @@
"plugin-data": "plugin-data":
{ {
"name": "Search", "name": "Search",
"description": "" "description": "Provide a search box to your users to search through the content of your site."
} }
} }

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Buscador",
"description": "Este plugin provee un buscador para tus usuarios para buscar a través del contenido de su sitio."
}
}

View File

@ -3,7 +3,7 @@
"email": "", "email": "",
"website": "https://plugins.bludit.com", "website": "https://plugins.bludit.com",
"version": "3.0", "version": "3.0",
"releaseDate": "2018-01-23", "releaseDate": "2018-10-07",
"license": "MIT", "license": "MIT",
"compatible": "3.0", "compatible": "3.0",
"notes": "" "notes": ""

View File

@ -9,8 +9,8 @@ class pluginSearch extends Plugin {
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>'search', 'label'=>'Search',
'wordsToCachePerPage'=>300 'wordsToCachePerPage'=>800
); );
} }

View File

@ -119,13 +119,13 @@ tinymce.init({
schema: "html5", schema: "html5",
statusbar: false, statusbar: false,
menubar:false, menubar:false,
remove_script_host: false,
branding: false, branding: false,
browser_spellcheck: true, browser_spellcheck: true,
pagebreak_separator: PAGE_BREAK, pagebreak_separator: PAGE_BREAK,
paste_as_text: true, paste_as_text: true,
relative_urls: true,
remove_script_host: false, remove_script_host: false,
convert_urls: true,
relative_urls: false,
$document_base_url $document_base_url
plugins: ["$plugins"], plugins: ["$plugins"],
toolbar1: "$toolbar1", toolbar1: "$toolbar1",