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
if (IMAGE_RESTRICT) {
$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;
$thumbnailHTML = HTML_PATH_UPLOADS_PAGES.$uuid.'/thumbnails/';
$thumbnailURL = DOMAIN_UPLOADS_PAGES.$uuid.'/thumbnails/';
} else {
$imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS);
$imagesURL = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS);
$thumbnailDirectory = 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']);
$preLoadFiles = array();
@ -99,15 +103,15 @@ function displayFiles(files) {
cleanFiles();
// Regenerate the table
$.each(files, function(key, filename) {
var thumbnail = "<?php echo $thumbnailHTML; ?>"+filename;
var path = "<?php echo $imagesDirectory; ?>";
var thumbnail = "<?php echo $thumbnailURL; ?>"+filename;
var image = "<?php echo $imagesURL; ?>"+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 class="information">'+
'<div class="pb-2">'+filename+'<\/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-secondary btn-sm float-right" onClick="deleteMedia(\''+filename+'\')"><?php $L->p('Delete') ?><\/button>'+
'<\/div>'+
@ -133,9 +137,10 @@ function getFiles(pageNumber) {
// Delete the file and the thumbnail if exist
function deleteMedia(filename) {
$.post(HTML_PATH_ADMIN_ROOT+"ajax/delete-file",
$.post(HTML_PATH_ADMIN_ROOT+"ajax/delete-image",
{ tokenCSRF: tokenCSRF,
filename: filename
filename: filename,
uuid: "<?php echo $uuid; ?>"
},
function(data) {
getFiles(1);
@ -144,9 +149,9 @@ function deleteMedia(filename) {
}
function setCoverImage(filename) {
var thumbnail = "<?php echo $thumbnailHTML; ?>"+filename;
var image = "<?php echo $imagesURL; ?>"+filename;
$("#jscoverImage").val(filename);
$("#jscoverImagePreview").attr("src", thumbnail);
$("#jscoverImagePreview").attr("src", image);
}
$(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
$filename = isset($_POST['filename']) ? $_POST['filename'] : false;
// (string) $_POST['uuid']
$uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
// ----------------------------------------------------------------------------
if ($filename==false) {
@ -14,19 +17,27 @@ if ($filename==false) {
)));
}
// Check if the filename exist
if (Sanitize::pathFile(PATH_UPLOADS.$filename)) {
Filesystem::rmfile(PATH_UPLOADS.$filename);
if ($uuid && IMAGE_RESTRICT) {
$imagePath = PATH_UPLOADS_PAGES.$uuid.DS;
$thumbnailPath = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS;
} else {
$imagePath = PATH_UPLOADS;
$thumbnailPath = PATH_UPLOADS_THUMBNAILS;
}
// Check if the file has a thumbnail
if (Sanitize::pathFile(PATH_UPLOADS_THUMBNAILS.$filename)) {
Filesystem::rmfile(PATH_UPLOADS_THUMBNAILS.$filename);
// Delete image
if (Sanitize::pathFile($imagePath.$filename)) {
Filesystem::rmfile($imagePath.$filename);
}
// Delete thumbnail
if (Sanitize::pathFile($thumbnailPath.$filename)) {
Filesystem::rmfile($thumbnailPath.$filename);
}
exit (json_encode(array(
'status'=>0,
'message'=>'File deleted.'
'message'=>'Image deleted.'
)));
?>

View File

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

View File

@ -2,6 +2,6 @@
"plugin-data":
{
"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": "",
"website": "https://plugins.bludit.com",
"version": "3.0",
"releaseDate": "2018-01-23",
"releaseDate": "2018-10-07",
"license": "MIT",
"compatible": "3.0",
"notes": ""

View File

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

View File

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