[Pkg-owncloud-commits] [owncloud] 07/199: Cleanup code a little bit
David Prévot
taffit at moszumanska.debian.org
Sun Jun 1 18:53:02 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 0b7d9e2668e3a2e2049eb84f9c49fac41d71d35e
Author: Lukas Reschke <lukas at statuscode.ch>
Date: Sun May 4 15:51:08 2014 +0200
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
---
apps/files_sharing/ajax/list.php | 16 ++++------------
apps/files_sharing/ajax/publicpreview.php | 21 ++++++++++-----------
lib/private/response.php | 1 +
3 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/apps/files_sharing/ajax/list.php b/apps/files_sharing/ajax/list.php
index 4b64549..76926d8 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 d12d212..6ba47e5 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);
}
diff --git a/lib/private/response.php b/lib/private/response.php
index 1aa5e62..19df971 100644
--- a/lib/private/response.php
+++ b/lib/private/response.php
@@ -10,6 +10,7 @@ class OC_Response {
const STATUS_FOUND = 304;
const STATUS_NOT_MODIFIED = 304;
const STATUS_TEMPORARY_REDIRECT = 307;
+ const STATUS_BAD_REQUEST = 400;
const STATUS_NOT_FOUND = 404;
const STATUS_INTERNAL_SERVER_ERROR = 500;
const STATUS_SERVICE_UNAVAILABLE = 503;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list