Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
youchenlee committed Oct 2, 2017
1 parent 4c7333e commit 882eb39
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
16 changes: 9 additions & 7 deletions src/controllers/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ public function getFolders()
public function getAddfolder()
{
$folder_name = parent::translateFromUtf8(trim(request('name')));

$path = parent::getCurrentPath($folder_name);

if (empty($folder_name)) {
return parent::error('folder-name');
} elseif (File::exists($path)) {
}

if (File::exists($path)) {
return parent::error('folder-exist');
} elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
return parent::error('folder-alnum');
} else {
parent::createFolderByPath($path);
}

return parent::$success_response;
if (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
return parent::error('folder-alnum');
}

parent::createFolderByPath($path);
return parent::$success_response;
}
}
35 changes: 22 additions & 13 deletions src/controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,29 @@ public function getItems()

private function getView()
{
$view_type = 'grid';
$show_list = request('show_list');

if ($show_list === '1') {
$view_type = 'list';
} elseif (is_null($show_list)) {
$type_key = parent::currentLfmType();
$startup_view = config('lfm.' . $type_key . 's_startup_view');

if (in_array($startup_view, ['list', 'grid'])) {
$view_type = $startup_view;
}
$view_type = request('show_list');

if (null === $view_type) {
return $this->composeViewName($this->getStartupViewFromConfig());
}

return 'laravel-filemanager::' . $view_type . '-view';
$view_mapping = [
'0' => 'grid',
'1' => 'list'
];

return $this->composeViewName($view_mapping[$view_type]);
}

private function composeViewName($view_type = 'grid')
{
return "laravel-filemanager::$view_type-view";
}

private function getStartupViewFromConfig($default = 'grid')
{
$type_key = parent::currentLfmType();
$startup_view = config('lfm.' . $type_key . 's_startup_view', $default);
return $startup_view;
}
}
1 change: 0 additions & 1 deletion src/controllers/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function __construct()
{
$delimiter = config('lfm.url_prefix') . '/';
$url = urldecode(request()->url());
// dd($delimiter);
$external_path = substr($url, strpos($url, $delimiter) + strlen($delimiter));

$this->file_path = base_path(config('lfm.base_directory', 'public') . '/' . $external_path);
Expand Down
1 change: 1 addition & 0 deletions src/controllers/ResizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getResize()

$scaled = false;

// FIXME size should be configurable
if ($original_width > 600) {
$ratio = 600 / $original_width;
$width = $original_width * $ratio;
Expand Down

0 comments on commit 882eb39

Please sign in to comment.