Skip to content

Commit

Permalink
Possibility to display QR code for contacts data (#5030)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Dec 11, 2016
1 parent 29d0b80 commit 2482088
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion composer.json-dist
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
20 changes: 19 additions & 1 deletion program/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 *********/
Expand Down
1 change: 1 addition & 0 deletions program/localization/en_US/labels.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
75 changes: 75 additions & 0 deletions program/steps/addressbook/qrcode.inc
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> |
+-----------------------------------------------------------------------+
*/

// 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');
}
1 change: 1 addition & 0 deletions program/steps/addressbook/show.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions skins/classic/templates/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions skins/larry/templates/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h1 class="boxtitle"><roundcube:label name="contactproperties" /></h1>

<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" />
Expand Down

0 comments on commit 2482088

Please sign in to comment.