@@ -23,56 +23,56 @@ |
||
| 23 | 23 | |
| 24 | 24 | class Application extends \OCP\AppFramework\App { |
| 25 | 25 | |
| 26 | - public function __construct() { |
|
| 27 | - parent::__construct('workflowengine'); |
|
| 26 | + public function __construct() { |
|
| 27 | + parent::__construct('workflowengine'); |
|
| 28 | 28 | |
| 29 | - $this->getContainer()->registerAlias('FlowOperationsController', 'OCA\WorkflowEngine\Controller\FlowOperations'); |
|
| 30 | - $this->getContainer()->registerAlias('RequestTimeController', 'OCA\WorkflowEngine\Controller\RequestTime'); |
|
| 31 | - } |
|
| 29 | + $this->getContainer()->registerAlias('FlowOperationsController', 'OCA\WorkflowEngine\Controller\FlowOperations'); |
|
| 30 | + $this->getContainer()->registerAlias('RequestTimeController', 'OCA\WorkflowEngine\Controller\RequestTime'); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Register all hooks and listeners |
|
| 35 | - */ |
|
| 36 | - public function registerHooksAndListeners() { |
|
| 37 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 38 | - $dispatcher->addListener( |
|
| 39 | - 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 40 | - function() { |
|
| 41 | - if (!function_exists('style')) { |
|
| 42 | - // This is hacky, but we need to load the template class |
|
| 43 | - class_exists('OCP\Template', true); |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * Register all hooks and listeners |
|
| 35 | + */ |
|
| 36 | + public function registerHooksAndListeners() { |
|
| 37 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 38 | + $dispatcher->addListener( |
|
| 39 | + 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 40 | + function() { |
|
| 41 | + if (!function_exists('style')) { |
|
| 42 | + // This is hacky, but we need to load the template class |
|
| 43 | + class_exists('OCP\Template', true); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - style('workflowengine', [ |
|
| 47 | - 'admin', |
|
| 48 | - ]); |
|
| 46 | + style('workflowengine', [ |
|
| 47 | + 'admin', |
|
| 48 | + ]); |
|
| 49 | 49 | |
| 50 | - script('core', [ |
|
| 51 | - 'files/fileinfo', |
|
| 52 | - 'files/client', |
|
| 53 | - 'oc-backbone-webdav', |
|
| 54 | - 'systemtags/systemtags', |
|
| 55 | - 'systemtags/systemtagmodel', |
|
| 56 | - 'systemtags/systemtagscollection', |
|
| 57 | - ]); |
|
| 50 | + script('core', [ |
|
| 51 | + 'files/fileinfo', |
|
| 52 | + 'files/client', |
|
| 53 | + 'oc-backbone-webdav', |
|
| 54 | + 'systemtags/systemtags', |
|
| 55 | + 'systemtags/systemtagmodel', |
|
| 56 | + 'systemtags/systemtagscollection', |
|
| 57 | + ]); |
|
| 58 | 58 | |
| 59 | - vendor_script('jsTimezoneDetect/jstz'); |
|
| 59 | + vendor_script('jsTimezoneDetect/jstz'); |
|
| 60 | 60 | |
| 61 | - script('workflowengine', [ |
|
| 62 | - 'admin', |
|
| 61 | + script('workflowengine', [ |
|
| 62 | + 'admin', |
|
| 63 | 63 | |
| 64 | - // Check plugins |
|
| 65 | - 'filemimetypeplugin', |
|
| 66 | - 'filesizeplugin', |
|
| 67 | - 'filesystemtagsplugin', |
|
| 68 | - 'requestremoteaddressplugin', |
|
| 69 | - 'requesttimeplugin', |
|
| 70 | - 'requesturlplugin', |
|
| 71 | - 'requestuseragentplugin', |
|
| 72 | - 'usergroupmembershipplugin', |
|
| 73 | - ]); |
|
| 74 | - }, |
|
| 75 | - -100 |
|
| 76 | - ); |
|
| 77 | - } |
|
| 64 | + // Check plugins |
|
| 65 | + 'filemimetypeplugin', |
|
| 66 | + 'filesizeplugin', |
|
| 67 | + 'filesystemtagsplugin', |
|
| 68 | + 'requestremoteaddressplugin', |
|
| 69 | + 'requesttimeplugin', |
|
| 70 | + 'requesturlplugin', |
|
| 71 | + 'requestuseragentplugin', |
|
| 72 | + 'usergroupmembershipplugin', |
|
| 73 | + ]); |
|
| 74 | + }, |
|
| 75 | + -100 |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -29,153 +29,153 @@ |
||
| 29 | 29 | |
| 30 | 30 | class FileMimeType extends AbstractStringCheck { |
| 31 | 31 | |
| 32 | - /** @var array */ |
|
| 33 | - protected $mimeType; |
|
| 34 | - |
|
| 35 | - /** @var IRequest */ |
|
| 36 | - protected $request; |
|
| 37 | - |
|
| 38 | - /** @var IMimeTypeDetector */ |
|
| 39 | - protected $mimeTypeDetector; |
|
| 40 | - |
|
| 41 | - /** @var IStorage */ |
|
| 42 | - protected $storage; |
|
| 43 | - |
|
| 44 | - /** @var string */ |
|
| 45 | - protected $path; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param IL10N $l |
|
| 49 | - * @param IRequest $request |
|
| 50 | - * @param IMimeTypeDetector $mimeTypeDetector |
|
| 51 | - */ |
|
| 52 | - public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) { |
|
| 53 | - parent::__construct($l); |
|
| 54 | - $this->request = $request; |
|
| 55 | - $this->mimeTypeDetector = $mimeTypeDetector; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param IStorage $storage |
|
| 60 | - * @param string $path |
|
| 61 | - */ |
|
| 62 | - public function setFileInfo(IStorage $storage, $path) { |
|
| 63 | - $this->storage = $storage; |
|
| 64 | - $this->path = $path; |
|
| 65 | - if (!isset($this->mimeType[$this->storage->getId()][$this->path]) |
|
| 66 | - || $this->mimeType[$this->storage->getId()][$this->path] === '') { |
|
| 67 | - $this->mimeType[$this->storage->getId()][$this->path] = null; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - protected function getActualValue() { |
|
| 75 | - if ($this->mimeType[$this->storage->getId()][$this->path] !== null) { |
|
| 76 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($this->isWebDAVRequest()) { |
|
| 80 | - if ($this->request->getMethod() === 'PUT') { |
|
| 81 | - $path = $this->request->getPathInfo(); |
|
| 82 | - $this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path); |
|
| 83 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
| 84 | - } |
|
| 85 | - } else if ($this->isPublicWebDAVRequest()) { |
|
| 86 | - if ($this->request->getMethod() === 'PUT') { |
|
| 87 | - $path = $this->request->getPathInfo(); |
|
| 88 | - if (strpos($path, '/webdav/') === 0) { |
|
| 89 | - $path = substr($path, strlen('/webdav')); |
|
| 90 | - } |
|
| 91 | - $path = $this->path . $path; |
|
| 92 | - $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path); |
|
| 93 | - return $this->mimeType[$this->storage->getId()][$path]; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (in_array($this->request->getMethod(), ['POST', 'PUT'])) { |
|
| 98 | - $files = $this->request->getUploadedFile('files'); |
|
| 99 | - if (isset($files['type'][0])) { |
|
| 100 | - $mimeType = $files['type'][0]; |
|
| 101 | - if ($this->mimeType === 'application/octet-stream') { |
|
| 102 | - // Maybe not... |
|
| 103 | - $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]); |
|
| 104 | - if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
| 105 | - $mimeType = $mimeTypeTest; |
|
| 106 | - } else { |
|
| 107 | - $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]); |
|
| 108 | - if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
| 109 | - $mimeType = $mimeTypeTest; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $this->mimeType[$this->storage->getId()][$this->path] = $mimeType; |
|
| 114 | - return $mimeType; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path); |
|
| 119 | - if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') { |
|
| 120 | - $this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $this->mimeType[$this->storage->getId()][$this->path]; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - protected function detectMimetypeFromPath() { |
|
| 130 | - $mimeType = $this->mimeTypeDetector->detectPath($this->path); |
|
| 131 | - if ($mimeType !== 'application/octet-stream' && $mimeType !== false) { |
|
| 132 | - return $mimeType; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local') |
|
| 136 | - || $this->storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 137 | - || $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) { |
|
| 138 | - $localFile = $this->storage->getLocalFile($this->path); |
|
| 139 | - if ($localFile !== false) { |
|
| 140 | - $mimeType = $this->mimeTypeDetector->detect($localFile); |
|
| 141 | - if ($mimeType !== false) { |
|
| 142 | - return $mimeType; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return 'application/octet-stream'; |
|
| 147 | - } else { |
|
| 148 | - $handle = $this->storage->fopen($this->path, 'r'); |
|
| 149 | - $data = fread($handle, 8024); |
|
| 150 | - fclose($handle); |
|
| 151 | - $mimeType = $this->mimeTypeDetector->detectString($data); |
|
| 152 | - if ($mimeType !== false) { |
|
| 153 | - return $mimeType; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return 'application/octet-stream'; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - protected function isWebDAVRequest() { |
|
| 164 | - return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
| 165 | - $this->request->getPathInfo() === '/webdav' || |
|
| 166 | - strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
| 167 | - $this->request->getPathInfo() === '/dav/files' || |
|
| 168 | - strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @return bool |
|
| 174 | - */ |
|
| 175 | - protected function isPublicWebDAVRequest() { |
|
| 176 | - return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && ( |
|
| 177 | - $this->request->getPathInfo() === '/webdav' || |
|
| 178 | - strpos($this->request->getPathInfo(), '/webdav/') === 0 |
|
| 179 | - ); |
|
| 180 | - } |
|
| 32 | + /** @var array */ |
|
| 33 | + protected $mimeType; |
|
| 34 | + |
|
| 35 | + /** @var IRequest */ |
|
| 36 | + protected $request; |
|
| 37 | + |
|
| 38 | + /** @var IMimeTypeDetector */ |
|
| 39 | + protected $mimeTypeDetector; |
|
| 40 | + |
|
| 41 | + /** @var IStorage */ |
|
| 42 | + protected $storage; |
|
| 43 | + |
|
| 44 | + /** @var string */ |
|
| 45 | + protected $path; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param IL10N $l |
|
| 49 | + * @param IRequest $request |
|
| 50 | + * @param IMimeTypeDetector $mimeTypeDetector |
|
| 51 | + */ |
|
| 52 | + public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) { |
|
| 53 | + parent::__construct($l); |
|
| 54 | + $this->request = $request; |
|
| 55 | + $this->mimeTypeDetector = $mimeTypeDetector; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param IStorage $storage |
|
| 60 | + * @param string $path |
|
| 61 | + */ |
|
| 62 | + public function setFileInfo(IStorage $storage, $path) { |
|
| 63 | + $this->storage = $storage; |
|
| 64 | + $this->path = $path; |
|
| 65 | + if (!isset($this->mimeType[$this->storage->getId()][$this->path]) |
|
| 66 | + || $this->mimeType[$this->storage->getId()][$this->path] === '') { |
|
| 67 | + $this->mimeType[$this->storage->getId()][$this->path] = null; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + protected function getActualValue() { |
|
| 75 | + if ($this->mimeType[$this->storage->getId()][$this->path] !== null) { |
|
| 76 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($this->isWebDAVRequest()) { |
|
| 80 | + if ($this->request->getMethod() === 'PUT') { |
|
| 81 | + $path = $this->request->getPathInfo(); |
|
| 82 | + $this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path); |
|
| 83 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
| 84 | + } |
|
| 85 | + } else if ($this->isPublicWebDAVRequest()) { |
|
| 86 | + if ($this->request->getMethod() === 'PUT') { |
|
| 87 | + $path = $this->request->getPathInfo(); |
|
| 88 | + if (strpos($path, '/webdav/') === 0) { |
|
| 89 | + $path = substr($path, strlen('/webdav')); |
|
| 90 | + } |
|
| 91 | + $path = $this->path . $path; |
|
| 92 | + $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path); |
|
| 93 | + return $this->mimeType[$this->storage->getId()][$path]; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (in_array($this->request->getMethod(), ['POST', 'PUT'])) { |
|
| 98 | + $files = $this->request->getUploadedFile('files'); |
|
| 99 | + if (isset($files['type'][0])) { |
|
| 100 | + $mimeType = $files['type'][0]; |
|
| 101 | + if ($this->mimeType === 'application/octet-stream') { |
|
| 102 | + // Maybe not... |
|
| 103 | + $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]); |
|
| 104 | + if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
| 105 | + $mimeType = $mimeTypeTest; |
|
| 106 | + } else { |
|
| 107 | + $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]); |
|
| 108 | + if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) { |
|
| 109 | + $mimeType = $mimeTypeTest; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $this->mimeType[$this->storage->getId()][$this->path] = $mimeType; |
|
| 114 | + return $mimeType; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path); |
|
| 119 | + if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') { |
|
| 120 | + $this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $this->mimeType[$this->storage->getId()][$this->path]; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + protected function detectMimetypeFromPath() { |
|
| 130 | + $mimeType = $this->mimeTypeDetector->detectPath($this->path); |
|
| 131 | + if ($mimeType !== 'application/octet-stream' && $mimeType !== false) { |
|
| 132 | + return $mimeType; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local') |
|
| 136 | + || $this->storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 137 | + || $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) { |
|
| 138 | + $localFile = $this->storage->getLocalFile($this->path); |
|
| 139 | + if ($localFile !== false) { |
|
| 140 | + $mimeType = $this->mimeTypeDetector->detect($localFile); |
|
| 141 | + if ($mimeType !== false) { |
|
| 142 | + return $mimeType; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return 'application/octet-stream'; |
|
| 147 | + } else { |
|
| 148 | + $handle = $this->storage->fopen($this->path, 'r'); |
|
| 149 | + $data = fread($handle, 8024); |
|
| 150 | + fclose($handle); |
|
| 151 | + $mimeType = $this->mimeTypeDetector->detectString($data); |
|
| 152 | + if ($mimeType !== false) { |
|
| 153 | + return $mimeType; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return 'application/octet-stream'; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + protected function isWebDAVRequest() { |
|
| 164 | + return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
| 165 | + $this->request->getPathInfo() === '/webdav' || |
|
| 166 | + strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
| 167 | + $this->request->getPathInfo() === '/dav/files' || |
|
| 168 | + strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @return bool |
|
| 174 | + */ |
|
| 175 | + protected function isPublicWebDAVRequest() { |
|
| 176 | + return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && ( |
|
| 177 | + $this->request->getPathInfo() === '/webdav' || |
|
| 178 | + strpos($this->request->getPathInfo(), '/webdav/') === 0 |
|
| 179 | + ); |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -88,7 +88,7 @@ |
||
| 88 | 88 | if (strpos($path, '/webdav/') === 0) { |
| 89 | 89 | $path = substr($path, strlen('/webdav')); |
| 90 | 90 | } |
| 91 | - $path = $this->path . $path; |
|
| 91 | + $path = $this->path.$path; |
|
| 92 | 92 | $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path); |
| 93 | 93 | return $this->mimeType[$this->storage->getId()][$path]; |
| 94 | 94 | } |