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

View File

@@ -726,4 +726,48 @@ class Helper
{ {
return dt('%A', strtotime('next Monday +'.($day - 1).' days')); return dt('%A', strtotime('next Monday +'.($day - 1).' days'));
} }
/**
* Get file icon
*
* @access public
* @param string $filename Filename
* @return string Font-Awesome-Icon-Name
*/
public function getFileIcon($filename){
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
switch ($extension) {
case 'jpeg':
case 'jpg':
case 'png':
case 'gif':
return 'fa-file-image-o';
case 'xls':
case 'xlsx':
return 'fa-file-excel-o';
case 'doc':
case 'docx':
return 'fa-file-word-o';
case 'ppt':
case 'pptx':
return 'fa-file-powerpoint-o';
case 'zip':
case 'rar':
return 'fa-archive-o';
case 'mp3':
return 'fa-audio-o';
case 'avi':
return 'fa-video-o';
case 'php':
case 'html':
case 'css':
return 'fa-code-o';
case 'pdf':
return 'fa-file-pdf-o';
}
return 'fa-file-o';
}
} }

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -775,4 +775,6 @@ return array(
'Remove time slot' => 'Supprimer un créneau horaire', 'Remove time slot' => 'Supprimer un créneau horaire',
'Add new time slot' => 'Ajouter un créneau horaire', 'Add new time slot' => 'Ajouter un créneau horaire',
'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => 'Ces horaires sont utilisés lorsque la case « Toute la journée » est cochée pour les heures d\'absences ou supplémentaires programmées.', 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => 'Ces horaires sont utilisés lorsque la case « Toute la journée » est cochée pour les heures d\'absences ou supplémentaires programmées.',
'Files' => 'Fichiers',
'Images' => 'Images',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -773,4 +773,6 @@ return array(
// 'Remove time slot' => '', // 'Remove time slot' => '',
// 'Add new time slot' => '', // 'Add new time slot' => '',
// 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '', // 'This timetable is used when the checkbox "all day" is checked for scheduled time off and overtime.' => '',
// 'Files' => '',
// 'Images' => '',
); );

View File

@@ -153,8 +153,7 @@ class File extends Base
*/ */
public function isImage($filename) public function isImage($filename)
{ {
$info = pathinfo($filename); $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$extension = strtolower($info['extension']);
switch ($extension) { switch ($extension) {
case 'jpeg': case 'jpeg':
@@ -162,65 +161,9 @@ class File extends Base
case 'png': case 'png':
case 'gif': case 'gif':
return true; return true;
break;
default:
return false;
break;
} }
}
/** return false;
* get Font-Awesome Icon for file extension
*
* @access public
* @param string $filename Filename
* @return string Font-Awesome-Icon-Name
*/
public function get_icon($filename){
$info = pathinfo($filename);
$extension = strtolower($info['extension']);
switch ($extension) {
case 'jpeg':
case 'jpg':
case 'png':
case 'gif':
$icon = 'fa-file-image-o';
break;
case 'xls':
case 'xlsx':
$icon = 'fa-file-excel-o';
break;
case 'doc':
case 'docx':
$icon = 'fa-file-word-o';
break;
case 'ppt':
case 'pptx':
$icon = 'fa-file-powerpoint-o';
break;
case 'zip':
case 'rar':
$icon = 'fa-archive-o';
break;
case 'mp3':
$icon = 'fa-audio-o';
break;
case 'avi':
$icon = 'fa-video-o';
break;
case 'php':
case 'html':
case 'css':
$icon = 'fa-code-o';
break;
case 'pdf':
$icon = 'fa-file-pdf-o';
break;
default:
$icon = 'fa-file-o';
break;
}
return $icon;
} }
/** /**

View File

@@ -1,12 +1,11 @@
<section> <section>
<table> <table>
<?php if (!empty($images)): ?> <?php if (! empty($images)): ?>
<?php foreach ($images as $file): ?> <?php foreach ($images as $file): ?>
<tr> <tr>
<td><i class="fa fa-file-image-o fa-fw"></i> <td class="column-70">
<?= <i class="fa fa-file-image-o fa-fw"></i>
$this->e($file['name']) <?= $this->e($file['name']) ?>
?>
</td> </td>
<td> <td>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?> <i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
@@ -15,13 +14,12 @@
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>
<?php endif ?> <?php endif ?>
<?php if (!empty($files)): ?> <?php if (! empty($files)): ?>
<?php foreach ($files as $file): ?> <?php foreach ($files as $file): ?>
<tr> <tr>
<td><i class="fa <?= $this->file->get_icon($file['name']) ?> fa-fw"></i> <td>
<?= <i class="fa <?= $this->getFileIcon($file['name']) ?> fa-fw"></i>
$this->e($file['name']) <?= $this->e($file['name']) ?>
?>
</td> </td>
<td> <td>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?> <i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>

View File

@@ -1,56 +1,48 @@
<?php if (!empty($files) || !empty($images)): ?> <?php if (! empty($files) || ! empty($images)): ?>
<div id="attachments" class="task-show-section"> <div id="attachments" class="task-show-section">
<div class="page-header"> <div class="page-header">
<h2><?= t('Attachments') ?></h2> <h2><?= t('Attachments') ?></h2>
</div> </div>
<?php if (!empty($images)): ?> <?php if (!empty($images)): ?>
<h3> <h3><?= t('Images') ?></h3>
<?= t('Images') ?> <ul class="task-show-images">
</h3> <?php foreach ($images as $file): ?>
<ul class="task-show-images"> <li>
<?php foreach ($images as $file): ?> <div class="img_container">
<li> <img src="<?= $this->u('file', 'thumbnail', array('width' => 250, 'file_id' => $file['id'], 'project_id' => $task['project_id'], 'task_id' => $file['task_id'])) ?>" alt="<?= $this->e($file['name']) ?>"/>
<div class="img_container"> </div>
<img src="<?= $this->u('file', 'imageThumbnail', array('width' => 250, 'file_id' => $file['id'], 'project_id' => $task['project_id'], 'task_id' => $file['task_id'])) ?>" alt="<?= $this->e($file['name']) ?>"/> <p>
</div> <?= $this->e($file['name']) ?>
<p> </p>
<?= $this->e($file['name']) ?> <span class="task-show-file-actions task-show-image-actions">
</p> <i class="fa fa-eye"></i> <?= $this->a(t('open'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?>
<span class="task-show-file-actions task-show-image-actions"> <i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-eye"></i> <?= $this->a(t('open'), 'file', 'open', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id']), false, 'popover') ?> <i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
</span>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?php if (! empty($files)): ?>
<h3><?= t('Files') ?></h3>
<table class="task-show-file-table">
<?php foreach ($files as $file): ?>
<tr>
<td><i class="fa <?= $this->getFileIcon($file['name']) ?> fa-fw"></i></td>
<td>
<?= $this->e($file['name']) ?>
</td>
<td>
<span class="task-show-file-actions">
<i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?> <i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?> <i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
</span> </span>
</li> </td>
<?php endforeach ?> </tr>
</ul> <?php endforeach ?>
<?php endif </table>
?> <?php endif ?>
<?php if (!empty($files)): ?> </div>
<h3> <?php endif ?>
<?= t('Files') ?>
</h3>
<table class="task-show-file-table">
<?php foreach ($files as $file): ?>
<tr>
<td><i class="fa <?= $this->file->get_icon($file['name']) ?> fa-fw"></i></td>
<td>
<?= $this->e($file['name']) ?>
</td><td>
<span class="task-show-file-actions">
<i class="fa fa-trash"></i> <?= $this->a(t('remove'), 'file', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
<i class="fa fa-download"></i> <?= $this->a(t('download'), 'file', 'download', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'file_id' => $file['id'])) ?>
</span>
</td></tr>
<?php endforeach ?>
</table>
</div>
<?php endif
?>
<?php
endif ?>