ActiveCampaign.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. if ( !defined("ACTIVECAMPAIGN_URL") || (!defined("ACTIVECAMPAIGN_API_KEY") && !defined("ACTIVECAMPAIGN_API_USER") && !defined("ACTIVECAMPAIGN_API_PASS")) ) {
  3. require_once(dirname(__FILE__) . "/config.php");
  4. }
  5. require_once("Connector.class.php");
  6. class ActiveCampaign extends AC_Connector {
  7. public $url_base;
  8. public $url;
  9. public $api_key;
  10. public $track_email;
  11. public $track_actid;
  12. public $track_key;
  13. public $version = 1;
  14. public $debug = false;
  15. function __construct($url, $api_key, $api_user = "", $api_pass = "") {
  16. $this->url_base = $this->url = $url;
  17. $this->api_key = $api_key;
  18. parent::__construct($url, $api_key, $api_user, $api_pass);
  19. }
  20. function version($version) {
  21. $this->version = (int)$version;
  22. if ($version == 2) {
  23. $this->url_base = $this->url_base . "/2";
  24. }
  25. }
  26. function api($path, $post_data = array()) {
  27. // IE: "contact/view"
  28. $components = explode("/", $path);
  29. $component = $components[0];
  30. if (count($components) > 2) {
  31. // IE: "contact/tag/add?whatever"
  32. // shift off the first item (the component, IE: "contact").
  33. array_shift($components);
  34. // IE: convert to "tag_add?whatever"
  35. $method_str = implode("_", $components);
  36. $components = array($component, $method_str);
  37. }
  38. if (preg_match("/\?/", $components[1])) {
  39. // query params appended to method
  40. // IE: contact/edit?overwrite=0
  41. $method_arr = explode("?", $components[1]);
  42. $method = $method_arr[0];
  43. $params = $method_arr[1];
  44. }
  45. else {
  46. // just a method provided
  47. // IE: "contact/view
  48. if ( isset($components[1]) ) {
  49. $method = $components[1];
  50. $params = "";
  51. }
  52. else {
  53. return "Invalid method.";
  54. }
  55. }
  56. // adjustments
  57. if ($component == "list") {
  58. // reserved word
  59. $component = "list_";
  60. }
  61. elseif ($component == "branding") {
  62. $component = "design";
  63. }
  64. elseif ($component == "sync") {
  65. $component = "contact";
  66. $method = "sync";
  67. }
  68. elseif ($component == "singlesignon") {
  69. $component = "auth";
  70. }
  71. $class = ucwords($component); // IE: "contact" becomes "Contact"
  72. $class = "AC_" . $class;
  73. // IE: new Contact();
  74. $add_tracking = false;
  75. if ($class == "AC_Tracking") $add_tracking = true;
  76. $class = new $class($this->version, $this->url_base, $this->url, $this->api_key);
  77. // IE: $contact->view()
  78. if ($add_tracking) {
  79. $class->track_email = $this->track_email;
  80. $class->track_actid = $this->track_actid;
  81. $class->track_key = $this->track_key;
  82. }
  83. if ($method == "list") {
  84. // reserved word
  85. $method = "list_";
  86. }
  87. $class->debug = $this->debug;
  88. $response = $class->$method($params, $post_data);
  89. return $response;
  90. }
  91. }
  92. require_once("Account.class.php");
  93. require_once("Auth.class.php");
  94. require_once("Automation.class.php");
  95. require_once("Campaign.class.php");
  96. require_once("Contact.class.php");
  97. require_once("Deal.class.php");
  98. require_once("Design.class.php");
  99. require_once("Form.class.php");
  100. require_once("Group.class.php");
  101. require_once("List.class.php");
  102. require_once("Message.class.php");
  103. require_once("Settings.class.php");
  104. require_once("Subscriber.class.php");
  105. require_once("Tracking.class.php");
  106. require_once("User.class.php");
  107. require_once("Webhook.class.php");
  108. ?>