--- chatcatcher.module 3 May 2009 22:54:24 -0000 1.4 +++ chatcatcher.module 23 Nov 2009 03:41:10 -0000 @@ -244,49 +244,32 @@ */ function _register_chatcatcher($secret) { global $base_url; - $plugin_url = $base_url .'/chatcatcher'; // this is the service endpoint - $account = user_load(1); - $email = $account->mail; - $url = 'http://api.chatcatcher.com/register.aspx'; // set by owner of service - $home = $base_url .'/'; + $queries = array(); + $queries['script'] = $base_url .'/chatcatcher'; // this is the service endpoint + $queries['secret'] = $secret; + $account = user_load(1); + $queries['email'] = $account->mail; + $queries['homeurl'] = $base_url .'/'; - $query_string = 'script='. $plugin_url .'&secret='. $secret .'&email='. $email .'&homeurl='. $home; + $query = http_build_query($queries); + + $query_url = 'http://api.chatcatcher.com/register.aspx'; // set by owner of service + + $content = drupal_http_request($query_url, $query, "POST"); + + $output = ''; - // Use curl to post to service - $ch = curl_init(); - if (isset($query_string)) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); - } - - curl_setopt($ch, CURLOPT_POST, TRUE); - curl_setopt($ch, CURLOPT_HTTPGET, FALSE); - curl_setopt($ch, CURLOPT_HEADER, TRUE); // No need of headers - curl_setopt($ch, CURLOPT_NOBODY, FALSE); // Return body - - curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Timeout - curl_setopt($ch, CURLOPT_URL, $url); // Target site - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return, don't echo - - $content = curl_exec($ch); // this also echoes to the browser? - $content_array = explode("\r\n\r\n", $content); - $status = curl_getinfo($ch); - $res_header = array_shift($content_array); - $results = implode($content_array, "\r\n\r\n"); - $error = curl_error($ch); - - $output .= $results; - curl_close($ch); /* Need to do some error checking here */ - if (strpos($results, 'Congratulations') != FALSE) { + if (strpos($content->data, 'Congratulations') != FALSE) { variable_set('chatcatcher_registered', 'true'); drupal_set_message('Your site is now registered. Thanks.', 'status'); } - if (strlen($results) > 0 && strpos($results, 'activated') != FALSE) { + if (strlen($content->data) > 0 && strpos($content->data, 'activated') != FALSE) { variable_set('chatcatcher_registered', 'true'); - drupal_set_message( 'Result: '. $results .'
', 'status'); + drupal_set_message( 'Result: '. $content->data .'
', 'status'); } else { drupal_set_message('Error contacting Chat Catcher Service. Try again later.', 'error');