[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/lib/vcard/ -> vcard.class.php (source)

   1  <?php
   2  /***************************************************************************
   3  
   4  php vCard class v2.0
   5  (c) Kai Blankenhorn
   6  www.bitfolge.de/en
   7  kaib@bitfolge.de
   8  
   9  
  10  This program is free software; you can redistribute it and/or
  11  modify it under the terms of the GNU General Public License
  12  as published by the Free Software Foundation; either version 2
  13  of the License, or (at your option) any later version.
  14  
  15  This program is distributed in the hope that it will be useful,
  16  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  GNU General Public License for more details.
  19  
  20  You should have received a copy of the GNU General Public License
  21  along with this program; if not, write to the Free Software
  22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  23  
  24  ***************************************************************************/
  25  
  26  /**
  27          \file       htdocs/lib/vcard/vcard.class.php
  28          \brief      Classe permettant de créer un fichier vcard.
  29          \author     Kai Blankenhorn.
  30          \version    2.0
  31  
  32          Ensemble des fonctions permettant de créer un fichier vcard.
  33  */
  34  
  35  
  36  function encode($string) {
  37      return escape(quoted_printable_encode($string));
  38  }
  39  
  40  function escape($string) {
  41      return str_replace(";","\;",$string);
  42  }
  43  
  44  // taken from php documentation comments
  45  function quoted_printable_encode($input, $line_max = 76) {
  46      $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  47      $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
  48      $eol = "\r\n";
  49      $linebreak = "=0D=0A";
  50      $escape = "=";
  51      $output = "";
  52  
  53      for ($j=0;$j<count($lines);$j++) {
  54          $line = $lines[$j];
  55          $linlen = strlen($line);
  56          $newline = "";
  57          for($i = 0; $i < $linlen; $i++) {
  58              $c = substr($line, $i, 1);
  59              $dec = ord($c);
  60              if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
  61                  $c = "=20"; 
  62              } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  63                  $h2 = floor($dec/16); $h1 = floor($dec%16); 
  64                  $c = $escape.$hex["$h2"].$hex["$h1"]; 
  65              }
  66              if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  67                  $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
  68                  $newline = "    ";
  69              }
  70              $newline .= $c;
  71          } // end of for
  72          $output .= $newline;
  73          if ($j<count($lines)-1) $output .= $linebreak;
  74      }
  75      return trim($output);
  76  }
  77  
  78  /** \class vCard
  79          \brief Classe permettant de créer un fichier vcard
  80  
  81          Ensemble des fonctions permettant de créer un fichier vcard
  82  */
  83  
  84  class vCard {
  85      var $properties;
  86      var $filename;
  87  
  88  /**
  89          \brief mise en forme du numéro de télephone
  90          \param    number        numéro de téléphone
  91          \param    type
  92  */
  93  
  94  	function setPhoneNumber($number, $type="") {
  95      // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE"
  96          $key = "TEL";
  97          if ($type!="") $key .= ";".$type;
  98          $key.= ";ENCODING=QUOTED-PRINTABLE";
  99          $this->properties[$key] = quoted_printable_encode($number);
 100      }
 101  
 102  /**
 103          \brief mise en forme de la photo
 104          \param    type
 105          \param    photo
 106          \warning NON TESTE !
 107  */
 108  
 109      // UNTESTED !!!
 110  	function setPhoto($type, $photo) { // $type = "GIF" | "JPEG"
 111          $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo);
 112      }
 113  
 114  /**
 115          \brief mise en forme du nom formaté
 116          \param    name
 117  */
 118  
 119  	function setFormattedName($name) {
 120          $this->properties["FN"] = quoted_printable_encode($name);
 121      }
 122  
 123  /**
 124          \brief mise en forme du nom complet
 125          \param    family
 126          \param    first
 127          \param    additional
 128          \param    prefix
 129          \param    suffix
 130  */
 131  
 132  	function setName($family="", $first="", $additional="", $prefix="", $suffix="") {
 133          $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix";
 134          $this->filename = "$first%20$family.vcf";
 135          if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
 136      }
 137  
 138  /**
 139          \brief mise en forme de l'anniversaire
 140          \param    date
 141  */
 142  
 143  	function setBirthday($date) { // $date format is YYYY-MM-DD
 144          $this->properties["BDAY"] = $date;
 145      }
 146  
 147  /**
 148          \brief mise en forme de l'adresse
 149          \param    postoffice
 150          \param    extended
 151          \param    street
 152          \param    city
 153          \param    region
 154          \param    zip
 155          \param    country
 156          \param    type
 157  */
 158  
 159  	function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
 160      // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
 161          $key = "ADR";
 162          if ($type!="") $key.= ";$type";
 163          $key.= ";ENCODING=QUOTED-PRINTABLE";
 164          $this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
 165  
 166          if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") {
 167              //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
 168          }
 169      }
 170  
 171  /**
 172          \brief mise en forme du label
 173          \param    postoffice
 174          \param    extended
 175          \param    street
 176          \param    city
 177          \param    region
 178          \param    zip
 179          \param    country
 180          \param    type
 181  */
 182  
 183  	function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
 184          $label = "";
 185          if ($postoffice!="") $label.= "$postoffice\r\n";
 186          if ($extended!="") $label.= "$extended\r\n";
 187          if ($street!="") $label.= "$street\r\n";
 188          if ($zip!="") $label.= "$zip ";
 189          if ($city!="") $label.= "$city\r\n";
 190          if ($region!="") $label.= "$region\r\n";
 191          if ($country!="") $country.= "$country\r\n";
 192  
 193          $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label);
 194      }
 195  
 196  /**
 197          \brief mise en forme de l'email
 198          \param    address
 199  */
 200  
 201  	function setEmail($address) {
 202          $this->properties["EMAIL;INTERNET"] = $address;
 203      }
 204  
 205  /**
 206          \brief mise en forme de la note
 207          \param    note
 208  */
 209  
 210  	function setNote($note) {
 211          $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note);
 212      }
 213  
 214  /**
 215          \brief mise en forme de l'url
 216          \param    url
 217          \param    type
 218  */
 219  
 220  	function setURL($url, $type="") {
 221      // $type may be WORK | HOME
 222          $key = "URL";
 223          if ($type!="") $key.= ";$type";
 224          $this->properties[$key] = $url;
 225      }
 226  
 227  /**
 228          \brief permet d'obtenir une vcard
 229  */
 230  
 231  	function getVCard() {
 232          $text = "BEGIN:VCARD\r\n";
 233          $text.= "VERSION:2.1\r\n";
 234          foreach($this->properties as $key => $value) {
 235              $text.= "$key:$value\r\n";
 236          }
 237          $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
 238          $text.= "MAILER:php vCard class by Kai Blankenhorn\r\n";
 239          $text.= "END:VCARD\r\n";
 240          return $text;
 241      }
 242  
 243  /**
 244          \brief permet d'obtenir le nom de fichier
 245  */
 246  
 247  	function getFileName() {
 248          return $this->filename;
 249      }
 250  }
 251  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics