/** * Get server path to thumbnails directory * * @access public * @return string */ public function getThumbsServerPath() { if (is_null($this->_thumbsServerPath)) { $this->_resourceTypeConfig = $this->getResourceTypeConfig(); $_config =& QFinder_Connector_Core_Factory::getInstance("Core_Config"); $_thumbnailsConfig = $_config->getThumbnailsConfig(); // Get the resource type directory. $this->_thumbsServerPath = QFinder_Connector_Utils_FileSystem::combinePaths($_thumbnailsConfig->getDirectory(), $this->_resourceTypeConfig->getName()); // Return the resource type directory combined with the required path. $this->_thumbsServerPath = QFinder_Connector_Utils_FileSystem::combinePaths($this->_thumbsServerPath, ltrim($this->_clientPath, '/')); if (!is_dir($this->_thumbsServerPath)) { if (!QFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_thumbsServerPath)) { /** * @todo Qfinder_Connector_Utils_Xml::raiseError(); perhaps we should return error * */ } } } return $this->_thumbsServerPath; }
/** * Check request * @access protected * */ protected function checkRequest() { if (preg_match(QFINDER_REGEX_INVALID_PATH, $this->_currentFolder->getClientPath())) { $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_INVALID_NAME); } $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); if (is_null($_resourceTypeConfig)) { $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_INVALID_TYPE); } $_clientPath = $this->_currentFolder->getClientPath(); $_clientPathParts = explode("/", trim($_clientPath, "/")); if ($_clientPathParts) { foreach ($_clientPathParts as $_part) { if ($_resourceTypeConfig->checkIsHiddenFolder($_part)) { $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_INVALID_REQUEST); } } } if (!is_dir($this->_currentFolder->getServerPath())) { if ($_clientPath == "/") { if (!QFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) { /** * @todo handle error */ } } else { $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); } } }
/** * Extract one file from zip archive * * @param string $extractPath * @param string $extractClientPath * @param array $filePathInfo * @param string $sFileName * @param string $originalFileName */ protected function extractTo($extractPath, $extractClientPath, $filePathInfo, $sFileName, $originalFileName) { $sfilePathInfo = pathinfo($extractPath . $sFileName); $extractClientPathDir = $filePathInfo['dirname']; if ($filePathInfo['dirname'] == '.') { $extractClientPathDir = ''; } $folderPath = QFinder_Connector_Utils_FileSystem::combinePaths($extractClientPath, $extractClientPathDir); $_aclConfig = $this->_config->getAccessControlConfig(); $aclMask = $_aclConfig->getComputedMask($this->_currentFolder->getResourceTypeName(), $folderPath); $canCreateFolder = ($aclMask & QFINDER_CONNECTOR_ACL_FOLDER_CREATE) == QFINDER_CONNECTOR_ACL_FOLDER_CREATE; // create sub-directory of zip archive if (empty($sfilePathInfo['extension'])) { $fileStat = $this->zip->statName($originalFileName); $isDir = false; if ($fileStat && empty($fileStat['size'])) { $isDir = true; } if (!empty($sfilePathInfo['dirname']) && !empty($sfilePathInfo['basename']) && !file_exists($sfilePathInfo['dirname'] . '/' . $sfilePathInfo['basename'])) { if (!$canCreateFolder) { return; } if ($isDir) { QFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname'] . '/' . $sfilePathInfo['basename']); return; } else { QFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname']); } } else { return; } } // extract file if (!file_exists($sfilePathInfo['dirname'])) { if (!$canCreateFolder) { $this->errorCode = QFINDER_CONNECTOR_ERROR_UNAUTHORIZED; $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); return; } QFinder_Connector_Utils_FileSystem::createDirectoryRecursively($sfilePathInfo['dirname']); } $isAuthorized = ($aclMask & QFINDER_CONNECTOR_ACL_FILE_UPLOAD) == QFINDER_CONNECTOR_ACL_FILE_UPLOAD; if (!$isAuthorized) { $this->errorCode = QFINDER_CONNECTOR_ERROR_COPY_FAILED; $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); return; } if (copy('zip://' . $this->filePath . '#' . $originalFileName, $extractPath . $sFileName)) { $this->appendUnzippedNode($this->unzippedNodes, $originalFileName); // chmod extracted file if (is_file($extractPath . $sFileName) && ($perms = $this->_config->getChmodFiles())) { $oldumask = umask(0); chmod($extractPath . $sFileName, $perms); umask($oldumask); } } else { $this->errorCode = QFINDER_CONNECTOR_ERROR_COPY_FAILED; $this->appendErrorNode($this->skippedFilesNode, $this->errorCode, $originalFileName); } }