]> git.sur5r.net Git - contagged/commitdiff
Fixed VCard import and handle photo URLs in VCF
authorBernhard Minks <bernhard@minks.de>
Thu, 7 May 2009 09:48:54 +0000 (11:48 +0200)
committerAndreas Gohr <gohr@cosmocode.de>
Thu, 7 May 2009 09:48:54 +0000 (11:48 +0200)
entry.php
import.php
templates/import_entry.tpl

index 9edd1717023604763444909f21697fa163b46aa2..15208345f9cb0f4ae7a19763a239398ffbeadaf9 100644 (file)
--- a/entry.php
+++ b/entry.php
@@ -233,6 +233,14 @@ function _getUploadData(){
     } else {
       $smarty->assign('jpegError',$lang['err_wrongFileType']);
     }
+  } elseif (preg_match('/http:\/\//', $_REQUEST["photo"])) {
+    $fd = fopen($_REQUEST["photo"], "rb");
+    $data = '';
+    while (!feof($fd)) {
+      $data .= fread($fd, 8192);
+    }
+    fclose($fd);
+    return $data;
   } else {
     $smarty->assign('jpegError',$lang['err_fileNotUploaded']);
   }
index 28006ed75cb9ea81769fa3bbcf2b2aa54c5ad5f3..0cfa1dc273b1bd225f0cc8a2aaa45aa08552e6bf 100644 (file)
@@ -69,6 +69,7 @@ $smarty->display('footer.tpl');
 function vcard_entry($vcf){
     $entry = array();
 
+
     $entry['name']         = $vcf['N'][0]['value'][0][0];
     $entry['givenname']    = trim($vcf['N'][0]['value'][1][0].' '.$vcf['N'][0]['value'][2][0]);
     $entry['title']        = $vcf['N'][0]['value'][3][0];
@@ -76,40 +77,43 @@ function vcard_entry($vcf){
     $entry['office']       = $vcf['ORG'][0]['value'][1][0];
     $entry['note']         = $vcf['NOTE'][0]['value'][0][0];
     $entry['url']          = $vcf['URL'][0]['value'][0][0];
+    $entry['photo']        = $vcf['PHOTO'][0]['value'][0][0];
     $bday                  = $vcf['BDAY'][0]['value'][0][0];
     $entry['birthday']     = substr($bday,0,4).'-'.substr($bday,4,2).'-'.substr($bday,6,2);
 
     foreach((array) $vcf['TEL'] as $tel){
       if(   empty($entry['phone']) &&
-            array_search('WORK',(array) $tel['param']['TYPE']) !== false &&
-            array_search('VOICE',(array) $tel['param']['TYPE']) !== false){
+            (my_array_search('WORK',(array) $tel['param']['TYPE']) != false ||
+            my_array_search('VOICE',(array) $tel['param']['TYPE']) != false))
+           {
         // Work phone
         $entry['phone'] = $tel['value'][0][0];
       }elseif(empty($entry['fax']) &&
-              array_search('FAX',(array) $tel['param']['TYPE']) !== false){
+              my_array_search('FAX',(array) $tel['param']['TYPE']) !== false){
         $entry['fax'] = $tel['value'][0][0];
       }elseif(empty($entry['mobile']) &&
-              array_search('CELL',(array) $tel['param']['TYPE']) !== false){
+              my_array_search('CELL',(array) $tel['param']['TYPE']) !== false){
         $entry['mobile'] = $tel['value'][0][0];
       }elseif(empty($entry['pager']) &&
-              array_search('PAGER',(array) $tel['param']['TYPE']) !== false){
+              my_array_search('PAGER',(array) $tel['param']['TYPE']) !== false){
         $entry['pager'] = $tel['value'][0][0];
       }elseif(empty($entry['homephone']) &&
-              array_search('HOME',(array) $tel['param']['TYPE']) !== false &&
-              array_search('VOICE',(array) $tel['param']['TYPE']) !== false){
+              my_array_search('HOME',(array) $tel['param']['TYPE']) !== false &&
+              my_array_search('VOICE',(array) $tel['param']['TYPE']) !== false){
         $entry['homephone'] = $tel['value'][0][0];
       }
     }
     foreach((array) $vcf['EMAIL'] as $mail){
+      if (! in_array($mail['value'][0][0], (array)$entry['mail']))
       $entry['mail'][] = $mail['value'][0][0];
     }
     foreach((array) $vcf['ADR'] as $adr){
-      if(array_search('HOME',(array)$adr['param']['TYPE']) !== false){
+      if(my_array_search('HOME',(array)$adr['param']['TYPE']) !== false){
         $entry['homestreet'] = $adr['value'][2][0]."\n". //str
                                $adr['value'][5][0]." ". //plz
                                $adr['value'][3][0];      //ort
 
-      }elseif((array) array_search('WORK',(array)$adr['param']['TYPE']) !== false){
+      }elseif(my_array_search('WORK',(array)$adr['param']['TYPE']) !== false){
         $entry['street']   = $adr['value'][2][0];
         $entry['location'] = $adr['value'][3][0];
         $entry['zip']      = $adr['value'][5][0];
@@ -121,5 +125,22 @@ function vcard_entry($vcf){
     return $entry;
 }
 
+function my_array_search ($needle, $haystack)
+{
+       foreach ($haystack as $value)
+       {
+               if ($value == $needle)
+               {
+                       return true;
+               }
+               else if ($value == strtolower($needle))
+               {
+                       return true;
+               }
+
+       }
+       return false;
+}
+
 
 ?>
index dd66dfa5a7f592a4e0ac93283e58b651c150b1fd..84dc6e527760a81098dbc324a50352cedd8e3634 100644 (file)
@@ -23,6 +23,7 @@
         <input type="hidden" name="entry[homephone]" value="{$entry.homephone|h}" />
         <input type="hidden" name="entry[mobile]" value="{$entry.mobile|h}" />
         <input type="hidden" name="entry[url]" value="{$entry.url|h}" />
+        <input type="hidden" name="photo" value="{$entry.photo|h}" />
         {foreach from=$entry.mail item=mail}
         <input type="hidden" name="entry[mail][]" value="{$mail|h}" />
         {/foreach}
@@ -38,6 +39,7 @@
        {else}
            <input type="hidden" name="type" value="public" />
        {/if}
+           <input type="submit" name="save" value="save" />
         </form>
     </td>
 </tr>