Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Identicon
  4. *
  5. * Plugin to display a unique github-like identification icons
  6. * for contacts/addresses that do not have a photo image.
  7. *
  8. * @todo: Make it optional and configurable via user preferences
  9. * @todo: Make color palettes match the curren skin
  10. * @todo: Implement optional SVG generator
  11. *
  12. * @license GNU GPLv3+
  13. * @author Aleksander Machniak <alec@alec.pl>
  14. * @website http://roundcube.net
  15. */
  16. class identicon extends rcube_plugin
  17. {
  18. public $task = 'addressbook';
  19. /**
  20. * Plugin initilization.
  21. */
  22. function init()
  23. {
  24. $this->add_hook('contact_photo', array($this, 'contact_photo'));
  25. }
  26. /**
  27. * 'contact_photo' hook handler to inject an identicon image
  28. */
  29. function contact_photo($args)
  30. {
  31. // pre-conditions, exit if photo already exists or invalid input
  32. if (!empty($args['url']) || !empty($args['data'])
  33. || (empty($args['record']) && empty($args['email']))
  34. ) {
  35. return $args;
  36. }
  37. $rcmail = rcmail::get_instance();
  38. // supporting edit/add action may be tricky, let's not do this
  39. if ($rcmail->action == 'show' || $rcmail->action == 'photo') {
  40. $email = $args['email'];
  41. if (!$email && $args['record']) {
  42. $addresses = rcube_addressbook::get_col_values('email', $args['record'], true);
  43. if (!empty($addresses)) {
  44. $email = $addresses[0];
  45. }
  46. }
  47. if ($email) {
  48. require_once __DIR__ . '/identicon_engine.php';
  49. $identicon = new identicon_engine($email);
  50. if ($rcmail->action == 'show') {
  51. // set photo URL using data-uri
  52. if (($icon = $identicon->getBinary()) && ($icon = base64_encode($icon))) {
  53. $mimetype =$identicon->getMimetype();
  54. $args['url'] = sprintf('data:%s;base64,%s', $mimetype, $icon);
  55. }
  56. }
  57. else {
  58. // send the icon to the browser
  59. $identicon = new identicon_engine($email);
  60. if ($identicon->sendOutput()) {
  61. exit;
  62. }
  63. }
  64. }
  65. }
  66. return $args;
  67. }
  68. }