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;
}
// | 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
*
*/
* Used to make string human-readable after being a vCard value.
*
* Converts...
+ * \: => :
* \; => ;
* \, => ,
* literal \n => newline
$text[$key] = $val;
}
} else {
+ $text = str_replace('\:', ':', $text);
$text = str_replace('\;', ';', $text);
$text = str_replace('\,', ',', $text);
$text = str_replace('\n', "\n", $text);
$split = $this->splitBySemi($text);
// only return first element (the typedef)
- return $split[0];
+ return strtoupper($split[0]);
}
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)
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
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
+++ /dev/null
-<?
- 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;
-}
-
-
-?>
* @subpackage plugins
*/
+require_once(dirname(__FILE__).'/modifier.escape.php');
/**
* Shortcut to the Smarty escape modifier plugin
/* forms */
-input, select, textarea {
+input, select, textarea, button {
border: 1px solid #999;
background-color: #F5F5F5;
}
border: 1px solid #06c;
}
+.button {
+ background-color: #ddd;
+ cursor: pointer;
+}
+
/* editing and other link icons */
a.ed_help {
<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>
<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>
<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}
<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}