From 0d831ef16184df383bf95eec5b79e1d8d989c37c Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 11 Oct 2010 15:58:46 +0200 Subject: [PATCH] Drop Net_SMS. --- framework/Net_SMS/SMS.php | 328 ------------- framework/Net_SMS/SMS/clickatell_http.php | 354 -------------- framework/Net_SMS/SMS/generic_smpp.php | 200 -------- framework/Net_SMS/SMS/generic_smtp.php | 192 -------- framework/Net_SMS/SMS/sms2email_http.php | 687 --------------------------- framework/Net_SMS/SMS/textmagic_http.php | 542 --------------------- framework/Net_SMS/SMS/vodafoneitaly_smtp.php | 137 ------ framework/Net_SMS/SMS/win_http.php | 272 ----------- framework/Net_SMS/package.xml | 131 ----- 9 files changed, 2843 deletions(-) delete mode 100644 framework/Net_SMS/SMS.php delete mode 100644 framework/Net_SMS/SMS/clickatell_http.php delete mode 100644 framework/Net_SMS/SMS/generic_smpp.php delete mode 100644 framework/Net_SMS/SMS/generic_smtp.php delete mode 100644 framework/Net_SMS/SMS/sms2email_http.php delete mode 100644 framework/Net_SMS/SMS/textmagic_http.php delete mode 100644 framework/Net_SMS/SMS/vodafoneitaly_smtp.php delete mode 100644 framework/Net_SMS/SMS/win_http.php delete mode 100644 framework/Net_SMS/package.xml diff --git a/framework/Net_SMS/SMS.php b/framework/Net_SMS/SMS.php deleted file mode 100644 index 90e4b2d8e..000000000 --- a/framework/Net_SMS/SMS.php +++ /dev/null @@ -1,328 +0,0 @@ - - * @package Net_SMS - */ -class Net_SMS { - - /** - * A hash containing any parameters for the current gateway driver. - * - * @var array - */ - var $_params = array(); - - var $_auth = null; - - /** - * Constructor - * - * @param array $params Any parameters needed for this gateway driver. - */ - function Net_SMS($params = null) - { - $this->_params = $params; - } - - /** - * Returns a list of available gateway drivers. - * - * @return array An array of available drivers. - */ - function getDrivers() - { - static $drivers = array(); - if (!empty($drivers)) { - return $drivers; - } - - $drivers = array(); - - if ($driver_dir = opendir(dirname(__FILE__) . '/SMS/')) { - while (false !== ($file = readdir($driver_dir))) { - /* Hide dot files and non .php files. */ - if (substr($file, 0, 1) != '.' && substr($file, -4) == '.php') { - $driver = substr($file, 0, -4); - $driver_info = Net_SMS::getGatewayInfo($driver); - $drivers[$driver] = $driver_info['name']; - } - } - closedir($driver_dir); - } - - return $drivers; - } - - /** - * Returns information on a gateway, such as name and a brief description, - * from the driver subclass getInfo() function. - * - * @return array An array of extra information. - */ - function getGatewayInfo($gateway) - { - static $info = array(); - if (isset($info[$gateway])) { - return $info[$gateway]; - } - - require_once 'Net/SMS/' . $gateway . '.php'; - $class = 'Net_SMS_' . $gateway; - $info[$gateway] = call_user_func(array($class, 'getInfo')); - - return $info[$gateway]; - } - - /** - * Returns parameters for a gateway from the driver subclass getParams() - * function. - * - * @param string The name of the gateway driver for which to return the - * parameters. - * - * @return array An array of extra information. - */ - function getGatewayParams($gateway) - { - static $params = array(); - if (isset($params[$gateway])) { - return $params[$gateway]; - } - - require_once 'Net/SMS/' . $gateway . '.php'; - $class = 'Net_SMS_' . $gateway; - $params[$gateway] = call_user_func(array($class, 'getParams')); - - return $params[$gateway]; - } - - /** - * Returns send parameters for a gateway from the driver subclass - * getDefaultSendParams()function. These are parameters which are available - * to the user during sending, such as setting a time for delivery, or type - * of SMS (normal text or flash), or source address, etc. - * - * @param string The name of the gateway driver for which to return the - * send parameters. - * - * @return array An array of available send parameters. - */ - function getDefaultSendParams($gateway) - { - static $params = array(); - if (isset($params[$gateway])) { - return $params[$gateway]; - } - - require_once 'Net/SMS/' . $gateway . '.php'; - $class = 'Net_SMS_' . $gateway; - $params[$gateway] = call_user_func(array($class, 'getDefaultSendParams')); - - return $params[$gateway]; - } - - /** - * Query the current Gateway object to find out if it supports the given - * capability. - * - * @param string $capability The capability to test for. - * - * @return mixed Whether or not the capability is supported or any other - * value that the capability wishes to report. - */ - function hasCapability($capability) - { - if (!empty($this->capabilities[$capability])) { - return $this->capabilities[$capability]; - } - return false; - } - - /** - * Authenticates against the gateway if required. - * - * @return mixed True on success or PEAR Error on failure. - */ - function authenticate() - { - /* Do authentication for this gateway if driver requires it. */ - if ($this->hasCapability('auth')) { - $this->_auth = $this->_authenticate(); - return $this->_auth; - } - return true; - } - - /** - * Sends a message to one or more recipients. Hands off the actual sending - * to the gateway driver. - * - * @param array $message The message to be sent, which is composed of: - *
-     *                          id   - A unique ID for the message;
-     *                          to   - An array of recipients;
-     *                          text - The text of the message;
-     *                        
- * - * - * @return mixed True on success or PEAR Error on failure. - */ - function send($message) - { - /* Authenticate. */ - if (is_a($this->authenticate(), 'PEAR_Error')) { - return $this->_auth; - } - - /* Make sure the recipients are in an array. */ - if (!is_array($message['to'])) { - $message['to'] = array($message['to']); - } - - /* Array to store each send. */ - $sends = array(); - - /* If gateway supports batch sending, preference is given to this - * method. */ - if ($max_per_batch = $this->hasCapability('batch')) { - /* Split up the recipients in the max recipients per batch as - * supported by gateway. */ - $iMax = count($message['to']); - $batches = ceil($iMax / $max_per_batch); - - /* Loop through the batches and compose messages to be sent. */ - for ($b = 0; $b < $batches; $b++) { - $recipients = array_slice($message['to'], ($b * $max_per_batch), $max_per_batch); - $response = $this->_send($message, $recipients); - foreach ($recipients as $recipient) { - if ($response[$recipient][0] == 1) { - /* Message was sent, store remote id. */ - $remote_id = $response[$recipient][1]; - $error = null; - } else { - /* Message failed, store error code. */ - $remote_id = null; - $error = $response[$recipient][1]; - } - - /* Store the sends. */ - $sends[] = array('message_id' => $message['id'], - 'remote_id' => $remote_id, - 'recipient' => $recipient, - 'error' => $error); - } - } - } else { - /* No batch sending available, just loop through all recipients - * and send a message for each one. */ - foreach ($message['to'] as $recipient) { - $response = $this->_send($message, $recipient); - if ($response[0] == 1) { - /* Message was sent, store remote id if any. */ - $remote_id = (isset($response[1]) ? $response[1] : null); - $error = null; - } else { - /* Message failed, store error code. */ - $remote_id = null; - $error = $response[1]; - } - - /* Store the sends. */ - $sends[] = array('message_id' => $message['id'], - 'remote_id' => $remote_id, - 'recipient' => $recipient, - 'error' => $error); - } - } - - return $sends; - } - - /** - * If the current driver has a credit capability, queries the gateway for - * a credit balance and returns the value. - * - * @return integer Value indicating available credit or null if not - * supported. - */ - function getBalance() - { - /* Authenticate. */ - if (is_a($this->authenticate(), 'PEAR_Error')) { - return $this->_auth; - } - - /* Check balance. */ - if ($this->hasCapability('credit')) { - return $this->_getBalance(); - } else { - return null; - } - } - - /** - * Attempts to return a concrete Gateway instance based on $driver. - * - * @param string $driver The type of concrete Gateway subclass to return. - * This is based on the gateway driver ($driver). - * The code is dynamically included. - * @param array $params A hash containing any additional configuration or - * connection parameters a subclass might need. - * - * @return Net_SMS The newly created concrete Gateway instance or false on - * an error. - */ - function &factory($driver, $params = array()) - { - include_once 'Net/SMS/' . $driver . '.php'; - $class = 'Net_SMS_' . $driver; - if (class_exists($class)) { - $sms = new $class($params); - } else { - $sms = PEAR::raiseError(sprintf(_("Class definition of %s not found."), $driver)); - } - - return $sms; - } - - /** - * Attempts to return a reference to a concrete Net_SMS instance based on - * $driver. - * - * It will only create a new instance if no Net_SMS instance with the same - * parameters currently exists. - * - * This method must be invoked as: $var = &Net_SMS::singleton() - * - * @param string $driver The type of concrete Net_SMS subclass to return. - * The is based on the gateway driver ($driver). - * The code is dynamically included. - * - * @param array $params A hash containing any additional configuration or - * connection parameters a subclass might need. - * - * @return mixed The created concrete Net_SMS instance, or false on error. - */ - function &singleton($driver, $params = array()) - { - static $instances; - if (!isset($instances)) { - $instances = array(); - } - - $signature = serialize(array($driver, $params)); - if (!isset($instances[$signature])) { - $instances[$signature] = &Net_SMS::factory($driver, $params); - } - - return $instances[$signature]; - } - -} diff --git a/framework/Net_SMS/SMS/clickatell_http.php b/framework/Net_SMS/SMS/clickatell_http.php deleted file mode 100644 index 8ecc78ea1..000000000 --- a/framework/Net_SMS/SMS/clickatell_http.php +++ /dev/null @@ -1,354 +0,0 @@ - - * @package Net_SMS - */ -class Net_SMS_clickatell_http extends Net_SMS { - - var $_session_id = null; - var $_base_url = 'http://api.clickatell.com/http/'; - - /** - * An array of capabilities, so that the driver can report which operations - * it supports and which it doesn't. Possible values are:
-     *   auth        - The gateway require authentication before sending;
-     *   batch       - Batch sending is supported;
-     *   multi       - Sending of messages to multiple recipients is supported;
-     *   receive     - Whether this driver is capable of receiving SMS;
-     *   credit      - Is use of the gateway based on credits;
-     *   addressbook - Are gateway addressbooks supported;
-     *   lists       - Gateway support for distribution lists.
-     * 
- * - * @var array - */ - var $capabilities = array('auth' => true, - 'batch' => 100, - 'multi' => true, - 'receive' => false, - 'credit' => true, - 'addressbook' => false, - 'lists' => false); - - /** - * Authenticate at the gateway and set a session id if successful. Caching - * is used to minimise the http calls for subsequent messages. - * - * @access private - * - * @return mixed True on success or PEAR Error on failure. - */ - function _authenticate() - { - /* We have already authenticated so return true. */ - if (!empty($this->_session_id)) { - return true; - } - - /* Set up the http authentication url. */ - $url = sprintf('auth?user=%s&password=%s&api_id=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - $this->_params['api_id']); - - /* Do the HTTP authentication and get the response. */ - $response = Net_SMS_clickatell_http::_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Authentication failed. %s"), $response->getMessage())); - } - - /* Split up the response. */ - $response = explode(':', $response); - if ($response[0] == 'OK') { - $this->_session_id = trim($response[1]); - return true; - } else { - return $this->getError($response[1], _("Authentication failed. %s")); - } - } - - /** - * This function does the actual sending of the message. - * - * @access private - * - * @param array $message The array containing the message and its send - * parameters. - * @param array $to The recipients. - * - * @return array An array with the success status and additional - * information. - */ - function _send($message, $to) - { - /* Set up the http sending url. */ - $url = sprintf('sendmsg?session_id=%s&text=%s', - $this->_session_id, - urlencode($message['text'])); - - $req_feat = 0; - if (!empty($message['send_params']['from'])) { - /* If source from is set, require it for transit gateways and append - to url. */ - $req_feat =+ 16; - $url .= '&from=' . urlencode($message['send_params']['from']); - } - if (!empty($message['send_params']['msg_type']) && - $message['send_params']['msg_type'] == 'SMS_FLASH') { - /* If message type is flash, require it for transit gateways. */ - $req_feat =+ 512; - $url .= '&msg_type=' . $message['send_params']['msg_type']; - } - if (!empty($req_feat)) { - /* If features have been required, add to url. */ - $url .= '&req_feat=' . $req_feat; - } - - /* Append the recipients of this message and call the url. */ - foreach ($to as $key => $val) { - if (preg_match('/^.*?|$)/', $val, $matches)) { - $to[$key] = $matches[1]; - } else { - /* FIXME: Silently drop bad recipients. This should be logged - * and/or reported. */ - unset($to[$key]); - } - } - $to = implode(',', $to); - $url .= '&to=' . $to; - $response = trim($this->_callURL($url)); - - /* Ugly parsing of the response, but that's how it comes back. */ - $lines = explode("\n", $response); - $response = array(); - - if (count($lines) > 1) { - foreach ($lines as $line) { - $parts = explode('To:', $line); - $recipient = trim($parts[1]); - $outcome = explode(':', $parts[0]); - $response[$recipient] = array(($outcome[0] == 'ID' ? 1 : 0), $outcome[1]); - } - } else { - /* Single recipient. */ - $outcome = explode(':', $lines[0]); - $response[$to] = array(($outcome[0] == 'ID' ? 1 : 0), $outcome[1]); - } - - return $response; - } - - /** - * Returns the current credit balance on the gateway. - * - * @access private - * - * @return integer The credit balance available on the gateway. - */ - function _getBalance() - { - /* Set up the url and call it. */ - $url = sprintf('getbalance?session_id=%s', - $this->_session_id); - $response = trim($this->_callURL($url)); - - /* Try splitting up the response. */ - $lines = explode('=', $response); - - /* Split up the response. */ - $response = explode(':', $response); - if ($response[0] == 'Credit') { - return trim($response[1]); - } else { - return $this->getError($response[1], _("Could not check balance. %s")); - } - } - - /** - * Identifies this gateway driver and returns a brief description. - * - * @return array Array of driver info. - */ - function getInfo() - { - return array( - 'name' => _("Clickatell via HTTP"), - 'desc' => _("This driver allows sending of messages through the Clickatell (http://clickatell.com) gateway, using the HTTP API"), - ); - } - - /** - * Returns the required parameters for this gateway driver. - * - * @return array Array of required parameters. - */ - function getParams() - { - return array( - 'user' => array('label' => _("Username"), 'type' => 'text'), - 'password' => array('label' => _("Password"), 'type' => 'text'), - 'api_id' => array('label' => _("API ID"), 'type' => 'text'), - ); - } - - /** - * Returns the parameters that can be set as default for sending messages - * using this gateway driver and displayed when sending messages. - * - * @return array Array of parameters that can be set as default. - * @todo Set up batch fields/params, would be nice to have ringtone/logo - * support too, queue choice, unicode choice. - */ - function getDefaultSendParams() - { - $params = array(); - $params['from'] = array( - 'label' => _("Source address"), - 'type' => 'text'); - - $params['deliv_time'] = array( - 'label' => _("Delivery time"), - 'type' => 'enum', - 'params' => array(array('now' => _("immediate"), 'user' => _("user select")))); - - $types = array('SMS_TEXT' => _("Standard"), 'SMS_FLASH' => _("Flash")); - $params['msg_type'] = array( - 'label' => _("Message type"), - 'type' => 'keyval_multienum', - 'params' => array($types)); - - return $params; - } - - /** - * Returns the parameters for sending messages using this gateway driver, - * displayed when sending messages. These are filtered out using the - * default values set for the gateway. - * - * @return array Array of required parameters. - * @todo Would be nice to use a time/date setup rather than minutes from - * now for the delivery time. Upload field for ringtones/logos? - */ - function getSendParams($params) - { - if (empty($params['from'])) { - $params['from'] = array( - 'label' => _("Source address"), - 'type' => 'text'); - } - - if ($params['deliv_time'] == 'user') { - $params['deliv_time'] = array( - 'label' => _("Delivery time"), - 'type' => 'int', - 'desc' => _("Value in minutes from now.")); - } - - if (count($params['msg_type']) > 1) { - $params['msg_type'] = array( - 'label' => _("Message type"), - 'type' => 'enum', - 'params' => array($params['msg_type'])); - } else { - $params['msg_type'] = $params['msg_type'][0]; - } - - return $params; - } - - /** - * Returns a string representation of an error code. - * - * @param integer $error The error code to look up. - * @param string $text An existing error text to use to raise a - * PEAR Error. - * - * @return mixed A textual message corresponding to the error code or a - * PEAR Error if passed an existing error text. - * - * @todo Check which of these are actually required and trim down the - * list. - */ - function getError($error, $error_text = '') - { - /* Make sure we get only the number at the start of an error. */ - list($error) = explode(',', $error); - $error = trim($error); - - /* An array of error codes returned by the gateway. */ - $errors = array('001' => _("Authentication failed"), - '002' => _("Unknown username or password."), - '003' => _("Session ID expired."), - '004' => _("Account frozen."), - '005' => _("Missing session ID."), - '007' => _("IP lockdown violation."), - '101' => _("Invalid or missing parameters."), - '102' => _("Invalid UDH. (User Data Header)."), - '103' => _("Unknown apimsgid (API Message ID)."), - '104' => _("Unknown climsgid (Client Message ID)."), - '105' => _("Invalid destination address."), - '106' => _("Invalid source address."), - '107' => _("Empty message."), - '108' => _("Invalid or missing api_id."), - '109' => _("Missing message ID."), - '110' => _("Error with email message."), - '111' => _("Invalid protocol."), - '112' => _("Invalid msg_type."), - '113' => _("Max message parts exceeded."), - '114' => _("Cannot route message to specified number."), - '115' => _("Message expired."), - '116' => _("Invalid unicode data."), - '201' => _("Invalid batch ID."), - '202' => _("No batch template."), - '301' => _("No credit left."), - '302' => _("Max allowed credit.")); - - if (empty($error_text)) { - return $errors[$error]; - } else { - return PEAR::raiseError(sprintf($error_text, $errors[$error])); - } - } - - /** - * Do the http call using a url passed to the function. - * - * @access private - * - * @param string $url The url to call. - * - * @return mixed The response on success or PEAR Error on failure. - */ - function _callURL($url) - { - $options['method'] = 'GET'; - $options['timeout'] = 5; - $options['allowRedirects'] = true; - - $http = new HTTP_Request($this->_base_url . $url, $options); - @$http->sendRequest(); - if ($http->getResponseCode() != 200) { - return PEAR::raiseError(sprintf(_("Could not open %s."), $url)); - } - - return $http->getResponseBody(); - } - -} diff --git a/framework/Net_SMS/SMS/generic_smpp.php b/framework/Net_SMS/SMS/generic_smpp.php deleted file mode 100644 index d8c02452e..000000000 --- a/framework/Net_SMS/SMS/generic_smpp.php +++ /dev/null @@ -1,200 +0,0 @@ - - * @link http://pear.php.net/package/Net_SMS - * @since Net_SMS 0.2.0 - */ -class Net_SMS_generic_smpp extends Net_SMS { - - /** - * Capabilities of this driver - * - * @var array - */ - var $capabilities = array( - 'auth' => true, - 'batch' => false, - 'multi' => false, - 'receive' => false, - 'credit' => false, - 'addressbook' => false, - 'lists' => false - ); - - /** - * Driver parameters - * - * @var array - * @access private - */ - var $_params = array( - 'host' => null, - 'port' => 0, - 'vendor' => null, - 'bindParams' => array(), - 'submitParams' => array() - ); - - /** - * Net_SMPP_Client instance - * - * @var Net_SMPP_Client - * @access private - */ - var $_client = null; - - /** - * Constructor. - * - * @param array $params Parameters. - */ - function Net_SMS_generic_smpp($params = null) - { - parent::Net_SMS($params); - $this->_client =& new Net_SMPP_Client($this->_params['host'], $this->_params['port']); - if (!is_null($this->_params['vendor'])) { - Net_SMPP::setVendor($this->_params['vendor']); - } - } - - /** - * Identifies this driver. - * - * @return array Driver info. - */ - function getInfo() - { - return array( - 'name' => _("SMPP Gateway"), - 'desc' => _("This driver allows sending of messages through an SMPP gateway.") - ); - } - - /** - * Get required paramaters - * - * @return array Array of required parameters. - */ - function getParams() - { - return array( - 'host' => array( - 'label' => _("Host"), 'type' => 'text'), - 'port' => array( - 'label' => _("Port"), 'type' => 'int'), -// 'bindParams' => array( -// 'label' => _('bind_transmitter paramaters'), 'type' => 'array'), -// 'submitParams' => array( -// 'label' => _('submit_sm parameters'), 'type' => 'array' -// ) - ); - } - - /** - * Sends the message. - * - * @access private - * - * @param array $message Message to send. - * @param string $to The recipient. - * - * @return array An array with the success status and additional - * information. - */ - function _send($message, $to) - { - $pdu =& Net_SMPP::PDU('submit_sm', $this->_params['submitParams']); - $pdu->destination_addr = $to; - $pdu->short_message = $message['text']; - if (count($message) > 1) { - // Other params to set - $v = $message; - unset($v['text']); - $pdu->set($v); - unset($v); - } - - $res =& $this->_client->sendPDU($pdu); - - // Error sending? - if ($res === false) { - return array(0, _("Error sending PDU")); - } - - $resp =& $this->_client->readPDU(); - if ($resp === false) { - return array(0, _("Could not read response PDU")); - } - if ($resp->isError()) { - return array(0, sprintf(_("Sending failed: %s") . $resp->statusDesc())); - } - - // Success! - return array(1, $resp->message_id); - } - - /** - * Authenticates with the SMSC. - * - * This method connects to the SMSC (if not already connected) and - * authenticates with the bind_transmitter command (if not already bound). - * - * @access protected - */ - function _authenticate() - { - if ($this->_client->state == NET_SMPP_CLIENT_STATE_CLOSED) { - $res = $this->_client->connect(); - if ($res === false) { - return false; - } - } - - if ($this->_client->state == NET_SMPP_CLIENT_STATE_OPEN) { - $resp =& $this->_client->bind($this->_params['bindParams']); - if ($resp === false || (is_object($resp) && $resp->isError())) { - return false; - } - } - - return true; - } - - /** - * Accepts an object. - * - * @see Net_SMPP_Client::accept() - * - * @return mixed {@link Net_SMPP_Client::accept()}'s return value - */ - function accept(&$obj) - { - return $this->_client->accept($obj); - } - - /** - * Returns a list of parameters specific for this driver. - * - * @return array Default sending parameters. - */ - function getDefaultSendParams() - { - return array(); - } - -} diff --git a/framework/Net_SMS/SMS/generic_smtp.php b/framework/Net_SMS/SMS/generic_smtp.php deleted file mode 100644 index 06ba7b2a6..000000000 --- a/framework/Net_SMS/SMS/generic_smtp.php +++ /dev/null @@ -1,192 +0,0 @@ - - * @since Net_SMS 0.0.2 - */ -class Net_SMS_generic_smtp extends Net_SMS { - - /** - * Capabilities of this driver. - * - * @var array - */ - var $capabilities = array( - 'auth' => false, - 'batch' => false, - 'multi' => false, - 'receive' => false, - 'credit' => false, - 'addressbook' => false, - 'lists' => false - ); - - /** - * Driver parameters. - * - * @var array - * - * @access private - */ - var $_params = array( - 'carrier' => null, - 'mailBackend' => 'mail', - 'mailParams' => array(), - 'mailHeaders' => array() - ); - - /** - * Carrier email map. - * - * @var array - * - * @access private - */ - var $_carriers = array( - /* U.S. carriers. */ - 'att' => '%s@mmode.com', - 'cingular' => '%s@mmode.com', - 'verizon' => '%s@vtext.com', - 'boost' => '%s@myboostmobile.com', - 'cellularone' => '%s@mycellone.net', - 'cincybell' => '%s@gocbw.com', - 'sprint' => '%s@messaging.sprintpcs.com', - 'tmobile_us' => '%s@tmomail.com', - 'suncom' => '%s@tms.suncom.com', - 'aircel' => '%s@airsms.com', - 'airtel' => '%s@airtelmail.com', - 'bplmobile' => '%s@bplmobile.com', - 'bellmobility' => '%s@txt.bellmobility.ca', - 'bluegrass' => '%s@sms.bluecell.com', - 'cellforce' => '%s@celforce.com', - 'cellularone' => '%s@mycellone.net', - /* German carriers. */ - 'eplus' => '%s@smsmail.eplus.de', - 'tmobile_de' => '%s@t-mobile-sms.de', - 'vodafone_de' => '%s@vodafone-sms.de', - ); - - /** - * Identifies this driver. - * - * @return array Driver info. - */ - function getInfo() - { - return array( - 'name' => _("Email-to-SMS Gateway"), - 'desc' => _("This driver allows sending of messages through an email-to-SMS gateway, for carriers which provide this service.") - ); - } - - /** - * Returns required parameters. - * - * @return array Array of required parameters. - */ - function getParams() - { - return array( - 'carrier' => array('label' => _("Carrier"), 'type' => 'text'), - 'mailBackend' => array('label' => _("Mail backend"), 'type' => 'text') - ); - } - - /** - * Sends the message. - * - * You may also specify the carrier with the 'carrier' key of the message - * to avoid creating a new instance for each carrier, or fiddling with the - * parameters. - * - * @access private - * - * @param array $message Message to send. - * @param string $to The recipient. - * - * @return array An array with the success status and additional - * information. - */ - function _send($message, $to) - { - $m = Horde_Mail::factory($this->_params['mailBackend'], $this->_params['mailParams']); - - if (isset($message['carrier'])) { - $dest = $this->_getDest($to, $message['carrier']); - } else { - $dest = $this->_getDest($to); - } - - try { - $m->send($dest, $this->_params['mailHeaders'], $message['text']); - return array(1, null); - } catch (Horde_Mail_Exception $e) { - return array(0, $e->getMessage()); - } - } - - /** - * Returns destination e-mail address. - * - * @param string $phone Phone number to send to. - * - * @return string Destination address. - */ - function _getDest($phone, $carrier = null) - { - $carrier = is_null($carrier) ? $this->_params['carrier'] : $carrier; - return sprintf($this->_carriers[$carrier], - preg_replace('/[^0-9]/', '', $phone)); - } - - /** - * Returns the address template for a carrier. - * - * @param string $carrier Carrier name. - * - * @return mixed Address template or false. - */ - function getAddressTemplate($carrier) - { - if (!isset($this->_carriers[$carrier])) { - return false; - } - return $this->_carriers[$carrier]; - } - - /** - * Adds a carrier to the list. - * - * Address templates need to be in the form of an email address, with a - * '%s' representing the place where the destination phone number goes. - * - * @param string $name Carrier name. - * @param string $addr Address template. - */ - function addCarrier($name, $addr) - { - $this->_carriers[$name] = $addr; - } - - /** - * Returns a list of parameters specific for this driver. - * - * @return array Default sending parameters. - */ - function getDefaultSendParams() - { - return array(); - } - -} diff --git a/framework/Net_SMS/SMS/sms2email_http.php b/framework/Net_SMS/SMS/sms2email_http.php deleted file mode 100644 index dd2e75a5d..000000000 --- a/framework/Net_SMS/SMS/sms2email_http.php +++ /dev/null @@ -1,687 +0,0 @@ - - * @package Net_SMS - */ -class Net_SMS_sms2email_http extends Net_SMS { - - var $_base_url = 'horde.sms2email.com/horde/'; - - /** - * An array of capabilities, so that the driver can report which - * operations it supports and which it doesn't. Possible values are:
-     *   auth        - The gateway requires authentication before sending;
-     *   batch       - Batch sending is supported;
-     *   multi       - Sending of messages to multiple recipients is supported;
-     *   receive     - Whether this driver is capable of receiving SMS;
-     *   credit      - Is use of the gateway based on credits;
-     *   addressbook - Are gateway addressbooks supported;
-     *   lists       - Gateway support for distribution lists.
-     * 
- * - * @var array - */ - var $capabilities = array('auth' => false, - 'batch' => 100, - 'multi' => true, - 'receive' => false, - 'credit' => true, - 'addressbook' => true, - 'lists' => true); - - /** - * This function does the actual sending of the message. - * - * @access private - * - * @param array $message The array containing the message and its send - * parameters. - * @param array $to The recipients. - * - * @return array An array with the success status and additional - * information. - */ - function _send($message, $to) - { - /* Set up the sending url. */ - $url = sprintf('postmsg.php?username=%s&password=%s&message=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - urlencode($message['text'])); - - /* Check if source from is set. */ - if (!empty($message['send_params']['from'])) { - $url .= '&orig=' . urlencode($message['send_params']['from']); - } - /* Check if message type is flash. */ - if (!empty($message['send_params']['msg_type']) && - $message['send_params']['msg_type'] == 'SMS_FLASH') { - $url .= '&flash=1'; - } - /* Check if delivery report url has been set. */ - if (!empty($this->_params['delivery_report'])) { - $url .= '&dlurl=' . urlencode($this->_params['delivery_report']) . - 'reportcode=%code&destinationnumber=%dest'; - } - - /* Loop through recipients and do some minimal validity checking. */ - if (is_array($to)) { - foreach ($to as $key => $val) { - if (preg_match('/^.*?|$)/', $val, $matches)) { - $to[$key] = $matches[1]; - } else { - /* FIXME: Silently drop bad recipients. This should be - * logged and/or reported. */ - unset($to[$key]); - } - } - $to = implode(',', $to); - } else { - if (preg_match('/^.*?|$)/', $to, $matches)) { - $to = $matches[1]; - } else { - return array(0, sprintf(_("Invalid recipient: \"%s\""), $to)); - } - } - - /* Append the recipients of this message and call the url. */ - $url .= '&to_num=' . $to; - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return array(0, $response->getMessage()); - } - - /* Parse the response, check for new lines in case of multiple - * recipients. */ - $lines = explode("\n", $response); - $response = array(); - - if (count($lines) > 1) { - /* Multiple recipients. */ - foreach ($lines as $line) { - $parts = explode('To:', $line); - $recipient = trim($parts[1]); - if ($lines[0] == 'AQSMS-OK') { - $response[$recipient] = array(1, null); - } else { - $response[$recipient] = array(0, $lines[0]); - } - } - } else { - /* Single recipient. */ - if ($lines[0] == 'AQSMS-OK') { - $response[$to] = array(1, null); - } else { - $response[$to] = array(0, $lines[0]); - } - } - - return $response; - } - - /** - * Returns the current credit balance on the gateway. - * - * @access private - * - * @return integer The credit balance available on the gateway. - */ - function _getBalance() - { - /* Set up the url and call it. */ - $url = sprintf('postmsg.php?username=%s&password=%s&cmd=credit', - urlencode($this->_params['user']), - urlencode($this->_params['password'])); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Try splitting up the response. */ - $lines = explode('=', $response); - - if ($lines[0] == 'AQSMS-CREDIT') { - return $lines[1]; - } else { - return $this->getError($lines[0], _("Could not check balance. %s")); - } - } - - /** - * Adds a contact to the gateway's addressbook. - * - * @param string $name The name for this contact - * @param integer $number The contact's phone number. - * - * @return mixed The remote contact ID on success or PEAR Error on - * failure. - */ - function addContact($name, $number) - { - /* Set up the url and call it. */ - $url = sprintf('postcontacts.php?username=%s&password=%s&cmd=ADDCONTACT&name=%s&number=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - urlencode($name), - $number); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check if there was an error response. */ - if (substr($response, 0, 17) != 'AQSMS-CONTACTIDOK') { - return $this->getError($response, _("Could not add contact. %s")); - } - - /* Split up the response. */ - $lines = explode(',=', $response); - return $lines[1]; - } - - /** - * Updates a contact in the gateway's addressbook. - * - * @param integer $id The contact's ID on the gateway. - * @param string $name The name for this contact - * @param integer $number The contact's phone number. - * - * @return mixed True on success or PEAR Error on failure. - */ - function updateContact($id, $name, $number) - { - /* Set up the url and call it. */ - $url = sprintf('postcontacts.php?username=%s&password=%s&cmd=UPDATECONTACT&id=%s&name=%s&number=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - $id, - urlencode($name), - $number); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Parse the response. */ - if ($response == 'AQSMS-OK') { - return true; - } else { - return $this->getError($response, _("Could not update contact. %s")); - } - } - - /** - * Deletes a contact in the gateway's addressbook. - * - * @param integer $id The contact's ID on the gateway. - * - * @return mixed True on success or PEAR Error on failure. - */ - function deleteContact($id) - { - /* Set up the url and call it. */ - $url = sprintf('postcontacts.php?username=%s&password=%s&cmd=DELETECONTACT&id=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - $id); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Parse the response. */ - if ($response == 'AQSMS-OK') { - return true; - } else { - return $this->getError($response, _("Could not delete contact. %s")); - } - } - - /** - * Fetches the entire address book from the gateway. - * - * @return mixed Array of contacts on success or PEAR Error on failure. - * Format of the returned contacts is for example: - * array( => array('name' => , - * 'number' => ), - * => array('name' => , - * 'number' => )); - * - */ - function getAddressBook() - { - /* Set up the url and call it. */ - $url = sprintf('postcontacts.php?username=%s&password=%s&cmd=GETADDRESSBOOK', - urlencode($this->_params['user']), - urlencode($this->_params['password'])); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check if there was an error response. */ - if (substr($response, 0, 19) != 'AQSMS-ADDRESSBOOKOK') { - return $this->getError($response, _("Could not retrieve address book. %s")); - } - - /* Parse the response and construct the array. */ - list($response, $contacts_str) = explode(',', $response, 2); - - /* Check that the full address book list has been received. */ - $length = substr($response, 19); - if (strlen($contacts_str) != $length) { - return PEAR::raiseError(_("Could not fetch complete address book.")); - } - $contacts_lines = explode("\n", $contacts_str); - $contacts = array(); - /* Loop through lines and pick out the fields, make sure that the "" - * are not included in the values, so get the line less 1 char on each - * end and split for ",". */ - foreach ($contacts_lines as $line) { - list($id, $name, $number) = explode('","', substr($line, 1, -1)); - $contacts[$id] = array('name' => $name, 'number' => $number); - } - - return $contacts; - } - - /** - * Creates a new distribution list on the gateway. - * - * @param string $name An arbitrary name for the new list. - * @param array $numbers A simple array of numbers to add to the list. - * - * @return mixed Gateway ID for the created list on success or PEAR Error - * on failure. - */ - function listCreate($name, $numbers) - { - /* Set up the url and call it. */ - $url = sprintf('postdistribution.php?username=%s&password=%s&cmd=ADDDISTLIST&name=%s&numlist=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - urlencode($name), - implode(',', $numbers)); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check if there was an error response. */ - if (substr($response, 0, 16) != 'AQSMS-DISTITEMID') { - return $this->getError($response, _("Could not create distribution list. %s")); - } - - /* Parse the response and get the distribution list ID. */ - list($response, $id) = explode('=', $response); - - /* TODO: do we need to check the length of the id string? */ - - return $id; - } - - /** - * Deletes a distribution list from the gateway. - * - * @param string $id The gateway ID for the list to delete. - * - * @return mixed True on success or PEAR Error on failure. - */ - function listDelete($id) - { - /* Set up the url and call it. */ - $url = sprintf('postdistribution.php?username=%s&password=%s&cmd=DELETEDISTLIST&distid=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - $id); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check response. */ - if ($response == 'AQSMS-OK') { - return true; - } else { - return $this->getError($response, _("Could not delete distribution list. %s")); - } - } - - /** - * Updates a distribution list on the gateway. - * - * @param string $id The gateway ID for the list to update. - * @param string $name The arbitrary name of the list. If different - * from the original name that the list was created - * under, the list will be renamed. - * @param string $numbers The new list of numbers in the list. If left - * empty, the result will be the same as calling - * the listRename() function. - * - * @return mixed True on success or PEAR Error on failure. - */ - function listUpdate($id, $name, $numbers = array()) - { - /* Set up the url and call it. */ - $url = sprintf('postdistribution.php?username=%s&password=%s&cmd=UPDATELISTNAME&distid=%s&name=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - $id, - urlencode($name)); - - /* Check if the list numbers need updating. */ - if (!empty($numbers)) { - $url .= '&numbers=' . implode(',', $numbers); - } - - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check response. */ - if ($response == 'AQSMS-OK') { - return true; - } else { - return $this->getError($response, _("Could not update distribution list. %s")); - } - } - - /** - * Renames a distribution list on the gateway. Does nothing other than - * calling the listUpdate() function with just the $id and $name - * variables. - * - * @param string $id The gateway ID for the list to update. - * @param string $name The new arbitrary name for the list. - * - * @return mixed True on success or PEAR Error on failure. - */ - function listRename($id, $name) - { - return $this->listUpdate($id, $name); - } - - /** - * Fetches a listing of available distribution lists on the server. - * - * @return mixed An array of lists on success or PEAR Error on failure. - * Format of the returned lists is for example: - * array( => array('name' => ), - * => array('name' => )); - * - */ - function getLists() - { - /* Set up the url and call it. */ - $url = sprintf('postdistribution.php?username=%s&password=%s&cmd=GETCOMPACTLIST', - urlencode($this->_params['user']), - urlencode($this->_params['password'])); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check if there was an error response. */ - if (substr($response, 0, 22) != 'AQSMS-DISTRIBUTIONLIST') { - return $this->getError($response, _("Could not retrieve distribution lists. %s")); - } - - /* Parse the response and construct the array. */ - list($response, $lists_str) = explode(',', $response, 2); - - /* Check that the full list of distribution lists has been received. */ - $length = substr($response, 22); - if (strlen($lists_str) != $length) { - return PEAR::raiseError(_("Could not fetch the complete list of distribution lists.")); - } - $lists_lines = explode("\n", $lists_str); - $lists = array(); - /* Loop through lines and pick out the fields, make sure that the "" - * are not included in the values, so get the line less 1 char on each - * end and split for ",". */ - foreach ($lists_lines as $line) { - list($id, $name, $count) = explode('","', substr($line, 1, -1)); - $lists[$id] = array('name' => $name, - 'count' => $count); - } - - return $lists; - } - - /** - * Fetches a specific distribution list from the gateway. - * - * @param string The ID of the distribution list to fetch. - * - * @return mixed An array of numbers in the list on success or PEAR Error - * on failure. - */ - function getList($id) - { - /* Set up the url and call it. */ - $url = sprintf('postdistribution.php?username=%s&password=%s&cmd=GETNUMBERSWITHID&distid=%s', - urlencode($this->_params['user']), - urlencode($this->_params['password']), - $id); - $response = $this->_callURL($url); - if (is_a($response, 'PEAR_Error')) { - return $response; - } - - /* Check if there was an error response. */ - if (substr($response, 0, 22) != 'AQSMS-DISTRIBUTIONLIST') { - return $this->getError($response, _("Could not retrieve distribution list. %s")); - } - - /* Parse the response and construct the array. */ - list($response, $list_str) = explode(',', $response, 2); - - /* Check that the full list of distribution lists has been received. */ - $length = substr($response, 22); - if (strlen($list_str) != $length) { - return PEAR::raiseError(_("Could not fetch complete distribution list.")); - } - $list_str = trim($list_str); - list($count, $numbers) = explode('","', $list_str); - - /* TODO: Anything useful that can be done with the count of numbers at - * the start? */ - $count = substr($count, 1); - - /* Explode the list of numbers into an array and return. */ - $numbers = substr($numbers, 0, -1); - return explode(',', $numbers); - } - - /** - * Identifies this gateway driver and returns a brief description. - * - * @return array Array of driver info. - */ - function getInfo() - { - return array( - 'name' => _("sms2email via HTTP"), - 'desc' => _("This driver allows sending of messages through the sms2email (http://sms2email.com) gateway, using the HTTP API"), - ); - } - - /** - * Returns the required parameters for this gateway driver. The settable - * parameters for this gateway are:
-     *   - user            - The username for authentication on the gateway;
-     *   - password        - The password for authentication on the gateway;
-     *   - ssl             - Whether or not to use SSL for communication with
-     *                       the gateway.
-     *   - delivery_report - A URL for a script which would accept delivery
-     *                       report from the gateway.
-     * 
- * - * @return array Array of required parameters. - */ - function getParams() - { - $params = array(); - $params['user'] = array('label' => _("Username"), 'type' => 'text'); - $params['password'] = array('label' => _("Password"), 'type' => 'text'); - $params['ssl'] = array('label' => _("Use SSL"), - 'type' => 'boolean', - 'required' => false); - $params['delivery_report'] = array('label' => _("URL for your script delivery status report"), - 'type' => 'text', - 'required' => false); - - - return $params; - } - - /** - * Returns the parameters that can be set as default for sending messages - * using this gateway driver and displayed when sending messages. - * - * @return array Array of parameters that can be set as default. - */ - function getDefaultSendParams() - { - $params = array(); - $params['from'] = array( - 'label' => _("Source address"), - 'type' => 'text'); - - $params['deliv_time'] = array( - 'label' => _("Delivery time"), - 'type' => 'enum', - 'params' => array(array('now' => _("immediate"), 'user' => _("user select")))); - - $types = array('SMS_TEXT' => _("Standard"), 'SMS_FLASH' => _("Flash")); - $params['msg_type'] = array( - 'label' => _("Message type"), - 'type' => 'keyval_multienum', - 'params' => array($types)); - - return $params; - } - - /** - * Returns the parameters for sending messages using this gateway driver, - * displayed when sending messages. These are filtered out using the - * default values set up when creating the gateway. - * - * @return array Array of required parameters. - * @todo Would be nice to use a time/date setup rather than minutes from - * now for the delivery time. Upload field for ringtones/logos? - */ - function getSendParams($params) - { - if (empty($params['from'])) { - $params['from'] = array( - 'label' => _("Source address"), - 'type' => 'text'); - } - - if ($params['deliv_time'] == 'user') { - $params['deliv_time'] = array( - 'label' => _("Delivery time"), - 'type' => 'int', - 'desc' => _("Value in minutes from now.")); - } - - if (count($params['msg_type']) > 1) { - $params['msg_type'] = array( - 'label' => _("Message type"), - 'type' => 'enum', - 'params' => array($params['msg_type'])); - } else { - $params['msg_type'] = $params['msg_type'][0]; - } - - return $params; - } - - /** - * Returns a string representation of an error code. - * - * @param integer $error The error code to look up. - * @param string $text An existing error text to use to raise a - * PEAR Error. - * - * @return mixed A textual message corresponding to the error code or a - * PEAR Error if passed an existing error text. - * - * @todo Check which of these are actually required and trim down the - * list. - */ - function getError($error, $error_text = '') - { - $error = trim($error); - - /* An array of error codes returned by the gateway. */ - $errors = array( - 'AQSMS-NOAUTHDETAILS' => _("No username and/or password sent."), - 'AQSMS-AUTHERROR' => _("Incorrect username and/or password."), - 'AQSMS-NOMSG' => _("No message supplied."), - 'AQSMS-NODEST' => _("No destination supplied."), - 'AQSMS-NOCREDIT' => _("Insufficient credit."), - 'AQSMS-NONAMESUPPLIED' => _("No name specified."), - 'AQSMS-NONUMBERSUPPLIED' => _("No number specified."), - 'AQSMS-ADDRESSBOOKERROR' => _("There was an error performing the specified address book function. Please try again later."), - 'AQSMS-CONTACTIDERROR' => _("The contact ID number was not specified, left blank or was not found in the database."), - 'AQSMS-CONTACTUPDATEERROR' => _("There was an error updating the contact details. Please try again later."), - 'AQSMS-DISTIDERROR' => _("The distribution list ID was either not specified, left blank or not found in the database."), - 'AQSMS-NODISTLISTSUPPLIED' => _("The distribution list was not specified."), - 'AQSMS-INSUFFICIENTCREDITS' => _("Insufficient credit to send to the distribution list."), - 'AQSMS-NONUMBERLISTSUPPLIED' => _("Numbers not specified for updating in distribution list."), - 'AQSMS-DISTLISTUPDATEERROR' => _("There was an error updating the distribution list. Please try again later.")); - - if (empty($error_text)) { - return $errors[$error]; - } else { - return PEAR::raiseError(sprintf($error_text, $errors[$error])); - } - } - - /** - * Do the http call using a url passed to the function. - * - * @access private - * - * @param string $url The url to call. - * - * @return mixed The response on success or PEAR Error on failure. - */ - function _callURL($url) - { - $options['method'] = 'POST'; - $options['timeout'] = 5; - $options['allowRedirects'] = true; - - $url = (empty($this->_params['ssl']) ? 'http://' : 'https://') . $this->_base_url . $url; - - $http = new HTTP_Request($url, $options); - @$http->sendRequest(); - if ($http->getResponseCode() != 200) { - return PEAR::raiseError(sprintf(_("Could not open %s."), $url)); - } - - return $http->getResponseBody(); - } - -} diff --git a/framework/Net_SMS/SMS/textmagic_http.php b/framework/Net_SMS/SMS/textmagic_http.php deleted file mode 100644 index 89557fe62..000000000 --- a/framework/Net_SMS/SMS/textmagic_http.php +++ /dev/null @@ -1,542 +0,0 @@ - - * - * See the enclosed file COPYING for license information (LGPL). If you did - * not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @package Net_SMS - * @author Fedyashev Nikita - * - */ -class Net_SMS_textmagic_http extends Net_SMS -{ - var $_base_url = 'https://www.textmagic.com/app/api?'; - - function Net_SMS_textmagic_http($params) - { - - parent::Net_SMS($params); - - if (!extension_loaded('json')) { - die ("JSON extenstion isn't loaded!"); - } - } - - /** - * An array of capabilities, so that the driver can report which operations - * it supports and which it doesn't. Possible values are:
-     *   send           - Send SMS, scheduled sending;
-     *   account        - Check account balance;
-     *   messageStatus  - Check messages's cost and delivery status;
-     *   receive        - Receive incoming messages;
-     *   deleteReply    - Delete specified incoming messages;
-     *   checkNumber    - Check phone number validity and destination price;
-     * 
- * - * @var array - */ - var $capabilities = array('auth' => false, - 'batch' => 100, - 'multi' => true, - 'receive' => true, - 'credit' => true, - 'addressbook' => false, - 'lists' => false, - - 'message_status' => true, - 'delete_reply' => true, - 'check_number' => true); - - /** - * This function does the actual sending of the message. - * - * @param array &$message The array containing the message and its send - * parameters. - * @param string $to The destination string. - * - * @return array An array with the success status and additional - * information. - */ - function _send(&$message, $to) - { - - $unicode = $this->_getUnicodeParam($message); - $max_length = $this->_getMaxLengthParam($message); - - $to = implode(',', $to); - - $url = sprintf('cmd=send&phone=%s&text=%s&unicode=%s&max_length=%s', - urlencode($to), - urlencode($message['text']), - $unicode, - $max_length); - - $response = $this->_callURL($url); - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed."))); - } - - $result = array(); - - if (!array_key_exists('error_code', $response)) { - - if (count(explode(',', $to)) == 1) { - - $message_ids = array_keys($response['message_id']); - - $result[$to] = array( - 0 => 1, - 1 => $message_ids[0] - ); - } else { - foreach ($response['message_id'] as $id => $recipient) { - $result[$recipient] = array(1, $id); - } - } - } else { - - if (count(explode(',', $to)) == 1) { - - $result[$to] = array( - 0 => 0, - 1 => $response['error_message'] - ); - } else { - foreach (explode(',', $to) as $recipient) { - $result[$recipient] = array(0, $response['error_message']); - } - } - } - - return $result; - } - - function _getMaxLengthParam($message) { - $default_params = $this->getDefaultSendParams(); - - if (isset($message['send_params']['max_length'])) { - $max_length = $message['send_params']['max_length']; - } else { - $max_length = $default_params['max_length']['default_value']; - } - - return $max_length; - - } - - function _getUnicodeParam($message) { - $default_params = $this->getDefaultSendParams(); - - if (isset($message['send_params']['unicode'])) { - $unicode = $message['send_params']['unicode']; - } else { - $unicode = $default_params['unicode']['default_value']; - } - - return $unicode; - } - - /** - * This function check message delivery status. - * - * @param array $ids The array containing message IDs. - * - * @return array An array with the success status and additional - * information. - */ - function messageStatus($ids) - { - - if (!is_array($ids)) { - $ids = array($ids); - } - - $ids = implode(',', $ids); - - $url = sprintf('cmd=message_status&ids=%s', - urlencode($ids)); - - $response = $this->_callURL($url); - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed."))); - } - - $result = array(); - - if (!array_key_exists('error_code', $response)) { - - if (count(explode(',', $ids)) == 1) { - - $result[$ids] = array( - 0 => 1, - 1 => $response[$ids] - ); - } else { - foreach ($response as $id => $message) { - $result[$id] = array(1, $message); - } - } - } else { - - if (count(explode(',', $ids)) == 1) { - - $result[$to] = array( - 0 => 0, - 1 => $response['error_message'] - ); - } else { - foreach (explode(',', $ids) as $id) { - $result[$id] = array(0, $response['error_message']); - } - } - } - - return $result; - } - - /** - * This function retrieves incoming messages. - * - * @param array $last_retrieved_id The array containing message IDs. - * - * @return array An array with the success status and additional - * information. - */ - function receive($last_retrieved_id) - { - if (!is_int($last_retrieved_id)) { - $last_retrieved_id = int($last_retrieved_id); - } - - $url = sprintf('cmd=receive&last=%s', $last_retrieved_id); - - $response = $this->_callURL($url); - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed."))); - } - - $result = array(); - - if (!array_key_exists('error_code', $response)) { - $result[0] = 1; - - $result[1] = $response; - } else { - $result[0] = 0; - - $result[1] = $response['error_message']; - } - - return $result; - } - - - /** - * This function allows you to delete Incoming message - * - * @param array $ids The array containing message IDs. - * - * @return array An array with the success status and additional - * information. - */ - function deleteReply($ids) - { - - if (!is_array($ids)) { - $ids = array($ids); - } - - $ids = implode(',', $ids); - - /* Set up the http sending url. */ - $url = sprintf('cmd=delete_reply&ids=%s', - urlencode($ids)); - - $response = $this->_callURL($url); - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed."))); - } - - $result = array(); - - if (!array_key_exists('error_code', $response)) { - - if (count(explode(',', $ids)) == 1) { - - $result[$ids] = array( - 0 => 1, - 1 => true - ); - } else { - foreach ($response['deleted'] as $id) { - $result[$id] = array(1, true); - } - } - } else { - - if (count(explode(',', $ids)) == 1) { - - $result[$to] = array( - 0 => 0, - 1 => $response['error_message'] - ); - } else { - foreach (explode(',', $ids) as $id) { - $result[$id] = array(0, $response['error_message']); - } - } - } - - return $result; - } - - /** - * This function allows you to validate phone number's format, - * check its country and message price to the destination . - * - * @param array $numbers Phone numbers array to be checked. - * - * @return array An array with the success status and additional - * information. - */ - function checkNumber($numbers) - { - - if (!is_array($numbers)) { - $numbers = array($numbers); - } - - $numbers = implode(',', $numbers); - - $url = sprintf('cmd=check_number&phone=%s', - urlencode($numbers)); - - $response = $this->_callURL($url); - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed."))); - } - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed."))); - } - - $result = array(); - - if (!array_key_exists('error_code', $response)) { - - if (count(explode(',', $numbers)) == 1) { - - $result[$numbers] = array( - 0 => 1, - 1 => array( - "price" => $response[$numbers]['price'], - "country" => $response[$numbers]['country'] - ) - ); - } else { - foreach (explode(',', $numbers) as $number) { - $result[$number] = array(1, array( - "price" => $response[$number]['price'], - "country" => $response[$number]['country'] - )); - } - } - } else { - - if (count(explode(',', $numbers)) == 1) { - - $result[explode(',', $numbers)] = array( - 0 => 0, - 1 => $response['error_message'] - ); - } else { - foreach (explode(',', $numbers) as $number) { - $result[$number] = array(0, $response['error_message']); - } - } - } - - return $result; - - } - - /** - * Returns the current credit balance on the gateway. - * - * @access private - * - * @return integer The credit balance available on the gateway. - */ - function _getBalance() - { - $url = 'cmd=account'; - - $response = $this->_callURL($url); - - if (is_a($response, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Send failed. %s"), $response['error_message'])); - } - - if (!array_key_exists('error_code', $response)) { - return $response['balance']; - } else { - return $this->getError($response['error_message'], _("Could not check balance. %s")); - } - } - - /** - * Identifies this gateway driver and returns a brief description. - * - * @return array Array of driver info. - */ - function getInfo() - { - $info['name'] = _("TextMagic via HTTP"); - $info['desc'] = _("This driver allows sending of messages through the TextMagic (http://api.textmagic.com) gateway, using the HTTP API"); - - return $info; - } - - /** - * Returns the required parameters for this gateway driver. - * - * @return array Array of required parameters. - */ - function getParams() - { - $params = array(); - $params['username'] = array('label' => _("Username"), 'type' => 'text'); - $params['password'] = array('label' => _("Password"), 'type' => 'text'); - $params['unicode'] = array('label' => _("Unicode message flag"), 'type' => 'int'); - $params['max_length'] = array('label' => _("Maximum messages to be sent at once"), 'type' => 'int'); - - return $params; - } - - /** - * Returns the parameters that can be set as default for sending messages - * using this gateway driver and displayed when sending messages. - * - * @return array Array of parameters that can be set as default. - * @todo Set up batch fields/params, would be nice to have ringtone/logo - * support too, queue choice, unicode choice. - */ - function getDefaultSendParams() - { - $params = array(); - - $params['max_length'] = array( - 'label' => _("Max messages quantity"), - 'type' => 'int', - 'default_value' => 3); - - $params['unicode'] = array( - 'label' => _("Unicode message flag"), - 'type' => 'int', - 'default_value' => 1); - - return $params; - } - - /** - * Returns the parameters for sending messages using this gateway driver, - * displayed when sending messages. These are filtered out using the - * default values set for the gateway. - * - * @return array Array of required parameters. - */ - function getSendParams($params) - { - if (empty($params['max_length'])) { - $params['max_length'] = array( - 'label' => _("Max messages quantity"), - 'type' => 'int'); - } - - if (empty($params['unicode'])) { - $params['unicode'] = array( - 'label' => _("Unicode message flag"), - 'type' => 'int'); - } - - return $params; - } - - /** - * Returns a string representation of an error code. - * - * @param string $error_text An existing error text to use to raise a - * PEAR Error. - * @param integer $error The error code to look up. - * - * @return mixed A textual message corresponding to the error code or a - * PEAR Error if passed an existing error text. - * - * @todo Check which of these are actually required and trim down the - * list. - */ - function getError($error_text = '', $error) - { - /* An array of error codes returned by the gateway. */ - $errors = array(2 => _("Low balance"), - 5 => _("Invalid username/password combination"), - 6 => _("Message was not sent"), - 7 => _("Too long message length"), - 8 => _("IP address is not allowed"), - 9 => _("Wrong phone number format"), - 10 => _("Wrong parameter value"), - 11 => _("Daily API requests limit exceeded"), - 12 => _("Too many items per request"), - 13 => _("Your account has been deactivated"), - 14 => _("Unknwon message ID"), - 15 => _("Unicode characters detected on unicode=0 option")); - - if (!empty($error_text)) { - return $error_text; - } else { - return PEAR::raiseError($errors[$error], $error); - } - } - - /** - * Do the http call using a url passed to the function. - * - * @param string $url The url to call. - * - * @return mixed The response on success or PEAR Error on failure. - */ - function _callURL($url) - { - $options['method'] = 'POST'; - $options['timeout'] = 5; - $options['allowRedirects'] = true; - - if (!@include_once 'HTTP/Request.php') { - return PEAR::raiseError(_("Missing PEAR package HTTP_Request.")); - } - $http = &new HTTP_Request($this->_base_url . $url, $options); - - /* Add the authentication values to POST. */ - $http->addPostData('username', $this->_params['user']); - $http->addPostData('password', $this->_params['password']); - - - @$http->sendRequest(); - if ($http->getResponseCode() != 200) { - return PEAR::raiseError(sprintf(_("Could not open %s."), $url)); - } - - return json_decode($http->getResponseBody(), true); - } - -} diff --git a/framework/Net_SMS/SMS/vodafoneitaly_smtp.php b/framework/Net_SMS/SMS/vodafoneitaly_smtp.php deleted file mode 100644 index ccd0f8342..000000000 --- a/framework/Net_SMS/SMS/vodafoneitaly_smtp.php +++ /dev/null @@ -1,137 +0,0 @@ - - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @author Marko Djukic - * @author Matteo Zambelli - * @package Net_SMS - */ -class Net_SMS_vodafoneitaly_smtp extends Net_SMS { - - /** - * An array of capabilities, so that the driver can report which operations - * it supports and which it doesn't. Possible values are:
-     *   auth        - The gateway require authentication before sending;
-     *   batch       - Batch sending is supported;
-     *   multi       - Sending of messages to multiple recipients is supported;
-     *   receive     - Whether this driver is capable of receiving SMS;
-     *   credit      - Is use of the gateway based on credits;
-     *   addressbook - Are gateway addressbooks supported;
-     *   lists       - Gateway support for distribution lists.
-     * 
- * - * @var array - */ - var $capabilities = array('auth' => false, - 'batch' => false, - 'multi' => false, - 'receive' => false, - 'credit' => false, - 'addressbook' => false, - 'lists' => false); - - /** - * This function does the actual sending of the message. - * - * @access private - * - * @param array $message The array containing the message and its send - * parameters. - * @param string $to The recipient. - * - * @return array An array with the success status and additional - * information. - */ - function _send($message, $to) - { - /* Since this only works for Italian numbers, this is hardcoded. */ - if (preg_match('/^.*??/', $to, $matches)) { - $headers['From'] = $this->_params['user']; - $to = $matches[2] . '@sms.vodafone.it'; - - try { - Horde_Mail::factory('Mail')->send($to, $headers, $message['text']); - return array(1, null); - } catch (Horde_Mail_Exception $e) { - return array(0, $e->getMessage()); - } - } else { - return array(0, _("You need to provide an Italian phone number")); - } - } - - /** - * Identifies this gateway driver and returns a brief description. - * - * @return array Array of driver info. - */ - function getInfo() - { - return array( - 'name' => _("Vodafone Italy via SMTP"), - 'desc' => _("This driver allows sending of messages via SMTP through the Vodafone Italy gateway, only to Vodafone numbers. It requires an email account with Vodafone Italy (http://www.190.it)."), - ); - } - - /** - * Returns the required parameters for this gateway driver. - * - * @return array Array of required parameters. - */ - function getParams() - { - return array('user' => array('label' => _("Username"), - 'type' => 'text')); - } - - /** - * Returns the parameters that can be set as default for sending messages - * using this gateway driver and displayed when sending messages. - * - * @return array Array of parameters that can be set as default. - */ - function getDefaultSendParams() - { - return array(); - } - - /** - * Returns the parameters for sending messages using this gateway driver, - * displayed when sending messages. These are filtered out using the - * default values set up when creating the gateway. - * - * @return array Array of required parameters. - * @todo Would be nice to use a time/date setup rather than minutes from - * now for the delivery time. Upload field for ringtones/logos? - */ - function getSendParams($params) - { - return array(); - } - - /** - * Returns a string representation of an error code. - * - * @param integer $error The error code to look up. - * @param string $text An existing error text to use to raise a - * PEAR Error. - * - * @return mixed A textual message corresponding to the error code or a - * PEAR Error if passed an existing error text. - * - * @todo Check which of these are actually required and trim down the - * list. - */ - function getError($error, $error_text = '') - { - } - -} diff --git a/framework/Net_SMS/SMS/win_http.php b/framework/Net_SMS/SMS/win_http.php deleted file mode 100644 index e3022c37d..000000000 --- a/framework/Net_SMS/SMS/win_http.php +++ /dev/null @@ -1,272 +0,0 @@ - - * @package Net_SMS - */ -class Net_SMS_win_http extends Net_SMS { - - var $_base_url = 'gateway3.go2mobile.net:10030/gateway/v3/gateway.aspx'; - - /** - * An array of capabilities, so that the driver can report which operations - * it supports and which it doesn't. Possible values are:
-     *   auth        - The gateway requires authentication before sending;
-     *   batch       - Batch sending is supported;
-     *   multi       - Sending of messages to multiple recipients is supported;
-     *   receive     - Whether this driver is capable of receiving SMS;
-     *   credit      - Is use of the gateway based on credits;
-     *   addressbook - Are gateway addressbooks supported;
-     *   lists       - Gateway support for distribution lists.
-     * 
- * - * @var array - */ - var $capabilities = array('auth' => false, - 'batch' => 100, - 'multi' => true, - 'receive' => false, - 'credit' => false, - 'addressbook' => false, - 'lists' => false); - - /** - * This function does the actual sending of the message. - * - * @access private - * - * @param array $message The array containing the message and its send - * parameters. - * @param array $to The destination string. - * - * @return array An array with the success status and additional - * information. - */ - function _send($message, $to) - { - /* Start the XML. */ - $xml = '' . $message['text'] . ''; - - /* Check if source from is set. */ - if (!empty($message['send_params']['from'])) { - $xml .= '' . $message['send_params']['from'] . ''; - } - - /* Loop through recipients and do some minimal validity checking. */ - if (is_array($to)) { - foreach ($to as $key => $val) { - if (preg_match('/^.*?|$)/', $val, $matches)) { - $to[$key] = $matches[1]; - } else { - /* If a recipient is invalid stop all further sending. */ - return array(0, sprintf(_("Invalid recipient: \"%s\""), $val)); - } - } - - $to = implode('', $to); - } else { - if (preg_match('/^.*?|$)/', $to, $matches)) { - $to = $matches[1]; - } else { - return array(0, sprintf(_("Invalid recipient: \"%s\""), $to)); - } - } - $xml .= '' . $to . ''; - - /* TODO: Should we have something more intelligent? Could actually - * be part of send parameters. */ - $xml .= '' . time() . ''; - - /* TODO: Add some extra tags, just tacked on for now. */ - $xml .= '21'; - - /* Send this message. */ - $response = $this->_post($xml); - if (is_a($response, 'PEAR_Error')) { - return array(0, $response->getMessage()); - } - - /* Parse the response, check for new lines in case of multiple - * recipients. */ - $lines = explode("\n", $response); - $response = array(); - - if (count($lines) > 1) { - /* Multiple recipients. */ - foreach ($lines as $line) { - $parts = explode('To:', $line); - $recipient = trim($parts[1]); - if ($lines[0] == 'AQSMS-OK') { - $response[$recipient] = array(1, null); - } else { - $response[$recipient] = array(0, $lines[0]); - } - } - } else { - /* Single recipient. */ - if ($lines[0] == 'AQSMS-OK') { - $response[$to] = array(1, null); - } else { - $response[$to] = array(0, $lines[0]); - } - } - - return $response; - } - - /** - * Identifies this gateway driver and returns a brief description. - * - * @return array Array of driver info. - */ - function getInfo() - { - return array( - 'name' => _("WIN via HTTP"), - 'desc' => _("This driver allows sending of messages through the WIN (http://winplc.com) gateway, using the HTTP API"), - ); - } - - /** - * Returns the required parameters for this gateway driver. The settable - * parameters for this gateway are: - * - user - The username for authentication on the gateway; - * - password - The password for authentication on the gateway; - * - * @return array Array of required parameters. - */ - function getParams() - { - $params = array(); - $params['user'] = array('label' => _("Username"), 'type' => 'text'); - $params['password'] = array('label' => _("Password"), 'type' => 'text'); - - return $params; - } - - /** - * Returns the parameters that can be set as default for sending messages - * using this gateway driver and displayed when sending messages. - * - * @return array Array of parameters that can be set as default. - */ - function getDefaultSendParams() - { - $params = array(); - $params['from'] = array( - 'label' => _("Source address"), - 'type' => 'text'); - - $params['cost_id'] = array( - 'label' => _("Cost ID"), - 'type' => 'int'); - - return $params; - } - - /** - * Returns the parameters for sending messages using this gateway driver, - * displayed when sending messages. These are filtered out using the - * default values set up when creating the gateway. - * - * @return array Array of required parameters. - * @todo Would be nice to use a time/date setup rather than minutes from - * now for the delivery time. Upload field for ringtones/logos? - */ - function getSendParams($params) - { - if (empty($params['from'])) { - $params['from'] = array( - 'label' => _("Source address"), - 'type' => 'text'); - } - - if (empty($params['cost_id'])) { - $params['deliv_time'] = array( - 'label' => _("Cost ID"), - 'type' => 'int'); - } - - return $params; - } - - /** - * Returns a string representation of an error code. - * - * @param integer $error The error code to look up. - * @param string $text An existing error text to use to raise a - * PEAR Error. - * - * @return mixed A textual message corresponding to the error code or a - * PEAR Error if passed an existing error text. - * - * @todo Check which of these are actually required and trim down the - * list. - */ - function getError($error, $error_text = '') - { - $error = trim($error); - - /* An array of error codes returned by the gateway. */ - $errors = array( - 'AQSMS-NOAUTHDETAILS' => _("No username and/or password sent."), - 'AQSMS-DISTLISTUPDATEERROR' => _("There was an error updating the distribution list. Please try again later.")); - - if (empty($error_text)) { - return $errors[$error]; - } else { - return PEAR::raiseError(sprintf($error_text, $errors[$error])); - } - } - - /** - * Do the http call using a url passed to the function. - * - * @access private - * - * @param string $xml The XML information passed to the gateway. - * - * @return mixed The response on success or PEAR Error on failure. - */ - function _post($xml) - { - $options['method'] = 'POST'; - $options['timeout'] = 5; - $options['allowRedirects'] = true; - - /* Wrap the xml with the standard tags. */ - $xml = '' . $xml . ''; - - $http = new HTTP_Request($this->_base_url, $options); - - /* Add the authentication values to POST. */ - $http->addPostData('User', $this->_params['user']); - $http->addPostData('Password', $this->_params['password']); - - /* Add the XML and send the request. */ - $http->addPostData('WIN_XML', $xml); - @$http->sendRequest(); - if ($http->getResponseCode() != 200) { - return PEAR::raiseError(sprintf(_("Could not open %s."), $this->_base_url)); - } - - return $http->getResponseBody(); - } - -} diff --git a/framework/Net_SMS/package.xml b/framework/Net_SMS/package.xml deleted file mode 100644 index 0ce91b7d4..000000000 --- a/framework/Net_SMS/package.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - Net_SMS - pear.php.net - SMS functionality. - This package provides SMS functionality and access to SMS gateways. - - - Marko Djukic - mdjukic - mdjukic@horde.org - yes - - - Jan Schneider - yunosh - jan@horde.org - yes - - - Chuck Hagenbuch - chagenbu - chuck@horde.org - yes - - 2006-12-31 - - 0.2.0 - 0.2.0 - - - beta - beta - - LGPL - * Added generic SMPP driver (Ian Eure, Request #5101). -* Fixed return values of the generic SMTP driver. -* Add textmagic_http driver (loci.master@gmail.com, Request #8439). - - - - - - - - - - - - - - - - - - - 4.2.0 - - - 1.4.0b1 - - - gettext - - - - - HTTP_Request - pear.php.net - - - Mail - pear.horde.org - - - Net_SMPP_Client - pear.php.net - - - - - - - - 0.1.0 - 0.1.0 - - - beta - beta - - 2006-04-12 - LGPL - * Fixed AT&T and Cingular SMTP gateways (Horde Bug #4139). -* Fixed warnings in sms2email and clickatell drivers. -* Added WIN driver. - - - - - 0.0.2 - 0.0.2 - - - beta - beta - - 2005-04-14 - LGPL - Added generic SMTP driver (Ian Eure). - - - - - 0.0.1 - 0.0.1 - - - beta - beta - - 2004-06-04 - LGPL - Initial release as a PEAR package - - - - -- 2.11.0