@@ -38,82 +38,82 @@ |
||
38 | 38 | */ |
39 | 39 | abstract 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 | - protected $_connectorNode; |
|
41 | + /** |
|
42 | + * Connector node - Ckfinder_Connector_Utils_XmlNode object |
|
43 | + * |
|
44 | + * @var Ckfinder_Connector_Utils_XmlNode |
|
45 | + * @access protected |
|
46 | + */ |
|
47 | + protected $_connectorNode; |
|
48 | 48 | |
49 | - /** |
|
50 | - * send response |
|
51 | - * @access public |
|
52 | - * |
|
53 | - */ |
|
54 | - public function sendResponse() |
|
55 | - { |
|
56 | - $xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
57 | - $this->_connectorNode =& $xml->getConnectorNode(); |
|
49 | + /** |
|
50 | + * send response |
|
51 | + * @access public |
|
52 | + * |
|
53 | + */ |
|
54 | + public function sendResponse() |
|
55 | + { |
|
56 | + $xml =& CKFinder_Connector_Core_Factory::getInstance("Core_Xml"); |
|
57 | + $this->_connectorNode =& $xml->getConnectorNode(); |
|
58 | 58 | |
59 | - $this->checkConnector(); |
|
60 | - if ($this->mustCheckRequest()) { |
|
61 | - $this->checkRequest(); |
|
62 | - } |
|
59 | + $this->checkConnector(); |
|
60 | + if ($this->mustCheckRequest()) { |
|
61 | + $this->checkRequest(); |
|
62 | + } |
|
63 | 63 | |
64 | - $resourceTypeName = $this->_currentFolder->getResourceTypeName(); |
|
65 | - if (!empty($resourceTypeName)) { |
|
66 | - $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName()); |
|
67 | - } |
|
64 | + $resourceTypeName = $this->_currentFolder->getResourceTypeName(); |
|
65 | + if (!empty($resourceTypeName)) { |
|
66 | + $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName()); |
|
67 | + } |
|
68 | 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())); |
|
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 | 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); |
|
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 | 78 | |
79 | - $_currentFolder->addAttribute("acl", $this->_currentFolder->getAclMask()); |
|
80 | - } |
|
79 | + $_currentFolder->addAttribute("acl", $this->_currentFolder->getAclMask()); |
|
80 | + } |
|
81 | 81 | |
82 | - $this->buildXml(); |
|
82 | + $this->buildXml(); |
|
83 | 83 | |
84 | - $_oErrorNode =& $xml->getErrorNode(); |
|
85 | - $_oErrorNode->addAttribute("number", "0"); |
|
84 | + $_oErrorNode =& $xml->getErrorNode(); |
|
85 | + $_oErrorNode->addAttribute("number", "0"); |
|
86 | 86 | |
87 | - echo $this->_connectorNode->asXML(); |
|
88 | - exit; |
|
89 | - } |
|
87 | + echo $this->_connectorNode->asXML(); |
|
88 | + exit; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Must check request? |
|
93 | - * |
|
94 | - * @return boolean |
|
95 | - * @access protected |
|
96 | - */ |
|
97 | - protected function mustCheckRequest() |
|
98 | - { |
|
99 | - return true; |
|
100 | - } |
|
91 | + /** |
|
92 | + * Must check request? |
|
93 | + * |
|
94 | + * @return boolean |
|
95 | + * @access protected |
|
96 | + */ |
|
97 | + protected function mustCheckRequest() |
|
98 | + { |
|
99 | + return true; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Must add CurrentFolder node? |
|
104 | - * |
|
105 | - * @return boolean |
|
106 | - * @access protected |
|
107 | - */ |
|
108 | - protected function mustAddCurrentFolderNode() |
|
109 | - { |
|
110 | - return true; |
|
111 | - } |
|
102 | + /** |
|
103 | + * Must add CurrentFolder node? |
|
104 | + * |
|
105 | + * @return boolean |
|
106 | + * @access protected |
|
107 | + */ |
|
108 | + protected function mustAddCurrentFolderNode() |
|
109 | + { |
|
110 | + return true; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @access protected |
|
115 | - * @abstract |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - abstract protected function buildXml(); |
|
113 | + /** |
|
114 | + * @access protected |
|
115 | + * @abstract |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + abstract protected function buildXml(); |
|
119 | 119 | } |
@@ -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 |
@@ -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,175 +27,175 @@ 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 | - protected $command = "FileUpload"; |
|
37 | - |
|
38 | - /** |
|
39 | - * send response (save uploaded file, resize if required) |
|
40 | - * @access public |
|
41 | - * |
|
42 | - */ |
|
43 | - public 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 | - |
|
67 | - $this->checkConnector(); |
|
68 | - $this->checkRequest(); |
|
69 | - |
|
70 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
71 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
72 | - } |
|
73 | - |
|
74 | - $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
75 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) { |
|
76 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
77 | - } |
|
78 | - |
|
79 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
80 | - if (!$resourceTypeInfo->checkExtension($sFileName)) { |
|
81 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
82 | - } |
|
83 | - |
|
84 | - $sFileNameOrginal = $sFileName; |
|
85 | - $oRegistry->set("FileUpload_fileName", $sFileName); |
|
86 | - $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
|
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 | - if (file_exists($sFilePath)) { |
|
144 | - $iCounter++; |
|
145 | - $sFileName = |
|
146 | - CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . |
|
147 | - "(" . $iCounter . ")" . "." . |
|
148 | - CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
149 | - $oRegistry->set("FileUpload_fileName", $sFileName); |
|
150 | - |
|
151 | - $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED; |
|
152 | - } else { |
|
153 | - if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) { |
|
154 | - $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
155 | - } |
|
156 | - else { |
|
157 | - if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) { |
|
158 | - @unlink($sFilePath); |
|
159 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
|
160 | - } |
|
161 | - else if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { |
|
162 | - @unlink($sFilePath); |
|
163 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
164 | - } |
|
165 | - } |
|
166 | - if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) { |
|
167 | - $oldumask = umask(0); |
|
168 | - chmod($sFilePath, $perms); |
|
169 | - umask($oldumask); |
|
170 | - } |
|
171 | - break; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - if (!$_config->checkSizeAfterScaling()) { |
|
176 | - $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
177 | - } |
|
178 | - |
|
179 | - //resize image if required |
|
180 | - require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php"; |
|
181 | - $_imagesConfig = $_config->getImagesConfig(); |
|
182 | - |
|
183 | - if ($_imagesConfig->getMaxWidth()>0 && $_imagesConfig->getMaxHeight()>0 && $_imagesConfig->getQuality()>0) { |
|
184 | - CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true) ; |
|
185 | - } |
|
186 | - |
|
187 | - if ($_config->checkSizeAfterScaling()) { |
|
188 | - //check file size after scaling, attempt to delete if too big |
|
189 | - clearstatcache(); |
|
190 | - if ($maxSize && filesize($sFilePath)>$maxSize) { |
|
191 | - @unlink($sFilePath); |
|
192 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
193 | - } |
|
194 | - else { |
|
195 | - $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - CKFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath)); |
|
200 | - } |
|
30 | + /** |
|
31 | + * Command name |
|
32 | + * |
|
33 | + * @access protected |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $command = "FileUpload"; |
|
37 | + |
|
38 | + /** |
|
39 | + * send response (save uploaded file, resize if required) |
|
40 | + * @access public |
|
41 | + * |
|
42 | + */ |
|
43 | + public 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 | + |
|
67 | + $this->checkConnector(); |
|
68 | + $this->checkRequest(); |
|
69 | + |
|
70 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_UPLOAD)) { |
|
71 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
72 | + } |
|
73 | + |
|
74 | + $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
75 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) { |
|
76 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
77 | + } |
|
78 | + |
|
79 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
80 | + if (!$resourceTypeInfo->checkExtension($sFileName)) { |
|
81 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
82 | + } |
|
83 | + |
|
84 | + $sFileNameOrginal = $sFileName; |
|
85 | + $oRegistry->set("FileUpload_fileName", $sFileName); |
|
86 | + $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
|
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 | + if (file_exists($sFilePath)) { |
|
144 | + $iCounter++; |
|
145 | + $sFileName = |
|
146 | + CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) . |
|
147 | + "(" . $iCounter . ")" . "." . |
|
148 | + CKFinder_Connector_Utils_FileSystem::getExtension($sFileNameOrginal); |
|
149 | + $oRegistry->set("FileUpload_fileName", $sFileName); |
|
150 | + |
|
151 | + $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED; |
|
152 | + } else { |
|
153 | + if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) { |
|
154 | + $iErrorNumber = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; |
|
155 | + } |
|
156 | + else { |
|
157 | + if (isset($detectHtml) && $detectHtml === -1 && CKFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) { |
|
158 | + @unlink($sFilePath); |
|
159 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE); |
|
160 | + } |
|
161 | + else if (isset($isImageValid) && $isImageValid === -1 && CKFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) { |
|
162 | + @unlink($sFilePath); |
|
163 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT); |
|
164 | + } |
|
165 | + } |
|
166 | + if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) { |
|
167 | + $oldumask = umask(0); |
|
168 | + chmod($sFilePath, $perms); |
|
169 | + umask($oldumask); |
|
170 | + } |
|
171 | + break; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + if (!$_config->checkSizeAfterScaling()) { |
|
176 | + $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
177 | + } |
|
178 | + |
|
179 | + //resize image if required |
|
180 | + require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php"; |
|
181 | + $_imagesConfig = $_config->getImagesConfig(); |
|
182 | + |
|
183 | + if ($_imagesConfig->getMaxWidth()>0 && $_imagesConfig->getMaxHeight()>0 && $_imagesConfig->getQuality()>0) { |
|
184 | + CKFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true) ; |
|
185 | + } |
|
186 | + |
|
187 | + if ($_config->checkSizeAfterScaling()) { |
|
188 | + //check file size after scaling, attempt to delete if too big |
|
189 | + clearstatcache(); |
|
190 | + if ($maxSize && filesize($sFilePath)>$maxSize) { |
|
191 | + @unlink($sFilePath); |
|
192 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG); |
|
193 | + } |
|
194 | + else { |
|
195 | + $this->_errorHandler->throwError($iErrorNumber, true, false); |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + CKFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath)); |
|
200 | + } |
|
201 | 201 | } |
@@ -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 | } |
@@ -29,99 +29,99 @@ |
||
29 | 29 | */ |
30 | 30 | class CKFinder_Connector_CommandHandler_CommandHandlerBase |
31 | 31 | { |
32 | - /** |
|
33 | - * CKFinder_Connector_Core_Connector object |
|
34 | - * |
|
35 | - * @access protected |
|
36 | - * @var CKFinder_Connector_Core_Connector |
|
37 | - */ |
|
38 | - protected $_connector; |
|
39 | - /** |
|
40 | - * CKFinder_Connector_Core_FolderHandler object |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @var CKFinder_Connector_Core_FolderHandler |
|
44 | - */ |
|
45 | - protected $_currentFolder; |
|
46 | - /** |
|
47 | - * Error handler object |
|
48 | - * |
|
49 | - * @access protected |
|
50 | - * @var CKFinder_Connector_ErrorHandler_Base|CKFinder_Connector_ErrorHandler_FileUpload|CKFinder_Connector_ErrorHandler_Http |
|
51 | - */ |
|
52 | - protected $_errorHandler; |
|
32 | + /** |
|
33 | + * CKFinder_Connector_Core_Connector object |
|
34 | + * |
|
35 | + * @access protected |
|
36 | + * @var CKFinder_Connector_Core_Connector |
|
37 | + */ |
|
38 | + protected $_connector; |
|
39 | + /** |
|
40 | + * CKFinder_Connector_Core_FolderHandler object |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @var CKFinder_Connector_Core_FolderHandler |
|
44 | + */ |
|
45 | + protected $_currentFolder; |
|
46 | + /** |
|
47 | + * Error handler object |
|
48 | + * |
|
49 | + * @access protected |
|
50 | + * @var CKFinder_Connector_ErrorHandler_Base|CKFinder_Connector_ErrorHandler_FileUpload|CKFinder_Connector_ErrorHandler_Http |
|
51 | + */ |
|
52 | + protected $_errorHandler; |
|
53 | 53 | |
54 | - function __construct() |
|
55 | - { |
|
56 | - $this->_currentFolder =& CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
57 | - $this->_connector =& CKFinder_Connector_Core_Factory::getInstance("Core_Connector"); |
|
58 | - $this->_errorHandler =& $this->_connector->getErrorHandler(); |
|
59 | - } |
|
54 | + function __construct() |
|
55 | + { |
|
56 | + $this->_currentFolder =& CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
57 | + $this->_connector =& CKFinder_Connector_Core_Factory::getInstance("Core_Connector"); |
|
58 | + $this->_errorHandler =& $this->_connector->getErrorHandler(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Get Folder Handler |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @return CKFinder_Connector_Core_FolderHandler |
|
66 | - */ |
|
67 | - public function getFolderHandler() |
|
68 | - { |
|
69 | - if (is_null($this->_currentFolder)) { |
|
70 | - $this->_currentFolder =& CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
71 | - } |
|
61 | + /** |
|
62 | + * Get Folder Handler |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @return CKFinder_Connector_Core_FolderHandler |
|
66 | + */ |
|
67 | + public function getFolderHandler() |
|
68 | + { |
|
69 | + if (is_null($this->_currentFolder)) { |
|
70 | + $this->_currentFolder =& CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
71 | + } |
|
72 | 72 | |
73 | - return $this->_currentFolder; |
|
74 | - } |
|
73 | + return $this->_currentFolder; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Check whether Connector is enabled |
|
78 | - * @access protected |
|
79 | - * |
|
80 | - */ |
|
81 | - protected function checkConnector() |
|
82 | - { |
|
83 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
84 | - if (!$_config->getIsEnabled()) { |
|
85 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED); |
|
86 | - } |
|
87 | - } |
|
76 | + /** |
|
77 | + * Check whether Connector is enabled |
|
78 | + * @access protected |
|
79 | + * |
|
80 | + */ |
|
81 | + protected function checkConnector() |
|
82 | + { |
|
83 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
84 | + if (!$_config->getIsEnabled()) { |
|
85 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Check request |
|
91 | - * @access protected |
|
92 | - * |
|
93 | - */ |
|
94 | - protected function checkRequest() |
|
95 | - { |
|
96 | - if (preg_match(CKFINDER_REGEX_INVALID_PATH, $this->_currentFolder->getClientPath())) { |
|
97 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
98 | - } |
|
89 | + /** |
|
90 | + * Check request |
|
91 | + * @access protected |
|
92 | + * |
|
93 | + */ |
|
94 | + protected function checkRequest() |
|
95 | + { |
|
96 | + if (preg_match(CKFINDER_REGEX_INVALID_PATH, $this->_currentFolder->getClientPath())) { |
|
97 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
98 | + } |
|
99 | 99 | |
100 | - $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
100 | + $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
101 | 101 | |
102 | - if (is_null($_resourceTypeConfig)) { |
|
103 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_TYPE); |
|
104 | - } |
|
102 | + if (is_null($_resourceTypeConfig)) { |
|
103 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_TYPE); |
|
104 | + } |
|
105 | 105 | |
106 | - $_clientPath = $this->_currentFolder->getClientPath(); |
|
107 | - $_clientPathParts = explode("/", trim($_clientPath, "/")); |
|
108 | - if ($_clientPathParts) { |
|
109 | - foreach ($_clientPathParts as $_part) { |
|
110 | - if ($_resourceTypeConfig->checkIsHiddenFolder($_part)) { |
|
111 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
106 | + $_clientPath = $this->_currentFolder->getClientPath(); |
|
107 | + $_clientPathParts = explode("/", trim($_clientPath, "/")); |
|
108 | + if ($_clientPathParts) { |
|
109 | + foreach ($_clientPathParts as $_part) { |
|
110 | + if ($_resourceTypeConfig->checkIsHiddenFolder($_part)) { |
|
111 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - if (!is_dir($this->_currentFolder->getServerPath())) { |
|
117 | - if ($_clientPath == "/") { |
|
118 | - if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) { |
|
116 | + if (!is_dir($this->_currentFolder->getServerPath())) { |
|
117 | + if ($_clientPath == "/") { |
|
118 | + if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) { |
|
119 | 119 | |
120 | - } |
|
121 | - } |
|
122 | - else { |
|
123 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
120 | + } |
|
121 | + } |
|
122 | + else { |
|
123 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | 127 | } |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | function CKFinder_Connector_CommandHandler_CommandHandlerBase() |
55 | 55 | { |
56 | - $this->_currentFolder =& CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
57 | - $this->_connector =& CKFinder_Connector_Core_Factory::getInstance("Core_Connector"); |
|
58 | - $this->_errorHandler =& $this->_connector->getErrorHandler(); |
|
56 | + $this->_currentFolder = & CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
57 | + $this->_connector = & CKFinder_Connector_Core_Factory::getInstance("Core_Connector"); |
|
58 | + $this->_errorHandler = & $this->_connector->getErrorHandler(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | function getFolderHandler() |
68 | 68 | { |
69 | 69 | if (is_null($this->_currentFolder)) { |
70 | - $this->_currentFolder =& CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
70 | + $this->_currentFolder = & CKFinder_Connector_Core_Factory::getInstance("Core_FolderHandler"); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $this->_currentFolder; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function checkConnector() |
82 | 82 | { |
83 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
83 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
84 | 84 | if (!$_config->getIsEnabled()) { |
85 | 85 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED); |
86 | 86 | } |
@@ -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 |
@@ -119,8 +121,7 @@ discard block |
||
119 | 121 | if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) { |
120 | 122 | |
121 | 123 | } |
122 | - } |
|
123 | - else { |
|
124 | + } else { |
|
124 | 125 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
125 | 126 | } |
126 | 127 | } |
@@ -32,68 +32,68 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_DeleteFile extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private $command = "DeleteFile"; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - protected function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
54 | - |
|
55 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
56 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | - } |
|
58 | - |
|
59 | - if (!isset($_GET["FileName"])) { |
|
60 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
61 | - } |
|
62 | - |
|
63 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); |
|
64 | - $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
65 | - |
|
66 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $_resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
67 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
68 | - } |
|
69 | - |
|
70 | - if (!$_resourceTypeInfo->checkExtension($fileName, false)) { |
|
71 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
72 | - } |
|
73 | - |
|
74 | - $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
75 | - |
|
76 | - $bDeleted = false; |
|
77 | - |
|
78 | - if (!file_exists($filePath)) { |
|
79 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
80 | - } |
|
81 | - |
|
82 | - if (!@unlink($filePath)) { |
|
83 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
84 | - } else { |
|
85 | - $bDeleted = true; |
|
86 | - } |
|
87 | - |
|
88 | - if ($bDeleted) { |
|
89 | - $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
|
90 | - |
|
91 | - @unlink($thumbPath); |
|
92 | - |
|
93 | - $oDeleteFileNode = new Ckfinder_Connector_Utils_XmlNode("DeletedFile"); |
|
94 | - $this->_connectorNode->addChild($oDeleteFileNode); |
|
95 | - |
|
96 | - $oDeleteFileNode->addAttribute("name", $fileName); |
|
97 | - } |
|
98 | - } |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private $command = "DeleteFile"; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + protected function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | + |
|
55 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_DELETE)) { |
|
56 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | + } |
|
58 | + |
|
59 | + if (!isset($_GET["FileName"])) { |
|
60 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
61 | + } |
|
62 | + |
|
63 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); |
|
64 | + $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
65 | + |
|
66 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $_resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
67 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
68 | + } |
|
69 | + |
|
70 | + if (!$_resourceTypeInfo->checkExtension($fileName, false)) { |
|
71 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
72 | + } |
|
73 | + |
|
74 | + $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
75 | + |
|
76 | + $bDeleted = false; |
|
77 | + |
|
78 | + if (!file_exists($filePath)) { |
|
79 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
80 | + } |
|
81 | + |
|
82 | + if (!@unlink($filePath)) { |
|
83 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
84 | + } else { |
|
85 | + $bDeleted = true; |
|
86 | + } |
|
87 | + |
|
88 | + if ($bDeleted) { |
|
89 | + $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
|
90 | + |
|
91 | + @unlink($thumbPath); |
|
92 | + |
|
93 | + $oDeleteFileNode = new Ckfinder_Connector_Utils_XmlNode("DeletedFile"); |
|
94 | + $this->_connectorNode->addChild($oDeleteFileNode); |
|
95 | + |
|
96 | + $oDeleteFileNode->addAttribute("name", $fileName); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |
@@ -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,96 +32,96 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_RenameFile extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private $command = "RenameFile"; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * handle request and build XML |
|
46 | - * @access protected |
|
47 | - * |
|
48 | - */ |
|
49 | - protected function buildXml() |
|
50 | - { |
|
51 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | - } |
|
54 | - |
|
55 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME)) { |
|
56 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | - } |
|
58 | - |
|
59 | - if (!isset($_GET["fileName"])) { |
|
60 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
61 | - } |
|
62 | - if (!isset($_GET["newFileName"])) { |
|
63 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
64 | - } |
|
65 | - |
|
66 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
67 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); |
|
68 | - $newFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["newFileName"]); |
|
69 | - |
|
70 | - $oRenamedFileNode = new Ckfinder_Connector_Utils_XmlNode("RenamedFile"); |
|
71 | - $this->_connectorNode->addChild($oRenamedFileNode); |
|
72 | - $oRenamedFileNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName)); |
|
73 | - |
|
74 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
75 | - if (!$resourceTypeInfo->checkExtension($newFileName)) { |
|
76 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
77 | - } |
|
78 | - |
|
79 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
80 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
81 | - } |
|
82 | - |
|
83 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($newFileName) || $resourceTypeInfo->checkIsHiddenFile($newFileName)) { |
|
84 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
85 | - } |
|
86 | - |
|
87 | - if (!$resourceTypeInfo->checkExtension($fileName, false)) { |
|
88 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
89 | - } |
|
90 | - |
|
91 | - if ($_config->forceAscii()) { |
|
92 | - $newFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($newFileName); |
|
93 | - } |
|
94 | - |
|
95 | - $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
96 | - $newFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $newFileName); |
|
97 | - |
|
98 | - $bMoved = false; |
|
99 | - |
|
100 | - if (!file_exists($filePath)) { |
|
101 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
102 | - } |
|
103 | - |
|
104 | - if (!is_writable(dirname($newFilePath))) { |
|
105 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
106 | - } |
|
107 | - |
|
108 | - if (!is_writable($filePath)) { |
|
109 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
110 | - } |
|
111 | - |
|
112 | - if (file_exists($newFilePath)) { |
|
113 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
|
114 | - } |
|
115 | - |
|
116 | - $bMoved = @rename($filePath, $newFilePath); |
|
117 | - |
|
118 | - if (!$bMoved) { |
|
119 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN, "File " . CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName) . "has not been renamed"); |
|
120 | - } else { |
|
121 | - $oRenamedFileNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFileName)); |
|
122 | - |
|
123 | - $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
|
124 | - CKFinder_Connector_Utils_FileSystem::unlink($thumbPath); |
|
125 | - } |
|
126 | - } |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private $command = "RenameFile"; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * handle request and build XML |
|
46 | + * @access protected |
|
47 | + * |
|
48 | + */ |
|
49 | + protected function buildXml() |
|
50 | + { |
|
51 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
52 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
53 | + } |
|
54 | + |
|
55 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME)) { |
|
56 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | + } |
|
58 | + |
|
59 | + if (!isset($_GET["fileName"])) { |
|
60 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
61 | + } |
|
62 | + if (!isset($_GET["newFileName"])) { |
|
63 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
64 | + } |
|
65 | + |
|
66 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
67 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); |
|
68 | + $newFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["newFileName"]); |
|
69 | + |
|
70 | + $oRenamedFileNode = new Ckfinder_Connector_Utils_XmlNode("RenamedFile"); |
|
71 | + $this->_connectorNode->addChild($oRenamedFileNode); |
|
72 | + $oRenamedFileNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName)); |
|
73 | + |
|
74 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
75 | + if (!$resourceTypeInfo->checkExtension($newFileName)) { |
|
76 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
|
77 | + } |
|
78 | + |
|
79 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { |
|
80 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
81 | + } |
|
82 | + |
|
83 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($newFileName) || $resourceTypeInfo->checkIsHiddenFile($newFileName)) { |
|
84 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
85 | + } |
|
86 | + |
|
87 | + if (!$resourceTypeInfo->checkExtension($fileName, false)) { |
|
88 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
89 | + } |
|
90 | + |
|
91 | + if ($_config->forceAscii()) { |
|
92 | + $newFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($newFileName); |
|
93 | + } |
|
94 | + |
|
95 | + $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
96 | + $newFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $newFileName); |
|
97 | + |
|
98 | + $bMoved = false; |
|
99 | + |
|
100 | + if (!file_exists($filePath)) { |
|
101 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
102 | + } |
|
103 | + |
|
104 | + if (!is_writable(dirname($newFilePath))) { |
|
105 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
106 | + } |
|
107 | + |
|
108 | + if (!is_writable($filePath)) { |
|
109 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
110 | + } |
|
111 | + |
|
112 | + if (file_exists($newFilePath)) { |
|
113 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
|
114 | + } |
|
115 | + |
|
116 | + $bMoved = @rename($filePath, $newFilePath); |
|
117 | + |
|
118 | + if (!$bMoved) { |
|
119 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN, "File " . CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName) . "has not been renamed"); |
|
120 | + } else { |
|
121 | + $oRenamedFileNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFileName)); |
|
122 | + |
|
123 | + $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
|
124 | + CKFinder_Connector_Utils_FileSystem::unlink($thumbPath); |
|
125 | + } |
|
126 | + } |
|
127 | 127 | } |
@@ -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 RenameFile command |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
64 | 64 | } |
65 | 65 | |
66 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
66 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
67 | 67 | $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); |
68 | 68 | $newFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["newFileName"]); |
69 | 69 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $bMoved = @rename($filePath, $newFilePath); |
115 | 115 | |
116 | 116 | if (!$bMoved) { |
117 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN, "File " . CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName) . "has not been renamed"); |
|
117 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN, "File ".CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName)."has not been renamed"); |
|
118 | 118 | } else { |
119 | 119 | $oRenamedFileNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFileName)); |
120 | 120 |
@@ -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,297 +27,297 @@ |
||
27 | 27 | */ |
28 | 28 | class CKFinder_Connector_CommandHandler_Thumbnail extends CKFinder_Connector_CommandHandler_CommandHandlerBase |
29 | 29 | { |
30 | - /** |
|
31 | - * Command name |
|
32 | - * |
|
33 | - * @access private |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $command = "Thumbnail"; |
|
37 | - |
|
38 | - /** |
|
39 | - * handle request and send response |
|
40 | - * @access public |
|
41 | - * |
|
42 | - */ |
|
43 | - public function sendResponse() |
|
44 | - { |
|
45 | - if (!function_exists('ob_list_handlers') || ob_list_handlers()) { |
|
46 | - @ob_end_clean(); |
|
47 | - } |
|
48 | - header("Content-Encoding: none"); |
|
49 | - |
|
50 | - $this->checkConnector(); |
|
51 | - $this->checkRequest(); |
|
52 | - |
|
53 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
54 | - |
|
55 | - $_thumbnails = $_config->getThumbnailsConfig(); |
|
56 | - if (!$_thumbnails->getIsEnabled()) { |
|
57 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED); |
|
58 | - } |
|
59 | - |
|
60 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { |
|
61 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
62 | - } |
|
63 | - |
|
64 | - if (!isset($_GET["FileName"])) { |
|
65 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
66 | - } |
|
67 | - |
|
68 | - $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); |
|
69 | - $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
70 | - |
|
71 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { |
|
72 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
73 | - } |
|
74 | - |
|
75 | - $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
76 | - |
|
77 | - if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($sourceFilePath)) { |
|
78 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
79 | - } |
|
80 | - |
|
81 | - $thumbFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
|
82 | - |
|
83 | - // If the thumbnail file doesn't exists, create it now. |
|
84 | - if (!file_exists($thumbFilePath)) { |
|
85 | - if(!$this->createThumb($sourceFilePath, $thumbFilePath, $_thumbnails->getMaxWidth(), $_thumbnails->getMaxHeight(), $_thumbnails->getQuality(), true, $_thumbnails->getBmpSupported())) { |
|
86 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - $size = filesize($thumbFilePath); |
|
91 | - $sourceImageAttr = getimagesize($thumbFilePath); |
|
92 | - $mime = $sourceImageAttr["mime"]; |
|
93 | - |
|
94 | - $rtime = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])?@strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]):0; |
|
95 | - $mtime = filemtime($thumbFilePath); |
|
96 | - $etag = dechex($mtime) . "-" . dechex($size); |
|
97 | - |
|
98 | - $is304 = false; |
|
99 | - |
|
100 | - if (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag) { |
|
101 | - $is304 = true; |
|
102 | - } |
|
103 | - else if($rtime == $mtime) { |
|
104 | - $is304 = true; |
|
105 | - } |
|
106 | - |
|
107 | - if ($is304) { |
|
108 | - header("HTTP/1.0 304 Not Modified"); |
|
109 | - exit(); |
|
110 | - } |
|
111 | - |
|
112 | - //header("Cache-Control: cache, must-revalidate"); |
|
113 | - //header("Pragma: public"); |
|
114 | - //header("Expires: 0"); |
|
115 | - header('Cache-control: public'); |
|
116 | - header('Etag: ' . $etag); |
|
117 | - header("Content-type: " . $mime . "; name=\"" . CKFinder_Connector_Utils_Misc::mbBasename($thumbFilePath) . "\""); |
|
118 | - header("Last-Modified: ".gmdate('D, d M Y H:i:s', $mtime) . " GMT"); |
|
119 | - //header("Content-type: application/octet-stream; name=\"{$file}\""); |
|
120 | - //header("Content-Disposition: attachment; filename=\"{$file}\""); |
|
121 | - header("Content-Length: ".$size); |
|
122 | - readfile($thumbFilePath); |
|
123 | - exit; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Create thumbnail |
|
128 | - * |
|
129 | - * @param string $sourceFile |
|
130 | - * @param string $targetFile |
|
131 | - * @param int $maxWidth |
|
132 | - * @param int $maxHeight |
|
133 | - * @param boolean $preserverAspectRatio |
|
134 | - * @param boolean $bmpSupported |
|
135 | - * @return boolean |
|
136 | - * @static |
|
137 | - * @access public |
|
138 | - */ |
|
139 | - public static function createThumb($sourceFile, $targetFile, $maxWidth, $maxHeight, $quality, $preserverAspectRatio, $bmpSupported = false) |
|
140 | - { |
|
141 | - $sourceImageAttr = @getimagesize($sourceFile); |
|
142 | - if ($sourceImageAttr === false) { |
|
143 | - return false; |
|
144 | - } |
|
145 | - $sourceImageWidth = isset($sourceImageAttr[0]) ? $sourceImageAttr[0] : 0; |
|
146 | - $sourceImageHeight = isset($sourceImageAttr[1]) ? $sourceImageAttr[1] : 0; |
|
147 | - $sourceImageMime = isset($sourceImageAttr["mime"]) ? $sourceImageAttr["mime"] : ""; |
|
148 | - $sourceImageBits = isset($sourceImageAttr["bits"]) ? $sourceImageAttr["bits"] : 8; |
|
149 | - $sourceImageChannels = isset($sourceImageAttr["channels"]) ? $sourceImageAttr["channels"] : 3; |
|
150 | - |
|
151 | - if (!$sourceImageWidth || !$sourceImageHeight || !$sourceImageMime) { |
|
152 | - return false; |
|
153 | - } |
|
154 | - |
|
155 | - $iFinalWidth = $maxWidth == 0 ? $sourceImageWidth : $maxWidth; |
|
156 | - $iFinalHeight = $maxHeight == 0 ? $sourceImageHeight : $maxHeight; |
|
157 | - |
|
158 | - if ($sourceImageWidth <= $iFinalWidth && $sourceImageHeight <= $iFinalHeight) { |
|
159 | - if ($sourceFile != $targetFile) { |
|
160 | - copy($sourceFile, $targetFile); |
|
161 | - } |
|
162 | - return true; |
|
163 | - } |
|
164 | - |
|
165 | - if ($preserverAspectRatio) |
|
166 | - { |
|
167 | - // Gets the best size for aspect ratio resampling |
|
168 | - $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight ); |
|
169 | - } |
|
170 | - else { |
|
171 | - $oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight); |
|
172 | - } |
|
173 | - |
|
174 | - CKFinder_Connector_Utils_Misc::setMemoryForImage($sourceImageWidth, $sourceImageHeight, $sourceImageBits, $sourceImageChannels); |
|
175 | - |
|
176 | - switch ($sourceImageAttr['mime']) |
|
177 | - { |
|
178 | - case 'image/gif': |
|
179 | - { |
|
180 | - if (@imagetypes() & IMG_GIF) { |
|
181 | - $oImage = @imagecreatefromgif($sourceFile); |
|
182 | - } else { |
|
183 | - $ermsg = 'GIF images are not supported'; |
|
184 | - } |
|
185 | - } |
|
186 | - break; |
|
187 | - case 'image/jpeg': |
|
188 | - { |
|
189 | - if (@imagetypes() & IMG_JPG) { |
|
190 | - $oImage = @imagecreatefromjpeg($sourceFile) ; |
|
191 | - } else { |
|
192 | - $ermsg = 'JPEG images are not supported'; |
|
193 | - } |
|
194 | - } |
|
195 | - break; |
|
196 | - case 'image/png': |
|
197 | - { |
|
198 | - if (@imagetypes() & IMG_PNG) { |
|
199 | - $oImage = @imagecreatefrompng($sourceFile) ; |
|
200 | - } else { |
|
201 | - $ermsg = 'PNG images are not supported'; |
|
202 | - } |
|
203 | - } |
|
204 | - break; |
|
205 | - case 'image/wbmp': |
|
206 | - { |
|
207 | - if (@imagetypes() & IMG_WBMP) { |
|
208 | - $oImage = @imagecreatefromwbmp($sourceFile); |
|
209 | - } else { |
|
210 | - $ermsg = 'WBMP images are not supported'; |
|
211 | - } |
|
212 | - } |
|
213 | - break; |
|
214 | - case 'image/bmp': |
|
215 | - { |
|
216 | - /* |
|
30 | + /** |
|
31 | + * Command name |
|
32 | + * |
|
33 | + * @access private |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $command = "Thumbnail"; |
|
37 | + |
|
38 | + /** |
|
39 | + * handle request and send response |
|
40 | + * @access public |
|
41 | + * |
|
42 | + */ |
|
43 | + public function sendResponse() |
|
44 | + { |
|
45 | + if (!function_exists('ob_list_handlers') || ob_list_handlers()) { |
|
46 | + @ob_end_clean(); |
|
47 | + } |
|
48 | + header("Content-Encoding: none"); |
|
49 | + |
|
50 | + $this->checkConnector(); |
|
51 | + $this->checkRequest(); |
|
52 | + |
|
53 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
54 | + |
|
55 | + $_thumbnails = $_config->getThumbnailsConfig(); |
|
56 | + if (!$_thumbnails->getIsEnabled()) { |
|
57 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED); |
|
58 | + } |
|
59 | + |
|
60 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { |
|
61 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
62 | + } |
|
63 | + |
|
64 | + if (!isset($_GET["FileName"])) { |
|
65 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
66 | + } |
|
67 | + |
|
68 | + $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]); |
|
69 | + $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
70 | + |
|
71 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) { |
|
72 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
73 | + } |
|
74 | + |
|
75 | + $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
|
76 | + |
|
77 | + if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($sourceFilePath)) { |
|
78 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
|
79 | + } |
|
80 | + |
|
81 | + $thumbFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
|
82 | + |
|
83 | + // If the thumbnail file doesn't exists, create it now. |
|
84 | + if (!file_exists($thumbFilePath)) { |
|
85 | + if(!$this->createThumb($sourceFilePath, $thumbFilePath, $_thumbnails->getMaxWidth(), $_thumbnails->getMaxHeight(), $_thumbnails->getQuality(), true, $_thumbnails->getBmpSupported())) { |
|
86 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + $size = filesize($thumbFilePath); |
|
91 | + $sourceImageAttr = getimagesize($thumbFilePath); |
|
92 | + $mime = $sourceImageAttr["mime"]; |
|
93 | + |
|
94 | + $rtime = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])?@strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]):0; |
|
95 | + $mtime = filemtime($thumbFilePath); |
|
96 | + $etag = dechex($mtime) . "-" . dechex($size); |
|
97 | + |
|
98 | + $is304 = false; |
|
99 | + |
|
100 | + if (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag) { |
|
101 | + $is304 = true; |
|
102 | + } |
|
103 | + else if($rtime == $mtime) { |
|
104 | + $is304 = true; |
|
105 | + } |
|
106 | + |
|
107 | + if ($is304) { |
|
108 | + header("HTTP/1.0 304 Not Modified"); |
|
109 | + exit(); |
|
110 | + } |
|
111 | + |
|
112 | + //header("Cache-Control: cache, must-revalidate"); |
|
113 | + //header("Pragma: public"); |
|
114 | + //header("Expires: 0"); |
|
115 | + header('Cache-control: public'); |
|
116 | + header('Etag: ' . $etag); |
|
117 | + header("Content-type: " . $mime . "; name=\"" . CKFinder_Connector_Utils_Misc::mbBasename($thumbFilePath) . "\""); |
|
118 | + header("Last-Modified: ".gmdate('D, d M Y H:i:s', $mtime) . " GMT"); |
|
119 | + //header("Content-type: application/octet-stream; name=\"{$file}\""); |
|
120 | + //header("Content-Disposition: attachment; filename=\"{$file}\""); |
|
121 | + header("Content-Length: ".$size); |
|
122 | + readfile($thumbFilePath); |
|
123 | + exit; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Create thumbnail |
|
128 | + * |
|
129 | + * @param string $sourceFile |
|
130 | + * @param string $targetFile |
|
131 | + * @param int $maxWidth |
|
132 | + * @param int $maxHeight |
|
133 | + * @param boolean $preserverAspectRatio |
|
134 | + * @param boolean $bmpSupported |
|
135 | + * @return boolean |
|
136 | + * @static |
|
137 | + * @access public |
|
138 | + */ |
|
139 | + public static function createThumb($sourceFile, $targetFile, $maxWidth, $maxHeight, $quality, $preserverAspectRatio, $bmpSupported = false) |
|
140 | + { |
|
141 | + $sourceImageAttr = @getimagesize($sourceFile); |
|
142 | + if ($sourceImageAttr === false) { |
|
143 | + return false; |
|
144 | + } |
|
145 | + $sourceImageWidth = isset($sourceImageAttr[0]) ? $sourceImageAttr[0] : 0; |
|
146 | + $sourceImageHeight = isset($sourceImageAttr[1]) ? $sourceImageAttr[1] : 0; |
|
147 | + $sourceImageMime = isset($sourceImageAttr["mime"]) ? $sourceImageAttr["mime"] : ""; |
|
148 | + $sourceImageBits = isset($sourceImageAttr["bits"]) ? $sourceImageAttr["bits"] : 8; |
|
149 | + $sourceImageChannels = isset($sourceImageAttr["channels"]) ? $sourceImageAttr["channels"] : 3; |
|
150 | + |
|
151 | + if (!$sourceImageWidth || !$sourceImageHeight || !$sourceImageMime) { |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + $iFinalWidth = $maxWidth == 0 ? $sourceImageWidth : $maxWidth; |
|
156 | + $iFinalHeight = $maxHeight == 0 ? $sourceImageHeight : $maxHeight; |
|
157 | + |
|
158 | + if ($sourceImageWidth <= $iFinalWidth && $sourceImageHeight <= $iFinalHeight) { |
|
159 | + if ($sourceFile != $targetFile) { |
|
160 | + copy($sourceFile, $targetFile); |
|
161 | + } |
|
162 | + return true; |
|
163 | + } |
|
164 | + |
|
165 | + if ($preserverAspectRatio) |
|
166 | + { |
|
167 | + // Gets the best size for aspect ratio resampling |
|
168 | + $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight ); |
|
169 | + } |
|
170 | + else { |
|
171 | + $oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight); |
|
172 | + } |
|
173 | + |
|
174 | + CKFinder_Connector_Utils_Misc::setMemoryForImage($sourceImageWidth, $sourceImageHeight, $sourceImageBits, $sourceImageChannels); |
|
175 | + |
|
176 | + switch ($sourceImageAttr['mime']) |
|
177 | + { |
|
178 | + case 'image/gif': |
|
179 | + { |
|
180 | + if (@imagetypes() & IMG_GIF) { |
|
181 | + $oImage = @imagecreatefromgif($sourceFile); |
|
182 | + } else { |
|
183 | + $ermsg = 'GIF images are not supported'; |
|
184 | + } |
|
185 | + } |
|
186 | + break; |
|
187 | + case 'image/jpeg': |
|
188 | + { |
|
189 | + if (@imagetypes() & IMG_JPG) { |
|
190 | + $oImage = @imagecreatefromjpeg($sourceFile) ; |
|
191 | + } else { |
|
192 | + $ermsg = 'JPEG images are not supported'; |
|
193 | + } |
|
194 | + } |
|
195 | + break; |
|
196 | + case 'image/png': |
|
197 | + { |
|
198 | + if (@imagetypes() & IMG_PNG) { |
|
199 | + $oImage = @imagecreatefrompng($sourceFile) ; |
|
200 | + } else { |
|
201 | + $ermsg = 'PNG images are not supported'; |
|
202 | + } |
|
203 | + } |
|
204 | + break; |
|
205 | + case 'image/wbmp': |
|
206 | + { |
|
207 | + if (@imagetypes() & IMG_WBMP) { |
|
208 | + $oImage = @imagecreatefromwbmp($sourceFile); |
|
209 | + } else { |
|
210 | + $ermsg = 'WBMP images are not supported'; |
|
211 | + } |
|
212 | + } |
|
213 | + break; |
|
214 | + case 'image/bmp': |
|
215 | + { |
|
216 | + /* |
|
217 | 217 | * This is sad that PHP doesn't support bitmaps. |
218 | 218 | * Anyway, we will use our custom function at least to display thumbnails. |
219 | 219 | * We'll not resize images this way (if $sourceFile === $targetFile), |
220 | 220 | * because user defined imagecreatefrombmp and imagecreatebmp are horribly slow |
221 | 221 | */ |
222 | - if ($bmpSupported && (@imagetypes() & IMG_JPG) && $sourceFile != $targetFile) { |
|
223 | - $oImage = CKFinder_Connector_Utils_Misc::imageCreateFromBmp($sourceFile); |
|
224 | - } else { |
|
225 | - $ermsg = 'BMP/JPG images are not supported'; |
|
226 | - } |
|
227 | - } |
|
228 | - break; |
|
229 | - default: |
|
230 | - $ermsg = $sourceImageAttr['mime'].' images are not supported'; |
|
231 | - break; |
|
232 | - } |
|
233 | - |
|
234 | - if (isset($ermsg) || false === $oImage) { |
|
235 | - return false; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - $oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]); |
|
240 | - //imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight); |
|
241 | - CKFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int)max(floor($quality/20), 1)); |
|
242 | - |
|
243 | - switch ($sourceImageAttr['mime']) |
|
244 | - { |
|
245 | - case 'image/gif': |
|
246 | - imagegif($oThumbImage, $targetFile); |
|
247 | - break; |
|
248 | - case 'image/jpeg': |
|
249 | - case 'image/bmp': |
|
250 | - imagejpeg($oThumbImage, $targetFile, $quality); |
|
251 | - break; |
|
252 | - case 'image/png': |
|
253 | - imagepng($oThumbImage, $targetFile); |
|
254 | - break; |
|
255 | - case 'image/wbmp': |
|
256 | - imagewbmp($oThumbImage, $targetFile); |
|
257 | - break; |
|
258 | - } |
|
259 | - |
|
260 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
261 | - if (file_exists($targetFile) && ($perms = $_config->getChmodFiles())) { |
|
262 | - $oldUmask = umask(0); |
|
263 | - chmod($targetFile, $perms); |
|
264 | - umask($oldUmask); |
|
265 | - } |
|
266 | - |
|
267 | - imageDestroy($oImage); |
|
268 | - imageDestroy($oThumbImage); |
|
269 | - |
|
270 | - return true; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Return aspect ratio size, returns associative array: |
|
277 | - * <pre> |
|
278 | - * Array |
|
279 | - * ( |
|
280 | - * [Width] => 80 |
|
281 | - * [Heigth] => 120 |
|
282 | - * ) |
|
283 | - * </pre> |
|
284 | - * |
|
285 | - * @param int $maxWidth |
|
286 | - * @param int $maxHeight |
|
287 | - * @param int $actualWidth |
|
288 | - * @param int $actualHeight |
|
289 | - * @return array |
|
290 | - * @static |
|
291 | - * @access public |
|
292 | - */ |
|
293 | - public static function getAspectRatioSize($maxWidth, $maxHeight, $actualWidth, $actualHeight) |
|
294 | - { |
|
295 | - $oSize = array("Width"=>$maxWidth, "Height"=>$maxHeight); |
|
296 | - |
|
297 | - // Calculates the X and Y resize factors |
|
298 | - $iFactorX = (float)$maxWidth / (float)$actualWidth; |
|
299 | - $iFactorY = (float)$maxHeight / (float)$actualHeight; |
|
300 | - |
|
301 | - // If some dimension have to be scaled |
|
302 | - if ($iFactorX != 1 || $iFactorY != 1) |
|
303 | - { |
|
304 | - // Uses the lower Factor to scale the oposite size |
|
305 | - if ($iFactorX < $iFactorY) { |
|
306 | - $oSize["Height"] = (int)round($actualHeight * $iFactorX); |
|
307 | - } |
|
308 | - else if ($iFactorX > $iFactorY) { |
|
309 | - $oSize["Width"] = (int)round($actualWidth * $iFactorY); |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - if ($oSize["Height"] <= 0) { |
|
314 | - $oSize["Height"] = 1; |
|
315 | - } |
|
316 | - if ($oSize["Width"] <= 0) { |
|
317 | - $oSize["Width"] = 1; |
|
318 | - } |
|
319 | - |
|
320 | - // Returns the Size |
|
321 | - return $oSize; |
|
322 | - } |
|
222 | + if ($bmpSupported && (@imagetypes() & IMG_JPG) && $sourceFile != $targetFile) { |
|
223 | + $oImage = CKFinder_Connector_Utils_Misc::imageCreateFromBmp($sourceFile); |
|
224 | + } else { |
|
225 | + $ermsg = 'BMP/JPG images are not supported'; |
|
226 | + } |
|
227 | + } |
|
228 | + break; |
|
229 | + default: |
|
230 | + $ermsg = $sourceImageAttr['mime'].' images are not supported'; |
|
231 | + break; |
|
232 | + } |
|
233 | + |
|
234 | + if (isset($ermsg) || false === $oImage) { |
|
235 | + return false; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + $oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]); |
|
240 | + //imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight); |
|
241 | + CKFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int)max(floor($quality/20), 1)); |
|
242 | + |
|
243 | + switch ($sourceImageAttr['mime']) |
|
244 | + { |
|
245 | + case 'image/gif': |
|
246 | + imagegif($oThumbImage, $targetFile); |
|
247 | + break; |
|
248 | + case 'image/jpeg': |
|
249 | + case 'image/bmp': |
|
250 | + imagejpeg($oThumbImage, $targetFile, $quality); |
|
251 | + break; |
|
252 | + case 'image/png': |
|
253 | + imagepng($oThumbImage, $targetFile); |
|
254 | + break; |
|
255 | + case 'image/wbmp': |
|
256 | + imagewbmp($oThumbImage, $targetFile); |
|
257 | + break; |
|
258 | + } |
|
259 | + |
|
260 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
261 | + if (file_exists($targetFile) && ($perms = $_config->getChmodFiles())) { |
|
262 | + $oldUmask = umask(0); |
|
263 | + chmod($targetFile, $perms); |
|
264 | + umask($oldUmask); |
|
265 | + } |
|
266 | + |
|
267 | + imageDestroy($oImage); |
|
268 | + imageDestroy($oThumbImage); |
|
269 | + |
|
270 | + return true; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Return aspect ratio size, returns associative array: |
|
277 | + * <pre> |
|
278 | + * Array |
|
279 | + * ( |
|
280 | + * [Width] => 80 |
|
281 | + * [Heigth] => 120 |
|
282 | + * ) |
|
283 | + * </pre> |
|
284 | + * |
|
285 | + * @param int $maxWidth |
|
286 | + * @param int $maxHeight |
|
287 | + * @param int $actualWidth |
|
288 | + * @param int $actualHeight |
|
289 | + * @return array |
|
290 | + * @static |
|
291 | + * @access public |
|
292 | + */ |
|
293 | + public static function getAspectRatioSize($maxWidth, $maxHeight, $actualWidth, $actualHeight) |
|
294 | + { |
|
295 | + $oSize = array("Width"=>$maxWidth, "Height"=>$maxHeight); |
|
296 | + |
|
297 | + // Calculates the X and Y resize factors |
|
298 | + $iFactorX = (float)$maxWidth / (float)$actualWidth; |
|
299 | + $iFactorY = (float)$maxHeight / (float)$actualHeight; |
|
300 | + |
|
301 | + // If some dimension have to be scaled |
|
302 | + if ($iFactorX != 1 || $iFactorY != 1) |
|
303 | + { |
|
304 | + // Uses the lower Factor to scale the oposite size |
|
305 | + if ($iFactorX < $iFactorY) { |
|
306 | + $oSize["Height"] = (int)round($actualHeight * $iFactorX); |
|
307 | + } |
|
308 | + else if ($iFactorX > $iFactorY) { |
|
309 | + $oSize["Width"] = (int)round($actualWidth * $iFactorY); |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + if ($oSize["Height"] <= 0) { |
|
314 | + $oSize["Height"] = 1; |
|
315 | + } |
|
316 | + if ($oSize["Width"] <= 0) { |
|
317 | + $oSize["Width"] = 1; |
|
318 | + } |
|
319 | + |
|
320 | + // Returns the Size |
|
321 | + return $oSize; |
|
322 | + } |
|
323 | 323 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $this->checkConnector(); |
51 | 51 | $this->checkRequest(); |
52 | 52 | |
53 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
53 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
54 | 54 | |
55 | 55 | $_thumbnails = $_config->getThumbnailsConfig(); |
56 | 56 | if (!$_thumbnails->getIsEnabled()) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | // If the thumbnail file doesn't exists, create it now. |
84 | 84 | if (!file_exists($thumbFilePath)) { |
85 | - if(!$this->createThumb($sourceFilePath, $thumbFilePath, $_thumbnails->getMaxWidth(), $_thumbnails->getMaxHeight(), $_thumbnails->getQuality(), true, $_thumbnails->getBmpSupported())) { |
|
85 | + if (!$this->createThumb($sourceFilePath, $thumbFilePath, $_thumbnails->getMaxWidth(), $_thumbnails->getMaxHeight(), $_thumbnails->getQuality(), true, $_thumbnails->getBmpSupported())) { |
|
86 | 86 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
87 | 87 | } |
88 | 88 | } |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | $sourceImageAttr = getimagesize($thumbFilePath); |
92 | 92 | $mime = $sourceImageAttr["mime"]; |
93 | 93 | |
94 | - $rtime = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])?@strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]):0; |
|
95 | - $mtime = filemtime($thumbFilePath); |
|
96 | - $etag = dechex($mtime) . "-" . dechex($size); |
|
94 | + $rtime = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) ? @strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) : 0; |
|
95 | + $mtime = filemtime($thumbFilePath); |
|
96 | + $etag = dechex($mtime)."-".dechex($size); |
|
97 | 97 | |
98 | 98 | $is304 = false; |
99 | 99 | |
100 | 100 | if (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag) { |
101 | 101 | $is304 = true; |
102 | 102 | } |
103 | - else if($rtime == $mtime) { |
|
103 | + else if ($rtime == $mtime) { |
|
104 | 104 | $is304 = true; |
105 | 105 | } |
106 | 106 | |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | //header("Pragma: public"); |
114 | 114 | //header("Expires: 0"); |
115 | 115 | header('Cache-control: public'); |
116 | - header('Etag: ' . $etag); |
|
117 | - header("Content-type: " . $mime . "; name=\"" . CKFinder_Connector_Utils_Misc::mbBasename($thumbFilePath) . "\""); |
|
118 | - header("Last-Modified: ".gmdate('D, d M Y H:i:s', $mtime) . " GMT"); |
|
116 | + header('Etag: '.$etag); |
|
117 | + header("Content-type: ".$mime."; name=\"".CKFinder_Connector_Utils_Misc::mbBasename($thumbFilePath)."\""); |
|
118 | + header("Last-Modified: ".gmdate('D, d M Y H:i:s', $mtime)." GMT"); |
|
119 | 119 | //header("Content-type: application/octet-stream; name=\"{$file}\""); |
120 | 120 | //header("Content-Disposition: attachment; filename=\"{$file}\""); |
121 | 121 | header("Content-Length: ".$size); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | if ($preserverAspectRatio) |
166 | 166 | { |
167 | 167 | // Gets the best size for aspect ratio resampling |
168 | - $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight ); |
|
168 | + $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight); |
|
169 | 169 | } |
170 | 170 | else { |
171 | 171 | $oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | case 'image/jpeg': |
188 | 188 | { |
189 | 189 | if (@imagetypes() & IMG_JPG) { |
190 | - $oImage = @imagecreatefromjpeg($sourceFile) ; |
|
190 | + $oImage = @imagecreatefromjpeg($sourceFile); |
|
191 | 191 | } else { |
192 | 192 | $ermsg = 'JPEG images are not supported'; |
193 | 193 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | case 'image/png': |
197 | 197 | { |
198 | 198 | if (@imagetypes() & IMG_PNG) { |
199 | - $oImage = @imagecreatefrompng($sourceFile) ; |
|
199 | + $oImage = @imagecreatefrompng($sourceFile); |
|
200 | 200 | } else { |
201 | 201 | $ermsg = 'PNG images are not supported'; |
202 | 202 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | $oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]); |
240 | 240 | //imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight); |
241 | - CKFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int)max(floor($quality/20), 1)); |
|
241 | + CKFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int)max(floor($quality / 20), 1)); |
|
242 | 242 | |
243 | 243 | switch ($sourceImageAttr['mime']) |
244 | 244 | { |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | break; |
258 | 258 | } |
259 | 259 | |
260 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
260 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
261 | 261 | if (file_exists($targetFile) && ($perms = $_config->getChmodFiles())) { |
262 | 262 | $oldUmask = umask(0); |
263 | 263 | chmod($targetFile, $perms); |
@@ -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 |
@@ -98,8 +100,7 @@ discard block |
||
98 | 100 | |
99 | 101 | if (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag) { |
100 | 102 | $is304 = true; |
101 | - } |
|
102 | - else if($rtime == $mtime) { |
|
103 | + } else if($rtime == $mtime) { |
|
103 | 104 | $is304 = true; |
104 | 105 | } |
105 | 106 | |
@@ -165,8 +166,7 @@ discard block |
||
165 | 166 | { |
166 | 167 | // Gets the best size for aspect ratio resampling |
167 | 168 | $oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight ); |
168 | - } |
|
169 | - else { |
|
169 | + } else { |
|
170 | 170 | $oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight); |
171 | 171 | } |
172 | 172 | |
@@ -303,8 +303,7 @@ discard block |
||
303 | 303 | // Uses the lower Factor to scale the oposite size |
304 | 304 | if ($iFactorX < $iFactorY) { |
305 | 305 | $oSize["Height"] = (int)round($actualHeight * $iFactorX); |
306 | - } |
|
307 | - else if ($iFactorX > $iFactorY) { |
|
306 | + } else if ($iFactorX > $iFactorY) { |
|
308 | 307 | $oSize["Width"] = (int)round($actualWidth * $iFactorY); |
309 | 308 | } |
310 | 309 | } |
@@ -32,98 +32,98 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_GetFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private $command = "GetFiles"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private $command = "GetFiles"; |
|
42 | 42 | |
43 | - /** |
|
44 | - * handle request and build XML |
|
45 | - * @access protected |
|
46 | - * |
|
47 | - */ |
|
48 | - protected function buildXml() |
|
49 | - { |
|
50 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
51 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) { |
|
52 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
53 | - } |
|
43 | + /** |
|
44 | + * handle request and build XML |
|
45 | + * @access protected |
|
46 | + * |
|
47 | + */ |
|
48 | + protected function buildXml() |
|
49 | + { |
|
50 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
51 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_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 | - // Create the "Files" node. |
|
59 | - $oFilesNode = new Ckfinder_Connector_Utils_XmlNode("Files"); |
|
60 | - $this->_connectorNode->addChild($oFilesNode); |
|
58 | + // Create the "Files" node. |
|
59 | + $oFilesNode = new Ckfinder_Connector_Utils_XmlNode("Files"); |
|
60 | + $this->_connectorNode->addChild($oFilesNode); |
|
61 | 61 | |
62 | - if (!is_dir($_sServerDir)) { |
|
63 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
64 | - } |
|
62 | + if (!is_dir($_sServerDir)) { |
|
63 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND); |
|
64 | + } |
|
65 | 65 | |
66 | - $files = array(); |
|
67 | - $thumbFiles = array(); |
|
66 | + $files = array(); |
|
67 | + $thumbFiles = array(); |
|
68 | 68 | |
69 | - if ($dh = @opendir($_sServerDir)) { |
|
70 | - while (($file = readdir($dh)) !== false) { |
|
71 | - if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) { |
|
72 | - $files[] = $file; |
|
73 | - } |
|
74 | - } |
|
75 | - closedir($dh); |
|
76 | - } else { |
|
77 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
78 | - } |
|
69 | + if ($dh = @opendir($_sServerDir)) { |
|
70 | + while (($file = readdir($dh)) !== false) { |
|
71 | + if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) { |
|
72 | + $files[] = $file; |
|
73 | + } |
|
74 | + } |
|
75 | + closedir($dh); |
|
76 | + } else { |
|
77 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
78 | + } |
|
79 | 79 | |
80 | - $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
80 | + $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
|
81 | 81 | |
82 | - if (sizeof($files)>0) { |
|
83 | - $_thumbnailsConfig = $_config->getThumbnailsConfig(); |
|
84 | - $_thumbServerPath = ''; |
|
85 | - $_showThumbs = (!empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1); |
|
86 | - if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) { |
|
87 | - $_thumbServerPath = $this->_currentFolder->getThumbsServerPath(); |
|
88 | - } |
|
82 | + if (sizeof($files)>0) { |
|
83 | + $_thumbnailsConfig = $_config->getThumbnailsConfig(); |
|
84 | + $_thumbServerPath = ''; |
|
85 | + $_showThumbs = (!empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1); |
|
86 | + if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) { |
|
87 | + $_thumbServerPath = $this->_currentFolder->getThumbsServerPath(); |
|
88 | + } |
|
89 | 89 | |
90 | - natcasesort($files); |
|
91 | - $i=0; |
|
92 | - foreach ($files as $file) { |
|
93 | - $filemtime = @filemtime($_sServerDir . $file); |
|
90 | + natcasesort($files); |
|
91 | + $i=0; |
|
92 | + foreach ($files as $file) { |
|
93 | + $filemtime = @filemtime($_sServerDir . $file); |
|
94 | 94 | |
95 | - //otherwise file doesn't exist or we can't get it's filename properly |
|
96 | - if ($filemtime !== false) { |
|
97 | - $filename = CKFinder_Connector_Utils_Misc::mbBasename($file); |
|
98 | - if (!$resourceTypeInfo->checkExtension($filename, false)) { |
|
99 | - continue; |
|
100 | - } |
|
101 | - if ($resourceTypeInfo->checkIsHiddenFile($filename)) { |
|
102 | - continue; |
|
103 | - } |
|
104 | - $oFileNode[$i] = new Ckfinder_Connector_Utils_XmlNode("File"); |
|
105 | - $oFilesNode->addChild($oFileNode[$i]); |
|
106 | - $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(CKFinder_Connector_Utils_Misc::mbBasename($file))); |
|
107 | - $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime)); |
|
108 | - if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) { |
|
109 | - if (file_exists($_thumbServerPath . $filename)) { |
|
110 | - $oFileNode[$i]->addAttribute("thumb", $filename); |
|
111 | - } |
|
112 | - elseif ($_showThumbs) { |
|
113 | - $oFileNode[$i]->addAttribute("thumb", "?" . $filename); |
|
114 | - } |
|
115 | - } |
|
116 | - $size = filesize($_sServerDir . $file); |
|
117 | - if ($size && $size<1024) { |
|
118 | - $size = 1; |
|
119 | - } |
|
120 | - else { |
|
121 | - $size = (int)round($size / 1024); |
|
122 | - } |
|
123 | - $oFileNode[$i]->addAttribute("size", $size); |
|
124 | - $i++; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
95 | + //otherwise file doesn't exist or we can't get it's filename properly |
|
96 | + if ($filemtime !== false) { |
|
97 | + $filename = CKFinder_Connector_Utils_Misc::mbBasename($file); |
|
98 | + if (!$resourceTypeInfo->checkExtension($filename, false)) { |
|
99 | + continue; |
|
100 | + } |
|
101 | + if ($resourceTypeInfo->checkIsHiddenFile($filename)) { |
|
102 | + continue; |
|
103 | + } |
|
104 | + $oFileNode[$i] = new Ckfinder_Connector_Utils_XmlNode("File"); |
|
105 | + $oFilesNode->addChild($oFileNode[$i]); |
|
106 | + $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(CKFinder_Connector_Utils_Misc::mbBasename($file))); |
|
107 | + $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime)); |
|
108 | + if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) { |
|
109 | + if (file_exists($_thumbServerPath . $filename)) { |
|
110 | + $oFileNode[$i]->addAttribute("thumb", $filename); |
|
111 | + } |
|
112 | + elseif ($_showThumbs) { |
|
113 | + $oFileNode[$i]->addAttribute("thumb", "?" . $filename); |
|
114 | + } |
|
115 | + } |
|
116 | + $size = filesize($_sServerDir . $file); |
|
117 | + if ($size && $size<1024) { |
|
118 | + $size = 1; |
|
119 | + } |
|
120 | + else { |
|
121 | + $size = (int)round($size / 1024); |
|
122 | + } |
|
123 | + $oFileNode[$i]->addAttribute("size", $size); |
|
124 | + $i++; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | 129 | } |
@@ -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 GetFiles 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_FILE_VIEW)) { |
52 | 52 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
53 | 53 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | if ($dh = @opendir($_sServerDir)) { |
70 | 70 | while (($file = readdir($dh)) !== false) { |
71 | - if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) { |
|
71 | + if ($file != "." && $file != ".." && !is_dir($_sServerDir.$file)) { |
|
72 | 72 | $files[] = $file; |
73 | 73 | } |
74 | 74 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
81 | 81 | |
82 | - if (sizeof($files)>0) { |
|
82 | + if (sizeof($files) > 0) { |
|
83 | 83 | $_thumbnailsConfig = $_config->getThumbnailsConfig(); |
84 | 84 | $_thumbServerPath = ''; |
85 | 85 | $_showThumbs = (!empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1); |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | natcasesort($files); |
91 | - $i=0; |
|
91 | + $i = 0; |
|
92 | 92 | foreach ($files as $file) { |
93 | - $filemtime = @filemtime($_sServerDir . $file); |
|
93 | + $filemtime = @filemtime($_sServerDir.$file); |
|
94 | 94 | |
95 | 95 | //otherwise file doesn't exist or we can't get it's filename properly |
96 | 96 | if ($filemtime !== false) { |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | $oFileNode[$i]->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(CKFinder_Connector_Utils_Misc::mbBasename($file))); |
107 | 107 | $oFileNode[$i]->addAttribute("date", date("YmdHi", $filemtime)); |
108 | 108 | if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) { |
109 | - if (file_exists($_thumbServerPath . $filename)) { |
|
109 | + if (file_exists($_thumbServerPath.$filename)) { |
|
110 | 110 | $oFileNode[$i]->addAttribute("thumb", $filename); |
111 | 111 | } |
112 | 112 | elseif ($_showThumbs) { |
113 | - $oFileNode[$i]->addAttribute("thumb", "?" . $filename); |
|
113 | + $oFileNode[$i]->addAttribute("thumb", "?".$filename); |
|
114 | 114 | } |
115 | 115 | } |
116 | - $size = filesize($_sServerDir . $file); |
|
117 | - if ($size && $size<1024) { |
|
116 | + $size = filesize($_sServerDir.$file); |
|
117 | + if ($size && $size < 1024) { |
|
118 | 118 | $size = 1; |
119 | 119 | } |
120 | 120 | else { |
@@ -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 |
@@ -108,16 +110,14 @@ discard block |
||
108 | 110 | if (!empty($_thumbServerPath) && preg_match(CKFINDER_REGEX_IMAGES_EXT, $filename)) { |
109 | 111 | if (file_exists($_thumbServerPath . $filename)) { |
110 | 112 | $oFileNode[$i]->addAttribute("thumb", $filename); |
111 | - } |
|
112 | - elseif ($_showThumbs) { |
|
113 | + } elseif ($_showThumbs) { |
|
113 | 114 | $oFileNode[$i]->addAttribute("thumb", "?" . $filename); |
114 | 115 | } |
115 | 116 | } |
116 | 117 | $size = filesize($_sServerDir . $file); |
117 | 118 | if ($size && $size<1024) { |
118 | 119 | $size = 1; |
119 | - } |
|
120 | - else { |
|
120 | + } else { |
|
121 | 121 | $size = (int)round($size / 1024); |
122 | 122 | } |
123 | 123 | $oFileNode[$i]->addAttribute("size", $size); |
@@ -32,19 +32,19 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_QuickUpload extends CKFinder_Connector_CommandHandler_FileUpload |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access protected |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $command = "QuickUpload"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access protected |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $command = "QuickUpload"; |
|
42 | 42 | |
43 | - function sendResponse() |
|
44 | - { |
|
45 | - $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
46 | - $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
|
43 | + function sendResponse() |
|
44 | + { |
|
45 | + $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
46 | + $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
|
47 | 47 | |
48 | - return parent::sendResponse(); |
|
49 | - } |
|
48 | + return parent::sendResponse(); |
|
49 | + } |
|
50 | 50 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Include file upload command handler |
23 | 23 | */ |
24 | -require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/FileUpload.php"; |
|
24 | +require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/FileUpload.php"; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Handle QuickUpload command |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | function sendResponse() |
44 | 44 | { |
45 | - $oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
45 | + $oRegistry = & CKFinder_Connector_Core_Factory::getInstance("Core_Registry"); |
|
46 | 46 | $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl()); |
47 | 47 | |
48 | 48 | return parent::sendResponse(); |
@@ -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,67 +32,67 @@ |
||
32 | 32 | */ |
33 | 33 | class CKFinder_Connector_CommandHandler_CreateFolder extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase |
34 | 34 | { |
35 | - /** |
|
36 | - * Command name |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private $command = "CreateFolder"; |
|
35 | + /** |
|
36 | + * Command name |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private $command = "CreateFolder"; |
|
42 | 42 | |
43 | - /** |
|
44 | - * handle request and build XML |
|
45 | - * @access protected |
|
46 | - * |
|
47 | - */ |
|
48 | - protected function buildXml() |
|
49 | - { |
|
50 | - if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
51 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
52 | - } |
|
43 | + /** |
|
44 | + * handle request and build XML |
|
45 | + * @access protected |
|
46 | + * |
|
47 | + */ |
|
48 | + protected function buildXml() |
|
49 | + { |
|
50 | + if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
|
51 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
|
52 | + } |
|
53 | 53 | |
54 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
55 | - if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) { |
|
56 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | - } |
|
54 | + $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
55 | + if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) { |
|
56 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
|
57 | + } |
|
58 | 58 | |
59 | - $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
60 | - $sNewFolderName = isset($_GET["NewFolderName"]) ? $_GET["NewFolderName"] : ""; |
|
61 | - $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName); |
|
62 | - if ($_config->forceAscii()) { |
|
63 | - $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sNewFolderName); |
|
64 | - } |
|
59 | + $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig(); |
|
60 | + $sNewFolderName = isset($_GET["NewFolderName"]) ? $_GET["NewFolderName"] : ""; |
|
61 | + $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName); |
|
62 | + if ($_config->forceAscii()) { |
|
63 | + $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToAscii($sNewFolderName); |
|
64 | + } |
|
65 | 65 | |
66 | - if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sNewFolderName) || $_resourceTypeConfig->checkIsHiddenFolder($sNewFolderName)) { |
|
67 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
68 | - } |
|
66 | + if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sNewFolderName) || $_resourceTypeConfig->checkIsHiddenFolder($sNewFolderName)) { |
|
67 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
|
68 | + } |
|
69 | 69 | |
70 | - $sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName); |
|
71 | - if (!is_writeable($this->_currentFolder->getServerPath())) { |
|
72 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
73 | - } |
|
70 | + $sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName); |
|
71 | + if (!is_writeable($this->_currentFolder->getServerPath())) { |
|
72 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
73 | + } |
|
74 | 74 | |
75 | - $bCreated = false; |
|
75 | + $bCreated = false; |
|
76 | 76 | |
77 | - if (file_exists($sServerDir)) { |
|
78 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
|
79 | - } |
|
77 | + if (file_exists($sServerDir)) { |
|
78 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
|
79 | + } |
|
80 | 80 | |
81 | - if ($perms = $_config->getChmodFolders()) { |
|
82 | - $oldUmask = umask(0); |
|
83 | - $bCreated = @mkdir($sServerDir, $perms); |
|
84 | - umask($oldUmask); |
|
85 | - } |
|
86 | - else { |
|
87 | - $bCreated = @mkdir($sServerDir); |
|
88 | - } |
|
81 | + if ($perms = $_config->getChmodFolders()) { |
|
82 | + $oldUmask = umask(0); |
|
83 | + $bCreated = @mkdir($sServerDir, $perms); |
|
84 | + umask($oldUmask); |
|
85 | + } |
|
86 | + else { |
|
87 | + $bCreated = @mkdir($sServerDir); |
|
88 | + } |
|
89 | 89 | |
90 | - if (!$bCreated) { |
|
91 | - $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
92 | - } else { |
|
93 | - $oNewFolderNode = new Ckfinder_Connector_Utils_XmlNode("NewFolder"); |
|
94 | - $this->_connectorNode->addChild($oNewFolderNode); |
|
95 | - $oNewFolderNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName)); |
|
96 | - } |
|
97 | - } |
|
90 | + if (!$bCreated) { |
|
91 | + $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
|
92 | + } else { |
|
93 | + $oNewFolderNode = new Ckfinder_Connector_Utils_XmlNode("NewFolder"); |
|
94 | + $this->_connectorNode->addChild($oNewFolderNode); |
|
95 | + $oNewFolderNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName)); |
|
96 | + } |
|
97 | + } |
|
98 | 98 | } |
@@ -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 CreateFolder command |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
52 | 52 | } |
53 | 53 | |
54 | - $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
54 | + $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
|
55 | 55 | if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) { |
56 | 56 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
57 | 57 | } |
@@ -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 { |