예제 #1
0
 /**
  * Execute command
  *
  * @param string $command
  * @access public
  */
 public function executeCommand($command)
 {
     if (!CKFinder_Connector_core_Hooks::run('BeforeExecuteCommand', array(&$command))) {
         return;
     }
     switch ($command) {
         case 'FileUpload':
             $this->_registry->set("errorHandler", "ErrorHandler_FileUpload");
             $obj =& CKFinder_Connector_core_Factory::getInstance("CommandHandler_" . $command);
             $obj->sendResponse();
             break;
         case 'QuickUpload':
             $this->_registry->set("errorHandler", "ErrorHandler_QuickUpload");
             $obj =& CKFinder_Connector_core_Factory::getInstance("CommandHandler_" . $command);
             $obj->sendResponse();
             break;
         case 'DownloadFile':
         case 'Thumbnail':
             $this->_registry->set("errorHandler", "ErrorHandler_Http");
             $obj =& CKFinder_Connector_core_Factory::getInstance("CommandHandler_" . $command);
             $obj->sendResponse();
             break;
         case 'CopyFiles':
         case 'CreateFolder':
         case 'DeleteFiles':
         case 'DeleteFolder':
         case 'GetFiles':
         case 'GetFolders':
         case 'Init':
         case 'LoadCookies':
         case 'MoveFiles':
         case 'RenameFile':
         case 'RenameFolder':
             $obj =& CKFinder_Connector_core_Factory::getInstance("CommandHandler_" . $command);
             $obj->sendResponse();
             break;
         default:
             $this->handleInvalidCommand();
             break;
     }
 }
예제 #2
0
파일: Hooks.php 프로젝트: denglitong/mvc
 /**
  * Run user defined hooks
  *
  * @param string $event
  * @param object $errorHandler
  * @param array $args
  * @return boolean (true to continue processing, false otherwise)
  */
 public static function run($event, $args = array())
 {
     $config = $GLOBALS['config'];
     if (!isset($config['Hooks'])) {
         return true;
     }
     $hooks =& $config['Hooks'];
     if (!is_array($hooks) || !array_key_exists($event, $hooks) || !is_array($hooks[$event])) {
         return true;
     }
     $errorHandler = $GLOBALS['connector']->getErrorHandler();
     foreach ($hooks[$event] as $i => $hook) {
         $object = NULL;
         $method = NULL;
         $function = NULL;
         $data = NULL;
         $passData = false;
         /* $hook can be: a function, an object, an array of $functiontion and $data,
          * an array of just a function, an array of object and method, or an
          * array of object, method, and data.
          */
         //function
         if (is_string($hook)) {
             $function = $hook;
         } else {
             if (is_object($hook)) {
                 $object = $hooks[$event][$i];
                 $method = "on" . $event;
             } else {
                 if (is_array($hook)) {
                     $count = count($hook);
                     if ($count) {
                         //...object
                         if (is_object($hook[0])) {
                             $object = $hooks[$event][$i][0];
                             if ($count < 2) {
                                 $method = "on" . $event;
                             } else {
                                 //...object and method
                                 $method = $hook[1];
                                 if (count($hook) > 2) {
                                     //...object, method and data
                                     $passData = true;
                                     $data = $hook[2];
                                 }
                             }
                         } else {
                             if (is_string($hook[0])) {
                                 $function = $hook[0];
                                 if ($count > 1) {
                                     //...function with data
                                     $passData = true;
                                     $data = $hook[1];
                                 }
                             }
                         }
                     }
                 }
             }
         }
         /* If defined, add data to the arguments array */
         if ($passData) {
             $args = array_merge(array($data), $args);
         }
         if (isset($object)) {
             $callback = array($object, $method);
         } else {
             if (false !== ($pos = strpos($function, '::'))) {
                 $callback = array(substr($function, 0, $pos), substr($function, $pos + 2));
             } else {
                 $callback = $function;
             }
         }
         if (is_callable($callback)) {
             $ret = call_user_func_array($callback, $args);
         } else {
             $functionName = CKFinder_Connector_core_Hooks::_printCallback($callback);
             $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, "CKFinder failed to call a hook: " . $functionName);
             return false;
         }
         //String return is a custom error
         if (is_string($ret)) {
             $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, $ret);
             return false;
         } else {
             if (is_int($ret)) {
                 $errorHandler->throwError($ret);
                 return false;
             } else {
                 if ($ret === null) {
                     $functionName = CKFinder_Connector_core_Hooks::_printCallback($callback);
                     $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, "CKFinder extension returned an invalid value (null)." . "Hook " . $functionName . " should return a value.");
                     return false;
                 } else {
                     if (!$ret) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
예제 #3
0
 /**
  * send response (save uploaded file, resize if required)
  * @access public
  *
  */
 public function sendResponse()
 {
     $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE;
     $_config =& CKFinder_Connector_core_Factory::getInstance("core_config");
     $oRegistry =& CKFinder_Connector_core_Factory::getInstance("core_Registry");
     $oRegistry->set("FileUpload_fileName", "unknown file");
     $uploadedFile = array_shift($_FILES);
     if (!isset($uploadedFile['name'])) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID);
     }
     $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name']));
     $sFileName = CKFinder_Connector_Utils_FileSystem::secureFileName($sUnsafeFileName);
     if ($sFileName != $sUnsafeFileName) {
         $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
         //增加自定义的重命名函数后在此增加的两行
         /*       $sextension = CKFinder_Connector_Utils_FileSystem::getextension($sFileName);
                  $sFileName = mySetFileName() . '.' . $sextension;
                  //添加以下两行解决中文乱码问题(重命名)  */
         /* $sextension=CKFinder_Connector_Utils_FileSystem::getextension($sFileName);
            $sFileName=date("Ymd")."_".date("His").".".$sextension; */
     }
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $this->checkConnector();
     $this->checkRequest();
     if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     $_resourceTypeconfig = $this->_currentFolder->getResourceTypeconfig();
     if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeconfig->checkIsHiddenFile($sFileName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeconfig();
     if (!$resourceTypeInfo->checkextension($sFileName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
     }
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
     $maxSize = $resourceTypeInfo->getMaxSize();
     if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
     }
     $htmlextensions = $_config->getHtmlextensions();
     $sextension = CKFinder_Connector_Utils_FileSystem::getextension($sFileName);
     if ($htmlextensions && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sextension, $htmlextensions) && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     }
     $secureImageUploads = $_config->getSecureImageUploads();
     if ($secureImageUploads && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sextension)) === false) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     }
     switch ($uploadedFile['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
             break;
         case UPLOAD_ERR_PARTIAL:
         case UPLOAD_ERR_NO_FILE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
         case UPLOAD_ERR_EXTENSION:
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
     }
     $sServerDir = $this->_currentFolder->getServerPath();
     while (true) {
         $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
         if (file_exists($sFilePath)) {
             $sFileName = CKFinder_Connector_Utils_FileSystem::autoRename($sServerDir, $sFileName);
             $oRegistry->set("FileUpload_fileName", $sFileName);
             $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
         } else {
             if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
                 $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
             } else {
                 if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
                     @unlink($sFilePath);
                     $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
                 } else {
                     if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sextension) === false) {
                         @unlink($sFilePath);
                         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                     }
                 }
             }
             if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
                 $oldumask = umask(0);
                 chmod($sFilePath, $perms);
                 umask($oldumask);
             }
             break;
         }
     }
     if (!$_config->checkSizeAfterScaling()) {
         $this->_errorHandler->throwError($iErrorNumber, true, false);
     }
     //resize image if required
     require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php";
     $_imagesconfig = $_config->getImagesconfig();
     if ($_imagesconfig->getMaxWidth() > 0 && $_imagesconfig->getMaxHeight() > 0 && $_imagesconfig->getQuality() > 0) {
         CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesconfig->getMaxWidth(), $_imagesconfig->getMaxHeight(), $_imagesconfig->getQuality(), true);
     }
     if ($_config->checkSizeAfterScaling()) {
         //check file size after scaling, attempt to delete if too big
         clearstatcache();
         if ($maxSize && filesize($sFilePath) > $maxSize) {
             @unlink($sFilePath);
             $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
         } else {
             $this->_errorHandler->throwError($iErrorNumber, true, false);
         }
     }
     CKFinder_Connector_core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath));
 }
예제 #4
0
파일: Init.php 프로젝트: denglitong/mvc
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     $_config =& CKFinder_Connector_core_Factory::getInstance("core_config");
     // Create the "ConnectorInfo" node.
     $_oConnInfo = new Ckfinder_Connector_Utils_XmlNode("ConnectorInfo");
     $this->_connectorNode->addChild($_oConnInfo);
     $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false");
     if (!$_config->getIsEnabled()) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     }
     $_ln = '';
     $_lc = $_config->getLicenseKey() . '                                  ';
     $pos = strpos(CKFINDER_CHARS, $_lc[0]) % 5;
     if ($pos == 1 || $pos == 4) {
         $_ln = $_config->getLicenseName();
     }
     $_oConnInfo->addAttribute("s", $_ln);
     $_oConnInfo->addAttribute("c", trim($_lc[11] . $_lc[0] . $_lc[8] . $_lc[12] . $_lc[26] . $_lc[2] . $_lc[3] . $_lc[25] . $_lc[1]));
     $_thumbnailsconfig = $_config->getThumbnailsconfig();
     $_thumbnailsEnabled = $_thumbnailsconfig->getIsEnabled();
     $_oConnInfo->addAttribute("thumbsEnabled", $_thumbnailsEnabled ? "true" : "false");
     if ($_thumbnailsEnabled) {
         $_oConnInfo->addAttribute("thumbsUrl", $_thumbnailsconfig->getUrl());
         $_oConnInfo->addAttribute("thumbsDirectAccess", $_thumbnailsconfig->getDirectAccess() ? "true" : "false");
         $_oConnInfo->addAttribute("thumbsWidth", $_thumbnailsconfig->getMaxWidth());
         $_oConnInfo->addAttribute("thumbsHeight", $_thumbnailsconfig->getMaxHeight());
     }
     $_imagesconfig = $_config->getImagesconfig();
     $_oConnInfo->addAttribute("imgWidth", $_imagesconfig->getMaxWidth());
     $_oConnInfo->addAttribute("imgHeight", $_imagesconfig->getMaxHeight());
     // Create the "ResourceTypes" node.
     $_oResourceTypes = new Ckfinder_Connector_Utils_XmlNode("ResourceTypes");
     $this->_connectorNode->addChild($_oResourceTypes);
     // Create the "PluginsInfo" node.
     $_oPluginsInfo = new Ckfinder_Connector_Utils_XmlNode("PluginsInfo");
     $this->_connectorNode->addChild($_oPluginsInfo);
     // Load the resource types in an array.
     $_aTypes = $_config->getDefaultResourceTypes();
     if (!sizeof($_aTypes)) {
         $_aTypes = $_config->getResourceTypeNames();
     }
     $_aTypesSize = sizeof($_aTypes);
     if ($_aTypesSize) {
         $phpMaxSize = 0;
         $max_upload = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('upload_max_filesize'));
         if ($max_upload) {
             $phpMaxSize = $max_upload;
         }
         $max_post = CKFinder_Connector_Utils_Misc::returnBytes(ini_get('post_max_size'));
         if ($max_post) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $max_post) : $max_post;
         }
         //ini_get('memory_limit') only works if compiled with "--enable-memory-limit"
         $memory_limit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'));
         if ($memory_limit && $memory_limit != -1) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memory_limit) : $memory_limit;
         }
         $_oConnInfo->addAttribute("uploadMaxSize", $phpMaxSize);
         $_oConnInfo->addAttribute("uploadCheckImages", $_config->checkSizeAfterScaling() ? "false" : "true");
         for ($i = 0; $i < $_aTypesSize; $i++) {
             $_resourceTypeName = $_aTypes[$i];
             $_acl = $_config->getAccessControlconfig();
             $_aclMask = $_acl->getComputedMask($_resourceTypeName, "/");
             if (($_aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) {
                 continue;
             }
             if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) {
                 //print $_resourceTypeName;
                 $_oTypeInfo = $_config->getResourceTypeconfig($_resourceTypeName);
                 //print_r($_oTypeInfo);
                 $_oResourceType[$i] = new Ckfinder_Connector_Utils_XmlNode("ResourceType");
                 $_oResourceTypes->addChild($_oResourceType[$i]);
                 $_oResourceType[$i]->addAttribute("name", $_resourceTypeName);
                 $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl());
                 $_oResourceType[$i]->addAttribute("allowedextensions", implode(",", $_oTypeInfo->getAllowedextensions()));
                 $_oResourceType[$i]->addAttribute("deniedextensions", implode(",", $_oTypeInfo->getDeniedextensions()));
                 $_oResourceType[$i]->addAttribute("hash", $_oTypeInfo->getHash());
                 $_oResourceType[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren('/', $_oTypeInfo) ? "true" : "false");
                 $_oResourceType[$i]->addAttribute("acl", $_aclMask);
                 $maxSize = $_oTypeInfo->getMaxSize();
                 if ($phpMaxSize) {
                     $maxSize = $maxSize ? min($maxSize, $phpMaxSize) : $phpMaxSize;
                 }
                 $_oResourceType[$i]->addAttribute("maxSize", $maxSize);
             }
         }
     }
     $config = $GLOBALS['config'];
     if (!empty($config['Plugins']) && is_array($config['Plugins'])) {
         $_oConnInfo->addAttribute("plugins", implode(",", $config['Plugins']));
     }
     CKFinder_Connector_core_Hooks::run('InitCommand', array(&$this->_connectorNode));
 }