Skip to content

Commit

Permalink
Fixed issue #5, Fixed issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
voslartomas committed Apr 17, 2014
1 parent f86e8d0 commit 7ff87f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
34 changes: 22 additions & 12 deletions AdminModule/presenters/FilesystemPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class FilesystemPresenter extends \AdminModule\BasePresenter {

const DESTINATION_BASE = 'upload/';
const DESTINATION_BASE = './upload/';

private $path;

Expand All @@ -32,9 +32,9 @@ protected function startup() {

public function actionDefault($path) {
if (!empty($path)){
$this->path = $path . '/';
$this->path = self::DESTINATION_BASE . $path . '/';
}else{
$this->path = realpath(self::DESTINATION_BASE) . '/';
$this->path = self::DESTINATION_BASE;
}
}

Expand All @@ -44,15 +44,18 @@ public function renderDefault($path, $dialog, $multiple) {

$files = $finder->findFiles('*')
->exclude('.htaccess')
->in($this->path);
$directories = $finder->findDirectories('*')->in($this->path);
->in(realpath($this->path));
$directories = $finder->findDirectories('*')->in(realpath($this->path));

if (empty($dialog))
$this->reloadContent();
else
$this->reloadModalContent();

$this->template->backLink = strpos($this->createBackLink($this->path), self::DESTINATION_BASE) === false ? realpath(self::DESTINATION_BASE) : $this->createBackLink($this->path);
$this->path = str_replace(self::DESTINATION_BASE, '', $path) . '/';

$this->template->fsPath = $this->path;
$this->template->backLink = $this->createBackLink($this->path);
$this->template->files = $files;
$this->template->directories = $directories;
$this->template->multiple = $multiple;
Expand All @@ -76,11 +79,14 @@ public function handleMakeDirectory($name) {
public function handleUploadFile($path) {
$file = new \Nette\Http\FileUpload($_FILES['files']);

$file->move($this->path . '' . $file->getSanitizedName());
$filePath = $this->path . '' . $file->getSanitizedName();
$file->move($filePath);

$f = new \SplFileInfo($filePath);
$f->getBasename();

if ($file->isImage()) {
// $this->path contains symlinked path, that is not the right way @see handleRegenerateThumbnails() function for the fix
$this->thumbnailCreator->createThumbnails($file->getSanitizedName(), $this->path);
$this->thumbnailCreator->createThumbnails($f->getBasename(), str_replace($f->getBasename(), '', $filePath));
}

$this->reloadContent();
Expand All @@ -90,8 +96,10 @@ public function handleUploadFile($path) {
}

public function handleDeleteFile($pathToRemove) {

$pathToRemove = self::DESTINATION_BASE . $pathToRemove;
if (is_file($pathToRemove)) {

// delete all thumbnails if this file is image
try {

Expand Down Expand Up @@ -121,6 +129,7 @@ public function handleDeleteFile($pathToRemove) {
if (is_dir($pathToRemove)) {
\WebCMS\Helpers\SystemHelper::rrmdir($pathToRemove);
// $pathToRemove contains symlinked path, that is not the right way @see handleRegenerateThumbnails() function for the fix

\WebCMS\Helpers\SystemHelper::rrmdir(str_replace('upload', 'thumbnails', $pathToRemove));
}

Expand All @@ -137,8 +146,9 @@ public function actionDownloadFile($path) {

$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension

$path = self::DESTINATION_BASE . $path;
$mimeType = finfo_file($finfo, $path);

$this->sendResponse(new \Nette\Application\Responses\FileResponse($path, $filename, $mimeType));
}

Expand Down Expand Up @@ -174,7 +184,7 @@ public function handleRegenerateThumbnails() {
\WebCMS\Helpers\SystemHelper::rrmdir('thumbnails', true);

$timeStart = time();

foreach (Finder::findFiles('*.jpg', '*.jpeg', '*.png', '*.gif')->from('upload') as $key => $file) {
if (file_exists($key) && @getimagesize($key)) {
$this->thumbnailCreator->createThumbnails($file->getBasename(), str_replace($file->getBasename(), '', $key));
Expand Down
8 changes: 4 additions & 4 deletions AdminModule/templates/Filesystem/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@
{foreach $directories as $path => $file}
<tr>
<td class="name">
<a class="ajax dir" data-path="{$file->getRealpath()}" n:href="default path => $file->getRealpath()">
<a class="ajax dir" data-path="{$fsPath}{$file->getBasename()}" n:href="default path => $fsPath . $file->getBasename()">
{$file->getBasename()}
</a>
</td>
<td class="time">{$file->getATime()|date:'%d.%m.%Y %H:%M:%S'}</td>
<td class="size">{$file->getRealPath()|dirSize|bytes}</td>
<td class="action">
<a n:href="deleteFile! pathToRemove => $file->getPathname()" class="btn btn-danger">{_'Delete'}</a>
<a n:href="deleteFile! pathToRemove => $fsPath . $file->getBasename()" class="btn btn-danger">{_'Delete'}</a>
</td>
</tr>
{/foreach}
Expand All @@ -198,8 +198,8 @@
<td class="time">{$file->getATime()|date:'%d.%m.%Y %H:%M:%S'}</td>
<td class="size">{$file->getSize()|bytes}</td>
<td class="action">
<a n:href="downloadFile path => $file->getPathname()" class="btn btn-primary">{_'Download'}</a>
<a n:href="deleteFile! pathToRemove => $file->getPathname()" class="btn btn-danger">{_'Delete'}</a>
<a n:href="downloadFile path => $fsPath . $file->getBasename()" class="btn btn-primary">{_'Download'}</a>
<a n:href="deleteFile! pathToRemove => $fsPath . $file->getBasename()" class="btn btn-danger">{_'Delete'}</a>
</td>
</tr>
{/foreach}
Expand Down
3 changes: 2 additions & 1 deletion libs/helpers/ThumbnailCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public function createThumbnails($filename, $filepath) {
}

$key = $conf->getKey();
if (!empty($key))
if (!empty($key)){
$tmpImage->save($thumbnails . $conf->getKey() . $filename, 90);
}
}
}
}
Expand Down

0 comments on commit 7ff87f8

Please sign in to comment.