Source for file smsapi.php

Documentation is available at smsapi.php

  1. <?php
  2. /**
  3.  * smsAPI
  4.  *
  5.  * Copyright (c) 2010, ComVision
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without modification,
  9.  * are permitted provided that the following conditions are met:
  10.  *
  11.  *  - Redistributions of source code must retain the above copyright notice,
  12.  *    this list of conditions and the following disclaimer.
  13.  *  - Redistributions in binary form must reproduce the above copyright notice,
  14.  *    this list of conditions and the following disclaimer in the documentation and/or
  15.  *    other materials provided with the distribution.
  16.  *  - Neither the name of the smsAPI.pl nor the names of its contributors may be used to
  17.  *    endorse or promote products derived from this software without specific prior written permission.
  18.  * 
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  23.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  26.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  *
  29.  * @author ComVision <info@smsapi.pl>
  30.  * @copyright 2010 ComVision
  31.  * @license BSD-3
  32.  * @package smsapi
  33.  * @version 1.0 14.10.2010
  34.  */
  35.  
  36. /**
  37.  * smsAPI
  38.  *
  39.  * <code>
  40.  * require_once 'smsapi.php';
  41.  * //Instrukcja odpowiedziala za automatyczne wczytywanie class
  42.  * spl_autoload_register(array('smsAPI','__autoload'));
  43.  * </code>
  44.  */
  45. class smsAPI
  46. {
  47.     /**
  48.      * vCard UDH
  49.      */
  50.     const UDH_VCARD            '06050423F40000';
  51.     /**
  52.      * WAPPush UDH
  53.      */
  54.     const UDH_WAPPUSH        '0605040b8423f0';
  55.     /**
  56.      * DATACODING BIN dla vCard i WAPPush
  57.      */
  58.     const DATACODING_BIN    'bin';
  59.  
  60.     /**
  61.      * Generator wiadomości WAPPush
  62.      *
  63.      * Przyklad:
  64.      * <code>
  65.      * $msg->datacoding = smsAPI::DATACODING_BIN;
  66.      * $msg->udh        = smsAPI::UDH_WAPPUSH;
  67.      * $msg->message    = smsAPI::make_WAPPush_message(
  68.      *                        'smsapi.pl', 'Link do http://smsapi.pl');
  69.      * </code>
  70.      *
  71.      * @param string $url 
  72.      * @param string $message 
  73.      * @return string 
  74.      */
  75.     public static function make_WAPPush_message($url$message)
  76.     {
  77.         $url self::ascii_to_hex$url );
  78.         $message self::ascii_to_hex$message );
  79.  
  80.         return
  81.             '860601ae02056a0045c60c03'.
  82.             $url.
  83.             '00070103'.
  84.             $message.
  85.             '000101';
  86.     }
  87.  
  88.     /**
  89.      * Konwerter vCard
  90.      *
  91.      * nie obsługiwane przez wszystkie telefony
  92.      *
  93.      * Przyklad:
  94.      * <code>
  95.      * $msg->datacoding = smsAPI::DATACODING_BIN;
  96.      * $msg->udh        = smsAPI::UDH_VCARD;
  97.      * $msg->message    = smsAPI::make_vCard_message(
  98.      *                'smsAPI', 'smsAPI', '500123321', 'bok@smsapi.pl', 'http://www.smsapi.pl');
  99.      * </code>
  100.      * 
  101.      * @param string $name 
  102.      * @param string $surname 
  103.      * @param string $phone 
  104.      * @param string $email 
  105.      * @param string $www 
  106.      * @return string 
  107.      */
  108.     public static function make_vCard_message($name$surname$phone$email$www)
  109.     {
  110.         $msg  "BEGIN:VCARD\r\nVERSION:2.1\r\n";
  111.  
  112.         if$name OR $surname )
  113.         {
  114.             $msg .= 'FN:'$name .' '$surname ."\r\nN:"$surname .';'$name .";;;\r\n";
  115.         }
  116.         else
  117.         {
  118.             if $name $msg .= 'FN:'$name ."\r\nN:"$name .";;;;\r\n";
  119.             else if $surname $msg .= "FN:$surname\r\nN:$surname;;;;\r\n";
  120.         }
  121.  
  122.         if $phone )    $msg .= 'TEL;PREF;CELL:'$phone ."\r\n";
  123.         if $email )    $msg .= 'EMAIL;INTERNET:'$email ."\r\n";
  124.         if $www )        $msg .= 'URL:'$www ."\r\n";
  125.  
  126.         $msg .= "END:VCARD";
  127.  
  128.         return self::ascii_to_hex$msg );
  129.     }
  130.  
  131.     /**
  132.      * string -> hex
  133.      *
  134.      * @param string $ascii 
  135.      * @return string 
  136.      */
  137.     public static function ascii_to_hex ($ascii)
  138.     {
  139.         $hexadecimal '';
  140.         for ($i 0$i strlen($ascii)$i++)
  141.         {
  142.             $byte strtoupper(dechex(ord($ascii{$i})));
  143.             $byte str_repeat('0'strlen($byte)) $byte;
  144.             $hexadecimal .= $byte;
  145.         }
  146.         
  147.         return $hexadecimal;
  148.     }
  149.  
  150.     /**
  151.      * @ignore
  152.      * @var array 
  153.      */
  154.     protected static $listners array();
  155.  
  156.     /**
  157.      * Dodaj nasłuch
  158.      *
  159.      * <code>
  160.      * smsAPI::add_listner('var_dump');
  161.      * smsAPI::add_listner(array('myClass','log'));
  162.      * </code>
  163.      *
  164.      * @param callback $listner 
  165.      * @return null 
  166.      */
  167.     public static function add_listner($listner)
  168.     {
  169.         if!isset ($listnerOR empty($listner) ) return;
  170.         
  171.         self::$listners[$listner;
  172.     }
  173.  
  174.     /**
  175.      * @ignore
  176.      */
  177.     public static function call_listners()
  178.     {
  179.         $args func_get_args();
  180.         foreach (self::$listners as $listner)
  181.         {
  182.             call_user_func_array($listner$args);
  183.         }
  184.     }
  185.  
  186.     /**
  187.      * Base Dir
  188.      *
  189.      * @var string 
  190.      */
  191.     protected static $base_dir null;
  192.  
  193.     /**
  194.      * Autoloader class
  195.      *
  196.      * Przyklad:
  197.      * <code>
  198.      * require_once 'smsapi.php';
  199.      * //Instrukcja odpowiedziala za automatyczne wczytywanie class
  200.      * spl_autoload_register(array('smsAPI','__autoload'));
  201.      * </code>
  202.      *
  203.      * @param string $class 
  204.      * @return null 
  205.      */
  206.     public static function __autoload ($class)
  207.     {
  208.         ifself::$base_dir == null self::$base_dir dirname(__FILE__DIRECTORY_SEPARATOR;
  209.  
  210.         $class strtolower($class);
  211.         $pos strpos($class'smsapi_');
  212.  
  213.         if$pos === false OR $pos return;
  214.  
  215.         $class str_replace('_'DIRECTORY_SEPARATOR$class);
  216.         require_once self::$base_dir $class '.php';
  217.     }
  218. }

Documentation generated on Thu, 27 Jan 2011 16:17:34 +0100 by phpDocumentor 1.4.3