Get files for a particular page
This commit is contained in:
parent
46fa8a1fab
commit
fd80820e0b
|
@ -191,6 +191,11 @@ class pluginAPI extends Plugin {
|
|||
$username = $parameters[1];
|
||||
$data = $this->getUser($username);
|
||||
}
|
||||
// (GET) /api/files/<page-key>
|
||||
elseif ( ($method==='GET') && ($parameters[0]==='files') && !empty($parameters[1]) ) {
|
||||
$pageKey = $parameters[1];
|
||||
$data = $this->getFiles($pageKey);
|
||||
}
|
||||
else {
|
||||
$this->response(401, 'Unauthorized', array('message'=>'Access denied or invalid endpoint.'));
|
||||
}
|
||||
|
@ -667,4 +672,40 @@ class pluginAPI extends Plugin {
|
|||
'data'=>$data
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
| Returns all files uploaded for a specific page, includes any type of file.
|
||||
|
|
||||
| @return array
|
||||
*/
|
||||
private function getFiles($pageKey)
|
||||
{
|
||||
$chunk = false;
|
||||
$sortByDate = true;
|
||||
$path = PATH_UPLOADS_PAGES.$pageKey.DS;
|
||||
$listFiles = Filesystem::listFiles($path, '*', '*', $sortByDate, $chunk);
|
||||
|
||||
$files = array();
|
||||
foreach ($listFiles as $file) {
|
||||
$info = array('thumbnail'=>'');
|
||||
$info['file'] = $file;
|
||||
$info['filename'] = basename($file);
|
||||
$info['mime'] = Filesystem::mimeType($file);
|
||||
$info['size'] = Filesystem::getSize($file);
|
||||
|
||||
// Check if thumbnail exists for the file
|
||||
$thumbnail = $path.'thumbnails'.DS.$info['filename'];
|
||||
if (Filesystem::fileExists($thumbnail)) {
|
||||
$info['thumbnail'] = $thumbnail;
|
||||
}
|
||||
|
||||
array_push($files, $info);
|
||||
}
|
||||
|
||||
return array(
|
||||
'status'=>'0',
|
||||
'message'=>'Files for the page key: '.$pageKey,
|
||||
'data'=>$files
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue