function poptin_generatepoptinlink in Website Popups, Email Popup, Exit-Intent Popup, and Contact Forms – Poptin 7
Implements poptin_generatepoptinlink().
1 string reference to 'poptin_generatepoptinlink'
- poptin_menu in ./
poptin.module - Implements poptin_menu().
File
- ./
poptin.module, line 261 - Module for adding popups on website.
Code
function poptin_generatepoptinlink() {
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();
}
$api_url = "https://app.popt.in/api/marketplace/";
$row_details = poptin_fetch_row();
if (!is_array($row_details)) {
exit(FALSE);
}
else {
if (isset($row_details['token']) && $row_details['token'] == '') {
drupal_goto("https://app.popt.in/login");
drupal_exit();
}
}
$url = $api_url . "auth";
$dataurl = "token=" . $row_details['token'] . "&user_id=" . $row_details['userid'];
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 {
$res = json_decode($response);
$query_params_get = drupal_get_query_parameters($_GET);
if (isset($query_params_get['utm_source'])) {
header("location:" . $res->login_url . "&utm_source=drupal7");
}
else {
header("location:" . $res->login_url);
}
drupal_exit();
}
}