/home/mip/mip/public/vendor/laravel-filemanager/files/folder-1/821668/unisharp.zip
PK �8]&
pUB B 4 laravel-filemanager/tests/LfmUploadValidatorTest.phpnu �[��� <?php
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use UniSharp\LaravelFilemanager\Exceptions\DuplicateFileNameException;
use UniSharp\LaravelFilemanager\Exceptions\EmptyFileException;
use UniSharp\LaravelFilemanager\Exceptions\ExcutableFileException;
use UniSharp\LaravelFilemanager\Exceptions\FileFailedToUploadException;
use UniSharp\LaravelFilemanager\Exceptions\FileSizeExceedConfigurationMaximumException;
use UniSharp\LaravelFilemanager\Exceptions\FileSizeExceedIniMaximumException;
use UniSharp\LaravelFilemanager\Exceptions\InvalidMimeTypeException;
use UniSharp\LaravelFilemanager\LfmPath;
use UniSharp\LaravelFilemanager\LfmUploadValidator;
function trans()
{
// leave empty
}
class LfmUploadValidatorTest extends TestCase
{
public function testPassesSizeLowerThanIniMaximum()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_OK);
$validator = new LfmUploadValidator($uploaded_file);
$this->assertEquals($validator->sizeLowerThanIniMaximum(), $validator);
}
public function testFailsSizeLowerThanIniMaximum()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_INI_SIZE);
$validator = new LfmUploadValidator($uploaded_file);
$this->expectException(FileSizeExceedIniMaximumException::class);
$validator->sizeLowerThanIniMaximum();
}
public function testPassesUploadWasSuccessful()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_OK);
$validator = new LfmUploadValidator($uploaded_file);
$this->assertEquals($validator->uploadWasSuccessful(), $validator);
}
public function testFailsUploadWasSuccessful()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_PARTIAL);
$validator = new LfmUploadValidator($uploaded_file);
$this->expectException(FileFailedToUploadException::class);
$validator->uploadWasSuccessful();
}
public function testPassesNameIsNotDuplicate()
{
$uploaded_file = m::mock(UploadedFile::class);
$lfm_path = m::mock(LfmPath::class);
$lfm_path->shouldReceive('setName')->andReturn($lfm_path);
$lfm_path->shouldReceive('exists')->andReturn(false);
$validator = new LfmUploadValidator($uploaded_file);
$this->assertEquals($validator->nameIsNotDuplicate('new_file_name', $lfm_path), $validator);
}
public function testFailsNameIsNotDuplicate()
{
$uploaded_file = m::mock(UploadedFile::class);
$lfm_path = m::mock(LfmPath::class);
$lfm_path->shouldReceive('setName')->andReturn($lfm_path);
$lfm_path->shouldReceive('exists')->andReturn(true);
$validator = new LfmUploadValidator($uploaded_file);
$this->expectException(DuplicateFileNameException::class);
$validator->nameIsNotDuplicate('new_file_name', $lfm_path);
}
public function testPassesMimetypeIsNotExcutable()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');
$validator = new LfmUploadValidator($uploaded_file);
$this->assertEquals($validator->mimetypeIsNotExcutable(['text/x-php']), $validator);
}
public function testFailsMimetypeIsNotExcutable()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getMimeType')->andReturn('text/x-php');
$validator = new LfmUploadValidator($uploaded_file);
$this->expectException(ExcutableFileException::class);
$validator->mimetypeIsNotExcutable(['text/x-php']);
}
public function testPassesMimeTypeIsValid()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');
$validator = new LfmUploadValidator($uploaded_file);
$this->assertEquals($validator->mimeTypeIsValid(['image/jpeg']), $validator);
}
public function testFailsMimeTypeIsValid()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');
$validator = new LfmUploadValidator($uploaded_file);
$this->expectException(InvalidMimeTypeException::class);
$validator->mimeTypeIsValid(['image/png']);
}
public function testPassesSizeIsLowerThanConfiguredMaximum()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getSize')->andReturn(500 * 1000);
$validator = new LfmUploadValidator($uploaded_file);
$this->assertEquals($validator->sizeIsLowerThanConfiguredMaximum(1000), $validator);
}
public function testFailsSizeIsLowerThanConfiguredMaximum()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getSize')->andReturn(2000 * 1000);
$validator = new LfmUploadValidator($uploaded_file);
$this->expectException(FileSizeExceedConfigurationMaximumException::class);
$validator->sizeIsLowerThanConfiguredMaximum(1000);
}
}
PK �8]}gF F ) laravel-filemanager/tests/LfmPathTest.phpnu �[��� <?php
namespace Tests;
use Illuminate\Http\Request;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use UniSharp\LaravelFilemanager\Lfm;
use UniSharp\LaravelFilemanager\LfmItem;
use UniSharp\LaravelFilemanager\LfmPath;
class LfmPathTest extends TestCase
{
public function tearDown(): void
{
m::close();
parent::tearDown();
}
public function testMagicGet()
{
$storage = m::mock(LfmStorage::class);
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$path = new LfmPath($helper);
$this->assertEquals($storage, $path->storage);
}
public function testMagicCall()
{
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('foo')->andReturn('bar');
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$path = new LfmPath($helper);
$this->assertEquals('bar', $path->foo());
}
public function testDirAndNormalizeWorkingDir()
{
$helper = m::mock(Lfm::class);
$helper->shouldReceive('input')->with('working_dir')->once()->andReturn('foo');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$path = new LfmPath($helper);
$this->assertEquals('foo', $path->normalizeWorkingDir());
$this->assertEquals('bar', $path->dir('bar')->normalizeWorkingDir());
}
public function testSetNameAndGetName()
{
$path = new LfmPath(m::mock(Lfm::class));
$path->setName('bar');
$this->assertEquals('bar', $path->getName());
}
public function testPath()
{
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getRootFolder')->andReturn('/foo');
$helper->shouldReceive('basePath')->andReturn(realpath(__DIR__ . '/../'));
$helper->shouldReceive('input')->with('working_dir')->andReturnNull();
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('rootPath')->andReturn(realpath(__DIR__ . '/../') . '/storage/app');
$helper->shouldReceive('getStorage')->andReturn($storage);
$path = new LfmPath($helper);
$this->assertEquals('files/foo', $path->path());
$this->assertEquals('files/foo/bar', $path->setName('bar')->path('storage'));
}
public function testUrl()
{
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getRootFolder')->andReturn('/foo');
$helper->shouldReceive('input')->with('working_dir')->andReturnNull();
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('url')->andReturn('/files/foo/foo');
$helper->shouldReceive('getStorage')->andReturn($storage);
$path = new LfmPath($helper);
$this->assertEquals('/files/foo/foo', $path->setName('foo')->url());
}
public function testFolders()
{
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('directories')->andReturn(['foo/bar']);
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('input')->with('working_dir')->andReturn('/shares');
$helper->shouldReceive('input')->with('sort_type')->andReturn('alphabetic');
$helper->shouldReceive('getStorage')->andReturn($storage);
$helper->shouldReceive('getNameFromPath')->andReturn('bar');
$helper->shouldReceive('getThumbFolderName')->andReturn('thumbs');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$helper->shouldReceive('config')
->with('item_columns')
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
$path = new LfmPath($helper);
$this->assertInstanceOf(LfmItem::class, $path->folders()[0]);
}
public function testFiles()
{
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('files')->andReturn(['foo/bar']);
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('input')->with('working_dir')->andReturn('/shares');
$helper->shouldReceive('input')->with('sort_type')->andReturn('alphabetic');
$helper->shouldReceive('getStorage')->andReturn($storage);
$helper->shouldReceive('getNameFromPath')->andReturn('bar');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$helper->shouldReceive('config')
->with('item_columns')
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
$path = new LfmPath($helper);
$this->assertInstanceOf(LfmItem::class, $path->files()[0]);
}
public function testPretty()
{
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getNameFromPath')->andReturn('bar');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('config')
->with('item_columns')
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
$path = new LfmPath($helper);
$this->assertInstanceOf(LfmItem::class, $path->pretty('foo'));
}
public function testCreateFolder()
{
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('rootPath')->andReturn(realpath(__DIR__ . '/../') . '/storage/app');
$storage->shouldReceive('exists')->andReturn(false);
$storage->shouldReceive('makeDirectory')->andReturn(true);
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$path = new LfmPath($helper);
$this->assertNull($path->createFolder('bar'));
}
public function testCreateFolderButFolderAlreadyExists()
{
$storage = m::mock(LfmStorage::class);
$storage->shouldReceive('exists')->andReturn(true);
$storage->shouldReceive('makeDirectory')->andReturn(true);
$helper = m::mock(Lfm::class);
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
$helper->shouldReceive('ds')->andReturn('/');
$path = new LfmPath($helper);
$this->assertFalse($path->createFolder('foo'));
}
}
PK �8]c�Y� � % laravel-filemanager/tests/LfmTest.phpnu �[��� <?php
namespace Tests;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Http\Request;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use UniSharp\LaravelFilemanager\Lfm;
use UniSharp\LaravelFilemanager\LfmFileRepository;
use UniSharp\LaravelFilemanager\LfmStorageRepository;
class LfmTest extends TestCase
{
public function tearDown(): void
{
m::close();
parent::tearDown();
}
public function testGetStorage()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.disk')->once()->andReturn('local');
$lfm = new Lfm($config);
$this->assertInstanceOf(LfmStorageRepository::class, $lfm->getStorage('foo/bar'));
}
public function testInput()
{
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('foo')->andReturn('bar');
$lfm = new Lfm(m::mock(Config::class), $request);
$this->assertEquals('bar', $lfm->input('foo'));
}
public function testGetNameFromPath()
{
$this->assertEquals('bar', (new Lfm)->getNameFromPath('foo/bar'));
}
public function testAllowFolderType()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.folder_categories')->andReturn([]);
$config->shouldReceive('has')->andReturn(false);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->andReturn('');
$lfm = new Lfm($config, $request);
$this->assertTrue($lfm->allowFolderType('user'));
$this->assertTrue($lfm->allowFolderType('shared'));
$this->assertFalse($lfm->allowFolderType('shared'));
}
public function testGetCategoryName()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')
->with('lfm.folder_categories.file.folder_name', m::type('string'))
->once()
->andReturn('files');
$config->shouldReceive('get')
->with('lfm.folder_categories.image.folder_name', m::type('string'))
->once()
->andReturn('photos');
$config->shouldReceive('get')
->with('lfm.folder_categories')
->andReturn(['file' => [], 'image' => []]);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->once()->andReturn('file');
$request->shouldReceive('input')->with('type')->once()->andReturn('image');
$lfm = new Lfm($config, $request);
$this->assertEquals('files', $lfm->getCategoryName('file'));
$this->assertEquals('photos', $lfm->getCategoryName('image'));
}
public function testCurrentLfmType()
{
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->once()->andReturn('file');
$request->shouldReceive('input')->with('type')->once()->andReturn('image');
$request->shouldReceive('input')->with('type')->once()->andReturn('foo');
$config = m::mock(Config::class);
$config->shouldReceive('get')
->with('lfm.folder_categories')
->andReturn(['file' => [], 'image' => []]);
$lfm = new Lfm($config, $request);
$this->assertEquals('file', $lfm->currentLfmType());
$this->assertEquals('image', $lfm->currentLfmType());
$this->assertEquals('file', $lfm->currentLfmType());
}
public function testGetUserSlug()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.private_folder_name')->once()->andReturn(function () {
return 'foo';
});
$lfm = new Lfm($config);
$this->assertEquals('foo', $lfm->getUserSlug());
}
public function testGetRootFolder()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->andReturn(true);
$config->shouldReceive('get')->with('lfm.private_folder_name')->once()->andReturn(function () {
return 'foo';
});
$config->shouldReceive('get')->with('lfm.shared_folder_name')->once()->andReturn('bar');
$lfm = new Lfm($config);
$this->assertEquals('/foo', $lfm->getRootFolder('user'));
$this->assertEquals('/bar', $lfm->getRootFolder('shared'));
}
public function testGetThumbFolderName()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.thumb_folder_name')->once()->andReturn('foo');
$lfm = new Lfm($config);
$this->assertEquals('foo', $lfm->getThumbFolderName());
}
public function testGetFileType()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.file_type_array.foo', m::type('string'))->once()->andReturn('foo');
$config->shouldReceive('get')->with(m::type('string'), m::type('string'))->once()->andReturn('File');
$lfm = new Lfm($config);
$this->assertEquals('foo', $lfm->getFileType('foo'));
$this->assertEquals('File', $lfm->getFileType('bar'));
}
public function testAllowMultiUser()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.folder_categories')->andReturn([]);
$config->shouldReceive('has')->andReturn(false);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->andReturn('');
$lfm = new Lfm($config, $request);
$this->assertTrue($lfm->allowMultiUser());
}
public function testAllowShareFolder()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.folder_categories')->andReturn([]);
$config->shouldReceive('has')->andReturn(false);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->andReturn('');
$lfm = new Lfm($config, $request);
$this->assertTrue($lfm->allowShareFolder());
$this->assertFalse($lfm->allowShareFolder());
}
public function testTranslateFromUtf8()
{
$input = 'test/測試';
$this->assertEquals($input, (new Lfm)->translateFromUtf8($input));
}
}
PK �8] U�a� � 6 laravel-filemanager/tests/LfmStorageRepositoryTest.phpnu �[��� <?php
namespace Tests;
use Illuminate\Support\Facades\Storage;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use UniSharp\LaravelFilemanager\Lfm;
use UniSharp\LaravelFilemanager\LfmPath;
use UniSharp\LaravelFilemanager\LfmStorageRepository;
class LfmStorageRepositoryTest extends TestCase
{
private $storage;
public function setUp(): void
{
parent::setUp();
$disk = m::mock('disk');
$disk->shouldReceive('getDriver')->andReturn($disk);
$disk->shouldReceive('getAdapter')->andReturn($disk);
$disk->shouldReceive('getPathPrefix')->andReturn('foo/bar');
$disk->shouldReceive('functionToCall')->with('foo/bar')->andReturn('baz');
$disk->shouldReceive('directories')->with('foo')->andReturn(['foo/bar']);
$disk->shouldReceive('move')->with('foo/bar', 'foo/bar/baz')->andReturn(true);
$disk->shouldReceive('path')->andReturn('foo/bar');
$helper = m::mock(Lfm::class);
$helper->shouldReceive('config')->with('disk')->andReturn('local');
Storage::shouldReceive('disk')->with('local')->andReturn($disk);
$this->storage = new LfmStorageRepository('foo/bar', $helper);
}
public function tearDown(): void
{
m::close();
}
public function testMagicCall()
{
$this->assertEquals('baz', $this->storage->functionToCall());
}
public function testRootPath()
{
$this->assertEquals('foo/bar', $this->storage->rootPath());
}
public function testMove()
{
$new_lfm_path = m::mock(LfmPath::class);
$new_lfm_path->shouldReceive('path')->with('storage')->andReturn('foo/bar/baz');
$this->assertTrue($this->storage->move($new_lfm_path));
}
}
PK �8]E�2l l ) laravel-filemanager/tests/LfmItemTest.phpnu �[��� <?php
namespace Tests;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use UniSharp\LaravelFilemanager\Lfm;
use UniSharp\LaravelFilemanager\LfmItem;
use UniSharp\LaravelFilemanager\LfmPath;
class LfmItemTest extends TestCase
{
private $lfm_path;
private $lfm;
public function setUp(): void
{
$this->lfm = m::mock(Lfm::class);
$this->lfm_path = m::mock(LfmPath::class);
$this->lfm_path->shouldReceive('thumb')->andReturn($this->lfm_path);
$this->lfm->shouldReceive('config')
->with('item_columns')
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
}
public function tearDown(): void
{
m::close();
parent::tearDown();
}
public function testMagicGet()
{
$this->lfm_item = new LfmItem($this->lfm_path, $this->lfm);
$this->lfm_item->attributes['foo'] = 'bar';
$this->assertEquals('bar', $this->lfm_item->foo);
}
public function testName()
{
$this->lfm_path->shouldReceive('getName')->andReturn('bar');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('bar', $item->name());
}
public function testAbsolutePath()
{
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('foo/bar.baz', $item->path());
}
public function testIsDirectory()
{
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertFalse($item->isDirectory());
}
public function testIsFile()
{
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertTrue($item->isFile());
}
public function testIsImage()
{
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain')->shouldReceive('isDirectory')
->andReturn(false);
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertFalse($item->isImage());
}
public function testMimeType()
{
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('application/plain', $item->mimeType());
}
public function testType()
{
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
$this->lfm_path->shouldReceive('extension')->andReturn('baz');
$this->lfm->shouldReceive('getFileType')->with('baz')->andReturn('File');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('File', $item->type());
}
public function testExtension()
{
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
$this->lfm_path->shouldReceive('extension')->andReturn('baz');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('baz', $item->extension());
}
public function testThumbUrl()
{
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertNull($item->thumbUrl());
}
// TODO: refactor
public function testUrl()
{
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$this->lfm_path->shouldReceive('getName')->andReturn('bar');
$this->lfm_path->shouldReceive('setName')->andReturn($this->lfm_path);
$this->lfm_path->shouldReceive('url')->andReturn('foo/bar');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('foo/bar', $item->url());
}
public function testSize()
{
$this->lfm_path->shouldReceive('size')->andReturn(1024);
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('1.00 kB', $item->size());
}
public function testTime()
{
$this->lfm_path->shouldReceive('lastModified')->andReturn(0)->shouldReceive('isDirectory')
->andReturn(false);
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals(0, $item->time());
}
public function testIcon()
{
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
$this->lfm_path->shouldReceive('extension')->andReturn('baz');
$this->lfm->shouldReceive('getFileIcon')->with('baz')->andReturn('fa-file');
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('baz', $item->icon());
// $path1 = m::mock(LfmPath::class);
// $path1->shouldReceive('path')->with('absolute')->andReturn('foo/bar');
// $path1->shouldReceive('isDirectory')->andReturn(false);
// $path1->shouldReceive('mimeType')->andReturn('image/png');
// $path3 = m::mock(LfmPath::class);
// $path3->shouldReceive('path')->with('absolute')->andReturn('foo/biz');
// $path3->shouldReceive('isDirectory')->andReturn(true);
// $this->assertEquals('fa-image', (new LfmItem($path1))->icon());
// $this->assertEquals('fa-folder-o', (new LfmItem($path3))->icon());
}
public function testHasThumb()
{
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain')->shouldReceive('isDirectory')
->andReturn(false);
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertFalse($item->hasThumb());
}
public function testHumanFilesize()
{
$item = new LfmItem($this->lfm_path, $this->lfm);
$this->assertEquals('1.00 kB', $item->humanFilesize(1024));
$this->assertEquals('1.00 MB', $item->humanFilesize(1024 ** 2));
$this->assertEquals('1.00 GB', $item->humanFilesize(1024 ** 3));
$this->assertEquals('1.00 TB', $item->humanFilesize(1024 ** 4));
$this->assertEquals('1.00 PB', $item->humanFilesize(1024 ** 5));
$this->assertEquals('1.00 EB', $item->humanFilesize(1024 ** 6));
}
}
PK �8]m���� � laravel-filemanager/LICENSEnu �[��� The MIT License (MIT)
Copyright (c) 2015 Trevor Sawler <https://github.com/tsawler>
Copyright (c) 2015-2017 All contributors from GitHub
Copyright (c) 2015-2017 UniSharp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
PK �8]�f}��) �) # laravel-filemanager/src/LfmPath.phpnu �[��� <?php
namespace UniSharp\LaravelFilemanager;
use Illuminate\Container\Container;
use Intervention\Image\Facades\Image as InterventionImageV2;
use Intervention\Image\Laravel\Facades\Image as InterventionImageV3;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use UniSharp\LaravelFilemanager\Events\FileIsUploading;
use UniSharp\LaravelFilemanager\Events\FileWasUploaded;
use UniSharp\LaravelFilemanager\Events\ImageIsUploading;
use UniSharp\LaravelFilemanager\Events\ImageWasUploaded;
use UniSharp\LaravelFilemanager\LfmUploadValidator;
class LfmPath
{
private $working_dir;
private $item_name;
private $is_thumb = false;
private $helper;
public function __construct(Lfm $lfm = null)
{
$this->helper = $lfm;
}
public function __get($var_name)
{
if ($var_name == 'storage') {
return $this->helper->getStorage($this->path('url'));
}
}
public function __call($function_name, $arguments)
{
return $this->storage->$function_name(...$arguments);
}
public function dir($working_dir)
{
$this->working_dir = $working_dir;
return $this;
}
public function thumb($is_thumb = true)
{
$this->is_thumb = $is_thumb;
return $this;
}
public function setName($item_name)
{
$this->item_name = $item_name;
return $this;
}
public function getName()
{
return $this->item_name;
}
public function path($type = 'storage')
{
if ($type == 'working_dir') {
// working directory: /{user_slug}
return $this->translateToLfmPath($this->normalizeWorkingDir());
} elseif ($type == 'url') {
// storage: files/{user_slug}
// storage without folder: {user_slug}
return $this->helper->getCategoryName() === '.'
? ltrim($this->path('working_dir'), '/')
: $this->helper->getCategoryName() . $this->path('working_dir');
} elseif ($type == 'storage') {
// storage: files/{user_slug}
// storage on windows: files\{user_slug}
return str_replace(Lfm::DS, $this->helper->ds(), $this->path('url'));
} else {
// absolute: /var/www/html/project/storage/app/files/{user_slug}
// absolute on windows: C:\project\storage\app\files\{user_slug}
return $this->storage->rootPath() . $this->path('storage');
}
}
public function translateToLfmPath($path)
{
return str_replace($this->helper->ds(), Lfm::DS, $path);
}
public function url()
{
return $this->storage->url($this->path('url'));
}
public function folders()
{
$all_folders = array_map(function ($directory_path) {
return $this->pretty($directory_path, true);
}, $this->storage->directories());
$folders = array_filter($all_folders, function ($directory) {
return $directory->name !== $this->helper->getThumbFolderName();
});
return $this->sortByColumn($folders);
}
public function files()
{
$files = array_map(function ($file_path) {
return $this->pretty($file_path);
}, $this->storage->files());
return $this->sortByColumn($files);
}
public function pretty($item_path, $isDirectory = false)
{
return Container::getInstance()->makeWith(LfmItem::class, [
'lfm' => (clone $this)->setName($this->helper->getNameFromPath($item_path)),
'helper' => $this->helper,
'isDirectory' => $isDirectory
]);
}
public function delete()
{
if ($this->isDirectory()) {
return $this->storage->deleteDirectory();
} else {
return $this->storage->delete();
}
}
/**
* Create folder if not exist.
*
* @param string $path Real path of a directory.
* @return bool
*/
public function createFolder()
{
if ($this->storage->exists($this)) {
return false;
}
$this->storage->makeDirectory(0777, true, true);
}
public function isDirectory()
{
$working_dir = $this->path('working_dir');
$parent_dir = substr($working_dir, 0, strrpos($working_dir, '/'));
$parent_directories = array_map(function ($directory_path) {
return app(static::class)->translateToLfmPath($directory_path);
}, app(static::class)->dir($parent_dir)->directories());
return in_array($this->path('url'), $parent_directories);
}
/**
* Check a folder and its subfolders is empty or not.
*
* @param string $directory_path Real path of a directory.
* @return bool
*/
public function directoryIsEmpty()
{
return count($this->storage->allFiles()) == 0;
}
public function normalizeWorkingDir()
{
$path = $this->working_dir
?: $this->helper->input('working_dir')
?: $this->helper->getRootFolder();
if ($this->is_thumb) {
// Prevent if working dir is "/" normalizeWorkingDir will add double "//" that breaks S3 functionality
$path = rtrim($path, Lfm::DS) . Lfm::DS . $this->helper->getThumbFolderName();
}
if ($this->getName()) {
// Prevent if working dir is "/" normalizeWorkingDir will add double "//" that breaks S3 functionality
$path = rtrim($path, Lfm::DS) . Lfm::DS . $this->getName();
}
return $path;
}
/**
* Sort files and directories.
*
* @param mixed $arr_items Array of files or folders or both.
* @return array of object
*/
public function sortByColumn($arr_items)
{
$sort_by = $this->helper->input('sort_type');
if (in_array($sort_by, ['name', 'time'])) {
$key_to_sort = $sort_by;
} else {
$key_to_sort = 'name';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
return strcasecmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
}
public function error($error_type, $variables = [])
{
throw new \Exception($this->helper->error($error_type, $variables));
}
// Upload section
public function upload($file)
{
$new_file_name = $this->getNewName($file);
$new_file_path = $this->setName($new_file_name)->path('absolute');
event(new FileIsUploading($new_file_path));
event(new ImageIsUploading($new_file_path));
try {
$this->setName($new_file_name)->storage->save($file);
$this->generateThumbnail($new_file_name);
} catch (\Exception $e) {
\Log::info($e);
return $this->error('invalid');
}
event(new FileWasUploaded($new_file_path));
event(new ImageWasUploaded($new_file_path));
return $new_file_name;
}
public function validateUploadedFile($file)
{
$validator = new LfmUploadValidator($file);
$validator->sizeLowerThanIniMaximum();
$validator->uploadWasSuccessful();
if (!config('lfm.over_write_on_duplicate')) {
$validator->nameIsNotDuplicate($this->getNewName($file), $this);
}
$validator->mimetypeIsNotExcutable(config('lfm.disallowed_mimetypes', ['text/x-php', 'text/html', 'text/plain']));
$validator->extensionIsNotExcutable(config('lfm.disallowed_extensions', ['php', 'html']));
if (config('lfm.should_validate_mime', false)) {
$validator->mimeTypeIsValid($this->helper->availableMimeTypes());
}
if (config('lfm.should_validate_size', false)) {
$validator->sizeIsLowerThanConfiguredMaximum($this->helper->maxUploadSize());
}
return true;
}
private function getNewName($file)
{
$new_file_name = $this->helper->translateFromUtf8(
trim($this->helper->utf8Pathinfo($file->getClientOriginalName(), "filename"))
);
$extension = $file->getClientOriginalExtension();
if (config('lfm.rename_file') === true) {
$new_file_name = uniqid();
} elseif (config('lfm.alphanumeric_filename') === true) {
$new_file_name = preg_replace('/[^A-Za-z0-9\-\']/', '_', $new_file_name);
}
if ($extension) {
$new_file_name_with_extention = $new_file_name . '.' . $extension;
}
if (config('lfm.rename_duplicates') === true) {
$counter = 1;
$file_name_without_extentions = $new_file_name;
while ($this->setName(($extension) ? $new_file_name_with_extention : $new_file_name)->exists()) {
if (config('lfm.alphanumeric_filename') === true) {
$suffix = '_'.$counter;
} else {
$suffix = " ({$counter})";
}
$new_file_name = $file_name_without_extentions.$suffix;
if ($extension) {
$new_file_name_with_extention = $new_file_name . '.' . $extension;
}
$counter++;
}
}
return ($extension) ? $new_file_name_with_extention : $new_file_name;
}
public function generateThumbnail($file_name)
{
$original_image = $this->pretty($file_name);
if (!$original_image->shouldCreateThumb()) {
return;
}
// create folder for thumbnails
$this->setName(null)->thumb(true)->createFolder();
// generate cropped image content
$this->setName($file_name)->thumb(true);
$thumbWidth = $this->helper->shouldCreateCategoryThumb() && $this->helper->categoryThumbWidth() ? $this->helper->categoryThumbWidth() : config('lfm.thumb_img_width', 200);
$thumbHeight = $this->helper->shouldCreateCategoryThumb() && $this->helper->categoryThumbHeight() ? $this->helper->categoryThumbHeight() : config('lfm.thumb_img_height', 200);
if (class_exists(InterventionImageV2::class)) {
$encoded_image = InterventionImageV2::make($original_image->get())
->fit($thumbWidth, $thumbHeight)
->stream()
->detach();
} else {
$encoded_image = InterventionImageV3::read($original_image->get())
->cover($thumbWidth, $thumbHeight)
->encodeByMediaType();
}
$this->storage->put($encoded_image, 'public');
}
}
PK �8]���I� � 5 laravel-filemanager/src/Handlers/LfmConfigHandler.phpnu �[��� <?php
namespace App\Handlers;
class LfmConfigHandler extends \UniSharp\LaravelFilemanager\Handlers\ConfigHandler
{
public function userField()
{
return parent::userField();
}
}
PK �8]��� � 2 laravel-filemanager/src/Handlers/ConfigHandler.phpnu �[��� <?php
namespace UniSharp\LaravelFilemanager\Handlers;
class ConfigHandler
{
public function userField()
{
return auth()->id();
}
}
PK �8]
���) �) laravel-filemanager/src/Lfm.phpnu �[��� <?php
namespace UniSharp\LaravelFilemanager;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use UniSharp\LaravelFilemanager\Middlewares\CreateDefaultFolder;
use UniSharp\LaravelFilemanager\Middlewares\MultiUser;
class Lfm
{
const PACKAGE_NAME = 'laravel-filemanager';
const DS = '/';
protected $config;
protected $request;
public function __construct(Config $config = null, Request $request = null)
{
$this->config = $config;
$this->request = $request;
}
public function getStorage($storage_path)
{
return new LfmStorageRepository($storage_path, $this);
}
public function input($key)
{
return $this->translateFromUtf8($this->request->input($key));
}
public function config($key)
{
return $this->config->get('lfm.' . $key);
}
/**
* Get only the file name.
*
* @param string $path Real path of a file.
* @return string
*/
public function getNameFromPath($path)
{
return $this->utf8Pathinfo($path, 'basename');
}
public function utf8Pathinfo($path, $part_name)
{
// XXX: all locale work-around for issue: utf8 file name got emptified
// if there's no '/', we're probably dealing with just a filename
// so just put an 'a' in front of it
if (strpos($path, '/') === false) {
$path_parts = pathinfo('a' . $path);
} else {
$path = str_replace('/', '/a', $path);
$path_parts = pathinfo($path);
}
return substr($path_parts[$part_name], 1);
}
public function allowFolderType($type)
{
if ($type == 'user') {
return $this->allowMultiUser();
} else {
return $this->allowShareFolder();
}
}
public function getCategoryName()
{
$type = $this->currentLfmType();
return $this->config->get('lfm.folder_categories.' . $type . '.folder_name', 'files');
}
/**
* Get current lfm type.
*
* @return string
*/
public function currentLfmType()
{
$lfm_type = 'file';
$request_type = lcfirst(Str::singular($this->input('type') ?: ''));
$available_types = array_keys($this->config->get('lfm.folder_categories') ?: []);
if (in_array($request_type, $available_types)) {
$lfm_type = $request_type;
}
return $lfm_type;
}
public function getDisplayMode()
{
$type_key = $this->currentLfmType();
$startup_view = $this->config->get('lfm.folder_categories.' . $type_key . '.startup_view');
$view_type = 'grid';
$target_display_type = $this->input('show_list') ?: $startup_view;
if (in_array($target_display_type, ['list', 'grid'])) {
$view_type = $target_display_type;
}
return $view_type;
}
public function getUserSlug()
{
$config = $this->config->get('lfm.private_folder_name');
if (is_callable($config)) {
return call_user_func($config);
}
if (class_exists($config)) {
return app()->make($config)->userField();
}
return empty(auth()->user()) ? '' : auth()->user()->$config;
}
public function getRootFolder($type = null)
{
if (is_null($type)) {
$type = 'share';
if ($this->allowFolderType('user')) {
$type = 'user';
}
}
if ($type === 'user') {
$folder = $this->getUserSlug();
} else {
$folder = $this->config->get('lfm.shared_folder_name');
}
// the slash is for url, dont replace it with directory seperator
return '/' . $folder;
}
public function getThumbFolderName()
{
return $this->config->get('lfm.thumb_folder_name');
}
public function getFileType($ext)
{
return $this->config->get("lfm.file_type_array.{$ext}", 'File');
}
public function availableMimeTypes()
{
return $this->config->get('lfm.folder_categories.' . $this->currentLfmType() . '.valid_mime');
}
public function shouldCreateCategoryThumb()
{
return $this->config->get('lfm.folder_categories.' . $this->currentLfmType() . '.thumb');
}
public function categoryThumbWidth()
{
return $this->config->get('lfm.folder_categories.' . $this->currentLfmType() . '.thumb_width');
}
public function categoryThumbHeight()
{
return $this->config->get('lfm.folder_categories.' . $this->currentLfmType() . '.thumb_height');
}
public function maxUploadSize()
{
return $this->config->get('lfm.folder_categories.' . $this->currentLfmType() . '.max_size');
}
public function getPaginationPerPage()
{
return $this->config->get("lfm.paginator.perPage", 30);
}
/**
* Check if users are allowed to use their private folders.
*
* @return bool
*/
public function allowMultiUser()
{
$type_key = $this->currentLfmType();
if ($this->config->has('lfm.folder_categories.' . $type_key . '.allow_private_folder')) {
return $this->config->get('lfm.folder_categories.' . $type_key . '.allow_private_folder') === true;
}
return $this->config->get('lfm.allow_private_folder') === true;
}
/**
* Check if users are allowed to use the shared folder.
* This can be disabled only when allowMultiUser() is true.
*
* @return bool
*/
public function allowShareFolder()
{
if (! $this->allowMultiUser()) {
return true;
}
$type_key = $this->currentLfmType();
if ($this->config->has('lfm.folder_categories.' . $type_key . '.allow_shared_folder')) {
return $this->config->get('lfm.folder_categories.' . $type_key . '.allow_shared_folder') === true;
}
return $this->config->get('lfm.allow_shared_folder') === true;
}
/**
* Translate file name to make it compatible on Windows.
*
* @param string $input Any string.
* @return string
*/
public function translateFromUtf8($input)
{
if ($this->isRunningOnWindows()) {
$input = iconv('UTF-8', mb_detect_encoding($input), $input);
}
return $input;
}
/**
* Get directory seperator of current operating system.
*
* @return string
*/
public function ds()
{
$ds = Lfm::DS;
if ($this->isRunningOnWindows()) {
$ds = '\\';
}
return $ds;
}
/**
* Check current operating system is Windows or not.
*
* @return bool
*/
public function isRunningOnWindows()
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
/**
* Shorter function of getting localized error message..
*
* @param mixed $error_type Key of message in lang file.
* @param mixed $variables Variables the message needs.
* @return string
*/
public function error($error_type, $variables = [])
{
throw new \Exception(trans(self::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables));
}
/**
* Generates routes of this package.
*
* @return void
*/
public static function routes()
{
$middleware = [ CreateDefaultFolder::class, MultiUser::class ];
$as = 'unisharp.lfm.';
$namespace = '\\UniSharp\\LaravelFilemanager\\Controllers\\';
Route::group(compact('middleware', 'as', 'namespace'), function () {
// display main layout
Route::get('/', [
'uses' => 'LfmController@show',
'as' => 'show',
]);
// display integration error messages
Route::get('/errors', [
'uses' => 'LfmController@getErrors',
'as' => 'getErrors',
]);
// upload
Route::any('/upload', [
'uses' => 'UploadController@upload',
'as' => 'upload',
]);
// list images & files
Route::get('/jsonitems', [
'uses' => 'ItemsController@getItems',
'as' => 'getItems',
]);
Route::get('/move', [
'uses' => 'ItemsController@move',
'as' => 'move',
]);
Route::get('/domove', [
'uses' => 'ItemsController@doMove',
'as' => 'doMove'
]);
// folders
Route::get('/newfolder', [
'uses' => 'FolderController@getAddfolder',
'as' => 'getAddfolder',
]);
// list folders
Route::get('/folders', [
'uses' => 'FolderController@getFolders',
'as' => 'getFolders',
]);
// crop
Route::get('/crop', [
'uses' => 'CropController@getCrop',
'as' => 'getCrop',
]);
Route::get('/cropimage', [
'uses' => 'CropController@getCropImage',
'as' => 'getCropImage',
]);
Route::get('/cropnewimage', [
'uses' => 'CropController@getNewCropImage',
'as' => 'getNewCropImage',
]);
// rename
Route::get('/rename', [
'uses' => 'RenameController@getRename',
'as' => 'getRename',
]);
// scale/resize
Route::get('/resize', [
'uses' => 'ResizeController@getResize',
'as' => 'getResize',
]);
Route::get('/doresize', [
'uses' => 'ResizeController@performResize',
'as' => 'performResize',
]);
Route::get('/doresizenew', [
'uses' => 'ResizeController@performResizeNew',
'as' => 'performResizeNew',
]);
// download
Route::get('/download', [
'uses' => 'DownloadController@getDownload',
'as' => 'getDownload',
]);
// delete
Route::get('/delete', [
'uses' => 'DeleteController@getDelete',
'as' => 'getDelete',
]);
Route::get('/demo', 'DemoController@index');
});
}
}
PK �8][��d d '