2012-09-18 17:09:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-04-29 12:41:53 +02:00
|
|
|
* EGroupware addressbook: vCard export plugin for importexport framework
|
2012-09-18 17:09:48 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* @copyright 2012 Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-29 12:41:53 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2012-09-18 17:09:48 +02:00
|
|
|
/**
|
|
|
|
* export addressbook contacts as vcard
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
class addressbook_export_vcard implements importexport_iface_export_plugin
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function export( $_stream, importexport_definition $_definition)
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
|
2012-10-09 20:01:00 +02:00
|
|
|
$options = $_definition->plugin_options;
|
2012-10-16 20:45:13 +02:00
|
|
|
$this->uicontacts = new addressbook_ui();
|
|
|
|
$this->selection = array();
|
2012-09-18 17:09:48 +02:00
|
|
|
|
|
|
|
// Addressbook defines its own export imits
|
2016-04-29 12:41:53 +02:00
|
|
|
$limit_exception = Api\Storage\Merge::is_export_limit_excepted();
|
|
|
|
$export_limit = Api\Storage\Merge::getExportLimit($app='addressbook');
|
2018-11-29 18:32:42 +01:00
|
|
|
if($export_limit == 'no' && !$limit_exception)
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to switch the app to get the same results
|
|
|
|
$old_app = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
|
|
|
|
|
2018-11-29 18:32:42 +01:00
|
|
|
if ($options['selection'] == 'search')
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
// uicontacts selection with checkbox 'use_all'
|
2016-04-29 12:41:53 +02:00
|
|
|
$query = Api\Cache::getSession('addressbook', 'index');
|
2012-09-18 17:09:48 +02:00
|
|
|
$query['num_rows'] = -1; // all
|
|
|
|
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
|
|
|
if(!array_key_exists('filter',$query)) $query['filter'] = $GLOBALS['egw_info']['user']['account_id'];
|
2016-04-29 12:41:53 +02:00
|
|
|
$readonlys = null;
|
2012-10-16 20:45:13 +02:00
|
|
|
$this->uicontacts->get_rows($query,$this->selection,$readonlys, true); // only return the ids
|
2012-09-18 17:09:48 +02:00
|
|
|
}
|
2018-11-29 18:32:42 +01:00
|
|
|
elseif ( $options['selection'] == 'all' )
|
|
|
|
{
|
|
|
|
if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '1')
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
$col_filter['account_id'] = null;
|
|
|
|
}
|
2012-10-16 20:45:13 +02:00
|
|
|
$this->selection = ExecMethod2('addressbook.addressbook_bo.search', array(), true, '', '','',false,'AND',false,$col_filter);
|
|
|
|
//$this->uicontacts->get_rows($query,$this->selection,$readonlys,true);
|
2018-11-29 18:32:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-16 20:45:13 +02:00
|
|
|
$this->selection = explode(',',$options['selection']);
|
2012-09-18 17:09:48 +02:00
|
|
|
}
|
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = $old_app;
|
|
|
|
|
2018-11-29 18:32:42 +01:00
|
|
|
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
|
|
|
|
{
|
2012-10-16 20:45:13 +02:00
|
|
|
$this->selection = array_slice($this->selection, 0, $export_limit);
|
2012-09-18 17:09:48 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 18:32:42 +01:00
|
|
|
foreach ($this->selection as &$_contact)
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
if(is_array($_contact) && ($_contact['id'] || $_contact['contact_id']))
|
|
|
|
{
|
|
|
|
$_contact = $_contact[$_contact['id'] ? 'id' : 'contact_id'];
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 12:41:53 +02:00
|
|
|
|
2017-04-25 23:41:16 +02:00
|
|
|
// vCard opens & closes the file itself, so we can't just pass in the stream
|
|
|
|
$fp = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'egw');
|
2012-09-18 17:09:48 +02:00
|
|
|
|
2012-11-15 18:11:31 +01:00
|
|
|
$vcard = new addressbook_vcal('addressbook','text/vcard');
|
2017-04-25 23:41:16 +02:00
|
|
|
$vcard->export($this->selection, $fp);
|
|
|
|
|
|
|
|
fwrite($_stream, file_get_contents($fp));
|
2012-09-18 17:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_name()
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
return lang('Addressbook vCard export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_description()
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
return lang("Exports contacts from your Addressbook into a vCard File.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retruns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_filesuffix()
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
return 'vcf';
|
|
|
|
}
|
|
|
|
|
2018-11-29 18:32:42 +01:00
|
|
|
public static function get_mimetype()
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
return 'text/x-vcard';
|
|
|
|
}
|
|
|
|
|
2012-10-16 20:45:13 +02:00
|
|
|
/**
|
|
|
|
* Suggest a file name for the downloaded file
|
|
|
|
* No suffix
|
|
|
|
*/
|
|
|
|
public function get_filename()
|
|
|
|
{
|
|
|
|
if(is_array($this->selection) && count($this->selection) == 1)
|
|
|
|
{
|
|
|
|
return $this->uicontacts->link_title($this->selection[0]);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:09:48 +02:00
|
|
|
/**
|
2018-11-29 18:32:42 +01:00
|
|
|
* Return array of settings for export dialog
|
2012-09-18 17:09:48 +02:00
|
|
|
*
|
2018-11-29 18:32:42 +01:00
|
|
|
* @param $definition Specific definition
|
|
|
|
*
|
|
|
|
* @return array (
|
|
|
|
* name => string,
|
|
|
|
* content => array,
|
|
|
|
* sel_options => array,
|
|
|
|
* readonlys => array,
|
|
|
|
* preserv => array,
|
|
|
|
* )
|
2012-09-18 17:09:48 +02:00
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function get_options_etpl(importexport_definition &$definition = NULL)
|
|
|
|
{
|
|
|
|
return false;
|
2012-09-18 17:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns slectors of this plugin via xajax
|
|
|
|
*
|
|
|
|
*/
|
2018-11-29 18:32:42 +01:00
|
|
|
public function get_selectors_etpl()
|
|
|
|
{
|
2012-09-18 17:09:48 +02:00
|
|
|
return array(
|
2014-05-13 23:10:07 +02:00
|
|
|
'name' => 'addressbook.export_vcard_selectors',
|
|
|
|
'content' => 'all',
|
2012-09-18 17:09:48 +02:00
|
|
|
);
|
|
|
|
}
|
2016-05-04 21:34:30 +02:00
|
|
|
/**
|
|
|
|
* Get the class name for the egw_record to use while exporting
|
|
|
|
*
|
|
|
|
* @return string;
|
|
|
|
*/
|
|
|
|
public static function get_egw_record_class()
|
|
|
|
{
|
|
|
|
return 'addressbook_egw_record';
|
|
|
|
}
|
2012-09-18 17:09:48 +02:00
|
|
|
}
|