steffen: server/kolab-horde-framework/kolab-horde-framework/Net_SMS SMS.php, NONE, 1.1 package.xml, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Fri Oct 14 16:33:11 CEST 2005
- Previous message: steffen: server/kolab-horde-framework/kolab-horde-framework/Net_LMTP LMTP.php, NONE, 1.1 package.xml, NONE, 1.1 test_lmtp.php, NONE, 1.1
- Next message: steffen: server/kolab-horde-framework/kolab-horde-framework/Net_SMS/SMS clickatell_http.php, NONE, 1.1 sms2email_http.php, NONE, 1.1 vodafoneitaly_smtp.php, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: steffen
Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/Net_SMS
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/Net_SMS
Added Files:
SMS.php package.xml
Log Message:
Separated Horde Framework from kolab-resource-handlers
--- NEW FILE: SMS.php ---
<?php
require_once 'PEAR.php';
/**
* Net_SMS Class
*
* Copyright 2003-2004 Marko Djukic <marko at 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 at oblo.com>
* @version $Revision: 1.1 $
* @package Net_SMS
*/
class Net_SMS {
/**
* A hash containing any parameters for the current gateway driver.
*
* @var array $_params
*/
var $_params = array();
var $_auth = null;
/**
* Constructor
*
* @param optional array $params Any parameters needed for this gateway
* driver.
*/
function Net_SMS($params = null)
{
$this->_params = $params;
}
/**
* Returns a list of available gateway drivers.
*
* @access public
*
* @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.
*
* @access public
*
* @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.
*
* @access public
*
* @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.
*
* @access public
*
* @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.
*
* @access public
*
* @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.
*
* @access public
*
* @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.
*
* @access public
*
* @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.
*
* @access public
*
* @return int 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 optional array $params A hash containing any additional
* configuration or connection parameters a
* subclass might need.
*
* @return object 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)) {
return $ret = &new $class($params);
} else {
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
* dynamically included.
*
* @param optional 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];
}
}
--- NEW FILE: package.xml ---
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- $Horde: framework/Net_SMS/package.xml,v 1.6 2004/04/24 17:01:39 mdjukic Exp $ -->
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
<package version="1.0">
<name>Net_SMS</name>
<summary>SMS functionality.</summary>
<description>This package provides SMS functionality and access to SMS gateways.
</description>
<license>LGPL</license>
<maintainers>
<maintainer>
<user>mdjukic</user>
<role>lead</role>
<name>Marko Djukic</name>
<email>mdjukic at horde.org</email>
</maintainer>
</maintainers>
<release>
<version>0.0.1</version>
<state>beta</state>
<date>2004-03-15</date>
<notes>Initial release as a PEAR package</notes>
<filelist>
<file role="php" name="SMS.php" baseinstalldir="/Net" />
<dir role="php" name="SMS" baseinstalldir="/Net">
<file name="clickatell_http.php" />
<file name="sms2email_http.php" />
<file name="vodafoneitaly_smtp.php" />
</dir>
</filelist>
<provides type="class" name="SMS"/>
<deps>
<dep type="php" rel="ge" version="4.2.0"/>
<dep type="ext" rel="has" name="gettext"/>
<dep type="pkg" rel="has" optional="yes">HTTP_Request</dep>
<dep type="pkg" rel="has" optional="yes">Mail</dep>
</deps>
</release>
<changelog>
<release>
<version>0.0.1</version>
<state>beta</state>
<date>2004-03-15</date>
<notes>Initial release as a PEAR package</notes>
</release>
</changelog>
</package>
- Previous message: steffen: server/kolab-horde-framework/kolab-horde-framework/Net_LMTP LMTP.php, NONE, 1.1 package.xml, NONE, 1.1 test_lmtp.php, NONE, 1.1
- Next message: steffen: server/kolab-horde-framework/kolab-horde-framework/Net_SMS/SMS clickatell_http.php, NONE, 1.1 sms2email_http.php, NONE, 1.1 vodafoneitaly_smtp.php, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the commits
mailing list