Beispiel #1
0
function clickatell_hook_sendsms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $clickatell_param;
    global $gateway_number;
    if ($clickatell_param['sender']) {
        $sms_from = $clickatell_param['sender'];
    } else {
        if ($gateway_number) {
            $sms_from = $gateway_number;
        } else {
            $sms_from = $mobile_sender;
        }
    }
    if ($sms_sender) {
        $sms_msg = $sms_msg . $sms_sender;
    }
    switch ($sms_type) {
        case "flash":
            $sms_type = "SMS_FLASH";
            break;
        case "logo":
            $sms_type = "SMS_NOKIA_OLOGO";
            break;
        case "picture":
            $sms_type = "SMS_NOKIA_PICTURE";
            break;
        case "ringtone":
        case "rtttl":
            $sms_type = "SMS_NOKIA_RTTTL";
            break;
        case "text":
        default:
            $sms_type = "SMS_TEXT";
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = str2hex($sms_msg);
        $unicode = 1;
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to clickatell
    $set_sms_from = $sms_from == $mobile_sender ? '' : "&from=" . urlencode($sms_from);
    $query_string = "sendmsg?api_id=" . $clickatell_param['api_id'] . "&user="******"&password="******"&to=" . urlencode($sms_to) . "&msg_type={$sms_type}&text=" . urlencode($sms_msg) . "&unicode=" . $unicode . $set_sms_from;
    $url = $clickatell_param['send_url'] . "/" . $query_string;
    if ($additional_param = $clickatell_param['additional_param']) {
        $additional_param = "&" . $additional_param;
    } else {
        $additional_param = "&deliv_ack=1&callback=3";
    }
    $url .= $additional_param;
    $url = str_replace("&&", "&", $url);
    logger_print("url:" . $url, 3, "clickatell outgoing");
    $fd = @implode('', file($url));
    $ok = false;
    // failed
    $p_status = 2;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    if ($fd) {
        $response = split(":", $fd);
        $err_code = trim($response[1]);
        if (strtoupper($response[0]) == "ID") {
            if ($apimsgid = trim($response[1])) {
                clickatell_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = clickatell_getsmsstatus($smslog_id);
                // pending
                $p_status = 0;
                if ($c_sms_status) {
                    $p_status = $c_sms_status;
                }
            } else {
                // sent
                $p_status = 1;
            }
            logger_print("smslog_id:" . $smslog_id . " charge:" . $c_sms_credit . " sms_status:" . $p_status . " response:" . $response[0] . " " . $response[1], 3, "clickatell outgoing");
            setsmsdeliverystatus($smslog_id, $uid, $p_status);
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("smslog_id:" . $smslog_id . " response:" . $fd, 3, "clickatell outgoing");
        }
        $ok = true;
    }
    return $ok;
}
Beispiel #2
0
function clickatell_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "clickatell_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['clickatell']['module_sender']) {
        $sms_sender = $plugin_config['clickatell']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $sms_from = $sms_sender;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    switch ($sms_type) {
        case "flash":
            $sms_type = "SMS_FLASH";
            break;
        case "logo":
            $sms_type = "SMS_NOKIA_OLOGO";
            break;
        case "picture":
            $sms_type = "SMS_NOKIA_PICTURE";
            break;
        case "ringtone":
        case "rtttl":
            $sms_type = "SMS_NOKIA_RTTTL";
            break;
        case "text":
        default:
            $sms_type = "SMS_TEXT";
    }
    // Automatically setting the unicode flag if necessary
    if (!$unicode) {
        $unicode = core_detect_unicode($sms_msg);
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = core_str2hex($sms_msg);
        $unicode = 1;
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to clickatell
    $set_sms_from = $sms_from ? "&from=" . urlencode($sms_from) : '';
    // fixme anton - temporary solution #385 Unable to send messages when clickatell password contains &
    $password = urlencode(htmlspecialchars_decode($plugin_config['clickatell']['password']));
    $query_string = "sendmsg?api_id=" . $plugin_config['clickatell']['api_id'] . "&user="******"&password="******"&to=" . urlencode($sms_to) . "&msg_type={$sms_type}&text=" . urlencode($sms_msg) . "&unicode=" . $unicode . $set_sms_from;
    $url = $plugin_config['clickatell']['send_url'] . "/" . $query_string;
    if ($additional_param = $plugin_config['clickatell']['additional_param']) {
        $additional_param = "&" . htmlspecialchars_decode($additional_param);
    } else {
        $additional_param = "&deliv_ack=1&callback=3";
    }
    $url .= $additional_param;
    $url = str_replace("&&", "&", $url);
    logger_print("url:" . $url, 3, "clickatell outgoing");
    $fd = @implode('', file($url));
    $ok = false;
    // failed
    $p_status = 2;
    if ($fd) {
        $response = explode(":", $fd);
        $err_code = trim($response[1]);
        if (strtoupper($response[0]) == "ID") {
            if ($apimsgid = trim($response[1])) {
                clickatell_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = clickatell_getsmsstatus($smslog_id);
                // pending
                $p_status = 0;
                if ($c_sms_status) {
                    $p_status = $c_sms_status;
                }
            } else {
                // sent
                $p_status = 1;
            }
            logger_print("smslog_id:" . $smslog_id . " charge:" . $c_sms_credit . " sms_status:" . $p_status . " response:" . $response[0] . " " . $response[1], 2, "clickatell outgoing");
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("smslog_id:" . $smslog_id . " response:" . $fd, 2, "clickatell outgoing");
        }
        $ok = true;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}