comparison program/steps/addressbook/qrcode.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/qrcode.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2016, The Roundcube Dev Team |
9 | |
10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. |
13 | |
14 | PURPOSE: |
15 | Show contact data as QR code |
16 | |
17 +-----------------------------------------------------------------------+
18 | Author: Aleksander Machniak <alec@alec.pl> |
19 +-----------------------------------------------------------------------+
20 */
21
22 // Get contact ID and source ID from request
23 $cids = rcmail_get_cids();
24 $source = key($cids);
25 $cid = $cids ? array_shift($cids[$source]) : null;
26
27 // read contact record
28 $abook = rcmail_contact_source($source, true);
29 $contact = $abook->get_record($cid, true);
30
31 // generate QR code image
32 if ($data = rcmail_contact_qrcode($contact)) {
33 header('Content-Type: image/png');
34 header('Content-Length: ' . strlen($data));
35 echo $data;
36 }
37 else {
38 header('HTTP/1.0 404 Contact not found');
39 }
40
41 exit;
42
43
44 function rcmail_contact_qrcode($contact)
45 {
46 $vcard = new rcube_vcard();
47
48 // QR code input is limited, use only common fields
49 $fields = array('firstname', 'surname', 'middlename', 'nickname', 'organization',
50 'prefix', 'suffix', 'phone', 'email', 'jobtitle');
51
52 foreach ($contact as $field => $value) {
53 list($field, $section) = explode(':', $field, 2);
54 if (in_array($field, $fields)) {
55 foreach ((array) $value as $v) {
56 $vcard->set($field, $v, $section);
57 }
58 }
59 }
60
61 $data = $vcard->export();
62
63 $qrCode = new Endroid\QrCode\QrCode();
64 $qrCode
65 ->setText($data)
66 ->setSize(300)
67 ->setPadding(0)
68 ->setErrorCorrection('high')
69 // ->setLabel('Scan the code')
70 // ->setLabelFontSize(16)
71 ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
72 ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0));
73
74 return $qrCode->get('png');
75 }