From 73dfca415dc65ef0a41f81feee02834d172aaead Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 26 Jun 2007 11:59:37 +0200 Subject: [PATCH] fixed vcf import darcs-hash:20070626095937-6e07b-b42ac2864e40cc41f984300bbfc3d07797c29290.gz --- import.php | 98 +++++++++++------------ inc/Contact_Vcard_Parse.php | 21 +++-- inc/importVCF.php | 127 ------------------------------ inc/smarty/plugins/modifier.h.php | 1 + styles/design.css | 7 +- templates/import.tpl | 2 +- templates/import_entry.tpl | 59 +++++++------- templates/search.tpl | 4 +- 8 files changed, 101 insertions(+), 218 deletions(-) delete mode 100644 inc/importVCF.php diff --git a/import.php b/import.php index de4d3a2..095f5f7 100644 --- a/import.php +++ b/import.php @@ -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 '
';
-print_r($entry);
-print '
'; -*/ + }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; } diff --git a/inc/Contact_Vcard_Parse.php b/inc/Contact_Vcard_Parse.php index da1f16f..2c2cc59 100644 --- a/inc/Contact_Vcard_Parse.php +++ b/inc/Contact_Vcard_Parse.php @@ -13,10 +13,10 @@ // | 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 | +// | Authors: Paul M. Jones | // +----------------------------------------------------------------------+ // -// $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 $ /** @@ -46,11 +46,11 @@ * * * -* @author Paul M. Jones +* @author Paul M. Jones * * @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 index 1138b99..0000000 --- a/inc/importVCF.php +++ /dev/null @@ -1,127 +0,0 @@ -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 '
';
-  print_r($entry);
-  print '
'; -*/ - - return $entry; -} - - -?> diff --git a/inc/smarty/plugins/modifier.h.php b/inc/smarty/plugins/modifier.h.php index 84274bf..1b50520 100644 --- a/inc/smarty/plugins/modifier.h.php +++ b/inc/smarty/plugins/modifier.h.php @@ -5,6 +5,7 @@ * @subpackage plugins */ +require_once(dirname(__FILE__).'/modifier.escape.php'); /** * Shortcut to the Smarty escape modifier plugin diff --git a/styles/design.css b/styles/design.css index 0f810e6..f23a280 100644 --- a/styles/design.css +++ b/styles/design.css @@ -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 { diff --git a/templates/import.tpl b/templates/import.tpl index fe08cc3..be56b5f 100644 --- a/templates/import.tpl +++ b/templates/import.tpl @@ -4,7 +4,7 @@ {$lang.upload} - + diff --git a/templates/import_entry.tpl b/templates/import_entry.tpl index 2054197..28ef22e 100644 --- a/templates/import_entry.tpl +++ b/templates/import_entry.tpl @@ -1,39 +1,40 @@ -
- {$entry.name}, {$entry.givenname} + {$entry.name|h}, {$entry.givenname|h}
+ {$entry.organization|h} {$entry.street|h} {$entry.zip|h} {$entry.location|h} - + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + {foreach from=$entry.mail item=mail} - + {/foreach} - - - - - - - -
+ + diff --git a/templates/search.tpl b/templates/search.tpl index eec6d6e..ead4fe7 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -1,7 +1,7 @@ {if $fields._marker} @@ -10,7 +10,7 @@ - + {/if} -- 2.39.5