@@ -32,50 +32,50 @@ |
||
32 | 32 | * @copyright CKSource - Frederico Knabben |
33 | 33 | */ |
34 | 34 | class CKFinder_Connector_ErrorHandler_FileUpload extends CKFinder_Connector_ErrorHandler_Base { |
35 | - /** |
|
36 | - * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
37 | - * |
|
38 | - * @param int $number |
|
39 | - * @param string $text |
|
40 | - * @access public |
|
41 | - */ |
|
42 | - public function throwError($number, $uploaded = false, $exit = true) { |
|
43 | - if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
44 | - return false; |
|
45 | - } |
|
35 | + /** |
|
36 | + * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
37 | + * |
|
38 | + * @param int $number |
|
39 | + * @param string $text |
|
40 | + * @access public |
|
41 | + */ |
|
42 | + public function throwError($number, $uploaded = false, $exit = true) { |
|
43 | + if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | - $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry"); |
|
48 | - $sFileName = $oRegistry->get("FileUpload_fileName"); |
|
49 | - $sFileUrl = $oRegistry->get("FileUpload_url"); |
|
47 | + $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry"); |
|
48 | + $sFileName = $oRegistry->get("FileUpload_fileName"); |
|
49 | + $sFileUrl = $oRegistry->get("FileUpload_url"); |
|
50 | 50 | |
51 | - header('Content-Type: text/html; charset=utf-8'); |
|
51 | + header('Content-Type: text/html; charset=utf-8'); |
|
52 | 52 | |
53 | - $errorMessage = CKFinder_Connector_Utils_Misc :: getErrorMessage($number, $sFileName); |
|
54 | - if (!$uploaded) { |
|
55 | - $sFileName = ""; |
|
56 | - } |
|
53 | + $errorMessage = CKFinder_Connector_Utils_Misc :: getErrorMessage($number, $sFileName); |
|
54 | + if (!$uploaded) { |
|
55 | + $sFileName = ""; |
|
56 | + } |
|
57 | 57 | |
58 | - echo "<script type=\"text/javascript\">"; |
|
58 | + echo "<script type=\"text/javascript\">"; |
|
59 | 59 | |
60 | - if (!empty($_GET['CKFinderFuncNum'])) { |
|
61 | - $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName); |
|
60 | + if (!empty($_GET['CKFinderFuncNum'])) { |
|
61 | + $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName); |
|
62 | 62 | |
63 | - if (!$uploaded) { |
|
64 | - $sFileUrl = ""; |
|
65 | - $sFileName = ""; |
|
66 | - } |
|
63 | + if (!$uploaded) { |
|
64 | + $sFileUrl = ""; |
|
65 | + $sFileName = ""; |
|
66 | + } |
|
67 | 67 | |
68 | - $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
|
69 | - echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
70 | - } |
|
71 | - else { |
|
72 | - echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
|
73 | - } |
|
68 | + $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
|
69 | + echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
70 | + } |
|
71 | + else { |
|
72 | + echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
|
73 | + } |
|
74 | 74 | |
75 | - echo "</script>"; |
|
75 | + echo "</script>"; |
|
76 | 76 | |
77 | - if ($exit) { |
|
78 | - exit; |
|
79 | - } |
|
80 | - } |
|
77 | + if ($exit) { |
|
78 | + exit; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * Throw file upload error, return true if error has been thrown, false if error has been catched |
36 | 36 | * |
37 | 37 | * @param int $number |
38 | - * @param string $text |
|
38 | + * @param string $exit |
|
39 | 39 | * @access public |
40 | 40 | */ |
41 | 41 | public function throwError($number, $uploaded = false, $exit = true) { |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base error handling class |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/ErrorHandler/Base.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * File upload error handler |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']); |
69 | - echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
|
69 | + echo "window.parent.CKFinder.tools.callFunction($funcNum, '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $errorMessage)."');"; |
|
70 | 70 | } |
71 | 71 | else { |
72 | - echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;"; |
|
72 | + echo "window.parent.OnUploadCompleted('".str_replace("'", "\\'", $sFileName)."', '".str_replace("'", "\\'", $errorMessage)."') ;"; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | echo "</script>"; |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -66,8 +68,7 @@ discard block |
||
66 | 68 | |
67 | 69 | $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']); |
68 | 70 | echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');"; |
69 | - } |
|
70 | - else { |
|
71 | + } else { |
|
71 | 72 | if (!$uploaded) { |
72 | 73 | echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;"; |
73 | 74 | } else { |
@@ -32,42 +32,42 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_ErrorHandler_Http extends CKFinder_Connector_ErrorHandler_Base |
34 | 34 | { |
35 | - /** |
|
36 | - * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
37 | - * |
|
38 | - * @param int $number |
|
39 | - * @param string $text |
|
40 | - * @access public |
|
41 | - */ |
|
42 | - public function throwError($number, $text = false, $exit = true) |
|
43 | - { |
|
44 | - if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
45 | - return false; |
|
46 | - } |
|
35 | + /** |
|
36 | + * Throw file upload error, return true if error has been thrown, false if error has been catched |
|
37 | + * |
|
38 | + * @param int $number |
|
39 | + * @param string $text |
|
40 | + * @access public |
|
41 | + */ |
|
42 | + public function throwError($number, $text = false, $exit = true) |
|
43 | + { |
|
44 | + if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | |
48 | - switch ($number) |
|
49 | - { |
|
50 | - case CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST: |
|
51 | - case CKFINDER_CONNECTOR_ERROR_INVALID_NAME: |
|
52 | - case CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED: |
|
53 | - case CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED: |
|
54 | - header("HTTP/1.0 403 Forbidden"); |
|
55 | - header("X-CKFinder-Error: ". $number); |
|
56 | - break; |
|
48 | + switch ($number) |
|
49 | + { |
|
50 | + case CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST: |
|
51 | + case CKFINDER_CONNECTOR_ERROR_INVALID_NAME: |
|
52 | + case CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED: |
|
53 | + case CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED: |
|
54 | + header("HTTP/1.0 403 Forbidden"); |
|
55 | + header("X-CKFinder-Error: ". $number); |
|
56 | + break; |
|
57 | 57 | |
58 | - case CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED: |
|
59 | - header("HTTP/1.0 500 Internal Server Error"); |
|
60 | - header("X-CKFinder-Error: ".$number); |
|
61 | - break; |
|
58 | + case CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED: |
|
59 | + header("HTTP/1.0 500 Internal Server Error"); |
|
60 | + header("X-CKFinder-Error: ".$number); |
|
61 | + break; |
|
62 | 62 | |
63 | - default: |
|
64 | - header("HTTP/1.0 404 Not Found"); |
|
65 | - header("X-CKFinder-Error: ". $number); |
|
66 | - break; |
|
67 | - } |
|
63 | + default: |
|
64 | + header("HTTP/1.0 404 Not Found"); |
|
65 | + header("X-CKFinder-Error: ". $number); |
|
66 | + break; |
|
67 | + } |
|
68 | 68 | |
69 | - if ($exit) { |
|
70 | - exit; |
|
71 | - } |
|
72 | - } |
|
69 | + if ($exit) { |
|
70 | + exit; |
|
71 | + } |
|
72 | + } |
|
73 | 73 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base error handling class |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/ErrorHandler/Base.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * HTTP error handler |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | case CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED: |
53 | 53 | case CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED: |
54 | 54 | header("HTTP/1.0 403 Forbidden"); |
55 | - header("X-CKFinder-Error: ". $number); |
|
55 | + header("X-CKFinder-Error: ".$number); |
|
56 | 56 | break; |
57 | 57 | |
58 | 58 | case CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED: |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | default: |
64 | 64 | header("HTTP/1.0 404 Not Found"); |
65 | - header("X-CKFinder-Error: ". $number); |
|
65 | + header("X-CKFinder-Error: ".$number); |
|
66 | 66 | break; |
67 | 67 | } |
68 | 68 |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -27,60 +27,60 @@ |
||
27 | 27 | */ |
28 | 28 | class CKFinder_Connector_ErrorHandler_Base |
29 | 29 | { |
30 | - /** |
|
31 | - * Try/catch emulation, if set to true, error handler will not throw any error |
|
32 | - * |
|
33 | - * @var boolean |
|
34 | - * @access protected |
|
35 | - */ |
|
36 | - protected $_catchAllErrors = false; |
|
37 | - /** |
|
38 | - * Array with error numbers that should be ignored |
|
39 | - * |
|
40 | - * @var array[]int |
|
41 | - * @access protected |
|
42 | - */ |
|
43 | - protected $_skipErrorsArray = array(); |
|
30 | + /** |
|
31 | + * Try/catch emulation, if set to true, error handler will not throw any error |
|
32 | + * |
|
33 | + * @var boolean |
|
34 | + * @access protected |
|
35 | + */ |
|
36 | + protected $_catchAllErrors = false; |
|
37 | + /** |
|
38 | + * Array with error numbers that should be ignored |
|
39 | + * |
|
40 | + * @var array[]int |
|
41 | + * @access protected |
|
42 | + */ |
|
43 | + protected $_skipErrorsArray = array(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Set whether all errors should be ignored |
|
47 | - * |
|
48 | - * @param boolean $newValue |
|
49 | - * @access public |
|
50 | - */ |
|
51 | - public function setCatchAllErros($newValue) |
|
52 | - { |
|
53 | - $this->_catchAllErrors = $newValue ? true : false; |
|
54 | - } |
|
45 | + /** |
|
46 | + * Set whether all errors should be ignored |
|
47 | + * |
|
48 | + * @param boolean $newValue |
|
49 | + * @access public |
|
50 | + */ |
|
51 | + public function setCatchAllErros($newValue) |
|
52 | + { |
|
53 | + $this->_catchAllErrors = $newValue ? true : false; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Set which errors should be ignored |
|
58 | - * |
|
59 | - * @param array $newArray |
|
60 | - */ |
|
61 | - public function setSkipErrorsArray($newArray) |
|
62 | - { |
|
63 | - if (is_array($newArray)) { |
|
64 | - $this->_skipErrorsArray = $newArray; |
|
65 | - } |
|
66 | - } |
|
56 | + /** |
|
57 | + * Set which errors should be ignored |
|
58 | + * |
|
59 | + * @param array $newArray |
|
60 | + */ |
|
61 | + public function setSkipErrorsArray($newArray) |
|
62 | + { |
|
63 | + if (is_array($newArray)) { |
|
64 | + $this->_skipErrorsArray = $newArray; |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Throw connector error, return true if error has been thrown, false if error has been catched |
|
70 | - * |
|
71 | - * @param int $number |
|
72 | - * @param string $text |
|
73 | - * @access public |
|
74 | - */ |
|
75 | - public function throwError($number, $text = false) |
|
76 | - { |
|
77 | - if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
78 | - return false; |
|
79 | - } |
|
68 | + /** |
|
69 | + * Throw connector error, return true if error has been thrown, false if error has been catched |
|
70 | + * |
|
71 | + * @param int $number |
|
72 | + * @param string $text |
|
73 | + * @access public |
|
74 | + */ |
|
75 | + public function throwError($number, $text = false) |
|
76 | + { |
|
77 | + if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) { |
|
78 | + return false; |
|
79 | + } |
|
80 | 80 | |
81 | - $_xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
82 | - $_xml->raiseError($number,$text); |
|
81 | + $_xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
82 | + $_xml->raiseError($number,$text); |
|
83 | 83 | |
84 | - exit; |
|
85 | - } |
|
84 | + exit; |
|
85 | + } |
|
86 | 86 | } |
@@ -78,8 +78,8 @@ |
||
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | |
81 | - $_xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
82 | - $_xml->raiseError($number,$text); |
|
81 | + $_xml = & CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
82 | + $_xml->raiseError($number, $text); |
|
83 | 83 | |
84 | 84 | exit; |
85 | 85 | } |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -32,224 +32,224 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_CopyFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - var $command = "CopyFiles"; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
54 | - |
|
55 | - $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | - $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | - $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | - $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | - $aclMasks = array(); |
|
61 | - $_resourceTypeConfig = array(); |
|
62 | - |
|
63 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | - } |
|
66 | - |
|
67 | - // Create the "Errors" node. |
|
68 | - $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | - $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | - $copied = 0; |
|
71 | - $copiedAll = 0; |
|
72 | - if (!empty($_POST['copied'])) { |
|
73 | - $copiedAll = intval($_POST['copied']); |
|
74 | - } |
|
75 | - $checkedPaths = array(); |
|
76 | - |
|
77 | - $oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles"); |
|
78 | - |
|
79 | - if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | - foreach ($_POST['files'] as $index => $arr) { |
|
81 | - if (empty($arr['name'])) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | - } |
|
87 | - |
|
88 | - // file name |
|
89 | - $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | - // resource type |
|
91 | - $type = $arr['type']; |
|
92 | - // client path |
|
93 | - $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | - // options |
|
95 | - $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
96 | - |
|
97 | - $destinationFilePath = $sServerDir.$name; |
|
98 | - |
|
99 | - // check #1 (path) |
|
100 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | - } |
|
103 | - |
|
104 | - // get resource type config for current file |
|
105 | - if (!isset($_resourceTypeConfig[$type])) { |
|
106 | - $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | - } |
|
108 | - |
|
109 | - // check #2 (resource type) |
|
110 | - if (is_null($_resourceTypeConfig[$type])) { |
|
111 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | - } |
|
113 | - |
|
114 | - // check #3 (extension) |
|
115 | - if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | - continue; |
|
119 | - } |
|
120 | - |
|
121 | - // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | - if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | - continue; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // check #5 (hidden folders) |
|
131 | - // cache results |
|
132 | - if (empty($checkedPaths[$path])) { |
|
133 | - $checkedPaths[$path] = true; |
|
134 | - |
|
135 | - if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
141 | - |
|
142 | - // check #6 (hidden file name) |
|
143 | - if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | - } |
|
146 | - |
|
147 | - // check #7 (Access Control, need file view permission to source files) |
|
148 | - if (!isset($aclMasks[$type."@".$path])) { |
|
149 | - $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | - } |
|
151 | - |
|
152 | - $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | - if (!$isAuthorized) { |
|
154 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | - } |
|
156 | - |
|
157 | - // check #8 (invalid file name) |
|
158 | - if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | - $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | - continue; |
|
162 | - } |
|
163 | - |
|
164 | - // check #9 (max size) |
|
165 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | - $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | - $fileSize = filesize($sourceFilePath); |
|
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
169 | - $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | - continue; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - //$overwrite |
|
176 | - // finally, no errors so far, we may attempt to copy a file |
|
177 | - // protection against copying files to itself |
|
178 | - if ($sourceFilePath == $destinationFilePath) { |
|
179 | - $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | - continue; |
|
182 | - } |
|
183 | - // check if file exists if we don't force overwriting |
|
184 | - else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) { |
|
185 | - if (strpos($options, "autorename") !== false) { |
|
186 | - $iCounter = 1; |
|
187 | - while (true) |
|
188 | - { |
|
189 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
190 | - "(" . $iCounter . ")" . "." . |
|
191 | - CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
192 | - |
|
193 | - $destinationFilePath = $sServerDir.$fileName; |
|
194 | - if (!file_exists($destinationFilePath)) { |
|
195 | - break; |
|
196 | - } |
|
197 | - else { |
|
198 | - $iCounter++; |
|
199 | - } |
|
200 | - } |
|
201 | - if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
202 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
203 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
204 | - continue; |
|
205 | - } |
|
206 | - else { |
|
207 | - $copied++; |
|
208 | - } |
|
209 | - } |
|
210 | - else { |
|
211 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
212 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
213 | - continue; |
|
214 | - } |
|
215 | - } |
|
216 | - // copy() overwrites without warning |
|
217 | - else { |
|
218 | - if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
219 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | - continue; |
|
222 | - } |
|
223 | - else { |
|
224 | - $copied++; |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - $this->_connectorNode->addChild($oCopyFilesNode); |
|
231 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
232 | - $this->_connectorNode->addChild($oErrorsNode); |
|
233 | - } |
|
234 | - $oCopyFilesNode->addAttribute("copied", $copied); |
|
235 | - $oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied); |
|
236 | - |
|
237 | - /** |
|
238 | - * Note: actually we could have more than one error. |
|
239 | - * This is just a flag for CKFinder interface telling it to check all errors. |
|
240 | - */ |
|
241 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
242 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED); |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - function appendErrorNode(&$oErrorsNode, $errorCode, $name, $type, $path) |
|
247 | - { |
|
248 | - $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
249 | - $oErrorNode->addAttribute("code", $errorCode); |
|
250 | - $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
251 | - $oErrorNode->addAttribute("type", $type); |
|
252 | - $oErrorNode->addAttribute("folder", $path); |
|
253 | - $oErrorsNode->addChild($oErrorNode); |
|
254 | - } |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + var $command = "CopyFiles"; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | + |
|
55 | + $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | + $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | + $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | + $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | + $aclMasks = array(); |
|
61 | + $_resourceTypeConfig = array(); |
|
62 | + |
|
63 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | + } |
|
66 | + |
|
67 | + // Create the "Errors" node. |
|
68 | + $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | + $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | + $copied = 0; |
|
71 | + $copiedAll = 0; |
|
72 | + if (!empty($_POST['copied'])) { |
|
73 | + $copiedAll = intval($_POST['copied']); |
|
74 | + } |
|
75 | + $checkedPaths = array(); |
|
76 | + |
|
77 | + $oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles"); |
|
78 | + |
|
79 | + if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | + foreach ($_POST['files'] as $index => $arr) { |
|
81 | + if (empty($arr['name'])) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | + } |
|
87 | + |
|
88 | + // file name |
|
89 | + $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | + // resource type |
|
91 | + $type = $arr['type']; |
|
92 | + // client path |
|
93 | + $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | + // options |
|
95 | + $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
96 | + |
|
97 | + $destinationFilePath = $sServerDir.$name; |
|
98 | + |
|
99 | + // check #1 (path) |
|
100 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | + } |
|
103 | + |
|
104 | + // get resource type config for current file |
|
105 | + if (!isset($_resourceTypeConfig[$type])) { |
|
106 | + $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | + } |
|
108 | + |
|
109 | + // check #2 (resource type) |
|
110 | + if (is_null($_resourceTypeConfig[$type])) { |
|
111 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | + } |
|
113 | + |
|
114 | + // check #3 (extension) |
|
115 | + if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | + continue; |
|
119 | + } |
|
120 | + |
|
121 | + // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | + if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | + continue; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // check #5 (hidden folders) |
|
131 | + // cache results |
|
132 | + if (empty($checkedPaths[$path])) { |
|
133 | + $checkedPaths[$path] = true; |
|
134 | + |
|
135 | + if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
141 | + |
|
142 | + // check #6 (hidden file name) |
|
143 | + if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | + } |
|
146 | + |
|
147 | + // check #7 (Access Control, need file view permission to source files) |
|
148 | + if (!isset($aclMasks[$type."@".$path])) { |
|
149 | + $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | + } |
|
151 | + |
|
152 | + $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | + if (!$isAuthorized) { |
|
154 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | + } |
|
156 | + |
|
157 | + // check #8 (invalid file name) |
|
158 | + if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | + $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | + continue; |
|
162 | + } |
|
163 | + |
|
164 | + // check #9 (max size) |
|
165 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | + $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | + $fileSize = filesize($sourceFilePath); |
|
168 | + if ($maxSize && $fileSize>$maxSize) { |
|
169 | + $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | + continue; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + //$overwrite |
|
176 | + // finally, no errors so far, we may attempt to copy a file |
|
177 | + // protection against copying files to itself |
|
178 | + if ($sourceFilePath == $destinationFilePath) { |
|
179 | + $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | + continue; |
|
182 | + } |
|
183 | + // check if file exists if we don't force overwriting |
|
184 | + else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) { |
|
185 | + if (strpos($options, "autorename") !== false) { |
|
186 | + $iCounter = 1; |
|
187 | + while (true) |
|
188 | + { |
|
189 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
190 | + "(" . $iCounter . ")" . "." . |
|
191 | + CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
192 | + |
|
193 | + $destinationFilePath = $sServerDir.$fileName; |
|
194 | + if (!file_exists($destinationFilePath)) { |
|
195 | + break; |
|
196 | + } |
|
197 | + else { |
|
198 | + $iCounter++; |
|
199 | + } |
|
200 | + } |
|
201 | + if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
202 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
203 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
204 | + continue; |
|
205 | + } |
|
206 | + else { |
|
207 | + $copied++; |
|
208 | + } |
|
209 | + } |
|
210 | + else { |
|
211 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
212 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
213 | + continue; |
|
214 | + } |
|
215 | + } |
|
216 | + // copy() overwrites without warning |
|
217 | + else { |
|
218 | + if (!@copy($sourceFilePath, $destinationFilePath)) { |
|
219 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | + continue; |
|
222 | + } |
|
223 | + else { |
|
224 | + $copied++; |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + $this->_connectorNode->addChild($oCopyFilesNode); |
|
231 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
232 | + $this->_connectorNode->addChild($oErrorsNode); |
|
233 | + } |
|
234 | + $oCopyFilesNode->addAttribute("copied", $copied); |
|
235 | + $oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied); |
|
236 | + |
|
237 | + /** |
|
238 | + * Note: actually we could have more than one error. |
|
239 | + * This is just a flag for CKFinder interface telling it to check all errors. |
|
240 | + */ |
|
241 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
242 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED); |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + function appendErrorNode(&$oErrorsNode, $errorCode, $name, $type, $path) |
|
247 | + { |
|
248 | + $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
249 | + $oErrorNode->addAttribute("code", $errorCode); |
|
250 | + $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
251 | + $oErrorNode->addAttribute("type", $type); |
|
252 | + $oErrorNode->addAttribute("folder", $path); |
|
253 | + $oErrorsNode->addChild($oErrorNode); |
|
254 | + } |
|
255 | 255 | } |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -193,8 +195,7 @@ discard block |
||
193 | 195 | $destinationFilePath = $sServerDir.$fileName; |
194 | 196 | if (!file_exists($destinationFilePath)) { |
195 | 197 | break; |
196 | - } |
|
197 | - else { |
|
198 | + } else { |
|
198 | 199 | $iCounter++; |
199 | 200 | } |
200 | 201 | } |
@@ -202,12 +203,10 @@ discard block |
||
202 | 203 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
203 | 204 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
204 | 205 | continue; |
205 | - } |
|
206 | - else { |
|
206 | + } else { |
|
207 | 207 | $copied++; |
208 | 208 | } |
209 | - } |
|
210 | - else { |
|
209 | + } else { |
|
211 | 210 | $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
212 | 211 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
213 | 212 | continue; |
@@ -219,8 +218,7 @@ discard block |
||
219 | 218 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
220 | 219 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
221 | 220 | continue; |
222 | - } |
|
223 | - else { |
|
221 | + } else { |
|
224 | 222 | $copied++; |
225 | 223 | } |
226 | 224 | } |
@@ -259,6 +259,10 @@ |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | + /** |
|
263 | + * @param integer $errorCode |
|
264 | + * @param string $path |
|
265 | + */ |
|
262 | 266 | private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
263 | 267 | { |
264 | 268 | $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base XML command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle MoveFiles command |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $clientPath = $this->_currentFolder->getClientPath(); |
56 | 56 | $sServerDir = $this->_currentFolder->getServerPath(); |
57 | 57 | $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
58 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | 59 | $_aclConfig = $_config->getAccessControlConfig(); |
60 | 60 | $aclMasks = array(); |
61 | 61 | $_resourceTypeConfig = array(); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | if ($currentResourceTypeConfig->getName() != $type) { |
166 | 166 | $maxSize = $currentResourceTypeConfig->getMaxSize(); |
167 | 167 | $fileSize = filesize($sourceFilePath); |
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
168 | + if ($maxSize && $fileSize > $maxSize) { |
|
169 | 169 | $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
170 | 170 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
171 | 171 | continue; |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $iCounter = 1; |
204 | 204 | while (true) |
205 | 205 | { |
206 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | - "(" . $iCounter . ")" . "." . |
|
206 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name). |
|
207 | + "(".$iCounter.")".".". |
|
208 | 208 | CKFinder_Connector_Utils_FileSystem::getExtension($name); |
209 | 209 | |
210 | 210 | $destinationFilePath = $sServerDir.$fileName; |
@@ -32,44 +32,44 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_DeleteFolder extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - var $command = "DeleteFolder"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + var $command = "DeleteFolder"; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | 54 | |
55 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_DELETE)) { |
|
56 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | - } |
|
55 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_DELETE)) { |
|
56 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | + } |
|
58 | 58 | |
59 | - // The root folder cannot be deleted. |
|
60 | - if ($this->_currentFolder->getClientPath() == "/") { |
|
61 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
62 | - } |
|
59 | + // The root folder cannot be deleted. |
|
60 | + if ($this->_currentFolder->getClientPath() == "/") { |
|
61 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
62 | + } |
|
63 | 63 | |
64 | - $folderServerPath = $this->_currentFolder->getServerPath(); |
|
65 | - if (!file_exists($folderServerPath) || !is_dir($folderServerPath)) { |
|
66 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
67 | - } |
|
64 | + $folderServerPath = $this->_currentFolder->getServerPath(); |
|
65 | + if (!file_exists($folderServerPath) || !is_dir($folderServerPath)) { |
|
66 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
67 | + } |
|
68 | 68 | |
69 | - if (!CKFinder_Connector_Utils_FileSystem::unlink($folderServerPath)) { |
|
70 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
71 | - } |
|
69 | + if (!CKFinder_Connector_Utils_FileSystem::unlink($folderServerPath)) { |
|
70 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
71 | + } |
|
72 | 72 | |
73 | - CKFinder_Connector_Utils_FileSystem::unlink($this->_currentFolder->getThumbsServerPath()); |
|
74 | - } |
|
73 | + CKFinder_Connector_Utils_FileSystem::unlink($this->_currentFolder->getThumbsServerPath()); |
|
74 | + } |
|
75 | 75 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | /** |
22 | 22 | * Include base XML command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle DeleteFile command |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -32,74 +32,74 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_GetFolders extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - var $command = "GetFolders"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + var $command = "GetFolders"; |
|
42 | 42 | |
43 | - /** |
|
44 | - * handle request and build XML |
|
45 | - * @access protected |
|
46 | - * |
|
47 | - */ |
|
48 | - function buildXml() |
|
49 | - { |
|
50 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
51 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_VIEW)) { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
53 | - } |
|
43 | + /** |
|
44 | + * handle request and build XML |
|
45 | + * @access protected |
|
46 | + * |
|
47 | + */ |
|
48 | + function buildXml() |
|
49 | + { |
|
50 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
51 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_VIEW)) { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
53 | + } |
|
54 | 54 | |
55 | - // Map the virtual path to the local server path. |
|
56 | - $_sServerDir = $this->_currentFolder->getServerPath(); |
|
55 | + // Map the virtual path to the local server path. |
|
56 | + $_sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | 57 | |
58 | - if (!is_dir($_sServerDir)) { |
|
59 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
60 | - } |
|
58 | + if (!is_dir($_sServerDir)) { |
|
59 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
60 | + } |
|
61 | 61 | |
62 | - // Create the "Folders" node. |
|
63 | - $oFoldersNode = new Ckfinder_Connector_Utils_XmlNode("Folders"); |
|
64 | - $this->_connectorNode->addChild($oFoldersNode); |
|
62 | + // Create the "Folders" node. |
|
63 | + $oFoldersNode = new Ckfinder_Connector_Utils_XmlNode("Folders"); |
|
64 | + $this->_connectorNode->addChild($oFoldersNode); |
|
65 | 65 | |
66 | - $files = array(); |
|
67 | - if ($dh = @opendir($_sServerDir)) { |
|
68 | - while (($file = readdir($dh)) !== false) { |
|
69 | - if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) { |
|
70 | - $files[] = $file; |
|
71 | - } |
|
72 | - } |
|
73 | - closedir($dh); |
|
74 | - } else { |
|
75 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
76 | - } |
|
66 | + $files = array(); |
|
67 | + if ($dh = @opendir($_sServerDir)) { |
|
68 | + while (($file = readdir($dh)) !== false) { |
|
69 | + if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) { |
|
70 | + $files[] = $file; |
|
71 | + } |
|
72 | + } |
|
73 | + closedir($dh); |
|
74 | + } else { |
|
75 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
76 | + } |
|
77 | 77 | |
78 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
78 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
79 | 79 | |
80 | - if (sizeof($files)>0) { |
|
81 | - natcasesort($files); |
|
82 | - $i=0; |
|
83 | - foreach ($files as $file) { |
|
84 | - $oAcl = $_config->getAccessControlConfig(); |
|
85 | - $aclMask = $oAcl->getComputedMask($this->_currentFolder->getResourceTypeName(), $this->_currentFolder->getClientPath() . $file . "/"); |
|
80 | + if (sizeof($files)>0) { |
|
81 | + natcasesort($files); |
|
82 | + $i=0; |
|
83 | + foreach ($files as $file) { |
|
84 | + $oAcl = $_config->getAccessControlConfig(); |
|
85 | + $aclMask = $oAcl->getComputedMask($this->_currentFolder->getResourceTypeName(), $this->_currentFolder->getClientPath() . $file . "/"); |
|
86 | 86 | |
87 | - if (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) { |
|
88 | - continue; |
|
89 | - } |
|
90 | - if ($resourceTypeInfo->checkIsHiddenFolder($file)) { |
|
91 | - continue; |
|
92 | - } |
|
87 | + if (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) { |
|
88 | + continue; |
|
89 | + } |
|
90 | + if ($resourceTypeInfo->checkIsHiddenFolder($file)) { |
|
91 | + continue; |
|
92 | + } |
|
93 | 93 | |
94 | - // Create the "Folder" node. |
|
95 | - $oFolderNode[$i] = new Ckfinder_Connector_Utils_XmlNode("Folder"); |
|
96 | - $oFoldersNode->addChild($oFolderNode[$i]); |
|
97 | - $oFolderNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($file)); |
|
98 | - $oFolderNode[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_sServerDir . $file) ? "true" : "false"); |
|
99 | - $oFolderNode[$i]->addAttribute("acl", $aclMask); |
|
94 | + // Create the "Folder" node. |
|
95 | + $oFolderNode[$i] = new Ckfinder_Connector_Utils_XmlNode("Folder"); |
|
96 | + $oFoldersNode->addChild($oFolderNode[$i]); |
|
97 | + $oFolderNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($file)); |
|
98 | + $oFolderNode[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_sServerDir . $file) ? "true" : "false"); |
|
99 | + $oFolderNode[$i]->addAttribute("acl", $aclMask); |
|
100 | 100 | |
101 | - $i++; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
101 | + $i++; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | 105 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base XML command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle GetFolders command |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function buildXml() |
49 | 49 | { |
50 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
50 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
51 | 51 | if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_VIEW)) { |
52 | 52 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
53 | 53 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $files = array(); |
67 | 67 | if ($dh = @opendir($_sServerDir)) { |
68 | 68 | while (($file = readdir($dh)) !== false) { |
69 | - if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) { |
|
69 | + if ($file != "." && $file != ".." && is_dir($_sServerDir.$file)) { |
|
70 | 70 | $files[] = $file; |
71 | 71 | } |
72 | 72 | } |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | |
78 | 78 | $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
79 | 79 | |
80 | - if (sizeof($files)>0) { |
|
80 | + if (sizeof($files) > 0) { |
|
81 | 81 | natcasesort($files); |
82 | - $i=0; |
|
82 | + $i = 0; |
|
83 | 83 | foreach ($files as $file) { |
84 | 84 | $oAcl = $_config->getAccessControlConfig(); |
85 | - $aclMask = $oAcl->getComputedMask($this->_currentFolder->getResourceTypeName(), $this->_currentFolder->getClientPath() . $file . "/"); |
|
85 | + $aclMask = $oAcl->getComputedMask($this->_currentFolder->getResourceTypeName(), $this->_currentFolder->getClientPath().$file."/"); |
|
86 | 86 | |
87 | 87 | if (($aclMask & CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) != CKFINDER_CONNECTOR_ACL_FOLDER_VIEW) { |
88 | 88 | continue; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $oFolderNode[$i] = new Ckfinder_Connector_Utils_XmlNode("Folder"); |
96 | 96 | $oFoldersNode->addChild($oFolderNode[$i]); |
97 | 97 | $oFolderNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($file)); |
98 | - $oFolderNode[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_sServerDir . $file) ? "true" : "false"); |
|
98 | + $oFolderNode[$i]->addAttribute("hasChildren", CKFinder_Connector_Utils_FileSystem::hasChildren($_sServerDir.$file) ? "true" : "false"); |
|
99 | 99 | $oFolderNode[$i]->addAttribute("acl", $aclMask); |
100 | 100 | |
101 | 101 | $i++; |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -38,85 +38,85 @@ |
||
38 | 38 | */ |
39 | 39 | class CKFinder_Connector_CommandHandler_XmlCommandHandlerBase extends CKFinder_Connector_CommandHandler_CommandHandlerBase |
40 | 40 | { |
41 | - /** |
|
42 | - * Connector node - Ckfinder_Connector_Utils_XmlNode object |
|
43 | - * |
|
44 | - * @var Ckfinder_Connector_Utils_XmlNode |
|
45 | - * @access protected |
|
46 | - */ |
|
47 | - var $_connectorNode; |
|
48 | - |
|
49 | - /** |
|
50 | - * send response |
|
51 | - * @access public |
|
52 | - * |
|
53 | - */ |
|
54 | - function sendResponse() |
|
55 | - { |
|
56 | - $xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
57 | - $this->_connectorNode =& $xml->getConnectorNode(); |
|
58 | - |
|
59 | - $this->checkConnector(); |
|
60 | - if ($this->mustCheckRequest()) { |
|
61 | - $this->checkRequest(); |
|
62 | - } |
|
63 | - |
|
64 | - $resourceTypeName = $this->_currentFolder->getResourceTypeName(); |
|
65 | - if (!empty($resourceTypeName)) { |
|
66 | - $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName()); |
|
67 | - } |
|
68 | - |
|
69 | - if ($this->mustAddCurrentFolderNode()) { |
|
70 | - $_currentFolder = new Ckfinder_Connector_Utils_XmlNode("CurrentFolder"); |
|
71 | - $this->_connectorNode->addChild($_currentFolder); |
|
72 | - $_currentFolder->addAttribute("path", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath())); |
|
73 | - |
|
74 | - $this->_errorHandler->setCatchAllErros(true); |
|
75 | - $_url = $this->_currentFolder->getUrl(); |
|
76 | - $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($_url)); |
|
77 | - $this->_errorHandler->setCatchAllErros(false); |
|
78 | - |
|
79 | - $_currentFolder->addAttribute("acl", $this->_currentFolder->getAclMask()); |
|
80 | - } |
|
81 | - |
|
82 | - $this->buildXml(); |
|
83 | - |
|
84 | - $_oErrorNode =& $xml->getErrorNode(); |
|
85 | - $_oErrorNode->addAttribute("number", "0"); |
|
86 | - |
|
87 | - echo $this->_connectorNode->asXML(); |
|
88 | - exit; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Must check request? |
|
93 | - * |
|
94 | - * @return boolean |
|
95 | - * @access protected |
|
96 | - */ |
|
97 | - function mustCheckRequest() |
|
98 | - { |
|
99 | - return true; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Must add CurrentFolder node? |
|
104 | - * |
|
105 | - * @return boolean |
|
106 | - * @access protected |
|
107 | - */ |
|
108 | - function mustAddCurrentFolderNode() |
|
109 | - { |
|
110 | - return true; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @access protected |
|
115 | - * @abstract |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - function buildXml() |
|
119 | - { |
|
120 | - |
|
121 | - } |
|
41 | + /** |
|
42 | + * Connector node - Ckfinder_Connector_Utils_XmlNode object |
|
43 | + * |
|
44 | + * @var Ckfinder_Connector_Utils_XmlNode |
|
45 | + * @access protected |
|
46 | + */ |
|
47 | + var $_connectorNode; |
|
48 | + |
|
49 | + /** |
|
50 | + * send response |
|
51 | + * @access public |
|
52 | + * |
|
53 | + */ |
|
54 | + function sendResponse() |
|
55 | + { |
|
56 | + $xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
57 | + $this->_connectorNode =& $xml->getConnectorNode(); |
|
58 | + |
|
59 | + $this->checkConnector(); |
|
60 | + if ($this->mustCheckRequest()) { |
|
61 | + $this->checkRequest(); |
|
62 | + } |
|
63 | + |
|
64 | + $resourceTypeName = $this->_currentFolder->getResourceTypeName(); |
|
65 | + if (!empty($resourceTypeName)) { |
|
66 | + $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName()); |
|
67 | + } |
|
68 | + |
|
69 | + if ($this->mustAddCurrentFolderNode()) { |
|
70 | + $_currentFolder = new Ckfinder_Connector_Utils_XmlNode("CurrentFolder"); |
|
71 | + $this->_connectorNode->addChild($_currentFolder); |
|
72 | + $_currentFolder->addAttribute("path", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath())); |
|
73 | + |
|
74 | + $this->_errorHandler->setCatchAllErros(true); |
|
75 | + $_url = $this->_currentFolder->getUrl(); |
|
76 | + $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($_url)); |
|
77 | + $this->_errorHandler->setCatchAllErros(false); |
|
78 | + |
|
79 | + $_currentFolder->addAttribute("acl", $this->_currentFolder->getAclMask()); |
|
80 | + } |
|
81 | + |
|
82 | + $this->buildXml(); |
|
83 | + |
|
84 | + $_oErrorNode =& $xml->getErrorNode(); |
|
85 | + $_oErrorNode->addAttribute("number", "0"); |
|
86 | + |
|
87 | + echo $this->_connectorNode->asXML(); |
|
88 | + exit; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Must check request? |
|
93 | + * |
|
94 | + * @return boolean |
|
95 | + * @access protected |
|
96 | + */ |
|
97 | + function mustCheckRequest() |
|
98 | + { |
|
99 | + return true; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Must add CurrentFolder node? |
|
104 | + * |
|
105 | + * @return boolean |
|
106 | + * @access protected |
|
107 | + */ |
|
108 | + function mustAddCurrentFolderNode() |
|
109 | + { |
|
110 | + return true; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @access protected |
|
115 | + * @abstract |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + function buildXml() |
|
119 | + { |
|
120 | + |
|
121 | + } |
|
122 | 122 | } |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/CommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/CommandHandlerBase.php"; |
|
25 | 25 | /** |
26 | 26 | * Include xml utils |
27 | 27 | */ |
28 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/Xml.php"; |
|
28 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/Core/Xml.php"; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Base XML commands handler |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | */ |
54 | 54 | function sendResponse() |
55 | 55 | { |
56 | - $xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
57 | - $this->_connectorNode =& $xml->getConnectorNode(); |
|
56 | + $xml = & CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
57 | + $this->_connectorNode = & $xml->getConnectorNode(); |
|
58 | 58 | |
59 | 59 | $this->checkConnector(); |
60 | 60 | if ($this->mustCheckRequest()) { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | $this->buildXml(); |
83 | 83 | |
84 | - $_oErrorNode =& $xml->getErrorNode(); |
|
84 | + $_oErrorNode = & $xml->getErrorNode(); |
|
85 | 85 | $_oErrorNode->addAttribute("number", "0"); |
86 | 86 | |
87 | 87 | echo $this->_connectorNode->asXML(); |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -32,240 +32,240 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_MoveFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - var $command = "MoveFiles"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + var $command = "MoveFiles"; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | 54 | |
55 | - $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | - $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | - $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | - $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | - $aclMasks = array(); |
|
61 | - $_resourceTypeConfig = array(); |
|
55 | + $clientPath = $this->_currentFolder->getClientPath(); |
|
56 | + $sServerDir = $this->_currentFolder->getServerPath(); |
|
57 | + $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
58 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | + $_aclConfig = $_config->getAccessControlConfig(); |
|
60 | + $aclMasks = array(); |
|
61 | + $_resourceTypeConfig = array(); |
|
62 | 62 | |
63 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | - } |
|
63 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
64 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
65 | + } |
|
66 | 66 | |
67 | - // Create the "Errors" node. |
|
68 | - $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | - $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | - $moved = 0; |
|
71 | - $movedAll = 0; |
|
72 | - if (!empty($_POST['moved'])) { |
|
73 | - $movedAll = intval($_POST['moved']); |
|
74 | - } |
|
75 | - $checkedPaths = array(); |
|
67 | + // Create the "Errors" node. |
|
68 | + $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors"); |
|
69 | + $errorCode = CKFINDER_CONNECTOR_ERROR_NONE; |
|
70 | + $moved = 0; |
|
71 | + $movedAll = 0; |
|
72 | + if (!empty($_POST['moved'])) { |
|
73 | + $movedAll = intval($_POST['moved']); |
|
74 | + } |
|
75 | + $checkedPaths = array(); |
|
76 | 76 | |
77 | - $oMoveFilesNode = new Ckfinder_Connector_Utils_XmlNode("MoveFiles"); |
|
77 | + $oMoveFilesNode = new Ckfinder_Connector_Utils_XmlNode("MoveFiles"); |
|
78 | 78 | |
79 | - if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | - foreach ($_POST['files'] as $index => $arr) { |
|
81 | - if (empty($arr['name'])) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | - } |
|
79 | + if (!empty($_POST['files']) && is_array($_POST['files'])) { |
|
80 | + foreach ($_POST['files'] as $index => $arr) { |
|
81 | + if (empty($arr['name'])) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + if (!isset($arr['name'], $arr['type'], $arr['folder'])) { |
|
85 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
86 | + } |
|
87 | 87 | |
88 | - // file name |
|
89 | - $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | - // resource type |
|
91 | - $type = $arr['type']; |
|
92 | - // client path |
|
93 | - $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | - // options |
|
95 | - $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
88 | + // file name |
|
89 | + $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']); |
|
90 | + // resource type |
|
91 | + $type = $arr['type']; |
|
92 | + // client path |
|
93 | + $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']); |
|
94 | + // options |
|
95 | + $options = (!empty($arr['options'])) ? $arr['options'] : ''; |
|
96 | 96 | |
97 | - $destinationFilePath = $sServerDir.$name; |
|
97 | + $destinationFilePath = $sServerDir.$name; |
|
98 | 98 | |
99 | - // check #1 (path) |
|
100 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | - } |
|
99 | + // check #1 (path) |
|
100 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) { |
|
101 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
102 | + } |
|
103 | 103 | |
104 | - // get resource type config for current file |
|
105 | - if (!isset($_resourceTypeConfig[$type])) { |
|
106 | - $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | - } |
|
104 | + // get resource type config for current file |
|
105 | + if (!isset($_resourceTypeConfig[$type])) { |
|
106 | + $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type); |
|
107 | + } |
|
108 | 108 | |
109 | - // check #2 (resource type) |
|
110 | - if (is_null($_resourceTypeConfig[$type])) { |
|
111 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | - } |
|
109 | + // check #2 (resource type) |
|
110 | + if (is_null($_resourceTypeConfig[$type])) { |
|
111 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | + } |
|
113 | 113 | |
114 | - // check #3 (extension) |
|
115 | - if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | - continue; |
|
119 | - } |
|
114 | + // check #3 (extension) |
|
115 | + if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) { |
|
116 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
117 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
118 | + continue; |
|
119 | + } |
|
120 | 120 | |
121 | - // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | - if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | - $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | - continue; |
|
127 | - } |
|
128 | - } |
|
121 | + // check #4 (extension) - when moving to another resource type, double check extension |
|
122 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
123 | + if (!$currentResourceTypeConfig->checkExtension($name, false)) { |
|
124 | + $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; |
|
125 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
126 | + continue; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - // check #5 (hidden folders) |
|
131 | - // cache results |
|
132 | - if (empty($checkedPaths[$path])) { |
|
133 | - $checkedPaths[$path] = true; |
|
130 | + // check #5 (hidden folders) |
|
131 | + // cache results |
|
132 | + if (empty($checkedPaths[$path])) { |
|
133 | + $checkedPaths[$path] = true; |
|
134 | 134 | |
135 | - if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | - } |
|
138 | - } |
|
135 | + if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) { |
|
136 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
140 | + $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name; |
|
141 | 141 | |
142 | - // check #6 (hidden file name) |
|
143 | - if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | - } |
|
142 | + // check #6 (hidden file name) |
|
143 | + if ($currentResourceTypeConfig->checkIsHiddenFile($name)) { |
|
144 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
145 | + } |
|
146 | 146 | |
147 | - // check #7 (Access Control, need file view permission to source files) |
|
148 | - if (!isset($aclMasks[$type."@".$path])) { |
|
149 | - $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | - } |
|
147 | + // check #7 (Access Control, need file view permission to source files) |
|
148 | + if (!isset($aclMasks[$type."@".$path])) { |
|
149 | + $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path); |
|
150 | + } |
|
151 | 151 | |
152 | - $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | - if (!$isAuthorized) { |
|
154 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | - } |
|
152 | + $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW); |
|
153 | + if (!$isAuthorized) { |
|
154 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
155 | + } |
|
156 | 156 | |
157 | - // check #8 (invalid file name) |
|
158 | - if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | - $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | - continue; |
|
162 | - } |
|
157 | + // check #8 (invalid file name) |
|
158 | + if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) { |
|
159 | + $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND; |
|
160 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
161 | + continue; |
|
162 | + } |
|
163 | 163 | |
164 | - // check #9 (max size) |
|
165 | - if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | - $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | - $fileSize = filesize($sourceFilePath); |
|
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
169 | - $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | - continue; |
|
172 | - } |
|
173 | - } |
|
164 | + // check #9 (max size) |
|
165 | + if ($currentResourceTypeConfig->getName() != $type) { |
|
166 | + $maxSize = $currentResourceTypeConfig->getMaxSize(); |
|
167 | + $fileSize = filesize($sourceFilePath); |
|
168 | + if ($maxSize && $fileSize>$maxSize) { |
|
169 | + $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
|
170 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
171 | + continue; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - //$overwrite |
|
176 | - // finally, no errors so far, we may attempt to copy a file |
|
177 | - // protection against copying files to itself |
|
178 | - if ($sourceFilePath == $destinationFilePath) { |
|
179 | - $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | - continue; |
|
182 | - } |
|
183 | - // check if file exists if we don't force overwriting |
|
184 | - else if (file_exists($destinationFilePath)) { |
|
185 | - if (strpos($options, "overwrite") !== false) { |
|
186 | - if (!@unlink($destinationFilePath)) { |
|
187 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
188 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
189 | - continue; |
|
190 | - } |
|
191 | - else { |
|
192 | - if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
193 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
194 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
195 | - continue; |
|
196 | - } |
|
197 | - else { |
|
198 | - $moved++; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - else if (strpos($options, "autorename") !== false) { |
|
203 | - $iCounter = 1; |
|
204 | - while (true) |
|
205 | - { |
|
206 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | - "(" . $iCounter . ")" . "." . |
|
208 | - CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
175 | + //$overwrite |
|
176 | + // finally, no errors so far, we may attempt to copy a file |
|
177 | + // protection against copying files to itself |
|
178 | + if ($sourceFilePath == $destinationFilePath) { |
|
179 | + $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL; |
|
180 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
181 | + continue; |
|
182 | + } |
|
183 | + // check if file exists if we don't force overwriting |
|
184 | + else if (file_exists($destinationFilePath)) { |
|
185 | + if (strpos($options, "overwrite") !== false) { |
|
186 | + if (!@unlink($destinationFilePath)) { |
|
187 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
188 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
189 | + continue; |
|
190 | + } |
|
191 | + else { |
|
192 | + if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
193 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
194 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
195 | + continue; |
|
196 | + } |
|
197 | + else { |
|
198 | + $moved++; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + else if (strpos($options, "autorename") !== false) { |
|
203 | + $iCounter = 1; |
|
204 | + while (true) |
|
205 | + { |
|
206 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | + "(" . $iCounter . ")" . "." . |
|
208 | + CKFinder_Connector_Utils_FileSystem::getExtension($name); |
|
209 | 209 | |
210 | - $destinationFilePath = $sServerDir.$fileName; |
|
211 | - if (!file_exists($destinationFilePath)) { |
|
212 | - break; |
|
213 | - } |
|
214 | - else { |
|
215 | - $iCounter++; |
|
216 | - } |
|
217 | - } |
|
218 | - if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
219 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | - continue; |
|
222 | - } |
|
223 | - else { |
|
224 | - $moved++; |
|
225 | - } |
|
226 | - } |
|
227 | - else { |
|
228 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
229 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
230 | - continue; |
|
231 | - } |
|
232 | - } |
|
233 | - else { |
|
234 | - if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
235 | - $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
236 | - $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
237 | - continue; |
|
238 | - } |
|
239 | - else { |
|
240 | - $moved++; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
210 | + $destinationFilePath = $sServerDir.$fileName; |
|
211 | + if (!file_exists($destinationFilePath)) { |
|
212 | + break; |
|
213 | + } |
|
214 | + else { |
|
215 | + $iCounter++; |
|
216 | + } |
|
217 | + } |
|
218 | + if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
219 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
220 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
221 | + continue; |
|
222 | + } |
|
223 | + else { |
|
224 | + $moved++; |
|
225 | + } |
|
226 | + } |
|
227 | + else { |
|
228 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
|
229 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
230 | + continue; |
|
231 | + } |
|
232 | + } |
|
233 | + else { |
|
234 | + if (!@rename($sourceFilePath, $destinationFilePath)) { |
|
235 | + $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
236 | + $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
|
237 | + continue; |
|
238 | + } |
|
239 | + else { |
|
240 | + $moved++; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - $this->_connectorNode->addChild($oMoveFilesNode); |
|
247 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
248 | - $this->_connectorNode->addChild($oErrorsNode); |
|
249 | - } |
|
250 | - $oMoveFilesNode->addAttribute("moved", $moved); |
|
251 | - $oMoveFilesNode->addAttribute("movedTotal", $movedAll + $moved); |
|
246 | + $this->_connectorNode->addChild($oMoveFilesNode); |
|
247 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
248 | + $this->_connectorNode->addChild($oErrorsNode); |
|
249 | + } |
|
250 | + $oMoveFilesNode->addAttribute("moved", $moved); |
|
251 | + $oMoveFilesNode->addAttribute("movedTotal", $movedAll + $moved); |
|
252 | 252 | |
253 | - /** |
|
254 | - * Note: actually we could have more than one error. |
|
255 | - * This is just a flag for CKFinder interface telling it to check all errors. |
|
256 | - */ |
|
257 | - if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
258 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_MOVE_FAILED); |
|
259 | - } |
|
260 | - } |
|
253 | + /** |
|
254 | + * Note: actually we could have more than one error. |
|
255 | + * This is just a flag for CKFinder interface telling it to check all errors. |
|
256 | + */ |
|
257 | + if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) { |
|
258 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_MOVE_FAILED); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - function appendErrorNode(&$oErrorsNode, $errorCode, $name, $type, $path) |
|
263 | - { |
|
264 | - $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
265 | - $oErrorNode->addAttribute("code", $errorCode); |
|
266 | - $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
267 | - $oErrorNode->addAttribute("type", $type); |
|
268 | - $oErrorNode->addAttribute("folder", $path); |
|
269 | - $oErrorsNode->addChild($oErrorNode); |
|
270 | - } |
|
262 | + function appendErrorNode(&$oErrorsNode, $errorCode, $name, $type, $path) |
|
263 | + { |
|
264 | + $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
|
265 | + $oErrorNode->addAttribute("code", $errorCode); |
|
266 | + $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name)); |
|
267 | + $oErrorNode->addAttribute("type", $type); |
|
268 | + $oErrorNode->addAttribute("folder", $path); |
|
269 | + $oErrorsNode->addChild($oErrorNode); |
|
270 | + } |
|
271 | 271 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include base XML command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle MoveFiles command |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $clientPath = $this->_currentFolder->getClientPath(); |
56 | 56 | $sServerDir = $this->_currentFolder->getServerPath(); |
57 | 57 | $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
58 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
58 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
59 | 59 | $_aclConfig = $_config->getAccessControlConfig(); |
60 | 60 | $aclMasks = array(); |
61 | 61 | $_resourceTypeConfig = array(); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | if ($currentResourceTypeConfig->getName() != $type) { |
166 | 166 | $maxSize = $currentResourceTypeConfig->getMaxSize(); |
167 | 167 | $fileSize = filesize($sourceFilePath); |
168 | - if ($maxSize && $fileSize>$maxSize) { |
|
168 | + if ($maxSize && $fileSize > $maxSize) { |
|
169 | 169 | $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; |
170 | 170 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
171 | 171 | continue; |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $iCounter = 1; |
204 | 204 | while (true) |
205 | 205 | { |
206 | - $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) . |
|
207 | - "(" . $iCounter . ")" . "." . |
|
206 | + $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name). |
|
207 | + "(".$iCounter.")".".". |
|
208 | 208 | CKFinder_Connector_Utils_FileSystem::getExtension($name); |
209 | 209 | |
210 | 210 | $destinationFilePath = $sServerDir.$fileName; |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -187,19 +189,16 @@ discard block |
||
187 | 189 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
188 | 190 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
189 | 191 | continue; |
190 | - } |
|
191 | - else { |
|
192 | + } else { |
|
192 | 193 | if (!@rename($sourceFilePath, $destinationFilePath)) { |
193 | 194 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
194 | 195 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
195 | 196 | continue; |
196 | - } |
|
197 | - else { |
|
197 | + } else { |
|
198 | 198 | $moved++; |
199 | 199 | } |
200 | 200 | } |
201 | - } |
|
202 | - else if (strpos($options, "autorename") !== false) { |
|
201 | + } else if (strpos($options, "autorename") !== false) { |
|
203 | 202 | $iCounter = 1; |
204 | 203 | while (true) |
205 | 204 | { |
@@ -210,8 +209,7 @@ discard block |
||
210 | 209 | $destinationFilePath = $sServerDir.$fileName; |
211 | 210 | if (!file_exists($destinationFilePath)) { |
212 | 211 | break; |
213 | - } |
|
214 | - else { |
|
212 | + } else { |
|
215 | 213 | $iCounter++; |
216 | 214 | } |
217 | 215 | } |
@@ -219,24 +217,20 @@ discard block |
||
219 | 217 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
220 | 218 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
221 | 219 | continue; |
222 | - } |
|
223 | - else { |
|
220 | + } else { |
|
224 | 221 | $moved++; |
225 | 222 | } |
226 | - } |
|
227 | - else { |
|
223 | + } else { |
|
228 | 224 | $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST; |
229 | 225 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
230 | 226 | continue; |
231 | 227 | } |
232 | - } |
|
233 | - else { |
|
228 | + } else { |
|
234 | 229 | if (!@rename($sourceFilePath, $destinationFilePath)) { |
235 | 230 | $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
236 | 231 | $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path); |
237 | 232 | continue; |
238 | - } |
|
239 | - else { |
|
233 | + } else { |
|
240 | 234 | $moved++; |
241 | 235 | } |
242 | 236 | } |
@@ -259,6 +259,10 @@ |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | + /** |
|
263 | + * @param integer $errorCode |
|
264 | + * @param string $path |
|
265 | + */ |
|
262 | 266 | private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path) |
263 | 267 | { |
264 | 268 | $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error"); |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * CKFinder |
|
4 | - * ======== |
|
5 | - * http://ckfinder.com |
|
6 | - * Copyright (C) 2007-2010, CKSource - Frederico Knabben. All rights reserved. |
|
7 | - * |
|
8 | - * The software, this file and its contents are subject to the CKFinder |
|
9 | - * License. Please read the license.txt file before using, installing, copying, |
|
10 | - * modifying or distribute this file or part of its contents. The contents of |
|
11 | - * this file is part of the Source Code of CKFinder. |
|
12 | - */ |
|
3 | + * CKFinder |
|
4 | + * ======== |
|
5 | + * http://ckfinder.com |
|
6 | + * Copyright (C) 2007-2010, CKSource - Frederico Knabben. All rights reserved. |
|
7 | + * |
|
8 | + * The software, this file and its contents are subject to the CKFinder |
|
9 | + * License. Please read the license.txt file before using, installing, copying, |
|
10 | + * modifying or distribute this file or part of its contents. The contents of |
|
11 | + * this file is part of the Source Code of CKFinder. |
|
12 | + */ |
|
13 | 13 | if (!defined('IN_CKFINDER')) exit; |
14 | 14 | |
15 | 15 | /** |
@@ -27,177 +27,177 @@ discard block |
||
27 | 27 | */ |
28 | 28 | class CKFinder_Connector_CommandHandler_FileUpload extends CKFinder_Connector_CommandHandler_CommandHandlerBase |
29 | 29 | { |
30 | - /** |
|
31 | - * Command name |
|
32 | - * |
|
33 | - * @access protected |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - var $command = "FileUpload"; |
|
37 | - |
|
38 | - /** |
|
39 | - * send response (save uploaded file, resize if required) |
|
40 | - * @access public |
|
41 | - * |
|
42 | - */ |
|
43 | - function sendResponse() |
|
44 | - { |
|
45 | - $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE; |
|
46 | - |
|
47 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
48 | - $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
49 | - $oRegistry->set("FileUpload_fileName", "unknown file"); |
|
50 | - |
|
51 | - $uploadedFile = array_shift($_FILES); |
|
52 | - |
|
53 | - if (!isset($uploadedFile['name'])) { |
|
54 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID); |
|
55 | - } |
|
56 | - |
|
57 | - $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name'])); |
|
58 | - $sFileName = str_replace(array(":", "*", "?", "|", "/"), "_", $sUnsafeFileName); |
|
59 | - if ($_config->forceAscii()) { |
|
60 | - $sFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sFileName); |
|
61 | - } |
|
62 | - if ($sFileName != $sUnsafeFileName) { |
|
63 | - $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED; |
|
64 | - } |
|
65 | - $oRegistry->set("FileUpload_fileName", $sFileName); |
|
66 | - $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
|
67 | - |
|
68 | - $this->checkConnector(); |
|
69 | - $this->checkRequest(); |
|
70 | - |
|
71 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
72 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
73 | - } |
|
74 | - |
|
75 | - $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
76 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) { |
|
77 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
78 | - } |
|
79 | - |
|
80 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
81 | - if (!$resourceTypeInfo->checkExtension($sFileName)) { |
|
82 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
83 | - } |
|
84 | - |
|
85 | - $sFileNameOrginal = $sFileName; |
|
86 | - $oRegistry->set("FileUpload_fileName", $sFileName); |
|
87 | - |
|
88 | - $maxSize = $resourceTypeInfo->getMaxSize(); |
|
89 | - if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size']>$maxSize) { |
|
90 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
91 | - } |
|
92 | - |
|
93 | - $htmlExtensions = $_config->getHtmlExtensions(); |
|
94 | - $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
95 | - |
|
96 | - if ($htmlExtensions |
|
97 | - && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) |
|
98 | - && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true ) { |
|
99 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
|
100 | - } |
|
101 | - |
|
102 | - $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
103 | - $secureImageUploads = $_config->getSecureImageUploads(); |
|
104 | - if ($secureImageUploads |
|
105 | - && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false ) { |
|
106 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
107 | - } |
|
108 | - |
|
109 | - switch ($uploadedFile['error']) { |
|
110 | - case UPLOAD_ERR_OK: |
|
111 | - break; |
|
112 | - |
|
113 | - case UPLOAD_ERR_INI_SIZE: |
|
114 | - case UPLOAD_ERR_FORM_SIZE: |
|
115 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
116 | - break; |
|
117 | - |
|
118 | - case UPLOAD_ERR_PARTIAL: |
|
119 | - case UPLOAD_ERR_NO_FILE: |
|
120 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
121 | - break; |
|
122 | - |
|
123 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
124 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR); |
|
125 | - break; |
|
126 | - |
|
127 | - case UPLOAD_ERR_CANT_WRITE: |
|
128 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
129 | - break; |
|
130 | - |
|
131 | - case UPLOAD_ERR_EXTENSION: |
|
132 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
133 | - break; |
|
134 | - } |
|
135 | - |
|
136 | - $sServerDir = $this->_currentFolder->getServerPath(); |
|
137 | - $iCounter = 0; |
|
138 | - |
|
139 | - while (true) |
|
140 | - { |
|
141 | - $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName); |
|
142 | - |
|
143 | - |
|
144 | - if (file_exists($sFilePath)) { |
|
145 | - |
|
146 | - $iCounter++; |
|
147 | - $sFileName = |
|
148 | - CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . |
|
149 | - "(" . $iCounter . ")" . "." . |
|
150 | - CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
151 | - $oRegistry->set("FileUpload_fileName", $sFileName); |
|
152 | - |
|
153 | - $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED; |
|
154 | - } else { |
|
155 | - if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) { |
|
156 | - $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
157 | - } |
|
158 | - else { |
|
159 | - if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) { |
|
160 | - @unlink($sFilePath); |
|
161 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
|
162 | - } |
|
163 | - else if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { |
|
164 | - @unlink($sFilePath); |
|
165 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
166 | - } |
|
167 | - } |
|
168 | - if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) { |
|
169 | - $oldumask = umask(0); |
|
170 | - chmod($sFilePath, $perms); |
|
171 | - umask($oldumask); |
|
172 | - } |
|
173 | - break; |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - if (!$_config->checkSizeAfterScaling()) { |
|
178 | - $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
179 | - } |
|
180 | - |
|
181 | - //resize image if required |
|
182 | - require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php"; |
|
183 | - $_imagesConfig = $_config->getImagesConfig(); |
|
184 | - |
|
185 | - if ($_imagesConfig->getMaxWidth()>0 && $_imagesConfig->getMaxHeight()>0 && $_imagesConfig->getQuality()>0) { |
|
186 | - CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true) ; |
|
187 | - } |
|
188 | - |
|
189 | - if ($_config->checkSizeAfterScaling()) { |
|
190 | - //check file size after scaling, attempt to delete if too big |
|
191 | - clearstatcache(); |
|
192 | - if ($maxSize && filesize($sFilePath)>$maxSize) { |
|
193 | - @unlink($sFilePath); |
|
194 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
195 | - } |
|
196 | - else { |
|
197 | - $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - CKFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath)); |
|
202 | - } |
|
30 | + /** |
|
31 | + * Command name |
|
32 | + * |
|
33 | + * @access protected |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + var $command = "FileUpload"; |
|
37 | + |
|
38 | + /** |
|
39 | + * send response (save uploaded file, resize if required) |
|
40 | + * @access public |
|
41 | + * |
|
42 | + */ |
|
43 | + function sendResponse() |
|
44 | + { |
|
45 | + $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE; |
|
46 | + |
|
47 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
48 | + $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
49 | + $oRegistry->set("FileUpload_fileName", "unknown file"); |
|
50 | + |
|
51 | + $uploadedFile = array_shift($_FILES); |
|
52 | + |
|
53 | + if (!isset($uploadedFile['name'])) { |
|
54 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID); |
|
55 | + } |
|
56 | + |
|
57 | + $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name'])); |
|
58 | + $sFileName = str_replace(array(":", "*", "?", "|", "/"), "_", $sUnsafeFileName); |
|
59 | + if ($_config->forceAscii()) { |
|
60 | + $sFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sFileName); |
|
61 | + } |
|
62 | + if ($sFileName != $sUnsafeFileName) { |
|
63 | + $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED; |
|
64 | + } |
|
65 | + $oRegistry->set("FileUpload_fileName", $sFileName); |
|
66 | + $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
|
67 | + |
|
68 | + $this->checkConnector(); |
|
69 | + $this->checkRequest(); |
|
70 | + |
|
71 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
72 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
73 | + } |
|
74 | + |
|
75 | + $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
76 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) { |
|
77 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
78 | + } |
|
79 | + |
|
80 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
81 | + if (!$resourceTypeInfo->checkExtension($sFileName)) { |
|
82 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
83 | + } |
|
84 | + |
|
85 | + $sFileNameOrginal = $sFileName; |
|
86 | + $oRegistry->set("FileUpload_fileName", $sFileName); |
|
87 | + |
|
88 | + $maxSize = $resourceTypeInfo->getMaxSize(); |
|
89 | + if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size']>$maxSize) { |
|
90 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
91 | + } |
|
92 | + |
|
93 | + $htmlExtensions = $_config->getHtmlExtensions(); |
|
94 | + $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
95 | + |
|
96 | + if ($htmlExtensions |
|
97 | + && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) |
|
98 | + && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true ) { |
|
99 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
|
100 | + } |
|
101 | + |
|
102 | + $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
103 | + $secureImageUploads = $_config->getSecureImageUploads(); |
|
104 | + if ($secureImageUploads |
|
105 | + && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false ) { |
|
106 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
107 | + } |
|
108 | + |
|
109 | + switch ($uploadedFile['error']) { |
|
110 | + case UPLOAD_ERR_OK: |
|
111 | + break; |
|
112 | + |
|
113 | + case UPLOAD_ERR_INI_SIZE: |
|
114 | + case UPLOAD_ERR_FORM_SIZE: |
|
115 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
116 | + break; |
|
117 | + |
|
118 | + case UPLOAD_ERR_PARTIAL: |
|
119 | + case UPLOAD_ERR_NO_FILE: |
|
120 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
121 | + break; |
|
122 | + |
|
123 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
124 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR); |
|
125 | + break; |
|
126 | + |
|
127 | + case UPLOAD_ERR_CANT_WRITE: |
|
128 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
129 | + break; |
|
130 | + |
|
131 | + case UPLOAD_ERR_EXTENSION: |
|
132 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
133 | + break; |
|
134 | + } |
|
135 | + |
|
136 | + $sServerDir = $this->_currentFolder->getServerPath(); |
|
137 | + $iCounter = 0; |
|
138 | + |
|
139 | + while (true) |
|
140 | + { |
|
141 | + $sFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName); |
|
142 | + |
|
143 | + |
|
144 | + if (file_exists($sFilePath)) { |
|
145 | + |
|
146 | + $iCounter++; |
|
147 | + $sFileName = |
|
148 | + CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . |
|
149 | + "(" . $iCounter . ")" . "." . |
|
150 | + CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
151 | + $oRegistry->set("FileUpload_fileName", $sFileName); |
|
152 | + |
|
153 | + $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED; |
|
154 | + } else { |
|
155 | + if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) { |
|
156 | + $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
157 | + } |
|
158 | + else { |
|
159 | + if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) { |
|
160 | + @unlink($sFilePath); |
|
161 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
|
162 | + } |
|
163 | + else if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { |
|
164 | + @unlink($sFilePath); |
|
165 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
166 | + } |
|
167 | + } |
|
168 | + if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) { |
|
169 | + $oldumask = umask(0); |
|
170 | + chmod($sFilePath, $perms); |
|
171 | + umask($oldumask); |
|
172 | + } |
|
173 | + break; |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + if (!$_config->checkSizeAfterScaling()) { |
|
178 | + $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
179 | + } |
|
180 | + |
|
181 | + //resize image if required |
|
182 | + require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php"; |
|
183 | + $_imagesConfig = $_config->getImagesConfig(); |
|
184 | + |
|
185 | + if ($_imagesConfig->getMaxWidth()>0 && $_imagesConfig->getMaxHeight()>0 && $_imagesConfig->getQuality()>0) { |
|
186 | + CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true) ; |
|
187 | + } |
|
188 | + |
|
189 | + if ($_config->checkSizeAfterScaling()) { |
|
190 | + //check file size after scaling, attempt to delete if too big |
|
191 | + clearstatcache(); |
|
192 | + if ($maxSize && filesize($sFilePath)>$maxSize) { |
|
193 | + @unlink($sFilePath); |
|
194 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
195 | + } |
|
196 | + else { |
|
197 | + $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + CKFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath)); |
|
202 | + } |
|
203 | 203 | } |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | { |
45 | 45 | $iErrorNumber = CKFINDER_CONNECTOR_ERROR_NONE; |
46 | 46 | |
47 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
48 | - $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
47 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
48 | + $oRegistry = & CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
49 | 49 | $oRegistry->set("FileUpload_fileName", "unknown file"); |
50 | 50 | |
51 | 51 | $uploadedFile = array_shift($_FILES); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $oRegistry->set("FileUpload_fileName", $sFileName); |
87 | 87 | |
88 | 88 | $maxSize = $resourceTypeInfo->getMaxSize(); |
89 | - if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size']>$maxSize) { |
|
89 | + if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) { |
|
90 | 90 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
91 | 91 | } |
92 | 92 | |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | |
96 | 96 | if ($htmlExtensions |
97 | 97 | && !CKFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) |
98 | - && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true ) { |
|
98 | + && ($detectHtml = CKFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) { |
|
99 | 99 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
100 | 100 | } |
101 | 101 | |
102 | 102 | $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
103 | 103 | $secureImageUploads = $_config->getSecureImageUploads(); |
104 | 104 | if ($secureImageUploads |
105 | - && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false ) { |
|
105 | + && ($isImageValid = CKFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) { |
|
106 | 106 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
107 | 107 | } |
108 | 108 | |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | |
146 | 146 | $iCounter++; |
147 | 147 | $sFileName = |
148 | - CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . |
|
149 | - "(" . $iCounter . ")" . "." . |
|
148 | + CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal). |
|
149 | + "(".$iCounter.")".".". |
|
150 | 150 | CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
151 | 151 | $oRegistry->set("FileUpload_fileName", $sFileName); |
152 | 152 | |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | //resize image if required |
182 | - require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php"; |
|
182 | + require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/Thumbnail.php"; |
|
183 | 183 | $_imagesConfig = $_config->getImagesConfig(); |
184 | 184 | |
185 | - if ($_imagesConfig->getMaxWidth()>0 && $_imagesConfig->getMaxHeight()>0 && $_imagesConfig->getQuality()>0) { |
|
186 | - CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true) ; |
|
185 | + if ($_imagesConfig->getMaxWidth() > 0 && $_imagesConfig->getMaxHeight() > 0 && $_imagesConfig->getQuality() > 0) { |
|
186 | + CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | if ($_config->checkSizeAfterScaling()) { |
190 | 190 | //check file size after scaling, attempt to delete if too big |
191 | 191 | clearstatcache(); |
192 | - if ($maxSize && filesize($sFilePath)>$maxSize) { |
|
192 | + if ($maxSize && filesize($sFilePath) > $maxSize) { |
|
193 | 193 | @unlink($sFilePath); |
194 | 194 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
195 | 195 | } |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | * modifying or distribute this file or part of its contents. The contents of |
11 | 11 | * this file is part of the Source Code of CKFinder. |
12 | 12 | */ |
13 | -if (!defined('IN_CKFINDER')) exit; |
|
13 | +if (!defined('IN_CKFINDER')) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | 17 | /** |
16 | 18 | * @package CKFinder |
@@ -154,13 +156,11 @@ discard block |
||
154 | 156 | } else { |
155 | 157 | if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) { |
156 | 158 | $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
157 | - } |
|
158 | - else { |
|
159 | + } else { |
|
159 | 160 | if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) { |
160 | 161 | @unlink($sFilePath); |
161 | 162 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
162 | - } |
|
163 | - else if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { |
|
163 | + } else if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { |
|
164 | 164 | @unlink($sFilePath); |
165 | 165 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
166 | 166 | } |
@@ -192,8 +192,7 @@ discard block |
||
192 | 192 | if ($maxSize && filesize($sFilePath)>$maxSize) { |
193 | 193 | @unlink($sFilePath); |
194 | 194 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
195 | - } |
|
196 | - else { |
|
195 | + } else { |
|
197 | 196 | $this->_errorHandler->throwError($iErrorNumber, true, false); |
198 | 197 | } |
199 | 198 | } |