您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

qrcode.inc 2.7KB

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