You are here

function poptin_signup in Website Popups, Email Popup, Exit-Intent Popup, and Contact Forms – Poptin 7

Implements poptin_signup().

1 string reference to 'poptin_signup'
poptin_menu in ./poptin.module
Implements poptin_menu().

File

./poptin.module, line 129
Module for adding popups on website.

Code

function poptin_signup() {
  if (!poptin_check_csrf_token()) {
    $return_mssg = array(
      'mssg' => t("Invalid CSRF TOKEN"),
      'status' => 0,
      'cccToken' => drupal_get_token(),
    );
    drupal_json_output($return_mssg);
    drupal_exit();
  }
  $query_params_post = drupal_get_query_parameters($_POST);
  $email_id = $query_params_post['email'];
  $api_url = "https://app.popt.in/api/marketplace/";
  $url = $api_url . "register";
  $dataurl = "email=" . $email_id . "&marketplace=drupal7";
  watchdog("API URL", $dataurl);
  $curl = curl_init();
  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $dataurl,
    CURLOPT_HTTPHEADER => array(
      "cache-control: no-cache",
      "content-type: application/x-www-form-urlencoded",
      "postman-token: 16ba048a-499c-06c8-517c-cea2abb11945",
    ),
  ));
  $response = curl_exec($curl);
  $err = curl_error($curl);
  if ($err) {
    echo "cURL Error #:" . $err;
  }
  else {
    $result = json_decode($response);
    if (!empty($result) && $result->success == 1) {
      $tmp_arr = array(
        'user_id' => $result->user_id,
        'client_id' => $result->client_id,
        'token' => $result->token,
      );
      db_insert('poptin')
        ->fields($tmp_arr)
        ->execute();
      $return_mssg = array(
        'mssg' => t("User Registered successfully"),
        'status' => 1,
        'cccToken' => drupal_get_token(),
      );
    }
    else {
      $return_mssg = array(
        'mssg' => $result->message,
        'status' => 0,
        'cccToken' => drupal_get_token(),
      );
    }
  }
  drupal_json_output($return_mssg);
  drupal_exit();
}