function sms_clickatell_command in SMS Framework 5
Same name and namespace in other branches
- 6 modules/sms_clickatell/sms_clickatell.module \sms_clickatell_command()
Executes a command using the Clickatell API
4 calls to sms_clickatell_command()
- sms_clickatell_admin_form_validate in modules/
sms_clickatell/ sms_clickatell.module - Validates the submission of the configuration form.
- sms_clickatell_balance in modules/
sms_clickatell/ sms_clickatell.module - sms_clickatell_get_session_id in modules/
sms_clickatell/ sms_clickatell.module - sms_clickatell_send in modules/
sms_clickatell/ sms_clickatell.module - Callback for sending messages.
File
- modules/
sms_clickatell/ sms_clickatell.module, line 99 - Adds support for sending SMS messages using the Clickatell gateway.
Code
function sms_clickatell_command($command = 'auth', $data = array(), $config = NULL) {
$gateway = sms_gateways('gateway', 'clickatell');
if ($config == NULL) {
$config = $gateway['configuration'];
}
if ($config['sms_clickatell_ssl']) {
$scheme = 'https';
}
else {
$scheme = 'http';
}
switch ($command) {
case 'auth':
$query = 'api_id=' . $config['sms_clickatell_api_id'] . '&user=' . $config['sms_clickatell_user'] . '&password=' . $config['sms_clickatell_password'];
break;
case 'sendmsg':
// Check if the message requires unicode handling
if ($unicode_message = sms_clickatell_unicode($data['message'])) {
$message = $unicode_message;
}
else {
$message = drupal_urlencode($data['message']);
}
$query = 'session_id=' . sms_clickatell_get_session_id() . '&to=' . $data['number'] . '&text=' . $message;
break;
case 'getbalance':
$query = 'session_id=' . sms_clickatell_get_session_id();
break;
}
// Run the command
$http_result = drupal_http_request($scheme . '://api.clickatell.com/http/' . $command . '?' . $query);
// Check for HTTP errors
if ($http_result->error) {
return array(
'status' => FALSE,
'message' => t('An error occured during the HTTP request: @error', array(
'@error' => $http_result->error,
)),
);
}
if ($http_result->data) {
// Check for Clickatell errors
if (strpos($http_result->data, 'ERR') !== FALSE) {
$result = array(
'status' => FALSE,
'message' => $http_result->data,
);
}
elseif ($command == 'auth') {
// Add Clickatell session ID to result array.
list($status, $sid) = explode(': ', $http_result->data);
$result = array(
'status' => TRUE,
'sid' => $sid,
);
}
else {
$result = array(
'status' => TRUE,
);
}
}
return $result;
}