? image_pub_205535-4.patch
? image_pub_menu.patch
Index: image_pub.common.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_pub/image_pub.common.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 image_pub.common.inc
--- image_pub.common.inc	31 Jan 2009 02:00:25 -0000	1.1.2.1
+++ image_pub.common.inc	8 Feb 2009 23:19:32 -0000
@@ -163,12 +163,9 @@ function _image_pub_image_add($album, $c
   }
 
   if (empty($caption)) {
-    $caption = $_POST['force_filename'];
+    $caption = basename($_FILES[$srcfield]['name']);
     if (empty($caption)) {
-      $caption = basename($_FILES[$srcfield]['name']);
-      if (empty($caption)) {
-        $caption = 'Untitled image';
-      }
+      $caption = 'Untitled image';
     }
   }
 
Index: image_pub.gr.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_pub/image_pub.gr.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 image_pub.gr.inc
--- image_pub.gr.inc	31 Jan 2009 02:00:25 -0000	1.1.2.1
+++ image_pub.gr.inc	8 Feb 2009 23:19:33 -0000
@@ -25,14 +25,39 @@ define('GR_STAT_CREATE_ALBUM_FAILED', 50
 
 define('GR_SERVER_VERSION', '2.15');
 
+/*
+ * This module implements version 2 of the Gallery remote application
+ * protocol. However, the protocol comes in two slightly different
+ * flavours: that implemented in Gallery 1 (G1) and that implemented
+ * in Gallery 2 (G2). The differences are evident from whether most of
+ * the data is wrapped in a g2_form array element. 
+ */
+
+function _image_pub_gr_gallery_version() {
+  return (isset($_GET['g2_form']) || isset($_POST['g2_form'])) ? 2 : 1;
+}
+
 function _image_pub_gr_get_albumname($term) {
-  return 'Album' . $term->tid;
+  if (_image_pub_gr_gallery_version() == 1) {
+    return 'Album' . $term->tid; 
+  } 
+  else {
+    return $term->tid; 
+  }
 }
+
 function _image_pub_gr_get_albumid($albname) {
-  if (!strncmp($albname, 'Album', 5)) {
-    return substr($albname, 5);
+  if (_image_pub_gr_gallery_version() == 1) {
+    if (!strncmp($albname, 'Album', 5)) {
+      return substr($albname, 5);
+    } 
+    else {
+      return 0;
+    }
+  }
+  else {
+    return $albname;
   }
-  return 0;
 }
 
 
@@ -49,50 +74,66 @@ function _image_pub_gr_get_albumid($albn
  */
 
 function _image_pub_gr_request() {
-  if (isset($_POST['cmd'])) {
-    $cmd = $_POST['cmd'];
+  if (_image_pub_gr_gallery_version() == 2) {
+    $g2_form = array();
+    if (isset($_POST['g2_form'])) {
+      $g2_form = array_merge($g2_form, $_POST['g2_form']);
+    }
+    if (isset($_GET['g2_form'])) {
+      $g2_form = array_merge($g2_form, $_GET['g2_form']);
+    }
   }
   else {
-    $cmd = $_GET['cmd'];
+    $g2_form = array_merge($_POST, $_GET);
   }
-
   $numref = FALSE;
-
+  
   // watchdog('image_pub', 'Processing command %cmd', array('%cmd' => $cmd));
  
-  switch ($cmd) {
-    case 'login':
-      _image_pub_gr_login($_POST['uname'], $_POST['password']);
+  switch ($g2_form['cmd']) {
+  case 'login':
+      _image_pub_gr_login($g2_form['uname'], $g2_form['password']);
       break;
 
     case 'fetch-albums':
       $numref = TRUE;
     case 'fetch-albums-prune':
-      $check_writeable = ($_POST['check-writeable'] == 'yes') ? TRUE : FALSE;
+      $check_writeable = ($g2_form['check-writeable'] == 'yes') ? TRUE : FALSE;
       _image_pub_gr_fetch_albums($numref, $check_writeable);
       break;
 
     case 'fetch-album-images':
-      $albums_too = ($_POST['albums_too'] == 'yes') ? TRUE : FALSE;
-      _image_pub_gr_fetch_album_images($_POST['set_albumName'],
+      $albums_too = ($g2_form['albums_too'] == 'yes') ? TRUE : FALSE;
+      _image_pub_gr_fetch_album_images($g2_form['set_albumName'],
                                        $albums_too);
       break;
 
     case 'new-album':
-      _image_pub_gr_add_album($_POST['set_albumName'],
-                              $_POST['newAlbumTitle'],
-                              $_POST['newAlbumDesc']);
+      _image_pub_gr_add_album($g2_form['set_albumName'],
+                              $g2_form['newAlbumTitle'],
+                              $g2_form['newAlbumDesc']);
       break;
 
     case 'move-album':
-      _image_pub_gr_move_album($_POST['set_albumName'],
-                               $_POST['set_destalbumName']);
+      _image_pub_gr_move_album($g2_form['set_albumName'],
+                               $g2_form['set_destalbumName']);
       break;
 
     case 'add-item':
-      _image_pub_gr_add_image($_POST['set_albumName'],
-	      $_POST['caption'],
-	      $_POST['extrafield_Description']);
+      if (!empty($g2_form['caption'])) {
+        $caption = $g2_form['caption'];
+      }
+      else {
+        $caption = $g2_form['force_filename'];
+      }
+      _image_pub_gr_add_image($g2_form['set_albumName'],
+                              $caption,
+                              $g2_form['extrafield_Description'],
+                              (_image_pub_gr_gallery_version() == 2) ? 'g2_userfile' : 'userfile');
+      break;
+
+    case 'no-op':
+      _image_pub_gr_finish(GR_STAT_SUCCESS, '', 'No-op successful');
       break;
 
     case '':
@@ -100,7 +141,7 @@ function _image_pub_gr_request() {
       exit;
 
     default:
-      _image_pub_gr_finish(GR_STAT_UNKNOWN_CMD, '', t('Unknown command "%cmd"', array('%cmd' => theme('placeholder', $cmd))));
+      _image_pub_gr_finish(GR_STAT_UNKNOWN_CMD, '', t('Unknown command "%cmd"', array('%cmd' => theme('placeholder', $g2_form['cmd']))));
       break;
   }
 }
@@ -344,7 +385,7 @@ function _image_pub_gr_move_album($albna
 }
 
 
-function _image_pub_gr_add_image($albname, $caption, $description) {
+function _image_pub_gr_add_image($albname, $caption, $description, $userfile) {
   $body = '';
   $album = _image_pub_album_get(_image_pub_gr_get_albumid($albname));
   if (!isset($album)) {
@@ -354,7 +395,7 @@ function _image_pub_gr_add_image($albnam
     _image_pub_gr_finish(GR_STAT_NO_ADD_PERMISSION);
   }
 
-  $result = _image_pub_image_add($album, $caption, $description, 'userfile');
+  $result = _image_pub_image_add($album, $caption, $description, $userfile);
 
   if (!$result['success']) {
     _image_pub_gr_finish(GR_STAT_UPLOAD_PHOTO_FAIL, $body, t('The file was received, but could not be processed or added to the album.') . ' ' . $result['reason']);
Index: image_pub.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_pub/image_pub.module,v
retrieving revision 1.16.2.1
diff -u -p -r1.16.2.1 image_pub.module
--- image_pub.module	31 Jan 2009 02:00:25 -0000	1.16.2.1
+++ image_pub.module	8 Feb 2009 23:19:33 -0000
@@ -12,7 +12,7 @@
 /**
  * Implementation of hook_help().
  */
-function image_pub_help($path = 'admin/help#image_pub', $arg=null) {
+function image_pub_help($path = 'admin/help#image_pub', $arg = null) {
   switch ($path) {
     case 'admin/help#image_pub':
       return '<p>'. t('The Image Publishing module supports third party image upload and management applications.') .'</p>';
@@ -29,6 +29,11 @@ function image_pub_menu() {
     'access callback' => TRUE,
     'file' => 'image_pub.gr.inc',
     'type' => MENU_CALLBACK);
+  $items['main.php'] = array(
+    'page callback' => '_image_pub_gr_request',
+    'access callback' => TRUE,
+    'file' => 'image_pub.gr.inc',
+    'type' => MENU_CALLBACK);
   $items['publish_xp'] = array(
     'page callback' => '_image_pub_xp_request',
     'access callback' => TRUE,
