From 234e547c002da9fe6444f072fe8c806d0dec75e0 Mon Sep 17 00:00:00 2001 From: Jens Bocklage Date: Fri, 31 May 2019 11:33:38 +0200 Subject: [PATCH 1/3] Map phone type 'main' to 'work' vcards my contain phone entries of type main as the standard type. So this type should not be discarded. --- carddav2fb.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/carddav2fb.php b/carddav2fb.php index 6ac06332..58499e01 100755 --- a/carddav2fb.php +++ b/carddav2fb.php @@ -468,12 +468,15 @@ public function get_carddav_entries() $type = "fax_work"; elseif(in_array("work", $typearr_lower)) $type = "work"; + elseif(in_array("main", $typearr_lower)) + $type = "work"; elseif(in_array("other", $typearr_lower)) $type = "other"; elseif(in_array("dom", $typearr_lower)) $type = "other"; elseif(in_array("voice", $typearr_lower)) $type = "other"; + else continue; } From 84a5e1cfa69253ae056668bb17f0c68b7ddaaa2d Mon Sep 17 00:00:00 2001 From: Jens Bocklage Date: Fri, 31 May 2019 12:39:15 +0200 Subject: [PATCH 2/3] Fax has a higher prio then home or work Home-fax and work-fax must map to fax --- carddav2fb.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/carddav2fb.php b/carddav2fb.php index 58499e01..f1f4a783 100755 --- a/carddav2fb.php +++ b/carddav2fb.php @@ -462,10 +462,10 @@ public function get_carddav_entries() // set the proper type if(in_array("cell", $typearr_lower)) $type = "mobile"; - elseif(in_array("home", $typearr_lower)) - $type = "home"; elseif(in_array("fax", $typearr_lower)) $type = "fax_work"; + elseif(in_array("home", $typearr_lower)) + $type = "home"; elseif(in_array("work", $typearr_lower)) $type = "work"; elseif(in_array("main", $typearr_lower)) From 3dc93b31c96282c1eae061338bf34a2a61971f08 Mon Sep 17 00:00:00 2001 From: Jens Bocklage Date: Fri, 31 May 2019 16:05:11 +0200 Subject: [PATCH 3/3] Add support for PNG pictures in vcards PNGs will be converted to JPGs by using imagejpeg($image_png, $image_jpg, 100); --- carddav2fb.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/carddav2fb.php b/carddav2fb.php index f1f4a783..26befa17 100755 --- a/carddav2fb.php +++ b/carddav2fb.php @@ -179,7 +179,7 @@ public function is_base64($str) } } - public function base64_to_jpeg($inputfile, $outputfile) + public function base64_to_picture($inputfile, $outputfile) { // read data (binary) $ifp = fopen($inputfile, "rb"); @@ -593,22 +593,36 @@ public function build_fb_xml() // we have to extract ['value'] and friends. if(is_array($entry['photo_data'][0]) and (array_key_exists('value', $entry['photo_data'][0]))) { - // check if photo_data really contains JPEG data + // check if photo_data really contains JPEG or PNG data if((array_key_exists('type', $entry['photo_data'][0])) and (is_array($entry['photo_data'][0]['type'])) and - ($entry['photo_data'][0]['type'][0] == 'jpeg' or $entry['photo_data'][0]['type'][0] == 'jpg' or $entry['photo_data'][0]['type'][0] == 'image/jpeg')) + ($entry['photo_data'][0]['type'][0] == 'jpeg' or $entry['photo_data'][0]['type'][0] == 'jpg' or $entry['photo_data'][0]['type'][0] == 'image/jpeg') or + ($entry['photo_data'][0]['type'][0] == 'png' or $entry['photo_data'][0]['type'][0] == 'image/png')) { // get photo, rename, base64 convert and save as jpg $photo_data = $entry['photo_data'][0]['value']; $photo_version = substr(sha1($photo_data), 0, 5); - $photo_file = $this->tmpdir . '/' . "{$entry['photo']}_{$photo_version}.jpg"; + $photo_file = $this->tmpdir . '/' . "{$entry['photo']}_{$photo_version}"; // check for base64 encoding of the photo data and convert it // accordingly. if(((array_key_exists('encoding', $entry['photo_data'][0])) and ($entry['photo_data'][0]['encoding'] == 'b')) or $this->is_base64($photo_data)) { file_put_contents($photo_file . ".b64", $photo_data); - $this->base64_to_jpeg($photo_file . ".b64", $photo_file); + $this->base64_to_picture($photo_file . ".b64", $photo_file); unlink($photo_file . ".b64"); + if($entry['photo_data'][0]['type'][0] == 'jpeg' or $entry['photo_data'][0]['type'][0] == 'jpg' or $entry['photo_data'][0]['type'][0] == 'image/jpeg') + { + rename($photo_file, $photo_file . ".jpg"); + $photo_file .= ".jpg"; + } + if($entry['photo_data'][0]['type'][0] == 'png' or $entry['photo_data'][0]['type'][0] == 'image/png') + { + print " Convert photo from png to jpg" . PHP_EOL; + $image = imagecreatefrompng($photo_file); + $photo_file .= ".jpg"; + imagejpeg($image, $photo_file, 100); // full quality + imagedestroy($image); + } } else { @@ -622,7 +636,7 @@ public function build_fb_xml() print " Added photo: " . basename($photo_file) . PHP_EOL; } else - print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; + print " WARNING: Only jpg and png contact photos are currently supported." . PHP_EOL; } elseif(substr($entry['photo_data'][0], 0, 4) == 'http') {