<?php
/**
** Module for SIB Visions.
**/
add_action('wpcf7_submit', 'wpcf7_sibvisions_submit', 10, 2);
function wpcf7_sibvisions_submit($contactform, $result)
{
if ($contactform->in_demo_mode() || $contactform->is_true('do_not_store'))
{
return;
}
$servletURL = $contactform->additional_setting('sib_servletURL');
if (empty($servletURL[0]))
{
error_log('Servlet URL is not set in form!');
return;
}
$cases = (array)apply_filters('wpcf7_sibvisions_submit_if',
array('spam', 'mail_sent', 'mail_failed'));
if (empty($result['status']) || ! in_array($result['status'], $cases ))
{
return;
}
$submission = WPCF7_Submission::get_instance();
if (!$submission || ! $posted_data = $submission->get_posted_data())
{
return;
}
if (isset($posted_data['g-recaptcha-response']))
{
if (empty($posted_data['g-recaptcha-response']))
{
return;
}
}
$fields_senseless = $contactform->scan_form_tags(
array('feature' => 'do-not-store'));
$exclude_names = array();
foreach ( $fields_senseless as $tag )
{
$exclude_names[] = $tag['name'];
}
$exclude_names[] = 'g-recaptcha-response';
foreach ($posted_data as $key => $value)
{
if ('_' == substr($key, 0, 1) || in_array($key, $exclude_names))
{
unset($posted_data[$key]);
}
}
$url = str_replace('"', "", $servletURL[0]);
$url = str_replace("'", "", $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = array();
foreach ($posted_data as $post => $value)
{
if (is_array($value))
{
foreach ($value as $post2 => $value2)
{
$data[] = $post.'[]='.urlencode($value2);
}
}
else
{
$data[] = $post.'='.urlencode($value);
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));
$data = curl_exec($ch);
if (curl_errno($ch))
{
wp_mail('noreply@sibvisions.com', 'Service error',
'Call to service ('.$url.') failed with error ('.curl_error($ch).')');
}
else
{
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)
if ($http_code != 200)
{
wp_mail('noreply@sibvisions.com', 'Service error',
'Call to service ('.$url.') failed with error ('.$data.')');
}
}
curl_close($ch);
}