X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fclass.api.php;h=21a4190b70c6d523083edb0ad08f7d7b8ff439c1;hb=e859e64134e6e181ac45d9c027998918f4cd921a;hp=df6ef1283f4c0c4149987fcc73cec06f868743b3;hpb=36f3e503e8446cfd9f142373252fe4e1782b4f3c;p=civicrm-core.git diff --git a/api/class.api.php b/api/class.api.php index df6ef1283f..21a4190b70 100644 --- a/api/class.api.php +++ b/api/class.api.php @@ -75,6 +75,17 @@ * // is the json encoded result * echo $api; * ``` + * + * For remote calls, you may need to set the UserAgent and Referer strings for some environments (eg WordFence) + * Add 'referer' and 'useragent' to the initialisation config: + * + * ``` + * $api = new civicrm_api3 (['server' => 'http://example.org', + * 'api_key'=>'theusersecretkey', + * 'key'=>'thesitesecretkey', + * 'referer'=>'https://my_site', + * 'useragent'=>'curl']); + * ``` */ class civicrm_api3 { @@ -109,6 +120,8 @@ class civicrm_api3 { else { die("\nFATAL:param['api_key] missing\n"); } + $this->referer = !empty($config['referer']) ? $config['referer'] : ''; + $this->useragent = !empty($config['useragent']) ? $config['useragent'] : 'curl'; return; } if (!empty($config) && !empty($config['conf_path'])) { @@ -140,8 +153,8 @@ class civicrm_api3 { /** * Perform action. * - * @param $action - * @param $params + * @param string $action + * @param array $params * * @return bool */ @@ -158,8 +171,8 @@ class civicrm_api3 { /** * Call via rest. * - * @param $entity - * @param $action + * @param string $entity + * @param string $action * @param array $params * * @return \stdClass @@ -180,6 +193,10 @@ class civicrm_api3 { curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent); + if ($this->referer) { + curl_setopt($ch, CURLOPT_REFERER, $this->referer); + } $result = curl_exec($ch); // CiviCRM expects to get back a CiviCRM error object. if (curl_errno($ch)) { @@ -211,7 +228,7 @@ class civicrm_api3 { /** * Call api function. * - * @param $entity + * @param string $entity * @param string $action * @param array $params * @@ -281,8 +298,8 @@ class civicrm_api3 { /** * Get attribute. * - * @param $name - * @param null $value + * @param string $name + * @param mixed $value * * @return $this */