2018-04-04 23:46:36 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// $_POST
|
2018-04-09 22:56:12 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2018-04-13 23:32:29 +02:00
|
|
|
// (integer) $_POST['pageNumber'] > 0
|
|
|
|
$pageNumber = !empty($_POST['pageNumber']) ? (int)$_POST['pageNumber'] : 1;
|
2018-04-04 23:46:36 +02:00
|
|
|
$pageNumber = $pageNumber - 1;
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// (string) $_POST['path']
|
|
|
|
$path = isset($_POST['path']) ? $_POST['path'] : false;
|
2018-04-09 22:56:12 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2018-04-04 23:46:36 +02:00
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
if ($path==false) {
|
|
|
|
exit (json_encode(array(
|
|
|
|
'status'=>1,
|
|
|
|
'files'=>'Invalid path.'
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
// Get all files from the directory $path, also split the array by numberOfItems
|
|
|
|
$listOfFilesByPage = Filesystem::listFiles($path, '*', '*', $GLOBALS['BLUDIT_MEDIA_MANAGER_SORT_BY_DATE'], $GLOBALS['BLUDIT_MEDIA_MANAGER_AMOUNT_OF_FILES']);
|
2018-04-04 23:46:36 +02:00
|
|
|
|
|
|
|
// 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
|
2018-04-04 23:46:36 +02:00
|
|
|
$tmp = array();
|
|
|
|
foreach ($listOfFilesByPage[$pageNumber] as $file) {
|
|
|
|
array_push($tmp, basename($file));
|
|
|
|
}
|
|
|
|
|
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
|
2018-04-04 23:46:36 +02:00
|
|
|
exit (json_encode(array(
|
|
|
|
'status'=>0,
|
|
|
|
'numberOfPages'=>count($listOfFilesByPage),
|
|
|
|
'files'=>$tmp
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (json_encode(array(
|
|
|
|
'status'=>1,
|
|
|
|
'files'=>'Out of index.'
|
|
|
|
)));
|
|
|
|
|
|
|
|
?>
|