`
zwnJava
  • 浏览: 205897 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

CKFinder命令扩展

阅读更多
CKFinder命令扩展
1.	CKFinder命令的扩展,在此以“新建 xml文件”为例讲述命令扩展的方法。
2.	在CKFinder_Connector_Core_Connector 类的executeCommand()方法下(大概 83-91之间任意位置)添加 “CreateFile”命令。
注意:添加命令一定要分析出其添加的位置,不同的命令添加的位置可能不同,但都是在executeCommand()方法下添加。
CKFinder_Connector_Core_Connector 类的实际存储位置为:
core\connector\php\php5\Core\Connector.php
3.	再在core\connnector\php\php5\CommandHandler文件夹下添加CreateFile.php文件。
由于新建文件的操作和 新建文件夹的操作是类似的,所以新CreateFolder.php中的代码拷贝到CreateFile.php中。
4.	修改CreateFile.php中的代码:
(1)	修改类名:将CKFinder_Connector_CommandHandler_CreateFolder 改为
CKFinder_Connector_CommandHandler_CreateFile

(2)	再将 40行的 private $command = "CreateFolder"; 改为
private $command = "CreateFile";
(3)	最后修改 buildXml()方法中的内容。新建文件夹和新建文件的操作类似,
大体方法不用改,只要改具体的细节即可。
例:新建文件夹操作将buildXml方法改为:
protected function buildXml()
{
$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
if(!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)){
			 $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
}
		//判断 fileName是否设置
		if (!isset($_GET["fileName"])) {
			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
		}
		//将fileName进行转码
		$sFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]);

		//判断文件扩展名是否合法
		$resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
		if (!$resourceTypeInfo->checkExtension($sFileName)) {
			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
		}
		// 检查文件名称是否合法,或 是否已有此名称的隐藏文件
		if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $resourceTypeInfo->checkIsHiddenFile($sFileName)) {
			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
		}
		//组合路径
		$sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sFileName);
		//检查文件是否已在存在
		if (file_exists($sServerDir)) {
		 	$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST);
		}
		if (!is_writeable($this->_currentFolder->getServerPath())) {
			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
		}$_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
	//判断 fileName是否已经存在
	if (!isset($_GET["fileName"])) {	
 $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
	}
	//将fileName进行转码
$sFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(
$_GET["fileName"]);
		 
	// 检查文件或文件夹名称是否合法
	if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) ||
 $_resourceTypeConfig->checkIsHiddenFolder($sFileName)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
	}
	//组合路径
	$sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths(
$this->_currentFolder->getServerPath(), $sFileName);
	if (!is_writeable($this->_currentFolder->getServerPath())) {	
		  $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
	}
	//创建标志
	$bCreated = false;
	if ($perms = $_config->getChmodFolders()) {
			$oldUmask = umask(0);
			$doc = new DOMDocument("1.0","utf-8");
			$root = $doc->createElement("course");
			$root = $doc->appendChild($root);
			$bCreated = $doc->save($sServerDir);
			umask($oldUmask);
	}else {
			$doc = new DOMDocument("1.0","utf-8");
			$root = $doc->createElement("course");
			$root = $doc->appendChild($root);
			$bCreated = $doc->save($sServerDir);
	}
	if (!$bCreated) {
		$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
	} else {
		$oNewFileNode = new Ckfinder_Connector_Utils_XmlNode("NewFile");
		$this->_connectorNode->addChild($oNewFileNode);
$oNewFileNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(
$sFileName));
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics