vcard_attachments: add link to contact actions menu

*) add 'forward vcard' link to contact actions manu
*) fix bug when a contact with a secondary email address is selected
*) improve support for multiple address books in contact list widget on compose screen
pull/6127/head
PhilW 6 years ago
parent abbb832c6f
commit d5071fedba

@ -19,4 +19,5 @@ $labels['addvcardmsg'] = 'Add vCard to addressbook';
$labels['vcardsavefailed'] = 'Unable to save vCard';
$labels['attachvcard'] = 'Attach vCard';
$labels['vcard'] = 'vCard';
$labels['forwardvcard'] = 'Forward vCard';
?>

@ -22,5 +22,6 @@ $labels['vcardsavefailed'] = 'Unable to save vCard';
$labels['attachvcard'] = 'Attach vCard';
$labels['vcardattached'] = 'vCard file attached.';
$labels['vcard'] = 'vCard';
$labels['forwardvcard'] = 'Forward vCard';
?>

@ -39,3 +39,8 @@ p.vcardattachment button {
.messagelist tr .attachment span.attachment.vcard {
background: url(vcard.png) 0 center no-repeat;
}
#contactmenu li a.vcard {
background: url(../../../../skins/classic/images/messageicons.png) no-repeat 7px 0;
background-position: 6px -168px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

@ -33,3 +33,8 @@ a.listbutton.vcard .inner
.messagelist tbody tr .attachment span.attachment.vcard {
background: url(vcard.png) 0 center no-repeat;
}
ul.toolbarmenu li span.vcard {
background: url(listicons.png) no-repeat 7px 0;
background-position: 0 -3px;
}

@ -9,7 +9,7 @@
*/
class vcard_attachments extends rcube_plugin
{
public $task = 'mail';
public $task = 'mail|addressbook';
private $message;
private $vcard_parts = array();
@ -19,37 +19,57 @@ class vcard_attachments extends rcube_plugin
{
$rcmail = rcmail::get_instance();
if ($rcmail->action == 'show' || $rcmail->action == 'preview') {
$this->add_hook('message_load', array($this, 'message_load'));
$this->add_hook('message_objects', array($this, 'message_objects'));
$this->add_hook('template_object_messagebody', array($this, 'html_output'));
}
else if ($rcmail->action == 'upload') {
$this->add_hook('attachment_from_uri', array($this, 'attach_vcard'));
}
else if ($rcmail->action == 'compose' && !$rcmail->output->framed) {
if ($rcmail->task == 'addressbook') {
$skin_path = $this->local_skin_path();
$btn_class = strpos($skin_path, 'classic') ? 'button' : 'listbutton';
$this->add_texts('localization', true);
$this->include_stylesheet($skin_path . '/style.css');
$this->include_script('vcardattach.js');
$this->add_button(
array(
'type' => 'link',
'label' => 'vcard_attachments.vcard',
'type' => 'link-menuitem',
'label' => 'vcard_attachments.forwardvcard',
'command' => 'attach-vcard',
'class' => $btn_class . ' vcard disabled',
'classact' => $btn_class . ' vcard',
'title' => 'vcard_attachments.attachvcard',
'innerclass' => 'inner',
'class' => 'icon vcard',
'classact' => 'icon vcard active',
'innerclass' => 'icon vcard',
),
'compose-contacts-toolbar');
'contactmenu');
}
else if (!$rcmail->output->framed && (!$rcmail->action || $rcmail->action == 'list')) {
$skin_path = $this->local_skin_path();
$this->include_stylesheet($skin_path . '/style.css');
$this->include_script('vcardattach.js');
else {
if ($rcmail->action == 'show' || $rcmail->action == 'preview') {
$this->add_hook('message_load', array($this, 'message_load'));
$this->add_hook('message_objects', array($this, 'message_objects'));
$this->add_hook('template_object_messagebody', array($this, 'html_output'));
}
else if ($rcmail->action == 'upload') {
$this->add_hook('attachment_from_uri', array($this, 'attach_vcard'));
}
else if ($rcmail->action == 'compose' && !$rcmail->output->framed) {
$skin_path = $this->local_skin_path();
$btn_class = strpos($skin_path, 'classic') ? 'button' : 'listbutton';
$this->add_texts('localization', true);
$this->include_stylesheet($skin_path . '/style.css');
$this->include_script('vcardattach.js');
$this->add_button(
array(
'type' => 'link',
'label' => 'vcard_attachments.vcard',
'command' => 'attach-vcard',
'class' => $btn_class . ' vcard disabled',
'classact' => $btn_class . ' vcard',
'title' => 'vcard_attachments.attachvcard',
'innerclass' => 'inner',
),
'compose-contacts-toolbar');
$this->add_hook('message_compose', array($this, 'message_compose'));
}
else if (!$rcmail->output->framed && (!$rcmail->action || $rcmail->action == 'list')) {
$skin_path = $this->local_skin_path();
$this->include_stylesheet($skin_path . '/style.css');
$this->include_script('vcardattach.js');
}
}
$this->register_action('plugin.savevcard', array($this, 'save_vcard'));
@ -129,6 +149,20 @@ class vcard_attachments extends rcube_plugin
return $p;
}
/**
* This callback function adds a vCard to the message when attached from the Address book
*/
function message_compose($p)
{
if (rcube_utils::get_input_value('_attach_vcard', rcube_utils::INPUT_GET) == '1' && ($uri = rcube_utils::get_input_value('_uri', rcube_utils::INPUT_GET))) {
if ($attachment = $this->attach_vcard(array('compose_id' => $p['compose_id'], 'uri' => $uri))) {
$p['attachments'][] = $attachment;
};
}
return $p;
}
/**
* This callback function removes message part's content
* for parts that are vcards
@ -268,7 +302,7 @@ class vcard_attachments extends rcube_plugin
public function attach_vcard($args)
{
if (preg_match('|^vcard://(.+)$|', $args['uri'], $m)) {
list($cid, $source) = explode('-', $m[1]);
list($source, $cid, $email) = explode('-', $m[1]);
$vcard = $this->get_contact_vcard($source, $cid, $filename);
$params = array(

@ -32,15 +32,21 @@ function plugin_vcard_insertrow(data)
function plugin_vcard_attach()
{
var id, n, contacts = [],
var source, id, n, contacts = [],
ts = new Date().getTime(),
args = {_uploadid: ts, _id: rcmail.env.compose_id},
args = {_uploadid: ts, _id: rcmail.env.compose_id || null},
selection = rcmail.contact_list.get_selection();
for (n=0; n < selection.length; n++) {
id = selection[n];
if (id && id.charAt(0) != 'E' && rcmail.env.contactdata[id])
contacts.push(id);
if (rcmail.env.task == 'addressbook') {
id = selection[n];
contacts.push(rcmail.env.source + '-' + id + '-0');
}
else {
id = selection[n];
if (id && id.charAt(0) != 'E' && rcmail.env.contactdata[id])
contacts.push(id);
}
}
if (!contacts.length)
@ -48,19 +54,27 @@ function plugin_vcard_attach()
args._uri = 'vcard://' + contacts.join(',');
// add to attachments list
if (!rcmail.add2attachment_list(ts, {name: '', html: rcmail.get_label('attaching'), classname: 'uploading', complete: false}))
rcmail.file_upload_id = rcmail.set_busy(true, 'attaching');
if (rcmail.env.task == 'addressbook') {
args._attach_vcard = 1;
rcmail.open_compose_step(args);
}
else {
// add to attachments list
if (!rcmail.add2attachment_list(ts, {name: '', html: rcmail.get_label('attaching'), classname: 'uploading', complete: false}))
rcmail.file_upload_id = rcmail.set_busy(true, 'attaching');
rcmail.http_post('upload', args);
rcmail.http_post('upload', args);
}
}
window.rcmail && rcmail.addEventListener('init', function(evt) {
if (rcmail.gui_objects.messagelist)
rcmail.addEventListener('insertrow', function(data, evt) { plugin_vcard_insertrow(data); });
if (rcmail.env.action == 'compose' && rcmail.gui_objects.contactslist) {
rcmail.env.compose_commands.push('attach-vcard');
if ((rcmail.env.action == 'compose' || (rcmail.env.task == 'addressbook' && rcmail.env.action == '')) && rcmail.gui_objects.contactslist) {
if (rcmail.env.action == 'compose')
rcmail.env.compose_commands.push('attach-vcard');
rcmail.register_command('attach-vcard', function() { plugin_vcard_attach(); });
rcmail.contact_list.addEventListener('select', function(list) {
// TODO: support attaching more than one at once

@ -104,7 +104,8 @@ else if (!empty($result) && $result->count > 0) {
// add record for every email address of the contact
$emails = $CONTACTS->get_col_values('email', $row, true);
foreach ($emails as $i => $email) {
$row_id = $row['ID'].'-'.$i;
$source = $row['sourceid'] ?: $source;
$row_id = $source.'-'.$row['ID'].'-'.$i;
$jsresult[$row_id] = format_email_recipient($email, $name);
$classname = $row['_type'] == 'group' ? 'group' : 'person';
$keyname = $row['_type'] == 'group' ? 'contactgroup' : 'contact';

@ -84,7 +84,7 @@ if (!empty($result) && $result->count > 0) {
// (same as in list_contacts.inc)
$emails = $source->get_col_values('email', $row, true);
foreach ($emails as $i => $email) {
$row_id = $row['ID'].'-'.$i;
$row_id = $row['sourceid'].'-'.$row['ID'].'-'.$i;
$jsresult[$row_id] = format_email_recipient($email, $name);
$title = rcube_addressbook::compose_search_name($row, $email, $name);

Loading…
Cancel
Save