Skip to content

Commit

Permalink
Merge pull request juzaweb#78 from mymocms/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
juzaweb authored Jun 26, 2021
2 parents f817d67 + 202129c commit 339f494
Show file tree
Hide file tree
Showing 36 changed files with 514 additions and 79 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v1.1.7
- File manager config
- Theme config
- Fix module commands
- Note for upgrade:
- Change type files/folders to string (default: image)
- Update your database if you upgrade

## v1.1.6.1
- Fix load hook actions

Expand Down Expand Up @@ -34,7 +42,6 @@
- Intall command

## 1.1.1
- Package cms
- Migrate when active plugin
- Fix load image thumbnail
- Current version and change logs updates pages
Expand Down
2 changes: 1 addition & 1 deletion assets/styles/css/backend.css

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"extra": {
"laravel": {
"providers": [
"Mymo\\Core\\Providers\\MymoCoreServiceProvider",
"Mymo\\Plugin\\PluginServiceProvider"
"Mymo\\Core\\Providers\\MymoCoreServiceProvider"
]
}
}
Expand Down
30 changes: 29 additions & 1 deletion config/mymo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
'admin_prefix' => env('ADMIN_PREFIX', 'admin-cp'),

'plugin' => [
/**
* Enable upload plugins
*
* Default: true
*/
'enable_upload' => true,

/**
* Enable autoload plugins
* If disable, you can require plugin by composer
*
* Default: true
*/
'autoload' => true,

/**
* Plugins path
*
Expand All @@ -33,6 +48,12 @@
],

'theme' => [
/**
* Enable upload themes
*
* Default: true
*/
'enable_upload' => true,
/**
* Themes path
*
Expand Down Expand Up @@ -62,6 +83,8 @@

'email' => [
/**
* Method send email
*
* Support: sync, queue, cron
* Default: sync
* */
Expand All @@ -70,13 +93,18 @@

'notification' => [
/**
* Method send notification
*
* Support: sync, queue, cron
* Default: sync
* */
'method' => 'sync',

/**
* Send mail via
*
* Support: database, mail
* */
*/
'via' => [
'database' => [
'enable' => true,
Expand Down
208 changes: 208 additions & 0 deletions src/Backend/Http/Controllers/Backend/MediaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<?php
/**
* MYMO CMS - The Best Laravel CMS
*
* @package mymocms/mymocms
* @author The Anh Dang <[email protected]>
* @link https://github.com/mymocms/mymocms
* @license MIT
*
* Created by The Anh.
* Date: 6/25/2021
* Time: 11:47 PM
*/

namespace Mymo\Backend\Http\Controllers\Backend;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Mymo\Backend\Http\Controllers\BackendController;
use Mymo\Core\Models\File;
use Mymo\Core\Models\Folder;

class MediaController extends BackendController
{
public function index($folderId = null)
{
$title = trans('mymo::app.media');
if ($folderId) {
$this->addBreadcrumb([
'title' => $title,
'url' => route('admin.media'),
]);

$folder = Folder::find($folderId);
$folder->load('parent');
$this->addBreadcrumbFolder($folder);
$title = $folder->name;
}

$query = collect(request()->query());
$mediaItems = array_merge(
$this->getDirectories($query, $folderId),
$this->getFiles($query, $folderId)
);

return view('mymo::backend.media.index', [
'fileTypes' => $this->getFileTypes(),
'folderId' => $folderId,
'mediaItems' => $mediaItems,
'title' => $title
]);
}

public function addFolder(Request $request)
{
$request->validate([
'name' => 'required|string|max:150',
'folder_id' => 'nullable|exists:folders,id',
], [], [
'name' => trans('mymo::filemanager.folder-name'),
'folder_id' => trans('mymo::filemanager.parent')
]);

$name = $request->post('name');
$parentId = $request->post('folder_id');

if (Folder::folderExists($name, $parentId)) {
return $this->error([
'message' => trans('mymo::filemanager.errors.folder-exists')
]);
}

try {
DB::beginTransaction();
Folder::create($request->all());
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
throw $e;
}

// event

return $this->success(trans('mymo::filemanager.add-folder-successfully'));
}

protected function getFileTypes()
{
return config('mymo.filemanager.types');
}

protected function addBreadcrumbFolder($folder)
{
$parent = $folder->parent;
if ($parent) {
$this->addBreadcrumb([
'title' => $parent->name,
'url' => route('admin.media.folder', $parent->id),
]);

$parent->load('parent');
if ($parent->parent) {
$this->addBreadcrumbFolder($parent);
}
}
}

/**
* Get files in folder
*
* @param Collection $sQuery
* @param integer $folderId
* @return array
*/
protected function getFiles($sQuery, $folderId)
{
$result = [];
$fileIcon = $this->getFileIcon();
$query = File::whereFolderId($folderId);

if ($sQuery->get('type')) {
$query->where('type', '=', $sQuery->get('type'));
}

$files = $query->get();
foreach ($files as $row) {
$fileUrl = upload_url($row->path);
$thumb = $row->isImage($row) ? $fileUrl : null;
$icon = isset($fileIcon[strtolower($row->extension)]) ?
$fileIcon[strtolower($row->extension)] : 'fa-file-o';

$result[] = (object) [
'id' => $row->id,
'name' => $row->name,
'url' => $fileUrl,
'size' => $row->size,
'updated' => strtotime($row->updated_at),
'path' => $row->path,
'time' => (string) $row->created_at,
'type' => $row->type,
'icon' => $icon,
'thumb' => $thumb,
'is_file' => true
];
}

return $result;
}

/**
* Get directories in folder
*
* @param Collection $sQuery
* @param integer $folderId
* @return array
*/
protected function getDirectories($sQuery, $folderId)
{
$result = [];
$query = Folder::whereFolderId($folderId);

if ($sQuery->get('type')) {
$query->where('type', '=', $sQuery->get('type'));
}

$directories = $query->get();
foreach ($directories as $row) {
$result[] = (object) [
'id' => $row->id,
'name' => $row->name,
'url' => '',
'size' => '',
'updated' => strtotime($row->updated_at),
'path' => $row->id,
'time' => (string) $row->created_at,
'type' => $row->type,
'icon' => 'fa-folder-o',
'thumb' => asset('mymo/filemanager/images/folder.png'),
'is_file' => false
];
}

return $result;
}

protected function getFileIcon()
{
return [
'pdf' => 'fa-file-pdf-o',
'doc' => 'fa-file-word-o',
'docx' => 'fa-file-word-o',
'xls' => 'fa-file-excel-o',
'xlsx' => 'fa-file-excel-o',
'rar' => 'fa-file-archive-o',
'zip' => 'fa-file-archive-o',
'gif' => 'fa-file-image-o',
'jpg' => 'fa-file-image-o',
'jpeg' => 'fa-file-image-o',
'png' => 'fa-file-image-o',
'ppt' => 'fa-file-powerpoint-o',
'pptx' => 'fa-file-powerpoint-o',
'mp4' => 'fa-file-video-o',
'mp3' => 'fa-file-video-o',
'jfif' => 'fa-file-image-o',
'txt' => 'fa-file-text-o',
];
}
}
8 changes: 4 additions & 4 deletions src/Backend/Http/Controllers/FileManager/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Mymo\Backend\Http\Controllers\FileManager;

use Illuminate\Http\Request;
use Mymo\Core\Models\Files;
use Mymo\Core\Models\Folders;
use Mymo\Core\Models\File;
use Mymo\Core\Models\Folder;

class DeleteController extends FileManagerController
{
Expand All @@ -21,10 +21,10 @@ public function delete(Request $request)

$is_directory = $this->isDirectory($file);
if ($is_directory) {
Folders::find($file)->deleteFolder();
Folder::find($file)->deleteFolder();
} else {
$file_path = $this->getPath($file);
Files::where('path', '=', $file_path)
File::where('path', '=', $file_path)
->first()
->delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Mymo\Backend\Http\Controllers\FileManager;

use Illuminate\Support\Facades\Storage;
use Mymo\Core\Models\Files;
use Mymo\Core\Models\File;

class DownloadController extends FileManagerController
{
public function getDownload()
{
$file = $this->getPath(request()->get('file'));
$data = Files::where('path', '=', $file)->first(['name']);
$data = File::where('path', '=', $file)->first(['name']);

$path = Storage::disk(config('mymo.filemanager.disk'))->path($file);
if ($data) {
Expand Down
6 changes: 3 additions & 3 deletions src/Backend/Http/Controllers/FileManager/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Mymo\Backend\Http\Controllers\FileManager;

use Illuminate\Support\Facades\DB;
use Mymo\Core\Models\Folders;
use Mymo\Core\Models\Folder;

class FolderController extends FileManagerController
{
public function getFolders()
{
$childrens = [];
$folders = Folders::whereNull('folder_id')
$folders = Folder::whereNull('folder_id')
->where('type', '=', $this->getType())
->get(['id', 'name']);

Expand Down Expand Up @@ -45,7 +45,7 @@ public function addfolder()
return $this->error('folder-name');
}

if (Folders::folderExists($folder_name, $parent_id)) {
if (Folder::folderExists($folder_name, $parent_id)) {
return $this->error('folder-exist');
}

Expand Down
8 changes: 4 additions & 4 deletions src/Backend/Http/Controllers/FileManager/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Mymo\Backend\Http\Controllers\FileManager;

use Illuminate\Support\Facades\Storage;
use Mymo\Core\Models\Files;
use Mymo\Core\Models\Folders;
use Mymo\Core\Models\File;
use Mymo\Core\Models\Folder;

class ItemsController extends FileManagerController
{
Expand All @@ -16,11 +16,11 @@ public function getItems()

$working_dir = request()->get('working_dir');

$folders = Folders::where('folder_id', '=', $working_dir)
$folders = Folder::where('folder_id', '=', $working_dir)
->where('type', '=', $file_type)
->orderBy('name', 'ASC')
->get(['id', 'name']);
$files = Files::where('folder_id', '=', $working_dir)
$files = File::where('folder_id', '=', $working_dir)
->where('type', '=', $file_type)
->orderBy('id', 'DESC')
->paginate($perPage);
Expand Down
Loading

0 comments on commit 339f494

Please sign in to comment.