2018-04-04 23:46:36 +02:00
|
|
|
<?php
|
2018-04-09 22:56:12 +02:00
|
|
|
// Preload the first 10 files to not call via AJAX when the user open the first time the media manager
|
2018-10-06 19:39:34 +02:00
|
|
|
if (IMAGE_RESTRICT) {
|
2018-10-07 13:19:36 +02:00
|
|
|
$imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS_PAGES.$uuid.'/');
|
2018-10-07 23:11:49 +02:00
|
|
|
$imagesURL = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS_PAGES.$uuid.'/');
|
2018-10-06 19:39:34 +02:00
|
|
|
$thumbnailDirectory = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS;
|
|
|
|
$thumbnailHTML = HTML_PATH_UPLOADS_PAGES.$uuid.'/thumbnails/';
|
2018-10-07 23:11:49 +02:00
|
|
|
$thumbnailURL = DOMAIN_UPLOADS_PAGES.$uuid.'/thumbnails/';
|
2018-10-06 19:39:34 +02:00
|
|
|
} else {
|
|
|
|
$imagesDirectory = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : HTML_PATH_UPLOADS);
|
2018-10-07 23:11:49 +02:00
|
|
|
$imagesURL = (IMAGE_RELATIVE_TO_ABSOLUTE? '' : DOMAIN_UPLOADS);
|
2018-10-06 19:39:34 +02:00
|
|
|
$thumbnailDirectory = PATH_UPLOADS_THUMBNAILS;
|
|
|
|
$thumbnailHTML = HTML_PATH_UPLOADS_THUMBNAILS;
|
2018-10-07 23:11:49 +02:00
|
|
|
$thumbnailURL = DOMAIN_UPLOADS_THUMBNAILS;
|
2018-10-06 19:39:34 +02:00
|
|
|
}
|
|
|
|
$listOfFilesByPage = Filesystem::listFiles($thumbnailDirectory, '*', '*', $GLOBALS['MEDIA_MANAGER_SORT_BY_DATE'], $GLOBALS['MEDIA_MANAGER_NUMBER_OF_FILES']);
|
2018-04-04 23:46:36 +02:00
|
|
|
$preLoadFiles = array();
|
2018-05-08 00:15:40 +02:00
|
|
|
if (!empty($listOfFilesByPage[0])) {
|
|
|
|
foreach ($listOfFilesByPage[0] as $file) {
|
2018-10-06 19:39:34 +02:00
|
|
|
$filename = basename($file);
|
|
|
|
array_push($preLoadFiles, $filename);
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
2018-04-09 22:56:12 +02:00
|
|
|
// Amount of pages for the paginator
|
2018-08-06 21:46:58 +02:00
|
|
|
$numberOfPages = count($listOfFilesByPage);
|
2018-04-04 23:46:36 +02:00
|
|
|
?>
|
|
|
|
|
2018-10-17 22:35:30 +02:00
|
|
|
<div id="jsmediaManagerModal" class="modal" tabindex="-1" role="dialog">
|
2018-04-04 23:46:36 +02:00
|
|
|
<div class="modal-dialog modal-lg">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="container-fluid">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col p-3">
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
<!--
|
|
|
|
UPLOAD INPUT
|
|
|
|
-->
|
2018-08-19 17:45:49 +02:00
|
|
|
<h3 class="mt-2 mb-3"><?php $L->p('Upload'); ?></h3>
|
2018-04-09 22:56:12 +02:00
|
|
|
|
|
|
|
<!-- Form and Input file -->
|
|
|
|
<form name="bluditFormUpload" id="jsbluditFormUpload" enctype="multipart/form-data">
|
|
|
|
<div class="custom-file">
|
|
|
|
<input type="file" class="custom-file-input" id="jsbluditInputFiles" name="bluditInputFiles[]" multiple>
|
2018-08-19 17:45:49 +02:00
|
|
|
<label class="custom-file-label" for="jsbluditInputFiles"><?php $L->p('Choose images to upload'); ?></label>
|
2018-04-09 22:56:12 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<!-- Progress bar -->
|
|
|
|
<div class="progress mt-2">
|
|
|
|
<div id="jsbluditProgressBar" class="progress-bar bg-info" role="progressbar" style="width:0%"></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!--
|
|
|
|
MANAGER
|
|
|
|
-->
|
2018-08-19 17:45:49 +02:00
|
|
|
<h3 class="mt-4 mb-3"><?php $L->p('Manage'); ?></h3>
|
2018-04-09 22:56:12 +02:00
|
|
|
|
|
|
|
<!-- Table for list files -->
|
2018-05-08 23:25:18 +02:00
|
|
|
<table id="jsbluditMediaTable" class="table">
|
|
|
|
<tr>
|
2018-08-19 17:45:49 +02:00
|
|
|
<td><?php $L->p('There are no images'); ?></td>
|
2018-05-08 23:25:18 +02:00
|
|
|
</tr>
|
|
|
|
</table>
|
2018-04-09 22:56:12 +02:00
|
|
|
|
|
|
|
<!-- Paginator -->
|
2018-04-04 23:46:36 +02:00
|
|
|
<nav>
|
|
|
|
<ul class="pagination justify-content-center">
|
2018-08-06 21:46:58 +02:00
|
|
|
<?php for ($i=1; $i<=$numberOfPages; $i++): ?>
|
2018-04-09 22:56:12 +02:00
|
|
|
<li class="page-item"><button type="button" class="btn btn-link page-link" onClick="getFiles(<?php echo $i ?>)"><?php echo $i ?></button></li>
|
|
|
|
<?php endfor; ?>
|
2018-04-04 23:46:36 +02:00
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
echo 'var preLoadFiles = '.json_encode($preLoadFiles).';';
|
|
|
|
?>
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
function openMediaManager() {
|
2018-10-17 22:35:30 +02:00
|
|
|
$('#jsmediaManagerModal').modal('show');
|
2018-04-13 23:32:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function closeMediaManager() {
|
2018-10-17 22:35:30 +02:00
|
|
|
$('#jsmediaManagerModal').modal('hide');
|
2018-04-13 23:32:29 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
// Remove all files from the table
|
2018-10-17 22:35:30 +02:00
|
|
|
function cleanTable() {
|
2018-04-09 22:56:12 +02:00
|
|
|
$('#jsbluditMediaTable').empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the files in the table
|
|
|
|
function displayFiles(files) {
|
|
|
|
// Clean table
|
2018-10-17 22:35:30 +02:00
|
|
|
cleanTable();
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
// Regenerate the table
|
2018-10-17 22:35:30 +02:00
|
|
|
if (files.length > 0) {
|
|
|
|
$.each(files, function(key, filename) {
|
|
|
|
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(\''+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>'+
|
|
|
|
'<\/td>'+
|
|
|
|
'<\/tr>';
|
|
|
|
$('#jsbluditMediaTable').append(tableRow);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (files.length == 0) {
|
|
|
|
$('#jsbluditMediaTable').html("<p><?php (IMAGE_RESTRICT ? $L->p('There are no images for the page') : $L->p('There are no images')) ?></p>");
|
|
|
|
}
|
2018-04-04 23:46:36 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
// Get the list of files via AJAX, filter by the page number
|
|
|
|
function getFiles(pageNumber) {
|
2018-10-06 19:39:34 +02:00
|
|
|
$.post(HTML_PATH_ADMIN_ROOT+"ajax/list-images",
|
2018-04-13 23:32:29 +02:00
|
|
|
{ tokenCSRF: tokenCSRF,
|
|
|
|
pageNumber: pageNumber,
|
2018-10-06 19:39:34 +02:00
|
|
|
uuid: "<?php echo $uuid; ?>",
|
|
|
|
path: "thumbnails" // the paths are defined in the list-images.php
|
2018-04-13 23:32:29 +02:00
|
|
|
},
|
2018-04-09 22:56:12 +02:00
|
|
|
function(data) {
|
|
|
|
displayFiles(data.files);
|
2018-10-06 19:39:34 +02:00
|
|
|
}
|
|
|
|
);
|
2018-04-09 22:56:12 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// Delete the file and the thumbnail if exist
|
|
|
|
function deleteMedia(filename) {
|
2018-10-07 23:11:49 +02:00
|
|
|
$.post(HTML_PATH_ADMIN_ROOT+"ajax/delete-image",
|
2018-04-13 23:32:29 +02:00
|
|
|
{ tokenCSRF: tokenCSRF,
|
2018-10-07 23:11:49 +02:00
|
|
|
filename: filename,
|
|
|
|
uuid: "<?php echo $uuid; ?>"
|
2018-04-13 23:32:29 +02:00
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
getFiles(1);
|
2018-10-06 19:39:34 +02:00
|
|
|
}
|
|
|
|
);
|
2018-04-13 23:32:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 23:25:18 +02:00
|
|
|
function setCoverImage(filename) {
|
2018-10-07 23:11:49 +02:00
|
|
|
var image = "<?php echo $imagesURL; ?>"+filename;
|
2018-05-08 23:25:18 +02:00
|
|
|
$("#jscoverImage").val(filename);
|
2018-10-07 23:11:49 +02:00
|
|
|
$("#jscoverImagePreview").attr("src", image);
|
2018-05-08 23:25:18 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
// Display the files preloaded for the first time
|
|
|
|
displayFiles(preLoadFiles);
|
|
|
|
|
|
|
|
// Event to wait the selected files
|
|
|
|
$("#jsbluditInputFiles").on("change", function() {
|
2018-04-04 23:46:36 +02:00
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
// Check file size ?
|
|
|
|
// Check file type/extension ?
|
|
|
|
|
2018-10-06 19:39:34 +02:00
|
|
|
$("#jsbluditProgressBar").width("1%");
|
|
|
|
|
|
|
|
// Data to send via AJAX
|
|
|
|
var uuid = $("#jsuuid").val();
|
|
|
|
var formData = new FormData($("#jsbluditFormUpload")[0]);
|
|
|
|
formData.append('uuid', uuid);
|
|
|
|
formData.append('tokenCSRF', tokenCSRF);
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
$.ajax({
|
2018-10-06 19:39:34 +02:00
|
|
|
url: HTML_PATH_ADMIN_ROOT+"ajax/upload-images",
|
2018-04-09 22:56:12 +02:00
|
|
|
type: "POST",
|
2018-10-06 19:39:34 +02:00
|
|
|
data: formData,
|
2018-04-09 22:56:12 +02:00
|
|
|
cache: false,
|
|
|
|
contentType: false,
|
|
|
|
processData: false,
|
|
|
|
xhr: function() {
|
|
|
|
var xhr = $.ajaxSettings.xhr();
|
|
|
|
if (xhr.upload) {
|
|
|
|
xhr.upload.addEventListener("progress", function(e) {
|
|
|
|
if (e.lengthComputable) {
|
2018-04-13 23:32:29 +02:00
|
|
|
var percentComplete = (e.loaded / e.total)*100;
|
2018-04-09 22:56:12 +02:00
|
|
|
$("#jsbluditProgressBar").width(percentComplete+"%");
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
return xhr;
|
|
|
|
}
|
2018-04-13 23:32:29 +02:00
|
|
|
}).done(function() {
|
2018-05-08 23:25:18 +02:00
|
|
|
// Get the files of the first page, this include the files uploaded
|
2018-04-13 23:32:29 +02:00
|
|
|
getFiles(1);
|
2018-04-09 22:56:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-04-04 23:46:36 +02:00
|
|
|
|
2018-05-08 00:15:40 +02:00
|
|
|
</script>
|