]> git.sur5r.net Git - contagged/commitdiff
fixed vcf import
authorAndreas Gohr <gohr@cosmocode.de>
Tue, 26 Jun 2007 09:59:37 +0000 (11:59 +0200)
committerAndreas Gohr <gohr@cosmocode.de>
Tue, 26 Jun 2007 09:59:37 +0000 (11:59 +0200)
darcs-hash:20070626095937-6e07b-b42ac2864e40cc41f984300bbfc3d07797c29290.gz

import.php
inc/Contact_Vcard_Parse.php
inc/importVCF.php [deleted file]
inc/smarty/plugins/modifier.h.php
styles/design.css
templates/import.tpl
templates/import_entry.tpl
templates/search.tpl

index de4d3a25055ad023e4c15558c332e13a8a902036..095f5f7861809703ed2983a51b50f5785a9c7046 100644 (file)
@@ -67,60 +67,58 @@ $smarty->display('footer.tpl');
 
 
 function vcard_entry($vcf){
-$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];
-$entry['organization'] = $vcf['ORG'][0]['value'][0][0];
-$entry['office']       = $vcf['ORG'][0]['value'][1][0];
-$entry['note']         = $vcf['NOTE'][0]['value'][0][0];
-$entry['url']          = $vcf['URL'][0]['value'][0][0];
-$bday                  = $vcf['BDAY'][0]['value'][0][0];
-$entry['anniversary']  = substr($bday,0,4).'-'.substr($bday,4,2).'-'.substr($bday,6,2);
+    $entry = array();
 
-foreach($vcf['TEL'] as $tel){
-  if(   empty($entry['phone']) &&
-        array_search('WORK',$tel['param']['TYPE']) !== FALSE &&
-        array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
-    // Work phone
-    $entry['phone'] = $tel['value'][0][0];
-  }elseif(empty($entry['fax']) &&
-          array_search('FAX',$tel['param']['TYPE']) !== FALSE){
-    $entry['fax'] = $tel['value'][0][0];
-  }elseif(empty($entry['mobile']) &&
-          array_search('CELL',$tel['param']['TYPE']) !== FALSE){
-    $entry['mobile'] = $tel['value'][0][0];
-  }elseif(empty($entry['pager']) &&
-          array_search('PAGER',$tel['param']['TYPE']) !== FALSE){
-    $entry['pager'] = $tel['value'][0][0];
-  }elseif(empty($entry['homephone']) &&
-          array_search('HOME',$tel['param']['TYPE']) !== FALSE &&
-          array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
-    $entry['homephone'] = $tel['value'][0][0];
-  }
-}
-foreach($vcf['EMAIL'] as $mail){
-  $entry['mail'][] = $mail['value'][0][0];
-}
-foreach($vcf['ADR'] as $adr){
-  if(array_search('HOME',$adr['param']['TYPE']) !== FALSE){
-    $entry['homestreet'] = $adr['value'][2][0]."\n". //str
-                           $adr['value'][5][0]." ". //plz
-                           $adr['value'][3][0];      //ort
+    $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];
+    $entry['organization'] = $vcf['ORG'][0]['value'][0][0];
+    $entry['office']       = $vcf['ORG'][0]['value'][1][0];
+    $entry['note']         = $vcf['NOTE'][0]['value'][0][0];
+    $entry['url']          = $vcf['URL'][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);
 
-  }elseif(array_search('WORK',$adr['param']['TYPE']) !== FALSE){
-    $entry['street']   = $adr['value'][2][0];
-    $entry['location'] = $adr['value'][3][0];
-    $entry['zip']      = $adr['value'][5][0];
-  }
-}
+    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){
+        // Work phone
+        $entry['phone'] = $tel['value'][0][0];
+      }elseif(empty($entry['fax']) &&
+              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){
+        $entry['mobile'] = $tel['value'][0][0];
+      }elseif(empty($entry['pager']) &&
+              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){
+        $entry['homephone'] = $tel['value'][0][0];
+      }
+    }
+    foreach((array) $vcf['EMAIL'] as $mail){
+      $entry['mail'][] = $mail['value'][0][0];
+    }
+    foreach((array) $vcf['ADR'] as $adr){
+      if(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
 
-/*
-print '<pre>';
-print_r($entry);
-print '</pre>';
-*/
+      }elseif((array) 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];
+        $entry['country']  = $adr['value'][6][0];
+        $entry['state']    = $adr['value'][4][0];
+      }
+    }
 
-return $entry;
+    return $entry;
 }
 
 
index da1f16f139184a473e778ea1f052dd50225def4f..2c2cc59434be261a3b9ce966f9b1c0bac9bd9b44 100644 (file)
 // | obtain it through the world-wide-web, please send a note to          | 
 // | license@php.net so we can mail you a copy immediately.               | 
 // +----------------------------------------------------------------------+ 
-// | Authors: Paul M. Jones <pmjones@ciaweb.net>                          | 
+// | Authors: Paul M. Jones <pmjones@php.net>                             | 
 // +----------------------------------------------------------------------+ 
 // 
-// $Id: Contact_Vcard_Parse.php,v 1.1 2004/06/01 08:48:59 gohr Exp $ 
+// $Id: Contact_Vcard_Parse.php,v 1.4 2005/05/28 15:40:17 pmjones Exp $ 
 
 
 /**
 * </code>
 * 
 *
-* @author Paul M. Jones <pmjones@ciaweb.net>
+* @author Paul M. Jones <pmjones@php.net>
 * 
 * @package Contact_Vcard_Parse
 * 
-* @version 1.30
+* @version 1.31
 * 
 */
 
@@ -273,6 +273,7 @@ class Contact_Vcard_Parse {
     * Used to make string human-readable after being a vCard value.
     * 
     * Converts...
+    *     \: => :
     *     \; => ;
     *     \, => ,
     *     literal \n => newline
@@ -293,6 +294,7 @@ class Contact_Vcard_Parse {
                 $text[$key] = $val;
             }
         } else {
+            $text = str_replace('\:', ':', $text);
             $text = str_replace('\;', ';', $text);
             $text = str_replace('\,', ',', $text);
             $text = str_replace('\n', "\n", $text);
@@ -496,7 +498,7 @@ class Contact_Vcard_Parse {
         $split = $this->splitBySemi($text);
         
         // only return first element (the typedef)
-        return $split[0];
+        return strtoupper($split[0]);
     }
     
     
@@ -698,7 +700,8 @@ class Contact_Vcard_Parse {
     
     function _parseN($text)
     {
-        $tmp = $this->splitBySemi($text);
+       // make sure there are always at least 5 elements
+        $tmp = array_pad($this->splitBySemi($text), 5, '');
         return array(
             $this->splitByComma($tmp[0]), // family (last)
             $this->splitByComma($tmp[1]), // given (first)
@@ -728,7 +731,8 @@ class Contact_Vcard_Parse {
     
     function _parseADR($text)
     {
-        $tmp = $this->splitBySemi($text);
+       // make sure there are always at least 7 elements
+        $tmp = array_pad($this->splitBySemi($text), 7, '');
         return array(
             $this->splitByComma($tmp[0]), // pob
             $this->splitByComma($tmp[1]), // extend
@@ -825,7 +829,8 @@ class Contact_Vcard_Parse {
     
     function _parseGEO($text)
     {
-        $tmp = $this->splitBySemi($text);
+       // make sure there are always at least 2 elements
+        $tmp = array_pad($this->splitBySemi($text), 2, '');
         return array(
             array($tmp[0]), // lat
             array($tmp[1])  // lon
diff --git a/inc/importVCF.php b/inc/importVCF.php
deleted file mode 100644 (file)
index 1138b99..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-<?
-  require_once('init.php');
-  require_once('Contact_Vcard_Parse.php');
-  ldap_login();
-
-  if(! $_SESSION['ldapab']['username'] ){
-    header("Location: login.php");
-    exit;
-  }
-
-  $error = '';
-  if(isset($_FILES['userfile'])){
-    if(preg_match('/\.vcf$/i', $_FILES['userfile']['name'])){
-      if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
-        //parse VCF
-                               $vcfparser = new Contact_Vcard_Parse();
-                               $vcards = $vcfparser->fromFile($_FILES['userfile']['tmp_name']);
-      }else{
-        switch($_FILES['userfile']['error']){
-         case 0: //no error; possible file attack!
-           $error = "There was a problem with your upload.";
-           break;
-         case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
-           $error = "The file you are trying to upload is too big.";
-           break;
-         case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
-           $error = "The file you are trying to upload is too big.";
-           break;
-         case 3: //uploaded file was only partially uploaded
-           $error = "The file you are trying upload was only partially uploaded.";
-           break;
-         case 4: //no file was uploaded
-           $error = "You must select a VCF file for upload.";
-           break;
-         default: //a default error, just in case!  :)
-           $error = "There was a problem with your upload.";
-           break;
-                 }
-      }
-    }else{
-      $error = "Only VCF extension is allowed";
-    }
-  }
-
-  //prepare templates for all found VCARDs
-  $list = '';
-  if (count($vcards)){
-         foreach ($vcards as $vcard){
-         $entry = vcard_entry($vcard);
-       $smarty->clear_all_assign();
-               tpl_std();
-           $smarty->assign('entry',$entry);
-         $list .= $smarty->fetch('importVCF_entry.tpl');
-         }
-       }
-
-  //prepare templates
-  tpl_std();
-  tpl_orgs();
-  tpl_markers();
-  $smarty->assign('error',$error);
-  $smarty->assign('list',$list);
-  //display templates
-  $smarty->display('header.tpl');
-  $smarty->display('importVCF.tpl');
-  $smarty->display('footer.tpl');
-
-
-function vcard_entry($vcf){
-  $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];
-  $entry['organization'] = $vcf['ORG'][0]['value'][0][0];
-  $entry['office'] = $vcf['ORG'][0]['value'][1][0];
-  $entry['note'] = $vcf['NOTE'][0]['value'][0][0];
-  $entry['url'] = $vcf['URL'][0]['value'][0][0];
-  $bday = $vcf['BDAY'][0]['value'][0][0];
-  $entry['anniversary'] = substr($bday,0,4).'-'.substr($bday,4,2).'-'.substr($bday,6,2);
-
-  foreach($vcf['TEL'] as $tel){
-    if(   empty($entry['phone']) &&
-          array_search('WORK',$tel['param']['TYPE']) !== FALSE &&
-          array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
-      // Work phone
-                       $entry['phone'] = $tel['value'][0][0];
-    }elseif(empty($entry['fax']) &&
-            array_search('FAX',$tel['param']['TYPE']) !== FALSE){
-                       $entry['fax'] = $tel['value'][0][0];
-    }elseif(empty($entry['mobile']) &&
-            array_search('CELL',$tel['param']['TYPE']) !== FALSE){
-                       $entry['mobile'] = $tel['value'][0][0];
-    }elseif(empty($entry['pager']) &&
-            array_search('PAGER',$tel['param']['TYPE']) !== FALSE){
-                       $entry['pager'] = $tel['value'][0][0];
-    }elseif(empty($entry['homephone']) &&
-            array_search('HOME',$tel['param']['TYPE']) !== FALSE &&
-            array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
-                       $entry['homephone'] = $tel['value'][0][0];
-    }
-  }
-  foreach($vcf['EMAIL'] as $mail){
-    $entry['mail'][] = $mail['value'][0][0];
-  }
-  foreach($vcf['ADR'] as $adr){
-    if(array_search('HOME',$adr['param']['TYPE']) !== FALSE){
-      $entry['homestreet'] = $adr['value'][2][0]."\n". //str
-                                                                                                                $adr['value'][5][0]." ". //plz
-                             $adr['value'][3][0];      //ort
-
-    }elseif(array_search('WORK',$adr['param']['TYPE']) !== FALSE){
-      $entry['street']   = $adr['value'][2][0];
-      $entry['location'] = $adr['value'][3][0];
-      $entry['plz']      = $adr['value'][5][0];
-    }
-  }
-
-/*
-  print '<pre>';
-  print_r($entry);
-  print '</pre>';
-*/
-
-  return $entry;
-}
-
-
-?>
index 84274bf873f752661387599ab6847e045a573466..1b50520cbdbb992e10b444ff2582f43f27c607df 100644 (file)
@@ -5,6 +5,7 @@
  * @subpackage plugins
  */
 
+require_once(dirname(__FILE__).'/modifier.escape.php');
 
 /**
  * Shortcut to the Smarty escape modifier plugin
index 0f810e654c2b1ede3fac4c1a8e3019f184476941..f23a280122990a5e8a5ecc436c80cf36b437ffa8 100644 (file)
@@ -49,7 +49,7 @@ img.photo {
 
 /* forms */
 
-input, select, textarea {
+input, select, textarea, button {
     border: 1px solid #999;
     background-color: #F5F5F5;
 }
@@ -58,6 +58,11 @@ input:focus, select:focus, textarea:focus {
     border: 1px solid #06c;
 }
 
+.button {
+    background-color: #ddd;
+    cursor: pointer;
+}
+
 /* editing and other link icons */
 
 a.ed_help {
index fe08cc3b977023cdec38d7130249734bb99bcf3d..be56b5fe67f2e30f61fb635ad38478d70102a94e 100644 (file)
@@ -4,7 +4,7 @@
         <legend>{$lang.upload}</legend>
         <label for="upload">{$lang.msg_uploadvcf}:</label>
         <input name="userfile" type="file" class="upload" id="upload" />
-        <input type="submit" value="{$lang.upload}" />
+        <input type="submit" value="{$lang.upload}" class="button" />
     </fieldset>
 </form>
 
index 205419739c64f5314bbb17966a4ae79856dac574..28ef22eaa02c3a21b14e3c90333764799ee877d9 100644 (file)
@@ -1,39 +1,40 @@
 <tr>
-    <form action="entry.php" method="post" target="_import_" accept-charset="utf-8">
     <td class="result">
-        <b>{$entry.name}, {$entry.givenname}</b>
+        <b>{$entry.name|h}, {$entry.givenname|h}</b><br />
+        <i>{$entry.organization|h} {$entry.street|h} {$entry.zip|h} {$entry.location|h}</i>
     </td>
-    <td>
+    <td class="result" align="right">
+        <form action="entry.php" method="post" target="import" accept-charset="utf-8">
         <input type="hidden" name="save" value="1" />
-        <input type="hidden" name="entry[name]" value="{$entry.name|escape}" />
-        <input type="hidden" name="entry[givenname]" value="{$entry.givenname|escape}" />
-        <input type="hidden" name="entry[title]" value="{$entry.title|escape}" />
-        <input type="hidden" name="entry[organization]" value="{$entry.organization|escape}" />
-        <input type="hidden" name="entry[office]" value="{$entry.office|escape}" />
-        <input type="hidden" name="entry[street]" value="{$entry.street|escape}" />
-        <input type="hidden" name="entry[zip]" value="{$entry.zip|escape}" />
-        <input type="hidden" name="entry[location]" value="{$entry.location|escape}" />
-        <input type="hidden" name="entry[phone]" value="{$entry.phone|escape}" />
-        <input type="hidden" name="entry[fax]" value="{$entry.fax|escape}" />
-        <input type="hidden" name="entry[pager]" value="{$entry.pager|escape}" />
-        <input type="hidden" name="entry[homestreet]" value="{$entry.homestreet|escape}" />
-        <input type="hidden" name="entry[homephone]" value="{$entry.homephone|escape}" />
-        <input type="hidden" name="entry[mobile]" value="{$entry.mobile|escape}" />
-        <input type="hidden" name="entry[url]" value="{$entry.url|escape}" />
+        <input type="hidden" name="entry[name]" value="{$entry.name|h}" />
+        <input type="hidden" name="entry[givenname]" value="{$entry.givenname|h}" />
+        <input type="hidden" name="entry[title]" value="{$entry.title|h}" />
+        <input type="hidden" name="entry[organization]" value="{$entry.organization|h}" />
+        <input type="hidden" name="entry[office]" value="{$entry.office|h}" />
+        <input type="hidden" name="entry[street]" value="{$entry.street|h}" />
+        <input type="hidden" name="entry[zip]" value="{$entry.zip|h}" />
+        <input type="hidden" name="entry[location]" value="{$entry.location|h}" />
+        <input type="hidden" name="entry[country]" value="{$entry.country|h}" />
+        <input type="hidden" name="entry[state]" value="{$entry.state|h}" />
+        <input type="hidden" name="entry[phone]" value="{$entry.phone|h}" />
+        <input type="hidden" name="entry[fax]" value="{$entry.fax|h}" />
+        <input type="hidden" name="entry[pager]" value="{$entry.pager|h}" />
+        <input type="hidden" name="entry[homestreet]" value="{$entry.homestreet|h}" />
+        <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}" />
         {foreach from=$entry.mail item=mail}
-        <input type="hidden" name="entry[mail][]" value="{$mail|escape}" />
+        <input type="hidden" name="entry[mail][]" value="{$mail|h}" />
         {/foreach}
-        <input type="hidden" name="entry[note]" value="{$entry.note|escape}" />
-        <input type="hidden" name="entry[anniversary]" value="{$entry.anniversary|escape}" />
-    </td>
-    <td class="result" align="right">
-        <button name="type" value="public">
-            <img src="pix/public.png" border="0" width="16" height="16" align="middle">{$lang.publicbook}
+        <input type="hidden" name="entry[note]" value="{$entry.note|h}" />
+        <input type="hidden" name="entry[birthday]" value="{$entry.birthday|h}" />
+        <button name="type" value="public" class="button">
+            <img src="pix/public.png" border="0" width="16" height="16" align="middle" alt="" />{$lang.publicbook}
         </button>
-        <button name="type" value="private">
-            <img src="pix/private.png" border="0" width="16" height="16" align="middle">{$lang.privatebook}
+        <button name="type" value="private" class="button">
+            <img src="pix/private.png" border="0" width="16" height="16" align="middle" alt="" />{$lang.privatebook}
         </button>
-  </td>
-  </form>
+        </form>
+    </td>
 </tr>
 
index eec6d6e315be8594b684953385436ba08f94255b..ead4fe793b189fc9142a5287cdb5156bae56e4a9 100644 (file)
@@ -1,7 +1,7 @@
     <form method="get" action="index.php" accept-charset="utf-8" class="search">
         <input type="text" name="search" class="searchfield" id="searchfield"
                value="{$smarty.request.search|h}" />
-        <input type="submit" value="{$lang.search}" class="searchbutton" />
+        <input type="submit" value="{$lang.search}" class="button" />
     </form>
 
 {if $fields._marker}
@@ -10,7 +10,7 @@
 
         <input name="marker" class="searchfield" type="text" id="taglookup"
                value="{$smarty.request.marker|h}" />
-        <input type="submit" value="{$lang.search}" class="searchbutton" />
+        <input type="submit" value="{$lang.search}" class="button" />
     </form>
 {/if}