/**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     if (!is_dir($_sServerDir)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     }
     // Create the "Folders" node.
     $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     $this->_connectorNode->addChild($oFoldersNode);
     $files = array();
     if ($dh = @opendir($_sServerDir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) {
                 $files[] = $file;
             }
         }
         closedir($dh);
     } else {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($files) > 0) {
         natcasesort($files);
         $i = 0;
         foreach ($files as $file) {
             // Create the "Folder" node.
             $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
             $oFoldersNode->addChild($oFolderNode[$i]);
             $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
             $i++;
         }
     }
 }
 /**
  * send response
  * @access public
  *
  */
 function sendResponse()
 {
     $xml =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     $this->_connectorNode =& $xml->getConnectorNode();
     $this->checkConnector();
     if ($this->mustCheckRequest()) {
         $this->checkRequest();
     }
     $resourceTypeName = $this->_currentFolder->getResourceTypeName();
     if (!empty($resourceTypeName)) {
         $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName());
     }
     if ($this->mustAddCurrentFolderNode()) {
         $_currentFolder = new CKEditor_Connector_Utils_XmlNode("CurrentFolder");
         $this->_connectorNode->addChild($_currentFolder);
         $_currentFolder->addAttribute("path", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath()));
         $this->_errorHandler->setCatchAllErros(true);
         $_url = $this->_currentFolder->getUrl();
         $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($_url));
         $this->_errorHandler->setCatchAllErros(false);
     }
     $this->buildXml();
     $_oErrorNode =& $xml->getErrorNode();
     $_oErrorNode->addAttribute("number", "0");
     echo $this->_connectorNode->asXML();
     exit;
 }
Esempio n. 3
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     $sNewFolderName = isset($_POST["newFolderName"]) ? $_POST["newFolderName"] : "";
     $sNewFolderName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName);
     if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sNewFolderName)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     }
     $sServerDir = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName);
     if (!is_writeable($this->_currentFolder->getServerPath())) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $bCreated = false;
     if (file_exists($sServerDir)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ALREADY_EXIST);
     }
     if ($perms = $_config->getChmodFolders()) {
         $oldUmask = umask(0);
         $bCreated = @mkdir($sServerDir, $perms);
         umask($oldUmask);
     } else {
         $bCreated = @mkdir($sServerDir);
     }
     if (!$bCreated) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     } else {
         $oNewFolderNode = new CKEditor_Connector_Utils_XmlNode("NewFolder");
         $this->_connectorNode->addChild($oNewFolderNode);
         $oNewFolderNode->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName));
     }
 }
 /**
  * handle request and build XML
  * @access protected
  *
  */
 function buildXml()
 {
     $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     $files = array();
     $folders = array();
     if ($dh = @opendir($_sServerDir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file == "." || $file == "..") {
                 continue;
             } else {
                 if (!is_dir($_sServerDir . $file)) {
                     $files[] = $file;
                 } else {
                     $folders[] = $file;
                 }
             }
         }
         closedir($dh);
     } else {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     // Create the "Folders" node.
     $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     $this->_connectorNode->addChild($oFoldersNode);
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($folders) > 0) {
         natcasesort($folders);
         $i = 0;
         foreach ($folders as $file) {
             // Create the "Folder" node.
             $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
             $oFoldersNode->addChild($oFolderNode[$i]);
             $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
             $i++;
         }
     }
     // Create the "Files" node.
     $oFilesNode = new CKEditor_Connector_Utils_XmlNode("Files");
     $this->_connectorNode->addChild($oFilesNode);
     if (!is_dir($_sServerDir)) {
         $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     }
     if (sizeof($files) > 0) {
         natcasesort($files);
         $i = 0;
         foreach ($files as $file) {
             $filemtime = @filemtime($_sServerDir . $file);
             //otherwise file doesn't exist or we can't get it's filename properly
             if ($filemtime !== false) {
                 $filename = basename($file);
                 if (!$resourceTypeInfo->checkExtension($filename, false)) {
                     continue;
                 }
                 $oFileNode[$i] = new CKEditor_Connector_Utils_XmlNode("File");
                 $oFilesNode->addChild($oFileNode[$i]);
                 $oFileNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding(basename($file)));
                 $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime));
                 $size = filesize($_sServerDir . $file);
                 if ($size && $size < 1024) {
                     $size = 1;
                 } else {
                     $size = (int) round($size / 1024);
                 }
                 $oFileNode[$i]->addAttribute("size", $size);
                 $i++;
             }
         }
     }
 }