bludit/bl-kernel/ajax/list-images.php

62 lines
1.8 KiB
PHP
Raw Normal View History

<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
2019-04-23 23:12:38 +02:00
/*
2019-05-27 19:41:46 +02:00
| Returns a list of images from a particular page
2019-04-23 23:12:38 +02:00
|
| @_POST['pageNumber'] int Page number for the paginator
| @_POST['path'] string Pre-defined name for the directory to read, its pre-defined to avoid security issues
2019-05-27 19:41:46 +02:00
| @_POST['uuid'] string Page UUID
2019-04-23 23:12:38 +02:00
|
| @return array
*/
// $_POST
2018-04-09 22:56:12 +02:00
// ----------------------------------------------------------------------------
2019-04-23 23:12:38 +02:00
// $_POST['pageNumber'] > 0
$pageNumber = empty($_POST['pageNumber']) ? 1 : (int)$_POST['pageNumber'];
$pageNumber = $pageNumber - 1;
$path = empty($_POST['path']) ? false : $_POST['path'];
$uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
2018-04-09 22:56:12 +02:00
// ----------------------------------------------------------------------------
// Set the path to get the file list
if ($path=='thumbnails') {
if ($uuid && IMAGE_RESTRICT) {
$path = PATH_UPLOADS_PAGES.$uuid.DS.'thumbnails'.DS;
} else {
$path = PATH_UPLOADS_THUMBNAILS;
}
} else {
ajaxResponse(1, 'Invalid path.');
}
2018-04-09 22:56:12 +02:00
// Get all files from the directory $path, also split the array by numberOfItems
// The function listFiles split in chunks
2019-04-23 23:12:38 +02:00
$listOfFilesByPage = Filesystem::listFiles($path, '*', '*', MEDIA_MANAGER_SORT_BY_DATE, MEDIA_MANAGER_NUMBER_OF_FILES);
// Check if the page number exists in the chunks
if (isset($listOfFilesByPage[$pageNumber])) {
2018-04-09 22:56:12 +02:00
// Get only the filename from the chunk
$files = array();
foreach ($listOfFilesByPage[$pageNumber] as $file) {
$filename = basename($file);
array_push($files, $filename);
}
2018-08-06 21:46:58 +02:00
// Returns the number of chunks for the paginator
2018-04-09 22:56:12 +02:00
// Returns the files inside the chunk
ajaxResponse(0, 'List of files and number of chunks.', array(
'numberOfPages'=>count($listOfFilesByPage),
'files'=>$files
));
}
ajaxResponse(0, 'List of files and number of chunks.', array(
'numberOfPages'=>0,
'files'=>array()
));
?>