Merge pull request #4372 from davecivicrm/CRM-15467
[civicrm-core.git] / CRM / Utils / REST.php
index 4605f1c28f831673a684573296f1ff3bc9a3746a..010cfe8156b0c69759895083d89c3de1af7a50be 100644 (file)
@@ -277,7 +277,8 @@ class CRM_Utils_REST {
     if (!empty($r)) {
       $q = $r;
     }
-    if (!empty($q)) {
+    $entity = CRM_Utils_array::value('entity', $requestParams);
+    if ( empty($entity) && !empty($q)) {
       $args = explode('/', $q);
       // If the function isn't in the civicrm namespace, reject the request.
       if ($args[0] != 'civicrm') {
@@ -420,8 +421,7 @@ class CRM_Utils_REST {
     if (array_key_exists('json', $requestParams) &&  $requestParams['json'][0] == "{") {
       $params = json_decode($requestParams['json'], TRUE);
       if($params === NULL) {
-        echo json_encode(array('is_error' => 1, 'error_message', 'Unable to decode supplied JSON.'));
-        CRM_Utils_System::civiExit();
+        CRM_Utils_JSON::output(array('is_error' => 1, 'error_message', 'Unable to decode supplied JSON.'));
       }
     }
     foreach ($requestParams as $n => $v) {
@@ -540,16 +540,13 @@ class CRM_Utils_REST {
           'reason' => 'CSRF suspected',
         )
       );
-      echo json_encode($error);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($error);
     }
     if (empty($requestParams['entity'])) {
-      echo json_encode(civicrm_api3_create_error('missing entity param'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(civicrm_api3_create_error('missing entity param'));
     }
     if (empty($requestParams['entity'])) {
-      echo json_encode(civicrm_api3_create_error('missing entity entity'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(civicrm_api3_create_error('missing entity entity'));
     }
     if (!empty($requestParams['json'])) {
       $params = json_decode($requestParams['json'], TRUE);
@@ -557,8 +554,7 @@ class CRM_Utils_REST {
     $entity = CRM_Utils_String::munge(CRM_Utils_Array::value('entity', $requestParams));
     $action = CRM_Utils_String::munge(CRM_Utils_Array::value('action', $requestParams));
     if (!is_array($params)) {
-      echo json_encode(array('is_error' => 1, 'error_message', 'invalid json format: ?{"param_with_double_quote":"value"}'));
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output(array('is_error' => 1, 'error_message', 'invalid json format: ?{"param_with_double_quote":"value"}'));
     }
 
     $params['check_permissions'] = TRUE;
@@ -599,8 +595,7 @@ class CRM_Utils_REST {
           'reason' => 'CSRF suspected',
         )
       );
-      echo json_encode($error);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($error);
     }
 
     $q = CRM_Utils_Array::value('fnName', $requestParams);