From 8e25c875f26b05e3138fb4d09d9f720456c09f76 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 14 Feb 2016 15:25:16 -0500 Subject: Add ProjecFile and TaskFile models --- tests/units/Model/TaskFileTest.php | 458 +++++++++++++++++++++++++++++++++++++ 1 file changed, 458 insertions(+) create mode 100644 tests/units/Model/TaskFileTest.php (limited to 'tests/units/Model/TaskFileTest.php') diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileTest.php new file mode 100644 index 00000000..753a1fb6 --- /dev/null +++ b/tests/units/Model/TaskFileTest.php @@ -0,0 +1,458 @@ +container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals('/tmp/foo', $file['path']); + $this->assertEquals(0, $file['is_image']); + $this->assertEquals(1, $file['task_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(10, $file['size']); + + $this->assertEquals(2, $fileModel->create(1, 'test2.png', '/tmp/foobar', 10)); + + $file = $fileModel->getById(2); + $this->assertEquals('test2.png', $file['name']); + $this->assertEquals('/tmp/foobar', $file['path']); + $this->assertEquals(1, $file['is_image']); + } + + public function testCreationWithFileNameTooLong() + { + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertNotFalse($fileModel->create(1, 'test', '/tmp/foo', 10)); + $this->assertNotFalse($fileModel->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); + + $files = $fileModel->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertEquals(str_repeat('a', 255), $files[0]['name']); + $this->assertEquals('test', $files[1]['name']); + } + + public function testCreationWithSessionOpen() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals(1, $file['user_id']); + } + + public function testGetAll() + { + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'B.pdf', '/tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'A.png', '/tmp/foo', 10)); + $this->assertEquals(3, $fileModel->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(4, $fileModel->create(1, 'C.JPG', '/tmp/foo', 10)); + + $fileModeliles = $fileModel->getAll(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(4, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('B.pdf', $fileModeliles[1]['name']); + $this->assertEquals('C.JPG', $fileModeliles[2]['name']); + $this->assertEquals('D.doc', $fileModeliles[3]['name']); + + $fileModeliles = $fileModel->getAllImages(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('C.JPG', $fileModeliles[1]['name']); + + $fileModeliles = $fileModel->getAllDocuments(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('B.pdf', $fileModeliles[0]['name']); + $this->assertEquals('D.doc', $fileModeliles[1]['name']); + } + + public function testIsImage() + { + $fileModel = new TaskFile($this->container); + + $this->assertTrue($fileModel->isImage('test.png')); + $this->assertTrue($fileModel->isImage('test.jpeg')); + $this->assertTrue($fileModel->isImage('test.gif')); + $this->assertTrue($fileModel->isImage('test.jpg')); + $this->assertTrue($fileModel->isImage('test.JPG')); + + $this->assertFalse($fileModel->isImage('test.bmp')); + $this->assertFalse($fileModel->isImage('test')); + $this->assertFalse($fileModel->isImage('test.pdf')); + } + + public function testGetMimeType() + { + $fileModel = new TaskFile($this->container); + + $this->assertEquals('image/jpeg', $fileModel->getImageMimeType('My File.JPG')); + $this->assertEquals('image/jpeg', $fileModel->getImageMimeType('My File.jpeg')); + $this->assertEquals('image/png', $fileModel->getImageMimeType('My File.PNG')); + $this->assertEquals('image/gif', $fileModel->getImageMimeType('My File.gif')); + $this->assertEquals('image/jpeg', $fileModel->getImageMimeType('My File.bmp')); + $this->assertEquals('image/jpeg', $fileModel->getImageMimeType('My File')); + } + + public function testGetThumbnailPath() + { + $fileModel = new TaskFile($this->container); + $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); + } + + public function testGeneratePath() + { + $fileModel = new TaskFile($this->container); + + $this->assertStringStartsWith('tasks'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); + $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); + } + + public function testUploadFiles() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); + + $this->assertTrue($fileModel->uploadFiles(1, $files)); + + $files = $fileModel->getAll(1); + $this->assertCount(2, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('file1.png', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(123, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + + $this->assertEquals(2, $files[1]['id']); + $this->assertEquals('file2.doc', $files[1]['name']); + $this->assertEquals(0, $files[1]['is_image']); + $this->assertEquals(1, $files[1]['task_id']); + $this->assertEquals(0, $files[1]['user_id']); + $this->assertEquals(456, $files[1]['size']); + $this->assertEquals(time(), $files[1]['date'], '', 2); + } + + public function testUploadFilesWithEmptyFiles() + { + $fileModel = new TaskFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, array())); + } + + public function testUploadFilesWithUploadError() + { + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_CANT_WRITE, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel = new TaskFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFilesWithObjectStorageError() + { + $files = array( + 'name' => array( + 'file1.csv', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $fileModel = new TaskFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFileContent() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('test.doc', $files[0]['name']); + $this->assertEquals(0, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testUploadFileContentWithObjectStorageError() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $this->assertFalse($fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + } + + public function testUploadScreenshot() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadScreenshot(1, base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertStringStartsWith('Screenshot taken ', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testRemove() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('remove') + ->with('tmp/foo'); + + $this->assertTrue($fileModel->remove(1)); + } + + public function testRemoveWithObjectStorageError() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('remove') + ->with('tmp/foo') + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $this->assertFalse($fileModel->remove(1)); + } + + public function testRemoveImage() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'image.gif', 'tmp/image.gif', 10)); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('remove') + ->with('tmp/image.gif'); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('remove') + ->with('thumbnails'.DIRECTORY_SEPARATOR.'tmp/image.gif'); + + $this->assertTrue($fileModel->remove(1)); + } + + public function testRemoveAll() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->exactly(2)) + ->method('remove') + ->with('tmp/foo'); + + $this->assertTrue($fileModel->removeAll(1)); + } +} -- cgit v1.2.3 From 8936792f6f7a408dae7e0a6a41274202822acd9c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 16 Feb 2016 21:12:43 -0500 Subject: Add file attachements to projects --- app/Controller/Base.php | 30 +++++++++ app/Controller/FileViewer.php | 89 +++++++++++++++++++++++++ app/Controller/ProjectFile.php | 79 ++++++++++++++++++++++ app/Controller/ProjectOverview.php | 2 + app/Controller/TaskFile.php | 96 ++------------------------- app/Helper/File.php | 24 +++++++ app/Model/File.php | 24 ------- app/Template/file_viewer/show.php | 8 +++ app/Template/project_file/create.php | 33 +++++++++ app/Template/project_file/remove.php | 15 +++++ app/Template/project_overview/columns.php | 8 +++ app/Template/project_overview/description.php | 8 +++ app/Template/project_overview/files.php | 92 +++++++++++++++++++++++++ app/Template/project_overview/information.php | 35 ++++++++++ app/Template/project_overview/show.php | 58 ++-------------- app/Template/task_file/create.php | 33 +++++++++ app/Template/task_file/new.php | 33 --------- app/Template/task_file/open.php | 6 -- app/Template/task_file/show.php | 6 +- tests/units/Helper/FileHelperText.php | 18 ++++- tests/units/Model/TaskFileTest.php | 12 ---- 21 files changed, 482 insertions(+), 227 deletions(-) create mode 100644 app/Controller/FileViewer.php create mode 100644 app/Controller/ProjectFile.php create mode 100644 app/Template/file_viewer/show.php create mode 100644 app/Template/project_file/create.php create mode 100644 app/Template/project_file/remove.php create mode 100644 app/Template/project_overview/columns.php create mode 100644 app/Template/project_overview/description.php create mode 100644 app/Template/project_overview/files.php create mode 100644 app/Template/project_overview/information.php create mode 100644 app/Template/task_file/create.php delete mode 100644 app/Template/task_file/new.php delete mode 100644 app/Template/task_file/open.php (limited to 'tests/units/Model/TaskFileTest.php') diff --git a/app/Controller/Base.php b/app/Controller/Base.php index c55ad9ad..884c439c 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -201,6 +201,36 @@ abstract class Base extends \Kanboard\Core\Base return $task; } + /** + * Get Task or Project file + * + * @access protected + */ + protected function getFile() + { + $task_id = $this->request->getIntegerParam('task_id'); + $file_id = $this->request->getIntegerParam('file_id'); + $model = 'projectFile'; + + if ($task_id > 0) { + $model = 'taskFile'; + $project_id = $this->taskFinder->getProjectId($task_id); + + if ($project_id !== $this->request->getIntegerParam('project_id')) { + $this->forbidden(); + } + } + + $file = $this->$model->getById($file_id); + + if (empty($file)) { + $this->notfound(); + } + + $file['model'] = $model; + return $file; + } + /** * Common method to get a project * diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php new file mode 100644 index 00000000..24ccc691 --- /dev/null +++ b/app/Controller/FileViewer.php @@ -0,0 +1,89 @@ +getFile(); + $params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id')); + + if ($file['model'] === 'taskFile') { + $params['task_id'] = $file['task_id']; + } + + $this->response->html($this->template->render('file_viewer/show', array( + 'file' => $file, + 'params' => $params, + ))); + } + + /** + * Display image + * + * @access public + */ + public function image() + { + try { + $file = $this->getFile(); + $this->response->contentType($this->helper->file->getImageMimeType($file['name'])); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } + + /** + * Display image thumbnail + * + * @access public + */ + public function thumbnail() + { + $this->response->contentType('image/jpeg'); + + try { + $file = $this->getFile(); + $model = $file['model']; + $this->objectStorage->output($this->$model->getThumbnailPath($file['path'])); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + + // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 + $data = $this->objectStorage->get($file['path']); + $this->$model->generateThumbnailFromData($file['path'], $data); + $this->objectStorage->output($this->$model->getThumbnailPath($file['path'])); + } + } + + /** + * File download + * + * @access public + */ + public function download() + { + try { + $file = $this->getFile(); + $this->response->forceDownload($file['name']); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } +} diff --git a/app/Controller/ProjectFile.php b/app/Controller/ProjectFile.php new file mode 100644 index 00000000..96764a92 --- /dev/null +++ b/app/Controller/ProjectFile.php @@ -0,0 +1,79 @@ +getProject(); + + $this->response->html($this->template->render('project_file/create', array( + 'project' => $project, + 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), + ))); + } + + /** + * Save uploaded files + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + + if (! $this->projectFile->uploadFiles($project['id'], $this->request->getFileInfo('files'))) { + $this->flash->failure(t('Unable to upload the file.')); + } + + $this->response->redirect($this->helper->url->to('ProjectOverview', 'show', array('project_id' => $project['id'])), true); + } + + /** + * Remove a file + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); + + if ($this->projectFile->remove($file['id'])) { + $this->flash->success(t('File removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this file.')); + } + + $this->response->redirect($this->helper->url->to('ProjectOverview', 'show', array('project_id' => $project['id']))); + } + + /** + * Confirmation dialog before removing a file + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); + + $this->response->html($this->template->render('project_file/remove', array( + 'project' => $project, + 'file' => $file, + ))); + } +} diff --git a/app/Controller/ProjectOverview.php b/app/Controller/ProjectOverview.php index cbd65777..b0687ed3 100644 --- a/app/Controller/ProjectOverview.php +++ b/app/Controller/ProjectOverview.php @@ -19,6 +19,8 @@ class ProjectOverview extends Base $params['users'] = $this->projectUserRole->getAllUsersGroupedByRole($params['project']['id']); $params['roles'] = $this->role->getProjectRoles(); $params['events'] = $this->projectActivity->getProject($params['project']['id'], 10); + $params['images'] = $this->projectFile->getAllImages($params['project']['id']); + $params['files'] = $this->projectFile->getAllDocuments($params['project']['id']); $this->project->getColumnStats($params['project']); diff --git a/app/Controller/TaskFile.php b/app/Controller/TaskFile.php index 102fdc5c..2b0152a7 100644 --- a/app/Controller/TaskFile.php +++ b/app/Controller/TaskFile.php @@ -2,10 +2,8 @@ namespace Kanboard\Controller; -use Kanboard\Core\ObjectStorage\ObjectStorageException; - /** - * File File Controller + * Task File Controller * * @package controller * @author Frederic Guillot @@ -26,7 +24,7 @@ class TaskFile extends Base return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); } - $this->response->html($this->helper->layout->task('task_file/screenshot', array( + $this->response->html($this->template->render('task_file/screenshot', array( 'task' => $task, ))); } @@ -40,7 +38,7 @@ class TaskFile extends Base { $task = $this->getTask(); - $this->response->html($this->helper->layout->task('task_file/new', array( + $this->response->html($this->template->render('task_file/create', array( 'task' => $task, 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), ))); @@ -62,92 +60,6 @@ class TaskFile extends Base $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); } - /** - * File download - * - * @access public - */ - public function download() - { - try { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } - - $this->response->forceDownload($file['name']); - $this->objectStorage->output($file['path']); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } - - /** - * Open a file (show the content in a popover) - * - * @access public - */ - public function open() - { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id']) { - $this->response->html($this->template->render('task_file/open', array( - 'file' => $file, - 'task' => $task, - ))); - } - } - - /** - * Display image - * - * @access public - */ - public function image() - { - try { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id']) { - $this->response->contentType($this->taskFile->getImageMimeType($file['name'])); - $this->objectStorage->output($file['path']); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } - - /** - * Display image thumbnails - * - * @access public - */ - public function thumbnail() - { - $this->response->contentType('image/jpeg'); - - try { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id']) { - $this->objectStorage->output($this->taskFile->getThumbnailPath($file['path'])); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - - // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 - $data = $this->objectStorage->get($file['path']); - $this->taskFile->generateThumbnailFromData($file['path'], $data); - $this->objectStorage->output($this->taskFile->getThumbnailPath($file['path'])); - } - } - /** * Remove a file * @@ -178,7 +90,7 @@ class TaskFile extends Base $task = $this->getTask(); $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - $this->response->html($this->helper->layout->task('task_file/remove', array( + $this->response->html($this->template->render('task_file/remove', array( 'task' => $task, 'file' => $file, ))); diff --git a/app/Helper/File.php b/app/Helper/File.php index 20eda1e3..6948fe6a 100644 --- a/app/Helper/File.php +++ b/app/Helper/File.php @@ -58,4 +58,28 @@ class File extends \Kanboard\Core\Base return 'fa-file-o'; } + + /** + * Return the image mimetype based on the file extension + * + * @access public + * @param $filename + * @return string + */ + public function getImageMimeType($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'jpeg': + case 'jpg': + return 'image/jpeg'; + case 'png': + return 'image/png'; + case 'gif': + return 'image/gif'; + default: + return 'image/jpeg'; + } + } } diff --git a/app/Model/File.php b/app/Model/File.php index e17ecb2b..03ea691d 100644 --- a/app/Model/File.php +++ b/app/Model/File.php @@ -188,30 +188,6 @@ abstract class File extends Base return false; } - /** - * Return the image mimetype based on the file extension - * - * @access public - * @param $filename - * @return string - */ - public function getImageMimeType($filename) - { - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - - switch ($extension) { - case 'jpeg': - case 'jpg': - return 'image/jpeg'; - case 'png': - return 'image/png'; - case 'gif': - return 'image/gif'; - default: - return 'image/jpeg'; - } - } - /** * Generate the path for a thumbnails * diff --git a/app/Template/file_viewer/show.php b/app/Template/file_viewer/show.php new file mode 100644 index 00000000..e0d1b21e --- /dev/null +++ b/app/Template/file_viewer/show.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/app/Template/project_file/create.php b/app/Template/project_file/create.php new file mode 100644 index 00000000..67315285 --- /dev/null +++ b/app/Template/project_file/create.php @@ -0,0 +1,33 @@ + + + + + +
+
+ +
+
+ + + +
+ + + url->link(t('cancel'), 'ProjectOverview', 'show', array('project_id' => $project['id']), false, 'close-popover') ?> +
diff --git a/app/Template/project_file/remove.php b/app/Template/project_file/remove.php new file mode 100644 index 00000000..4f0ba465 --- /dev/null +++ b/app/Template/project_file/remove.php @@ -0,0 +1,15 @@ + + +
+

+ e($file['name'])) ?> +

+ +
+ url->link(t('Yes'), 'ProjectFile', 'remove', array('project_id' => $project['id'], 'file_id' => $file['id']), true, 'btn btn-red') ?> + + url->link(t('cancel'), 'ProjectOverview', 'show', array('project_id' => $project['id']), false, 'close-popover') ?> +
+
\ No newline at end of file diff --git a/app/Template/project_overview/columns.php b/app/Template/project_overview/columns.php new file mode 100644 index 00000000..870d753f --- /dev/null +++ b/app/Template/project_overview/columns.php @@ -0,0 +1,8 @@ +
+ +
+
+ e($column['title']) ?> +
+ +
diff --git a/app/Template/project_overview/description.php b/app/Template/project_overview/description.php new file mode 100644 index 00000000..4137bf9f --- /dev/null +++ b/app/Template/project_overview/description.php @@ -0,0 +1,8 @@ + + +
+ text->markdown($project['description']) ?> +
+ diff --git a/app/Template/project_overview/files.php b/app/Template/project_overview/files.php new file mode 100644 index 00000000..fea20ad6 --- /dev/null +++ b/app/Template/project_overview/files.php @@ -0,0 +1,92 @@ + + + +

+ + + +
+ +
+ <?= $this->e($file['name']) ?> +
+
+ +
+
+ dt->datetime($file['date'])).'
'.t('Size: %s', $this->text->bytes($file['size'])) ?>'> + +
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ + + + e($file['user_name'] ?: $file['username']) ?> + + dt->date($file['date']) ?> + + text->bytes($file['size']) ?> +
+ diff --git a/app/Template/project_overview/information.php b/app/Template/project_overview/information.php new file mode 100644 index 00000000..12a1317d --- /dev/null +++ b/app/Template/project_overview/information.php @@ -0,0 +1,35 @@ + +
+
    + 0): ?> +
  • e($project['owner_name'] ?: $project['owner_username']) ?>
  • + + + + $role_name): ?> + +
  • + : + +
  • + + + + + +
  • dt->date($project['start_date']) ?>
  • + + + +
  • dt->date($project['end_date']) ?>
  • + + + +
  • url->link(t('Public link'), 'board', 'readonly', array('token' => $project['token']), false, '', '', true) ?>
  • +
  • url->link(t('RSS feed'), 'feed', 'project', array('token' => $project['token']), false, '', '', true) ?>
  • +
  • url->link(t('iCal feed'), 'ical', 'project', array('token' => $project['token'])) ?>
  • + +
+
diff --git a/app/Template/project_overview/show.php b/app/Template/project_overview/show.php index b53b1c26..0038d952 100644 --- a/app/Template/project_overview/show.php +++ b/app/Template/project_overview/show.php @@ -4,60 +4,10 @@ 'filters' => $filters, )) ?> -
- -
-
- e($column['title']) ?> -
- -
- - - -
- text->markdown($project['description']) ?> -
- - - -
-
    - - 0): ?> -
  • e($project['owner_name'] ?: $project['owner_username']) ?>
  • - - - - $role_name): ?> - -
  • - : - -
  • - - - - - -
  • dt->date($project['start_date']) ?>
  • - - - -
  • dt->date($project['end_date']) ?>
  • - - - -
  • url->link(t('Public link'), 'board', 'readonly', array('token' => $project['token']), false, '', '', true) ?>
  • -
  • url->link(t('RSS feed'), 'feed', 'project', array('token' => $project['token']), false, '', '', true) ?>
  • -
  • url->link(t('iCal feed'), 'ical', 'project', array('token' => $project['token'])) ?>
  • - -
-
+ render('project_overview/columns', array('project' => $project)) ?> + render('project_overview/description', array('project' => $project)) ?> + render('project_overview/files', array('project' => $project, 'images' => $images, 'files' => $files)) ?> + render('project_overview/information', array('project' => $project, 'users' => $users, 'roles' => $roles)) ?>