Source for file SMS.php
Documentation is available at SMS.php
* Copyright 2003-2004 Marko Djukic <marko@oblo.com>
* See the enclosed file COPYING for license information (LGPL). If you did not
* receive this file, see http://www.fsf.org/copyleft/lgpl.html.
* $Horde: framework/Net_SMS/SMS.php,v 1.10 2004/05/04 21:54:11 mdjukic Exp $
* @author Marko Djukic <marko@oblo.com>
* @version $Revision: 1.10 $
* A hash containing any parameters for the current gateway driver.
* @param optional array $params Any parameters needed for this gateway
$this->_params = $params;
* Returns a list of available gateway drivers.
* @return array An array of available drivers.
static $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'];
* 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.
if (isset ($info[$gateway])) {
require_once 'Net/SMS/' . $gateway . '.php';
$class = 'Net_SMS_' . $gateway;
* Returns parameters for a gateway from the driver subclass getParams()
* @param string The name of the gateway driver for which to return the
* @return array An array of extra information.
static $params = array ();
if (isset ($params[$gateway])) {
return $params[$gateway];
require_once 'Net/SMS/' . $gateway . '.php';
$class = 'Net_SMS_' . $gateway;
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
* @return array An array of available send parameters.
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
* @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.
if (!empty ($this->capabilities [$capability])) {
return $this->capabilities [$capability];
* Authenticates against the gateway if required.
* @return mixed True on success or PEAR Error on failure.
/* Do authentication for this gateway if driver requires it. */
$this->_auth = $this->_authenticate ();
* Sends a message to one or more recipients. Hands off the actual sending
* @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.
/* Make sure the recipients are in an array. */
$message['to'] = array ($message['to']);
/* Array to store each send. */
/* If gateway supports batch sending, preference is given to this
/* 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 ];
/* Message failed, store error code. */
$error = $response[$recipient][1 ];
$sends[] = array ('message_id' => $message['id'],
'remote_id' => $remote_id,
'recipient' => $recipient,
/* 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);
/* Message was sent, store remote id if any. */
$remote_id = (isset ($response[1 ]) ? $response[1 ] : null );
/* Message failed, store error code. */
$sends[] = array ('message_id' => $message['id'],
'remote_id' => $remote_id,
'recipient' => $recipient,
* If the current driver has a credit capability, queries the gateway for
* a credit balance and returns the value.
* @return int Value indicating available credit or null if not supported.
return $this->_getBalance ();
* 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
* @param optional array $params A hash containing any additional
* configuration or connection parameters a
* @return object Net_SMS The newly created concrete Gateway instance or
function &factory($driver, $params = array ())
include_once 'Net/SMS/' . $driver . '.php';
$class = 'Net_SMS_' . $driver;
return $ret = &new $class($params);
return PEAR ::raiseError (sprintf(_("Class definition of %s not found."), $driver));
* Attempts to return a reference to a concrete Net_SMS instance based on
* $driver. It wil 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
* @param optional array $params A hash containing any additional
* configuration or connection parameters a
* @return mixed The created concrete Net_SMS instance, or false on
function &singleton($driver, $params = array ())
if (!isset ($instances)) {
$signature = serialize(array ($driver, $params));
if (!isset ($instances[$signature])) {
return $instances[$signature];
Documentation generated on Mon, 11 Mar 2019 10:17:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|