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