Net_SMS
[ class tree: Net_SMS ] [ index: Net_SMS ] [ all elements ]

Source for file generic_smtp.php

Documentation is available at generic_smtp.php

  1. <?php
  2. /**
  3.  * Generic e-mail based SMS driver
  4.  *
  5.  * Copyright 2005-2007 WebSprockets, LLC
  6.  *
  7.  * See the enclosed file COPYING for license information (LGPL). If you
  8.  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  9.  *
  10.  * This driver interfaces with the email-to-sms gateways provided by many
  11.  * carriers, particularly those based in the U.S.
  12.  *
  13.  * $Horde: framework/Net_SMS/SMS/generic_smtp.php,v 1.15 2007/06/27 17:22:58 jan Exp $
  14.  *
  15.  * @category   Networking
  16.  * @package    Net_SMS
  17.  * @author     Ian Eure <ieure@php.net>
  18.  * @since      Horde 3.1
  19.  * @since      Net_SMS 0.0.2
  20.  */
  21. class Net_SMS_generic_smtp extends Net_SMS {
  22.  
  23.     protected $mail;
  24.  
  25.     /**
  26.      * Constructor.
  27.      *
  28.      * @param array $params  Parameters.
  29.      */
  30.     public function __construct($paramsMail $mail)
  31.     {
  32.         parent::__construct($params);
  33.         $this->mail = $mail;
  34.     }
  35.  
  36.     /**
  37.      * Capabilities of this driver.
  38.      *
  39.      * @var array 
  40.      */
  41.     var $capabilities = array(
  42.         'auth'        => false,
  43.         'batch'       => false,
  44.         'multi'       => false,
  45.         'receive'     => false,
  46.         'credit'      => false,
  47.         'addressbook' => false,
  48.         'lists'       => false
  49.     );
  50.  
  51.     /**
  52.      * Driver parameters.
  53.      *
  54.      * @var array 
  55.      *
  56.      * @access private
  57.      */
  58.     var $_params = array(
  59.         'carrier'     => null,
  60.         'mailBackend' => 'mail',
  61.         'mailParams'  => array(),
  62.         'mailHeaders' => array()
  63.     );
  64.  
  65.     /**
  66.      * Carrier email map.
  67.      *
  68.      * @var array 
  69.      *
  70.      * @access private
  71.      */
  72.     var $_carriers = array(
  73.         /* U.S. carriers. */
  74.         'att'          => '%s@mmode.com',
  75.         'cingular'     => '%s@mmode.com',
  76.         'verizon'      => '%s@vtext.com',
  77.         'boost'        => '%s@myboostmobile.com',
  78.         'cellularone'  => '%s@mycellone.net',
  79.         'cincybell'    => '%s@gocbw.com',
  80.         'sprint'       => '%s@messaging.sprintpcs.com',
  81.         'tmobile_us'   => '%s@tmomail.com',
  82.         'suncom'       => '%s@tms.suncom.com',
  83.         'aircel'       => '%s@airsms.com',
  84.         'airtel'       => '%s@airtelmail.com',
  85.         'bplmobile'    => '%s@bplmobile.com',
  86.         'bellmobility' => '%s@txt.bellmobility.ca',
  87.         'bluegrass'    => '%s@sms.bluecell.com',
  88.         'cellforce'    => '%s@celforce.com',
  89.         'cellularone'  => '%s@mycellone.net',
  90.         /* German carriers. */
  91.         'eplus'       => '%s@smsmail.eplus.de',
  92.         'tmobile_de'  => '%s@t-mobile-sms.de',
  93.         'vodafone_de' => '%s@vodafone-sms.de',
  94.     );
  95.  
  96.     /**
  97.      * Identifies this driver.
  98.      *
  99.      * @return array  Driver info.
  100.      */
  101.     function getInfo()
  102.     {
  103.         return array(
  104.             'name' => _("Email-to-SMS Gateway"),
  105.             'desc' => _("This driver allows sending of messages through an email-to-SMS gateway, for carriers which provide this service.")
  106.         );
  107.     }
  108.  
  109.     /**
  110.      * Returns required parameters.
  111.      *
  112.      * @return array  Array of required parameters.
  113.      */
  114.     function getParams()
  115.     {
  116.         return array(
  117.             'carrier'     => array('label' => _("Carrier")'type' => 'text'),
  118.             'mailBackend' => array('label' => _("PEAR::Mail backend")'type' => 'text')
  119.         );
  120.     }
  121.  
  122.     /**
  123.      * Sends the message.
  124.      *
  125.      * You may also specify the carrier with the 'carrier' key of the message
  126.      * to avoid creating a new instance for each carrier, or fiddling with the
  127.      * parameters.
  128.      *
  129.      * @access private
  130.      *
  131.      * @param array $message  Message to send.
  132.      * @param string $to      The recipient.
  133.      *
  134.      * @return array  An array with the success status and additional
  135.      *                 information.
  136.      */
  137.     function _send($message$to)
  138.     {
  139.         $carrier = null;
  140.         if (isset($this->_params['carrier'])) {
  141.             $carrier $this->_params['carrier'];
  142.         }
  143.         if (isset($message['carrier'])) {
  144.             $carrier $message['carrier'];
  145.         }
  146.  
  147.         $dest $this->_getDest($to$carrier);
  148.  
  149.         $res $this->mail->send($dest$this->_params['mailHeaders']$message['text']);
  150.         if (PEAR::isError($res)) {
  151.             return array(0$res->getMessage());
  152.         else {
  153.             return array(1null);
  154.         }
  155.     }
  156.  
  157.     /**
  158.      * Returns destination e-mail address.
  159.      *
  160.      * @param string $phone  Phone number to send to.
  161.      *
  162.      * @return string  Destination address.
  163.      */
  164.     function _getDest($phone$carrier)
  165.     {
  166.         if (!isset($this->_carriers[$carrier])) {
  167.             throw new InvalidArgumentException("Unknown carrier mapping: " $carrier);
  168.         }
  169.  
  170.         return sprintf($this->_carriers[$carrier],
  171.                        preg_replace('/[^0-9]/'''$phone));
  172.     }
  173.  
  174.     /**
  175.      * Returns the address template for a carrier.
  176.      *
  177.      * @param string $carrier  Carrier name.
  178.      *
  179.      * @return mixed  Address template or false.
  180.      */
  181.     function getAddressTemplate($carrier)
  182.     {
  183.         if (!isset($this->_carriers[$carrier])) {
  184.             return false;
  185.         }
  186.         return $this->_carriers[$carrier];
  187.     }
  188.  
  189.     /**
  190.      * Adds a carrier to the list.
  191.      *
  192.      * Address templates need to be in the form of an email address, with a
  193.      * '%s' representing the place where the destination phone number goes.
  194.      *
  195.      * @param string $name  Carrier name.
  196.      * @param string $addr  Address template.
  197.      */
  198.     function addCarrier($name$addr)
  199.     {
  200.         $this->_carriers[$name$addr;
  201.     }
  202.  
  203.     /**
  204.      * Returns a list of parameters specific for this driver.
  205.      *
  206.      * @return array Default sending parameters.
  207.      */
  208.     function getDefaultSendParams()
  209.     {
  210.         return array();
  211.     }
  212.  
  213. }

Documentation generated on Mon, 11 Mar 2019 15:57:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.