getPath( 'class', 'com_chronocontact' ) );
// the class name must be the same as the file name without the .php at the end
class cf_CURL
{
//the next 3 fields must be defined for every plugin
var $result_TITLE = "CURL";
var $result_TOOLTIP = "Submit form data to another URL using the CURL method.
Use this plugin to submit data to Acajoom, Salesforce or any other
script/web service which accepts data through a specific URL";
var $plugin_name = "cf_CURL"; // must be the same as the class name
var $event = "ONSUBMIT"; // must be defined and in Uppercase, should be ONSUBMIT or ONLOAD
// the next function must exist and will have the backend config code
function show_conf($row, $id, $form_id, $option)
{
global $mainframe;
if ( function_exists('curl_init') ) {
echo "CURL OK : the CURL function was found on this server.";
} else {
echo "CURL problem : the CURL function was not found on this server.
Sorry, but the CURL plugin cannot be used on this site as it is currently set up.";
return;
}
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact'.DS.'helpers'.DS.'plugin.php');
$helper = new ChronoContactHelperPlugin();
$tables = $db->getTableList();
$query = "
SELECT *
FROM `#__chrono_contact`
WHERE id = ".$db->Quote($form_id) ;
$db->setQuery($query);
$form = $db->loadObject();
$htmlstring = $form->html;
preg_match_all('/name=("|\')([^(>|"|\')]*?)("|\')/i', $htmlstring, $matches);
$names = array();
foreach ( $matches[2] as $name ) {
if ( strpos($name, '[]') ) {
$name = str_replace('[]', '', $name);
}
$names[] = trim($name);
}
$names = array_unique($names);
// identify and initialise the parameters used in this plugin
$params_array = array(
'debugging' => '0',
'target_url' => 'http://',
'header_in_response' => '0',
'onsubmit' => 'before_email');
$params = $helper->loadParams($row, $params_array);
$messages[] = '$params: '.print_r($params, true);
if ( $params->get('debugging') ) {
$helper->showPluginDebugMessages($messages);
}
?>
addStyleDeclaration($style);
if ( $script ) $doc->addScriptDeclaration($script);
}
// this function must exist and may not be changed unless you need to customize something
function save_conf( $option )
{
global $mainframe;
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact'
.DS.'helpers'.DS.'plugin.php');
$helper = new ChronoContactHelperPlugin();
$helper->save_conf($option);
}
/**
* The function that will be executed when the form is submitted
*
*/
function onsubmit( $option, $params, $row )
{
global $mainframe;
if ( !function_exists('curl_init') ) {
$mainframe->enqueuemessage("CURL problem : the CURL function was not found on this server.
Sorry, but the CURL plugin cannot be used on this site as it is currently set up.", 'error');
return;
}
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact'
.DS.'helpers'.DS.'plugin.php');
$helper = new ChronoContactHelperPlugin();
$doc =& JFactory::getDocument();
$doc->addStyleDeclaration("div.debug {border:1px solid red; padding:3px; margin-bottom:3px;}");
$messages = array();
/*********do the before onsubmit code**********/
if ( !empty($row->extra4) ) {
eval( "?>".$row->extra4 );
}
$curl_values = array();
/// add main fields
if ( trim($row->extra2) ) {
$extras2 = explode("\n", $row->extra2);
foreach ( $extras2 as $extra2 ) {
$values = array();
$values = explode( "=", $extra2 );
if ( $values[1] ) {
$v = urlencode(trim($values[1]));
$curl_values[$v] = JRequest::getVar(trim($values[0]), '', 'post', 'string', '');
}
}
}
if ( trim($row->extra1) ) {
$extras = explode("\n", $row->extra1);
foreach ( $extras as $extra ) {
// Note: accept only the first parameter pair on each line
$values = explode("=", $extra, 2);
$curl_values[$values[0]] = trim($values[1]);
}
}
$query = JURI::buildQuery($curl_values);
$messages[] = 'cf_CURL debug info';
$messages[] = '$curl_values: '.print_r($query, true);
$messages[] = '$params->target_url: '.print_r($params->get('target_url'), true);
$ch = curl_init($params->get('target_url'));
$messages[] = '$ch: '.print_r($ch, true);
curl_setopt($ch, CURLOPT_HEADER, $params->get('header_in_response')); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); // use HTTP POST to send form data
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch); //execute post and get results
curl_close ($ch);
$messages[] = 'CURL response: '.print_r($response, true);
$helper->showCFDebugMessage('CURL transaction executed');
/*********do the after onsubmit code**********/
if ( !empty($row->extra5) ) {
eval( "?>".$row->extra5 );
}
if ( $params->get('debugging') ) {
$helper->showPluginDebugMessages($messages);
}
}
}
?>