diff options
Diffstat (limited to 'lib/private/json.php')
-rw-r--r-- | lib/private/json.php | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/private/json.php b/lib/private/json.php index 6ba0b13806b..5c5d7e3a3da 100644 --- a/lib/private/json.php +++ b/lib/private/json.php @@ -65,6 +65,20 @@ class OC_JSON{ } /** + * Check is a given user exists - send json error msg if not + * @param string $user + */ + public static function checkUserExists($user) { + if (!OCP\User::userExists($user)) { + $l = OC_L10N::get('lib'); + OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user')))); + exit; + } + } + + + + /** * Check if the user is a subadmin, send json error msg if not */ public static function checkSubAdminUser() { @@ -109,7 +123,16 @@ class OC_JSON{ if($setContentType) { self::setContentTypeHeader(); } - array_walk_recursive($data, array('OC_JSON', 'to_string')); - echo json_encode($data); + echo self::encode($data); + } + + /** + * Encode JSON + */ + public static function encode($data) { + if (is_array($data)) { + array_walk_recursive($data, array('OC_JSON', 'to_string')); + } + return json_encode($data); } } |