Exemplo n.º 1
0
 /**
  * Processes getresponse list field. Called by AJAX script.
  */
 public static function field_getresponse_list_ajax()
 {
     if (!class_exists(MCAPI)) {
         require CH_Manager::$plugin_dir . 'lib/GetResponseAPI.class.php';
     }
     $api_key = $_POST['apikey'];
     $api = new GetResponseAPI($api_key);
     $lists = (array) $api->getCampaigns();
     /*$campaignIDs = array_keys($campaigns);
       $campaign      = $api->getCampaignByID($campaignIDs[0]);
       var_dump($campaigns, $campaign);*/
     $value = '';
     if (!empty($_POST['value'])) {
         $value = $_POST['value'];
     }
     $output = '';
     foreach ($lists['data'] as $key => $val) {
         $selected = '';
         if ($key == $value) {
             $selected = ' selected="selected"';
         }
         $output .= '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
     }
     echo $output;
     die;
 }
 /**
  * Processes integration with 3rd party APIs.
  * @param cf_Contest $contest
  * @param cf_Participant $participant
  */
 static function process_integration($contest, $participant)
 {
     // mailing lists
     $email = $participant->email;
     $name = '';
     $first_name = '';
     $last_name = '';
     if ($contest->cf_name_field == '1') {
         $name = $participant->first_name . ' ' . $participant->last_name;
         $first_name = $participant->first_name;
         $last_name = $participant->last_name;
     }
     if ($contest->cf_participants_export == 'campaignmonitor') {
         if (!class_exists(CS_REST_Subscribers)) {
             require cf_Manager::$plugin_dir . 'lib/campaign_monitor/csrest_subscribers.php';
         }
         $wrap = new CS_REST_Subscribers($contest->cf_campaignmonitor_list, $contest->cf_campaignmonitor_key);
         $res = $wrap->add(array('EmailAddress' => $email, 'Name' => $name, 'Resubscribe' => true));
         // $res->was_successful()
         // $res->http_status_code
         // $res->response
     } else {
         if ($contest->cf_participants_export == 'mailchimp') {
             if (!class_exists(MCAPI)) {
                 require cf_Manager::$plugin_dir . 'lib/MCAPI.class.php';
             }
             $double_optin = true;
             if ($contest->cf_double_optin == '1') {
                 $double_optin = false;
             }
             $api = new MCAPI($contest->cf_mailchimp_key);
             $api->listSubscribe($contest->cf_mailchimp_list, $email, array('FNAME' => $first_name, 'LNAME' => $last_name), 'html', $double_optin);
             // double optin;
             // if($api->errorCode)
             // $api->errorCode
             // $api->errorMessage
         } else {
             if ($contest->cf_participants_export == 'getresponse') {
                 require cf_Manager::$plugin_dir . 'lib/GetResponseAPI.class.php';
                 $api = new GetResponseAPI($contest->cf_getresponse_key);
                 $response = $api->addContact($contest->cf_getresponse_list, $name, $email);
                 // var_dump($response);
             } else {
                 if ($contest->cf_participants_export == 'aweber') {
                     require cf_Manager::$plugin_dir . 'lib/aweber/aweber_api.php';
                     $aweber_auth = $contest->cf_aweber_auth;
                     if (!empty($aweber_auth) && is_array($aweber_auth)) {
                         $api = new AWeberAPI($aweber_auth['consumer_key'], $aweber_auth['consumer_secret']);
                         try {
                             $account = $api->getAccount($aweber_auth['access_key'], $aweber_auth['access_secret']);
                             $listURL = "/accounts/{$account->id}/lists/{$contest->cf_aweber_list}";
                             $list = $account->loadFromUrl($listURL);
                             // create a subscriber
                             $params = array('email' => $email, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'name' => $name);
                             $subscribers = $list->subscribers;
                             $new_subscriber = $subscribers->create($params);
                         } catch (AWeberAPIException $exc) {
                             // TODO log (post comments?)
                         }
                     }
                 }
             }
         }
     }
     do_action('cf_process_integration', $contest, $participant);
 }