<?php
class person {
public $uid;
public $name;
public $surname;
public $fullname;
public $add_name;
public $honorPre;
public $honorSuf;
public $sortstring;
public $tel_cell;
public $tel_home;
public $tel_work;
public $tel_fax;
public $tel_other;
public $postbox;
public $ext_addr;
public $street;
public $city;
public $state;
public $zipcode;
public $country;
public $org;
public $email;
public $url;
public $birthday;
public $note;
public function set_person_uid($uid){
$this -> uid = $uid;
}
public function set_person_data($vCard){
$zeile = explode("\n", $vCard);
for($i = 0; $i < count($zeile); $i++){
$eintrag = explode(":", $zeile[$i]);
if( $eintrag[0] == "N" ){
$names = explode(";", $eintrag["1"]);
$this -> surname = $names[0];
$this -> name = $names[1];
$this -> add_name = $names[2];
$this -> honorPre = $names[3];
$this -> honorSuf = $names[4];
$this -> sortstring = $names[1];
}elseif( $eintrag[0] == "FN" ){
$this -> fullname = $eintrag[1];
}elseif( eregi("TEL", $eintrag[0]) ){
if( eregi("FAX", $eintrag[0]) ){
$this -> tel_fax = $eintrag[1];
}elseif( eregi("HOME", $eintrag[0]) and !eregi("FAX", $eintrag[1]) ){
$this -> tel_home = $eintrag[1];
}elseif( eregi("WORK", $eintrag[0]) and !eregi("FAX", $eintrag[1]) ){
$this -> tel_work = $eintrag[1];
}elseif( eregi("CELL", $eintrag[0]) ){
$this -> tel_cell = $eintrag[1];
}elseif( !eregi("FAX", $eintrag[0]) ){
$this -> tel_other = $eintrag[1];
}
}elseif( eregi("ADR", $eintrag[0]) ){
$adr = explode(";", $eintrag["1"]);
$this -> postbox = $adr[0];
$this -> ext_addr = $adr[1];
$this -> street = $adr[2];
$this -> city = $adr[3];
$this -> state = $adr[4];
$this -> zipcode = $adr[5];
$this -> country = $adr[6];
}elseif( eregi("EMAIL", $eintrag[0]) ){
if( eregi("PREF", $eintrag[0]) and eregi("INTERNET", $eintrag[0]) ){
$email_pref = $eintrag[1];
}else{
$email_nonpref = $eintrag[1];
}
if( !empty($email_pref) ){
$email = $email_pref;
}else{
$this -> email = $email_nonpref;
}
}elseif( eregi("URL", $eintrag[0])){
$this -> url = $eintrag[1].":".$eintrag[2];
}elseif( $eintrag[0] == "BDAY"){
$this -> birthbday = $eintrag[1];
}elseif( $eintrag[0] == "NOTE" ){
$this -> note = $eintrag[1];
}elseif( $eintrag[0] == "ORG" ){
$this -> org = $eintrag[1];
}
}
}
public function export_xml(){
$xml = "
<person uid=\"".$this -> uid."\" >\n
<class></class>\n
<fullname>".$this -> fullname."</fullname>\n
<name>".$this -> name."</name>\n
<surname>".$this -> surname."</surname>\n
<sort-string>".$this -> sortstring."</sort-string>\n
<tel>\n
<cell>".$this -> tel_cell."</cell>\n
<home>".$this -> tel_home."</home>\n
<work>".$this -> tel_work."</work>\n
<other>".$this -> tel_other."</other>\n
<fax>".$this -> tel_fax."</fax>\n
</tel>\n
<address>\n
<postbox>".$this -> postbox."</postbox>\n
<extaddr>".$this -> ext_addr."</extaddr>\n
<street>".$this -> street."</street>\n
<city>".$this -> city."</city>\n
<state>".$this -> state."</state>\n
<zipcode>".$this -> zipcode."</zipcode>\n
<country>".$this -> country."</country>\n
</address>\n
<org>".$this -> org."</org>\n
<note>".$this -> note."</note>\n
<birthday>".$this -> birthday."</birthday>\n
</person>\n";
return $xml;
}
}
$file = "address.txt";
$datei = implode ('', file ($file));
$datei = "\n".$datei;
$card = explode("END:VCARD", $datei);
for($a = 0; $a < count($card); $a++){
$person[$a] = new person;
$person[$a] -> set_person_data($card[$a]);
$person[$a] -> set_person_uid($a);
$xml_person[$a] = $person[$a] -> export_xml();
echo $xml_person[$a];
}
?>