6.0.0-alpha14
7/3/25

[#5971] Add support for contact photos with ability to sync
Summary Add support for contact photos with ability to sync
Queue Turba
Queue Version HEAD
Type Enhancement
State Resolved
Priority 1. Low
Owners jan (at) horde (dot) org
Requester xk3 (at) mompl (dot) org
Created 12/06/2007 (6419 days ago)
Due
Updated 09/29/2008 (6121 days ago)
Assigned 08/11/2008 (6170 days ago)
Resolved 08/12/2008 (6169 days ago)
Milestone
Patch No

History
09/29/2008 04:14:55 AM Gunnar Wrobel Comment #8 Reply to this comment

[Show Quoted Text - 107 lines]
Please open a new ticket rather than responding on a closed one.
09/27/2008 07:34:35 PM xk3 (at) mompl (dot) org Comment #7 Reply to this comment
Hi, just upgraded to current turba 2.3

and run into some problems with PHOTO



1) storing contact without a photo in LDAP



The attribute array always contains an array for the photo item. If

there is no photo set, this array is empty, but is not catched by the

function _emptyAttributeFilter in turba/lib/Driver/ldap.php. This

results in an error in _add to LDAP. Stripping empty arrays too solves

at least this problem.



     function _emptyAttributeFilter($var)

     {

         if (!is_array($var)) {

             return ($var != '');

         } else {

             if (count($var) == 0) { return false; }    <<===

             foreach ($var as $v) {

        ...



Storing in turba DB doesn't show this bug, but photos are stored as 0B

blobs instead of NULL blobs.







2) base64 is terminated by a blank line, so eliminate it before

    matching the following vCalender attributes. Otherwise the name of

    one following PHOTO will start with a \r\n, so it will be

    discarded afterward



    in /lib/Horde/iCalendar.php



         // Unfold any folded lines.

-       $vCal = preg_replace('/[\r\n]+[ \t]/', '', $vCal);

+       $vCal = preg_replace('/[\r\n]+[ \t]+/', '', $vCal);

+       $vCal = preg_replace('/\r\n\r\n/', "\r\n", $vCal);



    (First line only beautifies the base64 code by stripping all

    whitespace. The second line does the necessary work by deleting all

    blank lines.)



    and add the blank line in /turba/lib/Driver.php again before

    sending to mobile:



             case 'photo':

             case 'logo':

                 $params = array('ENCODING' => 'base64');

                 if (isset($hash[$key . 'type'])) {

                     $params['TYPE'] = $hash[$key . 'type'];

                 }

                 $vcard->setAttribute(String::upper($key),

-                                    base64_encode($val),

+                                    base64_encode($val) . "\r\n",

                                      $params);

                 break;







3) Browsing the address book with photo as a visible column results in a

    warning per entry containing a photo:



    Warning: htmlspecialchars() expects parameter 1 to be string, array

    given in 
/var/www/org.afaik.duff_ssl/mail-new/turba/templates/browse/row.inc

    on line 90



        if ($ob->hasValue($this->columns[$c - 1])) {

         $value = $ob->getValue($this->columns[$c - 1]);

-        $shown_columns[$c] = htmlspecialchars($value)

+        $shown_columns[$c] = is_array($value) ? $value : 
htmlspecialchars($value);

         if ($type == 'email') {



    No thinking on my side, just getting rid of this warning, so check

    again.







4) In toHash and tovCard, the encoding of a photo is tested against

    and set to 'b'. Is that a valid encoding name at all? Changed

    it to 'base64' and it worked again. In turba/lib/Driver.php



             case 'photo':

             case 'logo':

-               $params = array('ENCODING' => 'b');

+               $params = array('ENCODING' => 'base64');





                 if (!isset($item['params']['ENCODING']) ||

-                   String::lower($item['params']['ENCODING']) != 'b') {

+                   String::lower($item['params']['ENCODING']) != 'base64') {

                     // Invalid property.

                     break;





5) Finally, how am I supposed to delete a photo from a contact or save

    it to a local file (e.g. for doing some cropping stuff in an external

    tool)? There are no delete and save buttons as for a common file.





Having this patched, I can add (ldap), change, view and sync photos



      Martin



PS: any thoughts on adding crop support? Photos taken by mobiles have 
a stupid format for contact photos. Otherwise, I could live with as 
save as local file button.
08/12/2008 03:19:37 PM Jan Schneider Comment #6
State ⇒ Resolved
Reply to this comment
This has been implemented for Turba 2.2.2.
08/12/2008 03:19:14 PM Jan Schneider Deleted Original Message
 
08/11/2008 04:36:31 PM Jan Schneider State ⇒ Assigned
Assigned to Jan Schneider
 
08/11/2008 04:36:21 PM Jan Schneider Deleted Original Message
 
06/07/2008 08:29:38 PM xk3 (at) mompl (dot) org Comment #5 Reply to this comment
If you do a chop and explicitly add a CR LF for terminating the base64 string

in the first chunk of Driver.php in patch.photo.turba-h3-2.2.diff, i.e.



                 $vcard->setAttribute('PHOTO;ENCODING=BASE64', "\r\n" .

                                       
chop(chunk_split(preg_replace('/(\r\n|\r|\n| )/','',$val,-1),

                                                       64,"\r\n")) .

                                      "\r\n");





you can drop the read-only parameter from the photo attribute. As long 
as you put a base64 photo (only tested jpeg) in the longtext form 
field, it syncs fine to the E51 :o)



    Martin


06/07/2008 07:29:41 PM xk3 (at) mompl (dot) org Comment #4
New Attachment: patch.photo.turba-h3-2.2.diff
Reply to this comment
This is a quick and dirty hack to add a photo element to turba that
hmpf, my patch actually didn´t do the trick. Thus, a new one for 
syncing photos from Nokia E51 to turba (h3-2.2)



It´s still a hack, as I circumvent the encoding stuff in iCalendar.php 
and do it myself, but it should be a good guide for someone 
implementing it the proper way.



The photo is stored as base64 in the turba contact at the moment. 
Thus, I set the photo attribute to read-only. However, it would be 
really really cool, if someone could tell me, how to use an image form 
field for a contact. Should be similar to files, but they are treated 
different from the rest of the attributes :-/



   Martin
12/09/2007 01:17:45 PM xk3 (at) mompl (dot) org Comment #3
New Attachment: photo.diff
Reply to this comment
This is a quick and dirty hack to add a photo element to turba that 
can be synced. This is NOT a patch for common use but for my special 
case with a lot of assumptions made, e.g.:



a) turba is just a storage place (attribute is readonly)

b) photo is base64 (seems to be reasonable)

c) only one external client is syncing,

     so no format checking or anything like that



Using this hack allows for adding photos to contacts (on MY nokia) 
that survive a bi-directional sync.
12/06/2007 04:21:53 PM Chuck Hagenbuch Taken from Horde DevelopersHorde Developers
 
12/06/2007 04:15:25 PM Michael Rubinsky Comment #2
Priority ⇒ 1. Low
State ⇒ Accepted
Summary ⇒ Add support for contact photos with ability to sync
Assigned to Horde DevelopersHorde Developers
Reply to this comment
This is already planned, but we do not have a time frame.
12/06/2007 04:06:20 PM xk3 (at) mompl (dot) org Comment #1
Priority ⇒ 2. Medium
State ⇒ New
Queue ⇒ Turba
Summary ⇒ photo support
Type ⇒ Enhancement
Reply to this comment
Just started to play with horde/sync and my E51 syncs really fine with 
turba, but I miss the little photos you can attach to your contacts on 
your mobile. Is it possible to add photo support to turba (and its 
sync, of course)?



A vCard would contain something like:



PHOTO;TYPE=JPEG;ENCODING=BASE64:

     /9j/4AAQSkZJRgABAQ ...


Saved Queries