CKFinder插件 - PHP - 重命名文件夹时找到删除空格

问题描述 投票:0回答:1

我需要社区帮助,我需要创建一个插件,用于在重命名文件夹时检查用户输入。该插件应检查新的Renamed文件夹,在保存之前应删除找到的任何空间。

我被困在removeFolderSpace函数中,我不知道如何完成它。如果有人愿意帮助我,我会非常感激!

<?php
namespace CKSource\CKFinder\Plugin\FolderSpace;

use CKSource\CKFinder\Acl\Permission;
use CKSource\CKFinder\CKFinder;
use CKSource\CKFinder\Config;
use CKSource\CKFinder\Command\CommandAbstract;
use CKSource\CKFinder\Event\CKFinderEvent;
use CKSource\CKFinder\Event\RenameFolderEvent;
use CKSource\CKFinder\Filesystem\Folder\Folder;
use CKSource\CKFinder\Filesystem\Folder\WorkingFolder;
use CKSource\CKFinder\Plugin\PluginInterface;
use CKSource\CKFinder\Filesystem\Path;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class FolderSpace implements PluginInterface, EventSubscriberInterface
{
    protected $app;

    public function setContainer(CKFinder $app) {
        $this->app = $app;
    }

    protected $requires = [
        Permission::FOLDER_RENAME,
    ];

    public function getDefaultConfig() {
        return [];
    }

    public function removeFolderSpace(RenameFolderEvent $event) {
        $config = $this->app['config'];
        //$dispatcher = $this->app['dispatcher'];

        // $dispatcher->addListener(CKFinderEvent::AFTER_COMMAND_RENAME_FILE, function(AfterCommandEvent $e) {

        // });

        $request = $event->getRequest();


        $workingFolder = $this->app['working_folder'];



    }


    public static function getSubscribedEvents()
    {
        return [CKFinderEvent::AFTER_COMMAND_RENAME_FILE => 'removeFolderSpace'];
    }


}
php plugins ckeditor directory ckfinder
1个回答
0
投票

要实现此结果,您需要为以下两者创建一个小插件:前端(JavaScript)和连接器(PHP)。

PHP插件引导代码:

namespace CKSource\CKFinder\Plugin\SanitizeFolderName;

use CKSource\CKFinder\CKFinder;
use CKSource\CKFinder\Event\CKFinderEvent;
use CKSource\CKFinder\Event\RenameFolderEvent;
use CKSource\CKFinder\Plugin\PluginInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class SanitizeFolderName implements PluginInterface, EventSubscriberInterface
{
    protected $app;

    public function setContainer(CKFinder $app)
    {
        $this->app = $app;
    }

    public function getDefaultConfig()
    {
        return [];
    }

    public function onFolderRename(RenameFolderEvent $event)
    {
        $event->setNewFolderName(str_replace(' ', '_', $event->getNewFolderName()));
    }

    public static function getSubscribedEvents()
    {
        return [
            CKFinderEvent::RENAME_FOLDER => 'onFolderRename'
        ];
    }
}

JavaScript代码:

CKFinder.start({
    onInit: function(finder) {
        finder.on('command:before:RenameFolder', function() {
            finder.once('command:before:GetFiles', function(evt) {
                var folder = evt.data.folder;
                folder.set('name', folder.get('name').replace(/ /g, '_'));
            });
        });
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.