Gallery 2 Eye-Fi patch

Problem: Eye-Fi card uploads to Gallery 2 create top-level albums for every day an image is uploaded. This causes over-cluttering fast.
Solution: Patch Gallery so each ‘daily’ album gets created as sub-album of one top level album

The patch

This patch provides better support for Eye-Fi within Gallery by forcing all newly created albums to be created as sub-albums of a specific top level album, instead of each daily album being created on top level. This is achieved by creating an alternate guest user using the MultiRoot module within gallery, as well as a small patch to the Gallery 2 API in the fetch-albums-prune call so that it returns the data in a format that the Eye-Fi application is looking for. A further explanation of the reason for the API change is found at the bottom of this page after the patch for those who want to see why exactly the patch is necessary. The patch is as follows:

Note: This explanation assumes that the cleanURL module is enabled, and that the rule for admin has *not* been enabled (however, it is still possible to get this working even with the admin rule enabled, or with cleanURL disabled)

  1. Log in to your gallery as administrator
  2. Create the top level album that wish for all your Eye-Fi albums and images to be stored in. This album will be referred to as “EyeFi Album” for the rest of this document
  3. Return to the top level of the gallery
  4. Edit Permissions for the top level gallery
  5. Remove all permissions for the “Everybody” group, being sure to leave the “Apply Changes” box checked to have it filter to all sub-items
  6. Create a user permission for the user “guest”. Choose “[core] View all Versions”. Optionally, give “guest” user permission for commenting as well
  7. Go to the Site Administrator section
  8. Browse to the Plugins section
  9. In the Display group of plugins, install the module MultiRoot
  10. Click on Configure next to MultiRoot
  11. Pick the URL that Eye-Fi will connect to. In our example this is /gallery2/eyefi.php
  12. Select the album you created in step 2 (“EyeFi Album”) in the drop down
  13. Create a name for the for the guest user view (we chose “eyefi_guest” for ours)
  14. Click on “Generate Files”
  15. On your server, create a new file (/gallery2/eyefi.php) and paste the text displayed into it. Save this file
  16. Open your .htaccess file (/gallery2/.htaccess) and paste the rules shown into the bottom of the file. Leave any rules that already exist in the file there.
  17. Go back to the Site Admin
  18. Click Users
  19. Click Create User
  20. Create a user for the Eye-Fi uploader to use (our user will be called “eyefi”). Fill out the email and password for this user as well. Hit create once all required fields have been filled in
  21. Return to the top level of your gallery
  22. Browse to the “EyeFi Album” and Edit Permissions
  23. Stop to look at the URL of this page (this step assumes cleanURL is disabled for the admin rule). Look for the following parameter “&g2_itemId=ANUMBER”. Make a note of the number that is in the place of ANUMBER. We will need that number shortly.
  24. Create a new user permission for the user “eyefi”, with “All Permissions” (alternatively, creating 2 new permissions of “[core] Add sub-item” and “[core] Add sub-album” would likely work, but has not been tested)
  25. At this point, all that remains is applying the patch to the API
  26. Open the following file: /gallery2/modules/remote/GalleryRemote.inc
  27. Search for the following line of text – “Now add all the albums to the tree”
  28. Below that comment, replace the following block of code –

    /* Now add all the albums to the tree */
    $i = 1;
    foreach ($albums as $album) {
    /* Use id because path component is not unique */
    $response->setProperty('album.name.' . $i, $album->getId());
    $response->setProperty('album.title.' . $i, $album->getTitle());
    $response->setProperty('album.summary.' . $i, $album->getSummary());
    $response->setProperty('album.parent.' . $i, $album->getParentId());
    if ($fetchPermissions) {
    $perms = $permissionsTable[$album->getId()];
    $response->setProperty('album.perms.add.' . $i,
    isset($perms['core.addDataItem']) ? 'true' : 'false');
    $response->setProperty('album.perms.write.' . $i,
    isset($perms['core.edit']) ? 'true' : 'false');
    $response->setProperty('album.perms.del_alb.' . $i,
    isset($perms['core.delete']) ? 'true' : 'false');
    $response->setProperty('album.perms.create_sub.' . $i,
    isset($perms['core.addAlbumItem']) ? 'true' : 'false');
    }
    $response->setProperty('album.info.extrafields.' . $i, "Summary,Description");
    $i++;
    }

    with the following code

    /* Now add all the albums to the tree */
    $i = 1;
    $virtual_root_id = 9847;
    $virtual_user_name = "eyefi";
    $eyefi_upload = false;
    global $gallery;
    $user = $gallery->getActiveUser();
    if (isset($user) && ($user->getUserName() == $virtual_user_name)) {
    $eyefi_upload = true;
    }
    foreach ($albums as $album) {
    if ($eyefi_upload && $album->getID() == 0) {
    } else {
    /* Use id because path component is not unique */
    $response->setProperty('album.name.' . $i, $album->getId());
    $response->setProperty('album.title.' . $i, $album->getTitle());
    $response->setProperty('album.summary.' . $i, $album->getSummary());
    if ($eyefi_upload && $album->getID() == $virtual_root_id) {
    $response->setProperty('album.parent.' . $i, 0);
    } else {
    $response->setProperty('album.parent.' . $i, $album->getParentId());
    }
    if ($fetchPermissions) {
    $perms = $permissionsTable[$album->getId()];
    $response->setProperty('album.perms.add.' . $i,
    isset($perms['core.addDataItem']) ? 'true' : 'false');
    $response->setProperty('album.perms.write.' . $i,
    isset($perms['core.edit']) ? 'true' : 'false');
    $response->setProperty('album.perms.del_alb.' . $i,
    isset($perms['core.delete']) ? 'true' : 'false');
    $response->setProperty('album.perms.create_sub.' . $i,
    isset($perms['core.addAlbumItem']) ? 'true' : 'false');
    }
    $response->setProperty('album.info.extrafields.' . $i, "Summary,Description");
    }
    $i++;
    }
  29. Two changes should be made to the code snipped above. Replace the value in both $virtual_user_name with the 2nd user you created (ours was “eyefi”) and replace $virtual_root_id with the value of $g2_itemId (ANUMBER) that we found in step 23.
  30. At this point everything is ready on the Gallery side of things and we simply need to point Eye-Fi in the right direction
  31. Open the Eye-Fi manager and log in
  32. Click on Settings
  33. Change your “Upload to Web” configuration
  34. Click to Share Photos online and then to Add a Photo Service
  35. Scroll down and click on Gallery 2
  36. Enter the user name we created (eyefi) and whatever password you chose
  37. Enter the URL (http://yourdomain.com/gallery2/eyefi.php)
  38. Click connect card. If no errors appear, everything is working!
  39. Click Home
  40. Take a picture with your camera (I assume you have already linked your Eye-Fi card to your access point by this point)
  41. Watch the Eye-Fi Manager – shortly you will see the image begin to upload
  42. Once it says “Uploaded SIZE MB photo less than a minute ago” you know it successfully uploaded. If you see an error message, some piece of this was not working
  43. Assuming it worked correctly, return to your gallery. Browse to Eye-Fi Album, and within it you should see the album for today’s pictures (“Taken on June 12th, 2008”)
  44. Go take more pictures!

The Eye-fi API problem

The following section is simply a description of how Eye-Fi is interacting with the Gallery Remote API and why this doesn’t produce the expected behavior by default. If you simply wanted to get your gallery working, you’re done! No need to read this section.

Step 1 EyeFi authenticates


Query: ?g2_controller=remote:GalleryRemote
POST variables
cmd=login
protocol_version=2.0
uname=eyefi
password=THEPASSWORD

Step 2 Gallery replies with authentication token


POST VARIABLES
server_version=2.11
status=0
status_text=Login successful.
auth_token,4f79f4714e7d

Step 3 Eye-Fi requests a list of the user’s albums


Query: ?g2_controller=remote:GalleryRemote&g2_authToken=4f79f4714e7d
POST variables
cmd=fetch-albums-prune
protocol_version=2.0

Step 4 Gallery (unpatched) returns a similar response to the following


POST variables
album.name.1=9847
album.title.1=EyeFi Album
album.summary.1=Pictures uploaded by EyeFi
album.parent.1=7
album.perms.add.1=true
album.perms.write.1=true
album.perms.del_alb.1=true
album.perms.create_sub.1=true
album.info.extrafields.1=Summary,Description
album.name.4=7
album.title.4=Gallery
album.summary.4=
album.parent.4=0
album.perms.add.4=false
album.perms.write.4=false
album.perms.del_alb.4=false
album.perms.create_sub.4=false
album.info.extrafields.4=Summary,Description
can_create_root=false
album_count=2
status=0
status_text=Fetch-albums successful.
auth_token=4f79f4714e7d

The problem with this reply is that the EyeFi Album (our alternate guest root) is shown with a parent ID of 7 (the true root album’s ID). With the alternate guest view configured by the MultiRoot module, one might expect the EyeFi Album to have a parent of 0 (meaning it is the root album). Related to this issue, the true root album also shows up in the list of albums, even though the eyefi user has no permissions to view the album (and in Step 5 of our patch we removed permissions for the group “Registered Users”). EyeFi sees this album with parent of 0, and tries to create the new album in it. However, we have no permissions in this album so EyeFi gives us an error. The correct/expected behavior would be for the “Gallery” album to not show up in the list, and have the EyeFi Album be shown with a parent of 0, as it is the root of our view. This is achieved with the code changed in the patch above.

Step 4B Gallery (patched) return


POST variables
album.name.1=9847
album.title.1=EyeFi Album
album.summary.1=Pictures uploaded by EyeFi
album.parent.1=0
album.perms.add.1=true
album.perms.write.1=true
album.perms.del_alb.1=true
album.perms.create_sub.1=true
album.info.extrafields.1=Summary,Description
can_create_root=false
album_count=1
status=0
status_text=Fetch-albums successful.
auth_token=4f79f4714e7d

4 thoughts on “Gallery 2 Eye-Fi patch”

  1. How does one do this?:

    Create a user permission for the user “guest”. Choose “[core] View all Versions”. Optionally, give “guest” user permission for commenting as well

    Reply
  2. Chris, can I ask you a question here…

    It seems that when I set up the Eye-fi manager to tell the card to use the Admin account name and password, it works fine. But whenever I tell it to use any of my created user accounts, it gives me the error “Unable to log in…”

    I have assigned the user account(s) to the group “site admins”, but this does not help.

    I cannot figure out how to get Eye-fi to log into any account remotely for upload except for the Admin account.

    Here is some more info…

    when I try to set the user login info in the Eye-Fi manager window, I get this error:

    UNABLE TO EDIT PROFILE
    Unable to login to service. Please check
    username and password.

    in Gallery2>Admin Options>users:

    With every login attempt I try to set up in Eye-Fi Manager, I get another “Failed Login” next to the admin account in the user settings, but I am not logging in with the admin user/pw.

    Obviously, something is wrong here…

    Reply

Leave a Comment