Skip to content

Commit

Permalink
Merge pull request #77 from atmonshi/l6
Browse files Browse the repository at this point in the history
use Illuminate\Support\Str
  • Loading branch information
Krato authored Sep 10, 2019
2 parents 25acea7 + 88ec5c1 commit 317a720
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/Http/Services/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Infinety\Filemanager\Http\Services;

use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;

class DefaultNamingStrategy extends AbstractNamingStrategy
Expand All @@ -19,7 +20,7 @@ public function name(string $currentFolder, UploadedFile $file): string
$filename = sprintf(
'%s_%s.%s',
pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
str_random(7),
Str::random(7),
$file->getClientOriginalExtension()
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Services/FileTypesImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Infinety\Filemanager\Http\Services;

use Illuminate\Support\Str;

class FileTypesImages
{
/**
Expand Down Expand Up @@ -47,7 +49,7 @@ public function getImage($mime)
*/
private function checkMime($mime, $type)
{
if (str_contains($mime, $type)) {
if (Str::contains($mime, $type)) {
return true;
}

Expand Down
39 changes: 20 additions & 19 deletions src/Http/Services/GetFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use GuzzleHttp\Client;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;

trait GetFiles
Expand Down Expand Up @@ -234,63 +235,63 @@ public function getFileType($file)
$mime = $this->storage->getMimetype($file['path']);
$extension = $file['extension'];

if (str_contains($mime, 'directory')) {
if (Str::contains($mime, 'directory')) {
return 'dir';
}

if (str_contains($mime, 'image') || $extension == 'svg') {
if (Str::contains($mime, 'image') || $extension == 'svg') {
return 'image';
}

if (str_contains($mime, 'pdf')) {
if (Str::contains($mime, 'pdf')) {
return 'pdf';
}

if (str_contains($mime, 'audio')) {
if (Str::contains($mime, 'audio')) {
return 'audio';
}

if (str_contains($mime, 'video')) {
if (Str::contains($mime, 'video')) {
return 'video';
}

if (str_contains($mime, 'zip')) {
if (Str::contains($mime, 'zip')) {
return 'file';
}

if (str_contains($mime, 'rar')) {
if (Str::contains($mime, 'rar')) {
return 'file';
}

if (str_contains($mime, 'octet-stream')) {
if (Str::contains($mime, 'octet-stream')) {
return 'file';
}

if (str_contains($mime, 'excel')) {
if (Str::contains($mime, 'excel')) {
return 'text';
}

if (str_contains($mime, 'word')) {
if (Str::contains($mime, 'word')) {
return 'text';
}

if (str_contains($mime, 'css')) {
if (Str::contains($mime, 'css')) {
return 'text';
}

if (str_contains($mime, 'javascript')) {
if (Str::contains($mime, 'javascript')) {
return 'text';
}

if (str_contains($mime, 'plain')) {
if (Str::contains($mime, 'plain')) {
return 'text';
}

if (str_contains($mime, 'rtf')) {
if (Str::contains($mime, 'rtf')) {
return 'text';
}

if (str_contains($mime, 'text')) {
if (Str::contains($mime, 'text')) {
return 'text';
}

Expand All @@ -313,11 +314,11 @@ public function getThumb($file, $folder = false)
$mime = $this->storage->getMimetype($file['path']);
$extension = $file['extension'];

if (str_contains($mime, 'directory')) {
if (Str::contains($mime, 'directory')) {
return false;
}

if (str_contains($mime, 'image') || $extension == 'svg') {
if (Str::contains($mime, 'image') || $extension == 'svg') {
if (method_exists($this->storage, 'put')) {
return $this->storage->url($file['path']);
}
Expand Down Expand Up @@ -417,7 +418,7 @@ public function accept($file)
*/
public function isDot($file)
{
if (starts_with($file['basename'], '.')) {
if (Str::startsWith($file['basename'], '.')) {
return true;
}

Expand Down Expand Up @@ -488,7 +489,7 @@ public function getPaths($currentFolder)
*/
public function recursivePaths($name, $pathCollection)
{
return str_before($pathCollection->implode('/'), $name).$name;
return Str::before($pathCollection->implode('/'), $name).$name;
}

/**
Expand Down
23 changes: 12 additions & 11 deletions src/Http/Services/NormalizeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ZipArchive;
use SplFileInfo;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Filesystem\FilesystemAdapter;

Expand Down Expand Up @@ -68,25 +69,25 @@ private function setExtras(Collection $data)
$mime = $this->storage->getMimetype($this->storagePath);

// Image
if (str_contains($mime, 'image') || $data['ext'] == 'svg') {
if (Str::contains($mime, 'image') || $data['ext'] == 'svg') {
$data->put('type', 'image');
$data->put('dimensions', $this->getDimensions($this->storage->getMimetype($this->storagePath)));
}

// Video
if (str_contains($mime, 'audio')) {
if (Str::contains($mime, 'audio')) {
$data->put('type', 'audio');
$src = str_replace(env('APP_URL'), '', $this->storage->url($this->storagePath));
$data->put('src', $src);
}

// Video
if (str_contains($mime, 'video')) {
if (Str::contains($mime, 'video')) {
$data->put('type', 'video');
}

// text
if ($this->availablesTextExtensions() && str_contains($mime, 'text')) {
if ($this->availablesTextExtensions() && Str::contains($mime, 'text')) {
$data->put('type', 'text');

if ($data['size']) {
Expand All @@ -100,24 +101,24 @@ private function setExtras(Collection $data)
}

// text
if (str_contains($mime, 'pdf')) {
if (Str::contains($mime, 'pdf')) {
$data->put('type', 'pdf');
}

// docx
if (str_contains($mime, 'wordprocessingml')) {
if (Str::contains($mime, 'wordprocessingml')) {
$data->put('type', 'word');
// $data->put('source', $this->storage->get($this->storagePath));
}

// zip
if (str_contains($mime, 'zip')) {
if (Str::contains($mime, 'zip')) {
$data->put('type', 'zip');
$data->put('source', $this->readZip());
}

// // rar
// if (str_contains($mime, 'rar')) {
// if (Str::contains($mime, 'rar')) {
// $data->put('type', 'zip');
// $data->put('source', $this->readRar());
// }
Expand All @@ -143,7 +144,7 @@ public function getFileSize()
*/
private function getImage($mime, $extension = false)
{
if (str_contains($mime, 'image') || $extension == 'svg') {
if (Str::contains($mime, 'image') || $extension == 'svg') {
return $this->storage->url($this->storagePath);
}

Expand All @@ -161,7 +162,7 @@ private function getDimensions($mime)
return false;
}

if (str_contains($mime, 'image')) {
if (Str::contains($mime, 'image')) {
[$width, $height] = getimagesize($this->storage->path($this->storagePath));

if (! empty($width) && ! empty($height)) {
Expand Down Expand Up @@ -208,7 +209,7 @@ private function availablesTextExtensions()

$exist = false;
for ($i = 0; $i < count($types); $i++) {
if (str_contains($types[$i], 'text') || str_contains($types[$i], 'plain') || str_contains($types[$i], 'sql') || str_contains($types[$i], 'javascript')) {
if (Str::contains($types[$i], 'text') || Str::contains($types[$i], 'plain') || Str::contains($types[$i], 'sql') || Str::contains($types[$i], 'javascript')) {
$exist = true;
break;
}
Expand Down

0 comments on commit 317a720

Please sign in to comment.