vCard import/export improvements

This commit is contained in:
Nathan Gray 2012-11-16 16:56:40 +00:00
commit e1d06c0e59
9 changed files with 120 additions and 13 deletions

View File

@ -73,7 +73,7 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
// vCard opens & closes the resource itself, but this doesn't seem to matter
$meta = stream_get_meta_data($_stream);
$vcard = new addressbook_vcal();
$vcard = new addressbook_vcal('addressbook','text/vcard');
$vcard->export($selection, $meta['uri']);
}

View File

@ -157,10 +157,10 @@ class addressbook_hooks
$settings['vcard_charset'] = array(
'type' => 'select',
'label' => 'Charset for the vCard export',
'label' => 'Charset for the vCard import and export',
'name' => 'vcard_charset',
'values' => translation::get_installed_charsets(),
'help' => 'Which charset should be used for the vCard export.',
'help' => 'Which charset should be used for the vCard import and export.',
'xmlrpc' => True,
'admin' => false,
'default'=> 'iso-8859-1',

View File

@ -111,6 +111,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
$this->bocontacts = new addressbook_vcal();
$charset = $_definition->plugin_options['charset'];
if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
// Start counting successes
$this->current = 0;
@ -155,7 +156,9 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
*/
public function _vcard($_vcard, $owner)
{
$record = $this->bocontacts->vcardtoegw($_vcard,$this->definition->plugin_options['charset']);
$charset = $_definition->plugin_options['charset'];
if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
$record = $this->bocontacts->vcardtoegw($_vcard,$charset);
$record['owner'] = $owner;

View File

@ -1021,7 +1021,8 @@ class addressbook_vcal extends addressbook_bo
{
if (!$file)
{
html::content_header('addressbook.vcf','text/x-vcard');
$filename = count($ids) == 1 ? egw_link::title('addressbook',$ids[0]): 'egw_addressbook_'.date('Y-m-d');
html::content_header(($filename ? $filename : 'addressbook').'.vcf','text/x-vcard');
}
if (!($fp = fopen($file ? $file : 'php://output','w')))
{

View File

@ -0,0 +1,80 @@
<?php
/**
* Wizard for exporting vCard with import/export
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package addressbook
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
*/
/**
* We need to allow choosing of charset, so we'll just use the standard one from CSV
*/
class addressbook_wizard_export_vcard
{
public function __construct()
{
$this->steps = array(
'wizard_step40' => ''
);
$this->step_templates = array(
'wizard_step40' => 'addressbook.importexport_wizard_vcard_charset'
);
}
/**
* choose charset
*
* @param array $content
* @param array $sel_options
* @param array $readonlys
* @param array $preserv
* @return string template name
*/
function wizard_step40(&$content, &$sel_options, &$readonlys, &$preserv)
{
if($this->debug) error_log(get_class($this) . '::wizard_step40->$content '.print_r($content,true));
// return from step40
if ($content['step'] == 'wizard_step40') {
switch (array_search('pressed', $content['button']))
{
case 'next':
return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],1);
case 'previous' :
return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],-1);
case 'finish':
return 'wizard_finish';
default :
return $this->wizard_step40($content,$sel_options,$readonlys,$preserv);
}
}
// init step40
else
{
$content['msg'] = $this->steps['wizard_step40'];
$content['step'] = 'wizard_step40';
if(!$content['charset'] && $content['plugin_options']['charset']) {
$content['charset'] = $content['plugin_options']['charset'] ? $content['plugin_options']['charset'] : 'user';
}
$sel_options['charset'] = $GLOBALS['egw']->translation->get_installed_charsets()+
array(
'user' => lang('User preference'),
);
$preserv = $content;
// Add in extra allowed charsets
$config = config::read('importexport');
$extra_charsets = array_intersect(explode(',',$config['import_charsets']), mb_list_encodings());
if($extra_charsets)
{
$sel_options['charset'] += array(lang('Extra encodings') => array_combine($extra_charsets,$extra_charsets));
}
unset ($preserv['button']);
return $this->step_templates[$content['step']];
}
}
}

View File

@ -15,9 +15,10 @@
<entry type="string" name="0">Default</entry>
</entry>
<entry type="array" name="plugin_options">
<entry type="string" name="charset">user</entry>
<entry type="string" name="contact_owner">personal</entry>
</entry>
<entry type="string" name="modified">2012-10-23 09:46:56</entry>
<entry type="string" name="modified">2012-11-14 09:10:11</entry>
</entry>
<entry type="array" name="export-addressbook-vcard">
<entry type="string" name="name">export-addressbook-vcard</entry>
@ -27,7 +28,9 @@
<entry type="array" name="allowed_users">
<entry type="string" name="0">Default</entry>
</entry>
<entry type="string" name="plugin_options"/>
<entry type="string" name="plugin_options">
<entry type="string" name="charset">user</entry>
</entry>
<entry type="string" name="modified">2012-10-23 09:46:56</entry>
</entry>
<entry type="array" name="import-addressbook-csv">

View File

@ -542,7 +542,9 @@ class importexport_definitions_ui
if(!key_exists($content['step'],$this->steps))
$next_step = $this->plugin->$content['step']($content);
else
{
$next_step = $this->$content['step']($content);
}
} else {
die('Cannot find next step');
}
@ -728,9 +730,9 @@ class importexport_definitions_ui
{
case 'next':
// There's no real reason the plugin has to come from any of these, as long as it has a $steps variable
if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv) {
if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) {
$content['type'] = 'import';
} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv) {
} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) {
$content['type'] = 'export';
} else {
throw new egw_exception('Invalid plugin');

View File

@ -275,7 +275,17 @@ class importexport_export_ui {
if (! $charset = $definition->plugin_options['charset']) {
$charset = $GLOBALS['egw']->translation->charset();
}
if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
if($charset == 'user')
{
switch($definition->plugin)
{
case 'addressbook_export_vcard':
$charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
break;
default:
$charset = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
}
}
$plugin_object = new $definition->plugin;
$plugin_object->export( $file, $definition );

View File

@ -61,8 +61,16 @@
// Check file encoding matches import
$sample = file_get_contents($content['file']['tmp_name'],false, null, 0, 1024);
$required = $options['charset'] == 'user' || !$options['charset'] ? $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'] : $options['charset'];
$encoding = mb_detect_encoding($sample,$required,true);
if($appname == 'addressbook' && $definition_obj->plugin == 'addressbook_import_vcard')
{
$preference = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
}
else
{
$preference = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
}
$required = $options['charset'] == 'user' || !$options['charset'] ? $preference : $options['charset'];
$encoding = translation::detect_encoding($sample);
if($encoding && strtoupper($required) != strtoupper($encoding))
{
$this->message = lang("Encoding mismatch. Expected %1 file, you uploaded %2.<br />\n",
@ -71,7 +79,7 @@
);
}
$file = fopen($content['file']['tmp_name'], 'r');
$file = fopen($content['file']['tmp_name'], 'rb');
$count = 0;
// Some of the translation, conversion, etc look here