roundcubemail/plugins/identicon/identicon.php
function contact_photo($args)
    {
        // pre-conditions, exit if photo already exists or invalid input
        if (!empty($args['url']) || !empty($args['data'])
            || (empty($args['record']) && empty($args['email']))
        ) {
            return $args;
        }

        $rcmail = rcmail::get_instance();

        // supporting edit/add action may be tricky, let's not do this
        if ($rcmail->action == 'show' || $rcmail->action == 'photo') {
            $email = $args['email'];
            if (!$email && $args['record']) {
                $addresses = rcube_addressbook::get_col_values('email', $args['record'], true);
                if (!empty($addresses)) {
                    $email = $addresses[0];
                }
            }

            if ($email) {
                require_once __DIR__ . '/identicon_engine.php';

                $identicon = new identicon_engine($email);

                if ($rcmail->action == 'show') {
                    // set photo URL using data-uri
                    if (($icon = $identicon->getBinary()) && ($icon = base64_encode($icon))) {
                        $mimetype    =$identicon->getMimetype();
                        $args['url'] = sprintf('data:%s;base64,%s', $mimetype, $icon);
                    }
                }
                else {
                    // send the icon to the browser
                    $identicon = new identicon_engine($email);
                    if ($identicon->sendOutput()) {
                        exit;
                    }
                }
            }
        }

        return $args;
    }
function contact_photo($args)
    {
        // pre-conditions, exit if photo already exists or invalid input
        if (!empty($args['url']) || !empty($args['data'])
            || (empty($args['record']) && empty($args['email']))
        ) {
            return $args;
        }

        $rcmail = rcmail::get_instance();

        // supporting edit/add action may be tricky, let's not do this
        if ($rcmail->action == 'show' || $rcmail->action == 'photo') {
            $email = $args['email'];
            if (!$email && $args['record']) {
                $addresses = rcube_addressbook::get_col_values('email', $args['record'], true);
                if (!empty($addresses)) {
                    $email = $addresses[0];
                }
            }

            if ($email) {
                require_once __DIR__ . '/identicon_engine.php';

                $identicon = new identicon_engine($email);

                if ($rcmail->action == 'show') {
                    // set photo URL using data-uri
                    if (($icon = $identicon->getBinary()) && ($icon = base64_encode($icon))) {
                        $mimetype    =$identicon->getMimetype();
                        $args['url'] = sprintf('data:%s;base64,%s', $mimetype, $icon);
                    }
                }
                else {
                    // send the icon to the browser
                    $identicon = new identicon_engine($email);
                    if ($identicon->sendOutput()) {
                        exit;
                    }
                }
            }
        }

        return $args;
    }
function contact_photo ( $ args ) { // pre-conditions, exit if photo already exists or invalid input if ( ! empty ( $ args [ 'url' ] ) || ! empty ( $ args [ 'data' ] ) || ( empty ( $ args [ 'record' ] ) && empty ( $ args [ 'email' ] ) ) ) { return $ args ; } $ rcmail = rcmail :: get_instance ( ) ; // supporting edit/add action may be tricky, let's not do this if ( $ rcmail -> action == 'show' || $ rcmail -> action == 'photo' ) { $ email = $ args [ 'email' ] ; if ( ! $ email && $ args [ 'record' ] ) { $ addresses = rcube_addressbook :: get_col_values ( 'email' , $ args [ 'record' ] , true ) ; if ( ! empty ( $ addresses ) ) { $ email = $ addresses [ 0 ] ; } } if ( $ email ) { require_once __DIR__ . '/identicon_engine.php' ; $ identicon = new identicon_engine ( $ email ) ; if ( $ rcmail -> action == 'show' ) { // set photo URL using data-uri if ( ( $ icon = $ identicon -> getBinary ( ) ) && ( $ icon = base64_encode ( $ icon ) ) ) { $ mimetype = $ identicon -> getMimetype ( ) ; $ args [ 'url' ] = sprintf ( 'data:%s;base64,%s' , $ mimetype , $ icon ) ; } } else { // send the icon to the browser $ identicon = new identicon_engine ( $ email ) ; if ( $ identicon -> sendOutput ( ) ) { exit ; } } } } return $ args ; }
'contact_photo' hook handler to inject an identicon image
contact_photo hook handler to inject an identicon image