| | |
| | | */ |
| | | private static function vcard_decode($vcard) |
| | | { |
| | | // Perform RFC2425 line unfolding |
| | | // Perform RFC2425 line unfolding and split lines |
| | | $vcard = preg_replace(array("/\r/", "/\n\s+/"), '', $vcard); |
| | | |
| | | $lines = preg_split('/\r?\n/', $vcard); |
| | | $lines = explode("\n", $vcard); |
| | | $data = array(); |
| | | |
| | | for ($i=0; $i < count($lines); $i++) { |
| | | if (!preg_match('/^([^\\:]*):(.+)$/', $lines[$i], $line)) |
| | | if (!preg_match('/^([^:]+):(.+)$/', $lines[$i], $line)) |
| | | continue; |
| | | |
| | | if (preg_match('/^(BEGIN|END)$/i', $line[1])) |
| | | continue; |
| | | |
| | | // convert 2.1-style "EMAIL;internet;home:" to 3.0-style "EMAIL;TYPE=internet;TYPE=home:" |
| | |
| | | $line[1] .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop); |
| | | } |
| | | |
| | | if (!preg_match('/^(BEGIN|END)$/i', $line[1]) && preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) { |
| | | if (preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) { |
| | | $entry = array(); |
| | | $field = strtoupper($regs2[1][0]); |
| | | |
| | |
| | | |
| | | unset($data['VERSION']); |
| | | return $data; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Split quoted string |
| | | * |
| | | * @param string vCard string to split |
| | | * @param string Separator char/string |
| | | * @return array List with splitted values |
| | | */ |
| | | private static function vcard_unquote($s, $sep = ';') |
| | | { |
| | | // break string into parts separated by $sep, but leave escaped $sep alone |
| | | if (count($parts = explode($sep, strtr($s, array("\\$sep" => "\007")))) > 1) { |
| | | foreach($parts as $s) { |
| | | $result[] = self::vcard_unquote(strtr($s, array("\007" => "\\$sep")), $sep); |
| | | } |
| | | return $result; |
| | | } |
| | | else { |
| | | return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\,' => ',', '\;' => ';', '\:' => ':')); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | return(implode($sep, (array)$r)); |
| | | } |
| | | else { |
| | | return strtr($s, array('\\' => '\\\\', "\r" => '', "\n" => '\n', ';' => '\;', ':' => '\:')); |
| | | return strtr($s, array('\\' => '\\\\', "\r" => '', "\n" => '\n', ',' => '\,', ';' => '\;')); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Split quoted string |
| | | * |
| | | * @param string vCard string to split |
| | | * @param string Separator char/string |
| | | * @return array List with splitted values |
| | | */ |
| | | private static function vcard_unquote($s, $sep = ';') |
| | | { |
| | | // break string into parts separated by $sep, but leave escaped $sep alone |
| | | if (count($parts = explode($sep, strtr($s, array("\\$sep" => "\007")))) > 1) { |
| | | foreach($parts as $s) { |
| | | $result[] = self::vcard_unquote(strtr($s, array("\007" => "\\$sep")), $sep); |
| | | } |
| | | return $result; |
| | | } |
| | | else { |
| | | return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';')); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | |