CKFinder插件 - PHP - 重命名文件夹时找到删除空格
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CKFinder插件 - PHP - 重命名文件夹时找到删除空格相关的知识,希望对你有一定的参考价值。
我需要社区帮助,我需要创建一个插件,用于在重命名文件夹时检查用户输入。该插件应检查新的Renamed文件夹,在保存之前应删除找到的任何空间。
我被困在removeFolderSpace函数中,我不知道如何完成它。如果有人愿意帮助我,我会非常感激!
<?php
namespace CKSourceCKFinderPluginFolderSpace;
use CKSourceCKFinderAclPermission;
use CKSourceCKFinderCKFinder;
use CKSourceCKFinderConfig;
use CKSourceCKFinderCommandCommandAbstract;
use CKSourceCKFinderEventCKFinderEvent;
use CKSourceCKFinderEventRenameFolderEvent;
use CKSourceCKFinderFilesystemFolderFolder;
use CKSourceCKFinderFilesystemFolderWorkingFolder;
use CKSourceCKFinderPluginPluginInterface;
use CKSourceCKFinderFilesystemPath;
use SymfonyComponentEventDispatcherEventSubscriberInterface;
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'];
}
}
答案
要实现此结果,您需要为以下两者创建一个小插件:前端(javascript)和连接器(PHP)。
PHP插件引导代码:
namespace CKSourceCKFinderPluginSanitizeFolderName;
use CKSourceCKFinderCKFinder;
use CKSourceCKFinderEventCKFinderEvent;
use CKSourceCKFinderEventRenameFolderEvent;
use CKSourceCKFinderPluginPluginInterface;
use SymfonyComponentEventDispatcherEventSubscriberInterface;
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, '_'));
});
});
}
});
以上是关于CKFinder插件 - PHP - 重命名文件夹时找到删除空格的主要内容,如果未能解决你的问题,请参考以下文章
wordpress上传图片时重命名--修改插件时遇到的一些问题