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-2006 WebSprockets, LLC
  6.  *
  7.  * See the enclosed file COPYING for license information (LGPL). If you did
  8.  * 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.10 2006/01/01 21:10:07 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.     /**
  24.      * Capabilities of this driver.
  25.      *
  26.      * @var array 
  27.      */
  28.     var $capabilities = array(
  29.         'auth'        => false,
  30.         'batch'       => false,
  31.         'multi'       => false,
  32.         'receive'     => false,
  33.         'credit'      => false,
  34.         'addressbook' => false,
  35.         'lists'       => false
  36.     );
  37.  
  38.     /**
  39.      * Driver parameters.
  40.      *
  41.      * @var array 
  42.      *
  43.      * @access private
  44.      */
  45.     var $_params = array(
  46.         'carrier'     => null,
  47.         'mailBackend' => 'mail',
  48.         'mailParams'  => array(),
  49.         'mailHeaders' => array()
  50.     );
  51.  
  52.     /**
  53.      * Carrier email map.
  54.      *
  55.      * @var array 
  56.      *
  57.      * @access private
  58.      */
  59.     var $_carriers = array(
  60.         /* U.S. carriers. */
  61.         'att'          => '%s@mmode.com',
  62.         'cingular'     => '%s@mmode.com',
  63.         'verizon'      => '%s@vtext.com',
  64.         'boost'        => '%s@myboostmobile.com',
  65.         'cellularone'  => '%s@mycellone.net',
  66.         'cincybell'    => '%s@gocbw.com',
  67.         'sprint'       => '%s@messaging.sprintpcs.com',
  68.         'tmobile_us'   => '%s@tmomail.com',
  69.         'suncom'       => '%s@tms.suncom.com',
  70.         'aircel'       => '%s@airsms.com',
  71.         'airtel'       => '%s@airtelmail.com',
  72.         'bplmobile'    => '%s@bplmobile.com',
  73.         'bellmobility' => '%s@txt.bellmobility.ca',
  74.         'bluegrass'    => '%s@sms.bluecell.com',
  75.         'cellforce'    => '%s@celforce.com',
  76.         'cellularone'  => '%s@mycellone.net',
  77.         /* German carriers. */
  78.         'eplus'       => '%s@smsmail.eplus.de',
  79.         'tmobile_de'  => '%s@t-mobile-sms.de',
  80.         'vodafone_de' => '%s@vodafone-sms.de',
  81.     );
  82.  
  83.     /**
  84.      * Identifies this driver.
  85.      *
  86.      * @return array  Driver info.
  87.      */
  88.     function getInfo()
  89.     {
  90.         return array(
  91.             'name' => _("Email-to-SMS Gateway"),
  92.             'desc' => _("EMail-to-SMS gateway driver, for carriers which provide this service.")
  93.         );
  94.     }
  95.  
  96.     /**
  97.      * Returns required parameters.
  98.      *
  99.      * @return array  Array of required parameters.
  100.      */
  101.     function getParams()
  102.     {
  103.         return array(
  104.             'carrier'     => array('label' => _("Carrier")'type' => 'text'),
  105.             'mailBackend' => array('label' => _("PEAR::Mail backend")'type' => 'text')
  106.         );
  107.     }
  108.  
  109.     /**
  110.      * Sends the message.
  111.      *
  112.      * You may also specify the carrier with the 'carrier' key of the message
  113.      * to avoid creating a new instance for each carrier, or fiddling with the
  114.      * parameters.
  115.      *
  116.      * @access private
  117.      *
  118.      * @param array $message  Message to send.
  119.      * @param string $to      Destination phone number.
  120.      *
  121.      * @return array  An array with the success status and additional
  122.      *                 information.
  123.      */
  124.     function _send(&$message$to)
  125.     {
  126.         $response = array();
  127.         $destemail $this->_getDest($to);
  128.         require_once 'Mail.php';
  129.         $m = Mail::factory($this->_params['mailBackend']$this->_params['mailParams']);
  130.  
  131.         if (isset($message['carrier'])) {
  132.             $dest $this->_getDest($to$message['carrier']);
  133.         else {
  134.             $dest $this->_getDest($to);
  135.         }
  136.  
  137.         $res =$m->send($dest$this->_params['mailHeaders']$message['text']);
  138.         if (PEAR::isError($res)) {
  139.             $response[$to= array(0$res->getMessage());
  140.         else {
  141.             $response[$to= array(1null);
  142.         }
  143.  
  144.         return $response;
  145.     }
  146.  
  147.     /**
  148.      * Returns destination e-mail address.
  149.      *
  150.      * @param string $phone  Phone number to send to.
  151.      *
  152.      * @return string  Destination address.
  153.      */
  154.     function _getDest($phone$carrier = null)
  155.     {
  156.         $carrier is_null($carrier$this->_params['carrier'$carrier;
  157.         return sprintf($this->_carriers[$carrier],
  158.                        preg_replace('/[^0-9]/'''$phone));
  159.     }
  160.  
  161.     /**
  162.      * Returns the address template for a carrier.
  163.      *
  164.      * @param string $carrier  Carrier name.
  165.      *
  166.      * @return mixed  Address template or false.
  167.      */
  168.     function getAddressTemplate($carrier)
  169.     {
  170.         if (!isset($this->_carriers[$carrier])) {
  171.             return false;
  172.         }
  173.         return $this->_carriers[$carrier];
  174.     }
  175.  
  176.     /**
  177.      * Adds a carrier to the list.
  178.      *
  179.      * Address templates need to be in the form of an email address, with a
  180.      * '%s' representing the place where the destination phone number goes.
  181.      *
  182.      * @param string $name  Carrier name.
  183.      * @param string $addr  Address template.
  184.      */
  185.     function addCarrier($name$addr)
  186.     {
  187.         $this->_carriers[$name$addr;
  188.     }
  189. }

Documentation generated on Mon, 11 Mar 2019 14:39:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.