hashmode/cakephp-tinymce-elfinder

Elfinder文件管理器与tinymce 4.x对cakephp 3.x的集成

安装数: 24,082

依赖者: 2

建议者: 0

安全性: 0

星标: 1

关注者: 3

分支: 1

开放问题: 1

类型:cakephp插件

v1.0.9 2016-08-04 18:19 UTC

This package is not auto-updated.

Last update: 2024-09-15 01:42:36 UTC


README

Elfinder文件管理器与tinymce 4.x对cakephp 3.x的集成 - 允许像在本地文件系统中一样上传/访问图像/文件,以及Amazon S3、远程FTP服务器等。

对于cakephp 2.x - https://github.com/hashmode/Tinymce-Image-Upload-Cakephp

需求

  1. Cakephp 3.x
  2. Elfinder 2.x (目前为2.1) https://github.com/Studio-42/elFinder
  3. Tinymce 4.x (可能与3.x兼容)

安装

1) 使用composer安装:将以下内容添加到主composer.json(在require内),然后运行composer update

"hashmode/cakephp-tinymce-elfinder": "~1.0"

Elfinder需求在插件的composer中添加,因此它将自动安装,但是Tinymce需要单独安装:以及依赖的jQuery UI。因为插件视图文件中访问的静态文件需要位于webroot目录中,所以在安装/更新后,基于回调的composer脚本应将静态文件从elfinder文件夹复制到插件的webroot,因此应在应用程序的主composer.json文件中添加以下内容

    "scripts": {
        "post-update-cmd": "CakephpTinymceElfinder\\Console\\Installer::postUpdate"
    },

2)bootstrap.php中加载插件

Plugin::load('CakephpTinymceElfinder', ['routes' => true]);

3) 将配置选项添加到bootstrap.php(或者您可以在bootstrap中创建另一个文件并将其包含在内)

Configure::write('TinymceElfinder', array(
    'title' => __('Elfinder File Manager'),
    'client_options' => array(
        'width' => 900,
        'height' => 500,
        'resizable' => 'yes'
    ),
    'static_files' => array(
        'js' => array(
            'jquery' => 'jquery-2.1.4.min.js',
            'jquery_ui' => 'libs/jqueryui/jquery-ui.min.js'
        ),
        'css' => array(
            'jquery_ui' => 'libs/jqueryui/jquery-ui.min.css',
            'jquery_ui_theme' => ''
        )
    ),
    'options' => array(
        // 'debug' => true,
        'roots' => array(
            array(
                'driver' => 'LocalFileSystem',                  // driver for accessing file system (REQUIRED)
                'URL' => Router::url('/uploads', true),         // upload main folder
                'path' => WWW_ROOT . 'uploads',                 // path to files (REQUIRED)
                'attributes' => array(
                    array(
                        'pattern' => '!(thumbnails)!',
                        'hidden' => true
                    )
                ),
                'tmbPath' => 'thumbnails',
                'uploadOverwrite' => false,
                'checkSubfolders' => false,
                'disabled' => array()
            )
        ),
    )
));

client_options: 这是初始化JavaScript中的elfinder所使用的选项列表。https://github.com/Studio-42/elFinder/wiki/Client-configuration-options

static_files: Jquery minJquery UI对于elfinder的工作是必需的,因此它们在插件视图中使用,但是为了避免将它们复制到插件的webroot或应用程序的webroot(也许您已经使用它们),只是省略了它们,并需要提供css和js文件的路径,用于jQuery min js、jQuery UI min js和jQuery UI css。jQuery UI主题的css是可选的。这些文件应位于您的应用程序的webroot目录中(或任何插件的webroot目录 - 在这种情况下,您应使用插件语法https://book.cakephp.com.cn/3.0/en/appendices/glossary.html#term-plugin-syntax)

options: https://github.com/Studio-42/elFinder/wiki/Client-configuration-options-2.1

4) 通过将以下内容添加到您的AppView.php初始化中,加载插件的帮助器

$this->loadHelper('CakephpTinymceElfinder.TinymceElfinder');

5) 将tinymce包含到您的页面中(Tinymce不是与插件一起安装的)

<?php echo $this->Html->script('tinymce/tinymce.min.js'); ?>

6) 通过此行,将定义一个js函数用于tinymce的file_browser_callback

<?php $this->TinymceElfinder->defineElfinderBrowser()?>

7) Tinymce初始化

$(document).ready(function() {
	// tinymce init
	tinymce.init({
	  file_browser_callback : elFinderBrowser,
	  selector: "textarea",
	  theme: "modern",
	    
	  ... rest of your code

重要!! - 安全性

默认情况下,所有命令都是允许的,因此如果您需要只允许特定的命令,请确保在选项的roots下添加其余的命令(不应允许的命令)。https://github.com/Studio-42/elFinder/wiki/Client-Server-API-2.1#command-list

插件中的 ElfindersController.php 控制器中有2个操作,这些操作用于 elfinder 的功能。相应的访问权限应从应用程序手动处理。

许可证

MIT - 请参考 Elfinder 和 Tinymce 网站的许可证。