2004-10-20 00:42:23 +02:00
< ? php
2004-01-23 18:54:22 +01:00
/***************************************************************************
2004-10-20 00:42:23 +02:00
php vCard class v2 . 0
2004-01-23 18:54:22 +01:00
( c ) Kai Blankenhorn
www . bitfolge . de / en
kaib @ bitfolge . de
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
***************************************************************************/
2004-08-14 14:47:39 +02:00
/*! \file htdocs / lib / vcard / vcard . class . php
2004-07-16 08:41:58 +02:00
\brief Classe permettant de cr<EFBFBD> er un fichier vcard .
\author Kai Blankenhorn .
\version 2.0
Ensemble des fonctions permettant de cr<EFBFBD> er un fichier vcard .
*/
2004-01-23 18:54:22 +01:00
function encode ( $string ) {
return escape ( quoted_printable_encode ( $string ));
}
function escape ( $string ) {
return str_replace ( " ; " , " \ ; " , $string );
}
2004-10-20 00:42:23 +02:00
// taken from php documentation comments
2004-01-23 18:54:22 +01:00
function quoted_printable_encode ( $input , $line_max = 76 ) {
$hex = array ( '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' );
$lines = preg_split ( " /(?: \r \n | \r | \n )/ " , $input );
$eol = " \r \n " ;
$linebreak = " =0D=0A " ;
$escape = " = " ;
$output = " " ;
for ( $j = 0 ; $j < count ( $lines ); $j ++ ) {
$line = $lines [ $j ];
$linlen = strlen ( $line );
$newline = " " ;
for ( $i = 0 ; $i < $linlen ; $i ++ ) {
$c = substr ( $line , $i , 1 );
$dec = ord ( $c );
if ( ( $dec == 32 ) && ( $i == ( $linlen - 1 )) ) { // convert space at eol only
$c = " =20 " ;
} elseif ( ( $dec == 61 ) || ( $dec < 32 ) || ( $dec > 126 ) ) { // always encode "\t", which is *not* required
$h2 = floor ( $dec / 16 ); $h1 = floor ( $dec % 16 );
$c = $escape . $hex [ " $h2 " ] . $hex [ " $h1 " ];
}
if ( ( strlen ( $newline ) + strlen ( $c )) >= $line_max ) { // CRLF is not counted
$output .= $newline . $escape . $eol ; // soft line break; " =\r\n" is okay
$newline = " " ;
}
$newline .= $c ;
} // end of for
$output .= $newline ;
if ( $j < count ( $lines ) - 1 ) $output .= $linebreak ;
}
return trim ( $output );
}
2004-07-16 08:41:58 +02:00
/*! \class vCard
\brief Classe permettant de cr<EFBFBD> er un fichier vcard
Ensemble des fonctions permettant de cr<EFBFBD> er un fichier vcard
*/
2004-01-23 18:54:22 +01:00
class vCard {
var $properties ;
var $filename ;
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme du num<EFBFBD> ro de t<EFBFBD> lephone
\param number num<EFBFBD> ro de t<EFBFBD> l<EFBFBD> phone
\param type
*/
2004-01-23 18:54:22 +01:00
function setPhoneNumber ( $number , $type = " " ) {
// 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"
$key = " TEL " ;
if ( $type != " " ) $key .= " ; " . $type ;
$key .= " ;ENCODING=QUOTED-PRINTABLE " ;
$this -> properties [ $key ] = quoted_printable_encode ( $number );
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme de la photo
\param type
\param photo
\warning NON TESTE !
*/
2004-01-23 18:54:22 +01:00
// UNTESTED !!!
function setPhoto ( $type , $photo ) { // $type = "GIF" | "JPEG"
$this -> properties [ " PHOTO;TYPE= $type ;ENCODING=BASE64 " ] = base64_encode ( $photo );
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme du nom format<EFBFBD>
\param name
*/
2004-01-23 18:54:22 +01:00
function setFormattedName ( $name ) {
$this -> properties [ " FN " ] = quoted_printable_encode ( $name );
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme du nom complet
\param family
\param first
\param additional
\param prefix
\param suffix
*/
2004-01-23 18:54:22 +01:00
function setName ( $family = " " , $first = " " , $additional = " " , $prefix = " " , $suffix = " " ) {
$this -> properties [ " N " ] = " $family ; $first ; $additional ; $prefix ; $suffix " ;
$this -> filename = " $first %20 $family .vcf " ;
if ( $this -> properties [ " FN " ] == " " ) $this -> setFormattedName ( trim ( " $prefix $first $additional $family $suffix " ));
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme de l ' anniversaire
\param date
*/
2004-01-23 18:54:22 +01:00
function setBirthday ( $date ) { // $date format is YYYY-MM-DD
$this -> properties [ " BDAY " ] = $date ;
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme de l ' adresse
\param postoffice
\param extended
\param street
\param city
\param region
\param zip
\param country
\param type
*/
2004-01-23 18:54:22 +01:00
function setAddress ( $postoffice = " " , $extended = " " , $street = " " , $city = " " , $region = " " , $zip = " " , $country = " " , $type = " HOME;POSTAL " ) {
// $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
$key = " ADR " ;
if ( $type != " " ) $key .= " ; $type " ;
$key .= " ;ENCODING=QUOTED-PRINTABLE " ;
$this -> properties [ $key ] = encode ( $name ) . " ; " . encode ( $extended ) . " ; " . encode ( $street ) . " ; " . encode ( $city ) . " ; " . encode ( $region ) . " ; " . encode ( $zip ) . " ; " . encode ( $country );
2004-07-16 08:41:58 +02:00
2004-01-23 18:54:22 +01:00
if ( $this -> properties [ " LABEL; $type ;ENCODING=QUOTED-PRINTABLE " ] == " " ) {
//$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
}
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme du label
\param postoffice
\param extended
\param street
\param city
\param region
\param zip
\param country
\param type
*/
2004-01-23 18:54:22 +01:00
function setLabel ( $postoffice = " " , $extended = " " , $street = " " , $city = " " , $region = " " , $zip = " " , $country = " " , $type = " HOME;POSTAL " ) {
$label = " " ;
if ( $postoffice != " " ) $label .= " $postoffice\r\n " ;
if ( $extended != " " ) $label .= " $extended\r\n " ;
if ( $street != " " ) $label .= " $street\r\n " ;
if ( $zip != " " ) $label .= " $zip " ;
if ( $city != " " ) $label .= " $city\r\n " ;
if ( $region != " " ) $label .= " $region\r\n " ;
if ( $country != " " ) $country .= " $country\r\n " ;
2004-07-16 08:41:58 +02:00
2004-01-23 18:54:22 +01:00
$this -> properties [ " LABEL; $type ;ENCODING=QUOTED-PRINTABLE " ] = quoted_printable_encode ( $label );
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme de l ' email
\param address
*/
2004-01-23 18:54:22 +01:00
function setEmail ( $address ) {
$this -> properties [ " EMAIL;INTERNET " ] = $address ;
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme de la note
\param note
*/
2004-01-23 18:54:22 +01:00
function setNote ( $note ) {
$this -> properties [ " NOTE;ENCODING=QUOTED-PRINTABLE " ] = quoted_printable_encode ( $note );
}
2004-07-16 08:41:58 +02:00
/*!
\brief mise en forme de l ' url
\param url
\param type
*/
2004-01-23 18:54:22 +01:00
function setURL ( $url , $type = " " ) {
// $type may be WORK | HOME
$key = " URL " ;
if ( $type != " " ) $key .= " ; $type " ;
$this -> properties [ $key ] = $url ;
}
2004-07-16 08:41:58 +02:00
/*!
\brief permet d ' obtenir une vcard
*/
2004-01-23 18:54:22 +01:00
function getVCard () {
$text = " BEGIN:VCARD \r \n " ;
$text .= " VERSION:2.1 \r \n " ;
foreach ( $this -> properties as $key => $value ) {
$text .= " $key : $value\r\n " ;
}
$text .= " REV: " . date ( " Y-m-d " ) . " T " . date ( " H:i:s " ) . " Z \r \n " ;
2004-10-20 00:42:23 +02:00
$text .= " MAILER:php vCard class by Kai Blankenhorn \r \n " ;
2004-01-23 18:54:22 +01:00
$text .= " END:VCARD \r \n " ;
return $text ;
}
2004-07-16 08:41:58 +02:00
/*!
\brief permet d ' obtenir le nom de fichier
*/
2004-01-23 18:54:22 +01:00
function getFileName () {
return $this -> filename ;
}
}
?>