Improve pull-request

This commit is contained in:
Frederic Guillot
2015-03-10 22:37:09 -04:00
parent 788ef2bc07
commit d91b5d4aa3
20 changed files with 151 additions and 143 deletions

View File

@@ -20,8 +20,8 @@ class File extends Base
$task = $this->getTask();
$this->response->html($this->taskLayout('file/new', array(
'task' => $task,
'max_size' => ini_get('upload_max_filesize'),
'task' => $task,
'max_size' => ini_get('upload_max_filesize'),
)));
}
@@ -74,8 +74,8 @@ class File extends Base
if ($file['task_id'] == $task['id']) {
$this->response->html($this->template->render('file/open', array(
'file' => $file,
'task' => $task,
'file' => $file,
'task' => $task,
)));
}
}
@@ -102,29 +102,31 @@ class File extends Base
}
/**
* Return the file content (work only for images) resized
* Return image thumbnails
*
* @access public
*/
public function imageThumbnail() {
public function thumbnail()
{
$task = $this->getTask();
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$width_param = $this->request->getIntegerParam('width');
$height_param = $this->request->getIntegerParam('height');
$filename = FILES_DIR . $file['path'];
$filename = FILES_DIR.$file['path'];
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
// Get new sizes
list($width, $height) = getimagesize($filename);
if ($width_param == 0 && $height_param == 0) {
$newwidth = 100;
$newheight = 100;
} elseif ($width_param > 0 && $height_param == 0) {
$newwidth = $width_param;
$newheight = floor($height * ( $width_param / $width ));
$newheight = floor($height * ($width_param / $width));
} elseif ($width_param == 0 && $height_param > 0) {
$newwidth = floor($width * ( $height_param / $height ));
$newwidth = floor($width * ($height_param / $height));
$newheight = $height_param;
} else {
$newwidth = $width_param;
@@ -133,9 +135,7 @@ class File extends Base
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$info = pathinfo($file['name']);
$extension = strtolower($info['extension']);
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
switch ($extension) {
case 'jpeg':
@@ -153,17 +153,18 @@ class File extends Base
break;
}
// Resize
// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$metadata = getimagesize($filename);
if (isset($metadata['mime'])) {
$this->response->contentType($metadata['mime']);
imagejpeg($thumb);
}
}
}
/**
* Remove a file
*
@@ -195,8 +196,8 @@ class File extends Base
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$this->response->html($this->taskLayout('file/remove', array(
'task' => $task,
'file' => $file,
'task' => $task,
'file' => $file,
)));
}
}