Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Unknown

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /bitfolge/vcard.php

Documentation is available at vcard.php

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

Documentation generated on Mon, 05 Mar 2007 21:30:56 +0000 by phpDocumentor 1.3.1