diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2014-05-04 15:51:08 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2014-05-04 15:51:08 +0200 |
commit | 0b7d9e2668e3a2e2049eb84f9c49fac41d71d35e (patch) | |
tree | e68c70c2143dfbfa5be20af7efac929ce2ca034c /apps | |
parent | 9385b97b5f38ebf2ed85e740fe3c52f1e6117d49 (diff) | |
download | nextcloud-server-0b7d9e2668e3a2e2049eb84f9c49fac41d71d35e.tar.gz nextcloud-server-0b7d9e2668e3a2e2049eb84f9c49fac41d71d35e.zip |
Cleanup code a little bit
- Use OCP\Response constants instead of the HTTP error code
- Use checkAppEnabled() instead of OC_App::isEnabled with an if statement
- Remove uneeded variable $baseURL
- Rename $isvalid to $isValid
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/ajax/list.php | 16 | ||||
-rw-r--r-- | apps/files_sharing/ajax/publicpreview.php | 21 |
2 files changed, 14 insertions, 23 deletions
diff --git a/apps/files_sharing/ajax/list.php b/apps/files_sharing/ajax/list.php index 4b645496253..76926d84b22 100644 --- a/apps/files_sharing/ajax/list.php +++ b/apps/files_sharing/ajax/list.php @@ -20,17 +20,10 @@ * */ -// only need filesystem apps -$RUNTIME_APPTYPES=array('filesystem'); - -// Init owncloud - -if(!\OC_App::isEnabled('files_sharing')){ - exit; -} +OCP\JSON::checkAppEnabled('files_sharing'); if(!isset($_GET['t'])){ - \OC_Response::setStatus(400); //400 Bad Request + \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG); exit; } @@ -55,13 +48,12 @@ $dir = $data['realPath']; $dir = \OC\Files\Filesystem::normalizePath($dir); if (!\OC\Files\Filesystem::is_dir($dir . '/')) { - \OC_Response::setStatus(404); + \OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); \OCP\JSON::error(array('success' => false)); exit(); } $data = array(); -$baseUrl = OCP\Util::linkTo('files_sharing', 'index.php') . '?t=' . urlencode($token) . '&dir='; // make filelist $files = \OCA\Files\Helper::getFiles($dir); @@ -88,4 +80,4 @@ if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'n $data['permissions'] = $permissions; -OCP\JSON::success(array('data' => $data)); +OCP\JSON::success(array('data' => $data));
\ No newline at end of file diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index d12d212a2e6..6ba47e5b3a6 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -5,9 +5,8 @@ * later. * See the COPYING-README file. */ -if(!\OC_App::isEnabled('files_sharing')){ - exit; -} + +OCP\JSON::checkAppEnabled('files_sharing'); \OC_User::setIncognitoMode(true); @@ -18,20 +17,20 @@ $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; if($token === ''){ - \OC_Response::setStatus(400); //400 Bad Request + \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG); exit; } $linkedItem = \OCP\Share::getShareByToken($token); if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) { - \OC_Response::setStatus(404); + \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG); exit; } if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { - \OC_Response::setStatus(500); + \OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN); exit; } @@ -50,9 +49,9 @@ $pathInfo = $view->getFileInfo($path); $sharedFile = null; if($linkedItem['item_type'] === 'folder') { - $isvalid = \OC\Files\Filesystem::isValidPath($file); - if(!$isvalid) { - \OC_Response::setStatus(400); //400 Bad Request + $isValid = \OC\Files\Filesystem::isValidPath($file); + if(!$isValid) { + \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN); exit; } @@ -71,7 +70,7 @@ if(substr($path, 0, 1) === '/') { } if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request + \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); exit; } @@ -87,6 +86,6 @@ try{ $preview->show(); } catch (\Exception $e) { - \OC_Response::setStatus(500); + \OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); } |