├── codecov.yml ├── code-of-conduct.md ├── src ├── assets │ └── plugins │ │ └── system-file │ │ ├── images │ │ └── favicon-32x32.png │ │ ├── css │ │ └── main.css │ │ └── js │ │ └── bottom_of_all_admin_pages.js ├── resources │ ├── lang │ │ ├── zh │ │ │ └── plugin-system-file.php │ │ └── en │ │ │ └── plugin-system-file.php │ └── views │ │ └── plugins │ │ └── system-file │ │ ├── file-shortcut.blade.php │ │ ├── file-history.blade.php │ │ ├── file-crumb.blade.php │ │ ├── file-layout.blade.php │ │ ├── file-list.blade.php │ │ ├── file-create.blade.php │ │ └── file-edit.blade.php ├── LaravelCmsPluginServiceProvider.php ├── database │ └── migrations │ │ └── 2019_10_09_184421_update_plugin_settings_table.php └── Controllers │ └── SystemFileController.php ├── contributing.md ├── .styleci.yml ├── .editorconfig ├── .php_cs ├── license.md ├── README.md └── composer.json /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | - Check the .php_cs 4 | -------------------------------------------------------------------------------- /src/assets/plugins/system-file/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexStack/Laravel-CMS-Plugin-System-File/master/src/assets/plugins/system-file/images/favicon-32x32.png -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | - Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or simply helping others. No matter what your skill level is, every contribution counts. 4 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | risky: false 3 | enabled: 4 | - alpha_ordered_imports 5 | - align_double_arrow 6 | - align_equals 7 | disabled: 8 | - length_ordered_imports 9 | - unused_use 10 | - unalign_equals 11 | finder: 12 | exclude: 13 | - modules 14 | - node_modules 15 | - storage 16 | - vendor 17 | name: "*.php" 18 | not-name: "*.blade.php" 19 | -------------------------------------------------------------------------------- /src/assets/plugins/system-file/css/main.css: -------------------------------------------------------------------------------- 1 | .plugin-system-file .table-striped tbody tr:nth-of-type(2n+1) { 2 | background-color: #e9ecef3b; 3 | } 4 | 5 | .plugin-system-file .table-striped tbody tr:hover { 6 | background-color: #e9ecef; 7 | } 8 | 9 | .plugin-system-file .shortcut-logo { 10 | padding-top: 0.35rem; 11 | } 12 | 13 | .plugin-system-file .CodeMirror { 14 | border: 1px solid #d1d7dc; 15 | height: auto; 16 | } 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # For more information about the properties used in this file, 2 | # please see the EditorConfig documentation: 3 | # http://editorconfig.org 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.{yml,js,json,css,scss,feature,eslintrc}] 14 | indent_size = 2 15 | indent_style = space 16 | 17 | [composer.json] 18 | indent_size = 4 -------------------------------------------------------------------------------- /src/resources/lang/zh/plugin-system-file.php: -------------------------------------------------------------------------------- 1 | '修改文件', 5 | 'return_to_the_folder' => '返回目录列表', 6 | 'confirm_to_delete' => '确认删除', 7 | 'create_new_file' => '创建新文件', 8 | 'create_new_folder' => '创建新目录', 9 | 'cms_shortcuts' => 'CMS文件快捷入口', 10 | 'all_files' => '全部文件', 11 | 'system_file_explorer' => '系统文件管理', 12 | 'file_history' => '文件修改记录', 13 | ]; 14 | -------------------------------------------------------------------------------- /src/resources/lang/en/plugin-system-file.php: -------------------------------------------------------------------------------- 1 | 'Modify the File', 5 | 'return_to_the_folder' => 'Return to the Folder', 6 | 'confirm_to_delete' => 'Confirm to Delete', 7 | 'create_new_file' => 'Create New File', 8 | 'create_new_folder' => 'Create New Folder', 9 | 'cms_shortcuts' => 'CMS Shortcuts', 10 | 'all_files' => 'All Files', 11 | 'system_file_explorer' => 'System File Explorer', 12 | 'file_history' => 'File Edit History', 13 | ]; 14 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | notPath('bootstrap/cache') 7 | ->notPath('storage') 8 | ->notPath('vendor') 9 | ->in(__DIR__) 10 | ->name('*.php') 11 | ->notName('*.blade.php') 12 | ->ignoreDotFiles(true) 13 | ->ignoreVCS(true) 14 | ; 15 | 16 | return PhpCsFixer\Config::create() 17 | ->setRules(array( 18 | '@Symfony' => true, 19 | 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true], 20 | 'array_syntax' => ['syntax' => 'short'], 21 | 'linebreak_after_opening_tag' => true, 22 | 'not_operator_with_successor_space' => true, 23 | 'ordered_imports' => true, 24 | 'phpdoc_order' => true, 25 | )) 26 | ->setFinder($finder) 27 | ; 28 | -------------------------------------------------------------------------------- /src/LaravelCmsPluginServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([__DIR__.'/resources/views/plugins' => base_path('resources/views/vendor/laravel-cms/plugins')], 'system-file-views'); 16 | 17 | // Publish lang 18 | $this->publishes([__DIR__.'/resources/lang' => base_path('resources/lang/vendor/laravel-cms')], 'system-file-lang'); 19 | 20 | // Publish assets 21 | $this->publishes([__DIR__.'/assets/plugins' => public_path('laravel-cms/plugins')], 'system-file-assets'); 22 | } 23 | 24 | /** 25 | * Register the application services. 26 | */ 27 | public function register() 28 | { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2019-2020 Alex Zeng 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-shortcut.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | {{$helper->t('plugin-system-file.cms_shortcuts')}} : 4 | Templates 5 | Assets 6 | Plugin Controllers 7 | 8 | Lang 9 | 10 | Backups 11 | 12 | 13 | CMS Config 14 | ENV 15 | Web Routes 16 | 17 |
18 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-history.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | @forelse ($file_history as $filename => $date_str) 5 | 6 | 15 | 20 | 21 | @empty 22 | 23 | 26 | 27 | @endforelse 28 | 29 |
7 | @if ( strpos($date_str,'Deleted') === false ) 8 | 9 | {{$filename}} 10 | @else 11 | {{$filename}} 12 | @endif 13 | 14 | 16 | 17 | {{ $date_str }} 18 | 19 |
24 |
{{$helper->t('no_results')}}
25 |
30 |
31 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-crumb.blade.php: -------------------------------------------------------------------------------- 1 | 23 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-layout.blade.php: -------------------------------------------------------------------------------- 1 | @extends($helper->bladePath('includes.layout','b')) 2 | 3 | @section('content') 4 | 5 | 6 | 7 |
8 |
9 |
10 | @include($helper->bladePath('system-file.file-crumb','plugins')) 11 |
12 | 13 | @if ( isset($_GET['file']) && $file_content !== false ) 14 | 15 | @include($helper->bladePath('system-file.file-edit','plugins')) 16 | 17 | @elseif ( isset($_GET['file']) && $file_content === false ) 18 | 19 |
{{$helper->t('plugin-system-file.file_can_not_edit')}}
20 | @if( isset($image_preview_str) ) 21 |
{!! $image_preview_str !!}
22 | @endif 23 | 24 | @elseif ( isset($_GET['create_new_file'])) 25 | 26 | @include($helper->bladePath('system-file.file-create','plugins')) 27 | 28 | @elseif ( isset($_GET['show_file_history'])) 29 | 30 | @include($helper->bladePath('system-file.file-history','plugins')) 31 | 32 | @else 33 | 34 | @include($helper->bladePath('system-file.file-list','plugins')) 35 | 36 | @endif 37 | 38 | @include($helper->bladePath('system-file.file-shortcut','plugins')) 39 | 40 |
41 |
42 | 43 | @endsection 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel system file explorer, can view & edit files online. 2 | 3 | - This is an Amila Laravel CMS Plugin 4 | - Laravel system file explorer, can view & edit files online. 5 | 6 | ## Install it via the backend 7 | 8 | - Go to the CMS settings page -> Plugin -> search for remote image 9 | - Find alexstack/laravel-cms-plugin-system-file 10 | - Click the Install button 11 | 12 | ## What the plugin do for us? 13 | 14 | - Laravel system file explorer 15 | - Can view & edit files online. 16 | - Store file edit history in case make a mistake 17 | 18 | ## Install it via command line manually 19 | 20 | ```php 21 | composer require alexstack/laravel-cms-plugin-system-file 22 | 23 | php artisan migrate --path=./vendor/alexstack/laravel-cms-plugin-system-file/src/database/migrations 24 | 25 | php artisan vendor:publish --force --tag=Amila\\LaravelCms\\Plugins\\SystemFile\\LaravelCmsPluginServiceProvider 26 | 27 | php artisan laravelcms --action=clear 28 | 29 | ``` 30 | 31 | ## How to use it? 32 | 33 | - It's enabled after install by default. You can see a System File tab when you edit a page. 34 | - You don't need to do anything after install 35 | 36 | ## How to change the settings? 37 | 38 | - You can change the settings by edit plugin.system-file 39 | 40 | ```json 41 | 42 | ``` 43 | 44 | ## Improve this plugin & documents 45 | 46 | - You are very welcome to improve this plugin and how to use documents 47 | 48 | ## License 49 | 50 | - This Amila Laravel CMS plugin is an open-source software licensed under the MIT license. 51 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexstack/laravel-cms-plugin-system-file", 3 | "description": "Laravel system file explorer, can view & edit files online.(eg. .php/.blade.php/.js/.html/.txt/.json/.css)", 4 | "type": "amila-laravel-cms-plugin", 5 | "homepage": "https://github.com/AlexStack/Laravel-CMS-Plugin-System-File", 6 | "keywords": [ 7 | "laravel", 8 | "amila laravel cms", 9 | "laravel file", 10 | "file manager", 11 | "laravel file manager", 12 | "php file manager", 13 | "system file explorer", 14 | "amila laravel cms plugin" 15 | ], 16 | "license": "MIT", 17 | "support": { 18 | "issues": "https://github.com/AlexStack/Laravel-CMS-Plugin-System-File/issues" 19 | }, 20 | "authors": [{ 21 | "name": "Alex", 22 | "homepage": "https://github.com/AlexStack/Laravel-CMS-Plugin-System-File" 23 | }], 24 | "require": { 25 | "php": ">=7.0.0", 26 | "alexstack/laravel-cms": "*" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Amila\\LaravelCms\\Plugins\\SystemFile\\": "src/" 31 | } 32 | }, 33 | "minimum-stability": "dev", 34 | "extra": { 35 | "laravel": { 36 | "providers": [ 37 | "Amila\\LaravelCms\\Plugins\\SystemFile\\LaravelCmsPluginServiceProvider" 38 | ] 39 | }, 40 | "laravel-cms": { 41 | "plugin-param-name": "system-file" 42 | } 43 | }, 44 | "scripts": { 45 | "post-package-install": [ 46 | "php artisan migrate --path=./vendor/alexstack/laravel-cms-plugin-system-file/src/database/migrations/", 47 | "php artisan vendor:publish --provider=Amila\\LaravelCms\\Plugins\\SystemFile\\LaravelCmsPluginServiceProvider", 48 | "php artisan laravelcms --action=clear" 49 | ] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/database/migrations/2019_10_09_184421_update_plugin_settings_table.php: -------------------------------------------------------------------------------- 1 | config = include base_path('config/laravel-cms.php'); 14 | $this->table_name = $this->config['table_name']['settings']; 15 | } 16 | 17 | /** 18 | * Run the migrations. 19 | */ 20 | public function up() 21 | { 22 | $setting_data = [ 23 | 'category' => 'plugin', 24 | 'param_name' => 'system-file', 25 | 'input_attribute' => '{"rows":10,"required":"required"}', 26 | 'enabled' => 1, 27 | 'sort_value' => 40, 28 | 'abstract' => 'Laravel system file explorer, can view & edit files online. Tutorial', 29 | 'param_value' => '{ 30 | "plugin_name" : "System File Explorer", 31 | "blade_file" : "file-layout", 32 | "tab_name" : "__(system,file)", 33 | "php_class" : "Amila\\\\LaravelCms\\\\Plugins\\\\SystemFile\\\\Controllers\\\\SystemFileController", 34 | "hide_in_menu" : false, 35 | "allow_delete_folder": "no_sub_folder", 36 | "js_for_all_admin_pages" : "js/bottom_of_all_admin_pages.js", 37 | "composer_install_only" : false, 38 | "plugin_type" : "standalone" 39 | }', 40 | ]; 41 | LaravelCmsSetting::UpdateOrCreate( 42 | ['category'=>'plugin', 'param_name' => 'system-file'], 43 | $setting_data 44 | ); 45 | } 46 | 47 | /** 48 | * Reverse the migrations. 49 | */ 50 | public function down() 51 | { 52 | LaravelCmsSetting::where('param_name', 'system-file')->where('category', 'plugin')->delete(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-list.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | @forelse ($files as $filename => $f) 5 | 6 | 18 | 24 | 25 | @empty 26 | 27 | 30 | 31 | @endforelse 32 | 33 |
7 | @if ( $f['is_dir']) 8 | 9 | 10 | {{$filename}} 11 | 12 | @else 13 | 14 | 15 | {{$filename}} 16 | @endif 17 | 19 | {{$f['is_dir'] ? '-' : $f['size_str']}} 20 | 21 | {{date("Y-m-d H:i:s",$f['mtime']) }} 22 | 23 |
28 |
{{$helper->t('no_results')}}
29 |
34 | 35 |
36 | 38 | 39 |
40 |
41 | 42 | 67 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-create.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 |
12 |
13 | 15 |
16 |
17 | 19 |
20 |
21 |
22 |
23 | 24 | {{--
--}} 25 | 26 | {{-- create new folder --}} 27 |
28 |
29 | 30 | 31 | 32 | 33 | 34 |
35 |
36 | 37 | 38 |
39 |
40 | 43 |
44 |
45 | 47 |
48 |
49 |
50 |
51 | 52 |
53 | 54 |
55 |
56 | {{$helper->t('plugin-system-file.return_to_the_folder')}} 58 |
59 | 60 | 61 |
62 | -------------------------------------------------------------------------------- /src/assets/plugins/system-file/js/bottom_of_all_admin_pages.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | 3 | /** 4 | * This js file will attach to the bottom of all admin pages 5 | * We should optimize it to speed up load the page 6 | * Suggest function name format: pluginNameFuncName() to avoid be override by the same function name of other js file 7 | */ 8 | 9 | function systemFileAddLinkToSetting() { 10 | var category = $("#cms_setting_form .input-category").val(); 11 | var param_name = $("#cms_setting_form .input-param_name").val(); 12 | if ( 13 | category == "template" && 14 | (param_name == "frontend_dir" || param_name == "backend_dir") 15 | ) { 16 | $(".label-param_value").after( 17 | 'View/Edit template files' 18 | ); 19 | } else if ( 20 | category == "template" && 21 | (param_name == "frontend_language" || param_name == "frontend_language") 22 | ) { 23 | $(".label-param_value").after( 24 | 'View/Edit language files' 25 | ); 26 | } else if (category == "plugin") { 27 | $(".label-param_value").after( 28 | 'View/Edit plugin template files' + 31 | 'View/Edit plugin PHP files' 32 | ); 33 | } 34 | } 35 | 36 | function systemFileAddLinkToFileManager() { 37 | // todo 38 | } 39 | 40 | function systemFileShowTopLinks() { 41 | $(".breadcrumb").after( 42 | '" 45 | ); 46 | $(".top-links").hide() 47 | .removeClass("d-none") 48 | .fadeIn("slow"); 49 | } 50 | 51 | 52 | function systemFileCountFiles() { 53 | $(".folder-action").prepend( 54 | 'Folders : ' + 55 | $("#file-list-table i.fa-folder").length + ' Files : ' + $("#file-list-table i.fa-file").length + 56 | "" 57 | ); 58 | $(".count-files").hide() 59 | .removeClass("d-none") 60 | .fadeIn("slow"); 61 | } 62 | 63 | // Main controller function will invoke after the page dom loaded 64 | $(function () { 65 | if (location.href.indexOf(admin_route + "/settings/") !== -1) { 66 | systemFileAddLinkToSetting(); 67 | } else if ( 68 | location.href.indexOf(admin_route + "/files") !== -1 && 69 | location.href.indexOf("editor_id=") == -1 70 | ) { 71 | systemFileAddLinkToFileManager(); 72 | } else if ( 73 | location.href.indexOf(admin_route + "/plugins/system-file") !== -1 && 74 | location.href.indexOf("path=") == -1 75 | ) { 76 | systemFileShowTopLinks(); 77 | } 78 | 79 | if ( 80 | location.href.indexOf(admin_route + "/plugins/system-file") !== -1 && 81 | location.href.indexOf("file=") == -1 82 | ) { 83 | systemFileCountFiles(); 84 | } 85 | }); 86 | -------------------------------------------------------------------------------- /src/resources/views/plugins/system-file/file-edit.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 6 |
7 |
8 |
9 | 11 | 12 | {{$helper->t('plugin-system-file.return_to_the_folder')}} 14 | 15 | 17 |
18 |
19 | 20 |
21 | 22 | @if( isset($file_history) && ! empty($file_history) ) 23 | 32 | @endif 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 46 | 47 | 48 | 125 | -------------------------------------------------------------------------------- /src/Controllers/SystemFileController.php: -------------------------------------------------------------------------------- 1 | helper = new LaravelCmsHelper(); 17 | } 18 | 19 | public function checkUser() 20 | { 21 | if (! $this->user) { 22 | $this->user = $this->helper->hasPermission(); 23 | } 24 | } 25 | 26 | public function show($form_data, $plugin, $plugin_settings) 27 | { 28 | $this->checkUser(); 29 | $base_path = base_path(); 30 | 31 | if (isset($form_data['fullpath']) && '' != trim($form_data['fullpath'])) { 32 | $pathinfo = pathinfo($form_data['fullpath']); 33 | $form_data['path'] = ('.' == $pathinfo['dirname']) ? '' : $pathinfo['dirname']; 34 | $form_data['file'] = $pathinfo['basename']; 35 | 36 | return redirect()->route('LaravelCmsAdminPlugins.show', ['plugin'=> $plugin->param_name, 'path'=>$form_data['path'], 'file'=>$form_data['file']]); 37 | } elseif (isset($form_data['delete_path']) && '' != trim($form_data['delete_path'])) { 38 | return $this->deleteFolder($form_data, $plugin, $plugin_settings); 39 | } 40 | 41 | if (isset($form_data['path']) && '' != trim($form_data['path'])) { 42 | if (false !== strpos($form_data['path'], '..')) { 43 | exit('Invalid path: '.$form_data['path']); 44 | } 45 | $real_path = $base_path.'/'.trim($form_data['path']); 46 | $crumbs = explode('/', trim($form_data['path'])); 47 | $crumb_links = []; 48 | $temp_path_str = ''; 49 | foreach ($crumbs as $crumb) { 50 | $temp_path_str = ('' == $temp_path_str) ? $crumb : $temp_path_str.'/'.$crumb; 51 | $crumb_links[] = ''.$crumb.''; 52 | } 53 | 54 | if (! isset($form_data['file'])) { 55 | $crumb_links[count($crumbs) - 1] = ''.$crumb.''; 56 | } 57 | $data['breadcrumbs'] = $crumb_links; 58 | 59 | // $this->helper->debug($crumb_links); 60 | } else { 61 | $real_path = $base_path; 62 | $data['breadcrumbs'] = []; 63 | } 64 | $data['files'] = []; 65 | // foreach (glob($real_path.'/{,.}[!.,!..]*', GLOB_BRACE) as $file) { 66 | $all_files = array_merge(glob($real_path.'/.[!.]*'), glob($real_path.'/*')); 67 | foreach ($all_files as $file) { 68 | $pathinfo = pathinfo($file); 69 | $fn = $pathinfo['basename']; 70 | 71 | $data['files'][$fn] = lstat($file); 72 | $data['files'][$fn]['is_dir'] = is_dir($file); 73 | $data['files'][$fn]['path'] = str_replace($base_path.'/', '', $file); 74 | $data['files'][$fn]['suffix'] = $pathinfo['extension'] ?? ''; 75 | $data['files'][$fn]['size_str'] = $this->humanFilesize($data['files'][$fn]['size']); 76 | } 77 | // $this->helper->debug($data); 78 | 79 | $data['plugin_settings'] = $plugin_settings; 80 | $data['plugin'] = $plugin; 81 | $data['helper'] = $this->helper; 82 | 83 | if (isset($form_data['show_file_history'])) { 84 | $data['file_history'] = $this->fileHistory(); 85 | } 86 | 87 | // edit a file 88 | if (isset($form_data['file']) && '' != trim($form_data['file'])) { 89 | if (false !== strpos($form_data['file'], '..') || false !== strpos($form_data['file'], '/')) { 90 | exit('Invalid file: '.$form_data['file']); 91 | } 92 | 93 | $real_file_path = isset($form_data['path']) ? base_path($form_data['path'].'/'.$form_data['file']) : base_path($form_data['file']); 94 | if (! file_exists($real_file_path)) { 95 | exit($form_data['file'].' not exists!'); 96 | } 97 | $mime_type = mime_content_type($real_file_path); 98 | if (false !== strpos($mime_type, 'text') || false !== strpos($mime_type, 'xml') || false !== strpos($mime_type, 'json') || false !== strpos($mime_type, 'svg') || false !== strpos($mime_type, 'javascript') || false !== strpos($mime_type, 'empty')) { 99 | $data['file_content'] = file_get_contents($real_file_path); 100 | 101 | $data['file_history'] = $this->fileHistory($real_file_path); 102 | } else { 103 | $data['file_content'] = false; 104 | if (false !== strpos($mime_type, 'image')) { 105 | $data['image_preview_str'] = ''; 106 | } 107 | } 108 | } else { 109 | $data['file_content'] = 'no file'; 110 | //$this->helper->debug($form_data); 111 | } 112 | 113 | return view($this->helper->bladePath('system-file.file-layout', 'plugins'), $data); 114 | } 115 | 116 | // public function create($form_data, $plugin, $plugin_settings) 117 | // { 118 | // } 119 | 120 | public function store($form_data, $plugin, $plugin_settings) 121 | { 122 | $real_file_path = isset($form_data['path']) ? base_path($form_data['path'].'/'.$form_data['filename']) : base_path($form_data['filename']); 123 | 124 | if (file_exists($real_file_path)) { 125 | echo ''; 126 | exit(); 127 | } 128 | 129 | if (isset($form_data['is_dir'])) { 130 | mkdir($real_file_path, 0755); 131 | 132 | $path = '' == trim($form_data['path']) ? $form_data['filename'] : $form_data['path'].'/'.$form_data['filename']; 133 | 134 | return redirect()->route('LaravelCmsAdminPlugins.show', ['plugin'=> $plugin->param_name, 'path'=>$path]); 135 | } 136 | 137 | $rs = file_put_contents($real_file_path, "\n\n\n\n\n\n\n\n"); 138 | 139 | return redirect()->route('LaravelCmsAdminPlugins.show', ['plugin'=> $plugin->param_name, 'path'=>$form_data['path'], 'file'=>$form_data['filename']]); 140 | } 141 | 142 | public function edit($id, $plugin) 143 | { 144 | // uncomment exit() line to make sure your plugin method invoked 145 | // please check the php_class value if not invoked 146 | 147 | //exit('Looks good, the plugin\'s edit() method invoked. id='.$id.'
FILE='.__FILE__.'
PAGE TITLE='.$page->title); 148 | 149 | return $id; 150 | } 151 | 152 | public function update($form_data, $plugin, $plugin_settings) 153 | { 154 | // $this->helper->debug($form_data); 155 | 156 | $real_file_path = isset($form_data['path']) ? base_path($form_data['path'].'/'.$form_data['file']) : base_path($form_data['file']); 157 | 158 | $this->backupFile($real_file_path); 159 | 160 | $rs = file_put_contents($real_file_path, $form_data['file_content']); 161 | 162 | if ('json' == request()->response_type) { 163 | $result['success'] = false !== $rs; 164 | $result['success_content'] = 'File '.$form_data['file'].' modified'; 165 | $result['error_message'] = 'Modify the file '.$form_data['file'].' failed!'; 166 | 167 | return response()->json($result); 168 | } 169 | 170 | return $rs; 171 | } 172 | 173 | public function destroy($form_data, $plugin, $plugin_settings) 174 | { 175 | $real_file_path = isset($form_data['path']) ? base_path($form_data['path'].'/'.$form_data['file']) : base_path($form_data['file']); 176 | 177 | $this->backupFile($real_file_path, 'delete'); 178 | 179 | $rs = unlink($real_file_path); 180 | 181 | if ('json' == request()->response_type) { 182 | $result['success'] = false !== $rs; 183 | $result['success_content'] = 'File '.$form_data['file'].' deleted'; 184 | $result['error_message'] = 'Delete the file '.$form_data['file'].' failed!'; 185 | 186 | return response()->json($result); 187 | } 188 | 189 | return $rs; 190 | } 191 | 192 | /* 193 | * Other methods. 194 | */ 195 | 196 | public function humanFilesize($size, $precision = 2) 197 | { 198 | static $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; 199 | $step = 1024; 200 | $i = 0; 201 | while (($size / $step) > 0.9) { 202 | $size = $size / $step; 203 | $i = $i + 1; 204 | } 205 | 206 | return round($size, $precision).' '.$units[$i]; 207 | } 208 | 209 | public function backupFile($real_file_path, $action='edit') 210 | { 211 | if (strpos($real_file_path, '/laravel-cms/backups/system-files/')) { 212 | return false; 213 | } 214 | 215 | $file_backup_dir = storage_path('app/laravel-cms/backups/system-files/'.date('Y-m')); 216 | if (! file_exists($file_backup_dir)) { 217 | mkdir($file_backup_dir, 0755, true); 218 | } 219 | $new_name = basename($real_file_path).'-'.$action.'-'.date('Y-m-d-His'); 220 | if (is_dir($real_file_path) && '' != trim(request()->delete_path)) { 221 | $rs = rename($real_file_path, $file_backup_dir.'/'.$new_name); 222 | } else { 223 | $rs = copy($real_file_path, $file_backup_dir.'/'.$new_name); 224 | } 225 | 226 | if ($rs) { 227 | $this->updateHistory($new_name, $real_file_path); 228 | } 229 | 230 | return $rs; 231 | } 232 | 233 | public function updateHistory($filename, $real_file_path) 234 | { 235 | $max_number = 2000; 236 | $history_file = storage_path('app/laravel-cms/backups/system-files/history.php'); 237 | $real_file_path = substr(str_replace(base_path(), '', $real_file_path), 1); 238 | if (file_exists($history_file)) { 239 | $history_ary = include $history_file; 240 | if (! isset($history_ary[$filename])) { 241 | if (count($history_ary) >= $max_number) { 242 | array_shift($history_ary); 243 | } 244 | $history_ary[$filename] = $real_file_path; 245 | } else { 246 | return true; 247 | } 248 | } else { 249 | $history_ary[$filename] = $real_file_path; 250 | } 251 | 252 | $history_str = "helper->debug($history_ary); 295 | return $history_ary; 296 | } 297 | 298 | public function deleteFolder($form_data, $plugin, $plugin_settings) 299 | { 300 | $delete_path = trim($form_data['delete_path']); 301 | if (false !== strpos($delete_path, '..') || false !== strpos($delete_path, './')) { 302 | exit('Invalid path: '.$delete_path); 303 | } 304 | 305 | $real_file_path = base_path($delete_path); 306 | 307 | if (strpos($real_file_path, '/laravel-cms/backups/system-files/')) { 308 | \File::deleteDirectory($real_file_path); // destroy for every 309 | } else { 310 | $rs = $this->backupFile($real_file_path, 'delete'); // it rename,move to backup folder 311 | } 312 | 313 | $upper_path = '.' == dirname($delete_path) ? null : dirname($delete_path); 314 | 315 | return redirect()->route('LaravelCmsAdminPlugins.show', ['plugin'=> $plugin->param_name, 'path'=>$upper_path]); 316 | } 317 | } 318 | --------------------------------------------------------------------------------