Possibility to display QR code for contacts data (#5030)

pull/5560/head
Aleksander Machniak 8 years ago
parent 29d0b80449
commit 2482088a76

@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- Possibility to display QR code for contacts data (#5030)
- Added identicon plugin
- Widescreen layout aka three column view (#5093)
- Unify automatic marking as \Seen in preview pane, full-page and extwin views (#5071)

@ -24,6 +24,7 @@ REQUIREMENTS
- Auth_SASL 1.0.6 or newer
- Net_Sieve 1.3.2 or newer (for managesieve plugin)
- Crypt_GPG 1.6.0 or newer (for enigma plugin)
- Endroid/QrCode 1.6.0 or newer (https://github.com/endroid/QrCode)
* php.ini options (see .htaccess file):
- error_reporting E_ALL & ~E_NOTICE & ~E_STRICT
- memory_limit > 16MB (increase as suitable to support large attachments)

@ -30,7 +30,8 @@
"pear-pear.php.net/mail_mime": "~1.10.0",
"pear-pear.php.net/net_smtp": "~1.7.1",
"pear-pear.php.net/crypt_gpg": "~1.6.0@beta",
"roundcube/net_sieve": "~1.5.0"
"roundcube/net_sieve": "~1.5.0",
"endroid/qrcode": "~1.6.5"
},
"require-dev": {
"phpunit/phpunit": "*"

@ -474,7 +474,7 @@ function rcube_webmail()
this.set_page_buttons();
if (this.env.cid) {
this.enable_command('show', 'edit', true);
this.enable_command('show', 'edit', 'qrcode', true);
// register handlers for group assignment via checkboxes
if (this.gui_objects.editform) {
$('input.groupmember').change(function() {
@ -6632,6 +6632,24 @@ function rcube_webmail()
this.http_request('search', {_sid: id}, lock);
};
// display a dialog with QR code image
this.qrcode = function()
{
var title = this.get_label('qrcode'),
buttons = [{
text: this.get_label('close'),
'class': 'mainaction',
click: function() {
(ref.is_framed() ? parent.$ : $)(this).dialog('destroy');
}
}],
img = new Image(300, 300);
img.src = this.url('addressbook/qrcode', {_source: this.env.source, _cid: this.env.cid});
return this.show_popup_dialog(img, title, buttons, {width: 310, height: 410});
};
/*********************************************************/
/********* user settings methods *********/

@ -369,6 +369,7 @@ $labels['advsearch'] = 'Advanced Search';
$labels['advanced'] = 'Advanced';
$labels['other'] = 'Other';
$labels['printcontact'] = 'Print contact';
$labels['qrcode'] = 'QR Code';
$labels['typehome'] = 'Home';
$labels['typework'] = 'Work';

@ -0,0 +1,75 @@
<?php
/**
+-----------------------------------------------------------------------+
| program/steps/addressbook/qrcode.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2016, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Show contact data as QR code |
| |
+-----------------------------------------------------------------------+
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
// Get contact ID and source ID from request
$cids = rcmail_get_cids();
$source = key($cids);
$cid = $cids ? array_shift($cids[$source]) : null;
// read contact record
$abook = rcmail_contact_source($source, true);
$contact = $abook->get_record($cid, true);
// generate QR code image
if ($data = rcmail_contact_qrcode($contact)) {
header('Content-Type: image/png');
header('Content-Length: ' . strlen($data));
echo $data;
}
else {
header('HTTP/1.0 404 Contact not found');
}
exit;
function rcmail_contact_qrcode($contact)
{
$vcard = new rcube_vcard();
// QR code input is limited, use only common fields
$fields = array('firstname', 'surname', 'middlename', 'nickname', 'organization',
'prefix', 'suffix', 'phone', 'email', 'jobtitle');
foreach ($contact as $field => $value) {
list($field, $section) = explode(':', $field, 2);
if (in_array($field, $fields)) {
foreach ((array) $value as $v) {
$vcard->set($field, $v, $section);
}
}
}
$data = $vcard->export();
$qrCode = new Endroid\QrCode\QrCode();
$qrCode
->setText($data)
->setSize(300)
->setPadding(0)
->setErrorCorrection('high')
// ->setLabel('Scan the code')
// ->setLabelFontSize(16)
->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0));
return $qrCode->get('png');
}

@ -42,6 +42,7 @@ if ($cid && ($record = ($CONTACT_RECORD ?: $CONTACTS->get_record($cid, true))))
// get address book name (for display)
rcmail_set_sourcename($CONTACTS);
$OUTPUT->add_label('qrcode');
$OUTPUT->add_handlers(array(
'contacthead' => 'rcmail_contact_head',
'contactdetails' => 'rcmail_contact_details',

@ -21,6 +21,7 @@
</div>
<p>
<roundcube:button command="edit" type="input" class="button" label="editcontact" condition="!ENV:readonly" />
<roundcube:button command="qrcode" type="input" class="button" label="qrcode" />
</p>
</div>
<script type="text/javascript">rcube_init_tabs('contacttabs')</script>

@ -25,6 +25,7 @@
<div id="headerbuttons" class="formbuttons">
<roundcube:button command="edit" type="input" class="button mainaction" label="editcontact" condition="!ENV:readonly" />
<roundcube:button command="qrcode" type="input" class="button" label="qrcode" />
</div>
<roundcube:include file="/includes/footer.html" />

Loading…
Cancel
Save