function AutoResponderGetResponseAPI($that, $ar, $wpm_id, $email, $unsub = false)
 {
     global $wpdb;
     require_once $that->pluginDir . '/extlib/jsonRPCClient.php';
     if ($ar['campaign'][$wpm_id]) {
         $campaign = trim($ar['campaign'][$wpm_id]);
         $name = trim($that->ARSender['name']);
         $email = trim($that->ARSender['email']);
         $api_key = trim($ar['apikey']);
         $api_url = empty($ar['api_url']) ? "http://api2.getresponse.com" : trim($ar['api_url']);
         $grUnsub = $ar['grUnsub'][$wpm_id] == 1 ? true : false;
         $uid = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE `user_email`='" . esc_sql($that->ARSender['email']) . "'");
         $ip = trim($that->Get_UserMeta($uid, 'wpm_login_ip'));
         $ip = $ip ? $ip : trim($that->Get_UserMeta($uid, 'wpm_registration_ip'));
         $ip = $ip ? $ip : trim($_SERVER['REMOTE_ADDR']);
         try {
             if (!extension_loaded('curl') || !extension_loaded('json')) {
                 # these extensions are a must
                 throw new Exception("CURL and JSON are modules required to use" . " the GetResponse Integration");
             }
             $api = new jsonRPCClient($api_url);
             #get the campaign id
             $resp = $api->get_campaigns($api_key);
             $cid = null;
             if (!empty($resp)) {
                 foreach ($resp as $i => $item) {
                     if (strtolower($item['name']) == strtolower($campaign)) {
                         $cid = $i;
                     }
                 }
             }
             if (empty($cid)) {
                 throw new Exception("Could not find campaign {$campaign}");
             }
             if ($unsub) {
                 if ($grUnsub) {
                     //list contacts
                     $contacts = $api->get_contacts($api_key, array('campaigns' => array($cid), 'email' => array('EQUALS' => "{$email}")));
                     if (empty($contacts)) {
                         #could not find the contact, nothing to remove
                         return;
                     }
                     $pid = key($contacts);
                     $res = $api->delete_contact($api_key, array('contact' => $pid));
                     if (empty($res)) {
                         throw new Exception("Empty server response while deleting contact");
                     }
                 }
             } else {
                 $resp = $api->add_contact($api_key, array('campaign' => $cid, 'name' => $name, 'email' => $email, 'ip' => $ip, 'cycle_day' => 0));
                 if (empty($resp)) {
                     throw new Exception("Empty server response while sending");
                 }
             }
         } catch (Exception $e) {
             return;
         }
     }
 }
Esempio n. 2
0
 public function export()
 {
     $this->load->model('module/getresponse');
     $contacts = $this->model_module_getresponse->getContacts();
     $this->gr_apikey = $this->request->post['api_key'];
     $this->campaign = $this->request->post['campaign'];
     $this->load->library('jsonRPCClient');
     try {
         $client = new jsonRPCClient($this->gr_apikey_url);
         $result = $client->get_campaigns($this->gr_apikey, array('name' => array('EQUALS' => $this->campaign)));
     } catch (Exception $e) {
         $this->data['error_warning'] = 'Error!' . $e;
     }
     if (empty($result)) {
         $results = array('status' => 2, 'response' => '  No campaign with the specified name.');
     } else {
         $duplicated = 0;
         $queued = 0;
         $contact = 0;
         $not_added = 0;
         $allow_fields = array('telephone', 'country', 'city', 'address', 'postcode');
         $campaign_id = key($result);
         foreach ($contacts as $row) {
             $customs = array();
             $customs[] = array('name' => 'ref', 'content' => 'OpenCart');
             foreach ($allow_fields as $af) {
                 if (!empty($row[$af])) {
                     $customs[] = array('name' => $af, 'content' => $row[$af]);
                 }
             }
             $check_cycle_day = $client->get_contacts($this->gr_apikey, array('campaigns' => array($campaign_id), 'email' => array('EQUALS' => $row['email'])));
             if (!empty($check_cycle_day) and is_array($check_cycle_day)) {
                 $res = array_shift($check_cycle_day);
                 $cycle_day = $res['cycle_day'];
             } else {
                 $cycle_day = '0';
             }
             $params = array('campaign' => $campaign_id, 'name' => $row['firstname'] . ' ' . $row['lastname'], 'email' => $row['email'], 'cycle_day' => $cycle_day, 'customs' => $customs);
             try {
                 $r = $client->add_contact($this->gr_apikey, $params);
                 $contact++;
                 if (array_key_exists('queued', $r)) {
                     $queued++;
                 } else {
                     if (array_key_exists('duplicated', $r)) {
                         $duplicated++;
                     }
                 }
             } catch (Exception $e) {
                 $not_added++;
             }
         }
         $results = array('status' => 1, 'response' => '  Export completed. Contacts: ' . $contact . '. Queued:' . $queued . '. Updated: ' . $duplicated . '. Not added (Contact already queued): ' . $not_added . '.');
     }
     $this->response->setOutput(json_encode($results));
 }
Esempio n. 3
0
 function process()
 {
     global $order;
     if (!$this->enabled) {
         return;
     }
     $client = new jsonRPCClient('http://api2.getresponse.com');
     $result = NULL;
     try {
         $result = $client->get_campaigns(MODULE_ORDER_TOTAL_GETRESPONSE_API_KEY, array('name' => array('EQUALS' => MODULE_ORDER_TOTAL_GETRESPONSE_CAMPAIGN)));
         if (empty($result)) {
             throw new Exception('Missing GetResponse campaign: ' . MODULE_ORDER_TOTAL_GETRESPONSE_CAMPAIGN);
         }
         $campaign_id = array_pop(array_keys($result));
         $check_cycle_day = $client->get_contacts(MODULE_ORDER_TOTAL_GETRESPONSE_API_KEY, array('campaigns' => array($campaign_id), 'email' => array('EQUALS' => $order->customer['email_address'])));
         $cycle_day = (!empty($check_cycle_day) and isset($check_cycle_day[$campaign_id]['cycle_day'])) ? "'cycle_day' => " . $check_cycle_day[$campaign_id]['cycle_day'] . "," : '0';
         $client->add_contact(MODULE_ORDER_TOTAL_GETRESPONSE_API_KEY, array('campaign' => $campaign_id, 'name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'email' => $order->customer['email_address'], 'cycle_day' => $cycle_day, 'customs' => array(array('name' => 'ref', 'content' => STORE_NAME), array('name' => 'telephone', 'content' => $order->customer['telephone']), array('name' => 'country', 'content' => $order->customer['country']['title']), array('name' => 'city', 'content' => $order->customer['city']))));
     } catch (Exception $e) {
         error_log($e->getMessage());
         return;
     }
 }