<?php 


/** 
***************************************************
*欢迎使用免费版SiteTeam企业建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.SiteTeam.cn 
***************************************************
**/




 if (!defined('IN_CKFINDER')) exit; require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; class CKFinder_Connector_CommandHandler_CopyFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase { var $command = "CopyFiles"; function buildXml() { if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $clientPath = $this->_currentFolder->getClientPath(); $sServerDir = $this->_currentFolder->getServerPath(); $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); $_aclConfig = $_config->getAccessControlConfig(); $aclMasks = array(); $_resourceTypeConfig = array(); if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; $copied = 0; $copiedAll = 0; if (!empty($_POST['copied'])) { $copiedAll = intval($_POST['copied']); } $checkedPaths = array(); $oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles"); if (!empty($_POST['files']) && is_array($_POST['files'])) { foreach ($_POST['files'] as $index => $arr) { if (empty($arr['name'])) { continue; } if (!isset($arr['name'], $arr['type'], $arr['folder'])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); $type = $arr['type']; $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); $options = (!empty($arr['options'])) ? $arr['options'] : ''; $destinationFilePath = $sServerDir.$name; if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!isset($_resourceTypeConfig[$type])) { $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); } if (is_null($_resourceTypeConfig[$type])) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } if ($currentResourceTypeConfig->getName() != $type) { if (!$currentResourceTypeConfig->checkExtension($name, false)) { $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } } if (empty($checkedPaths[$path])) { $checkedPaths[$path] = true; if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } } $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } if (!isset($aclMasks[$type."@".$path])) { $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); } $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); if (!$isAuthorized) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); } if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } if ($currentResourceTypeConfig->getName() != $type) { $maxSize = $currentResourceTypeConfig->getMaxSize(); $fileSize = filesize($sourceFilePath); if ($maxSize && $fileSize>$maxSize) { $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } } if ($sourceFilePath == $destinationFilePath) { $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) { if (strpos($options, "autorename") !== false) { $iCounter = 1; while (true) { $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . "(" . $iCounter . ")" . "." . CKFinder_Connector_Utils_FileSystem::getExtension($name); $destinationFilePath = $sServerDir.$fileName; if (!file_exists($destinationFilePath)) { break; } else { $iCounter++; } } if (!@copy($sourceFilePath, $destinationFilePath)) { $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } else { $copied++; } } else { $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } } else { if (!@copy($sourceFilePath, $destinationFilePath)) { $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); continue; } else { $copied++; } } } } $this->_connectorNode->addChild($oCopyFilesNode); if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { $this->_connectorNode->addChild($oErrorsNode); } $oCopyFilesNode->addAttribute("copied", $copied); $oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied); if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED); } } function appendErrorNode(&$oErrorsNode, $errorCode, $name, $type, $path) { $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); $oErrorNode->addAttribute("code", $errorCode); $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); $oErrorNode->addAttribute("type", $type); $oErrorNode->addAttribute("folder", $path); $oErrorsNode->addChild($oErrorNode); } } 