diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index 5d986caf..098d1707 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -191,6 +191,11 @@ class pluginAPI extends Plugin { $username = $parameters[1]; $data = $this->getUser($username); } + // (GET) /api/files/ + 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 + ); + } } \ No newline at end of file