| 1 |
<?php |
<?php |
| 2 |
// $Id: image_pub.gr.inc,v 1.16 2008/12/02 22:46:58 egfrith Exp $ |
// $Id: image_pub.gr.inc,v 1.1.2.1 2009/01/31 02:00:25 egfrith Exp $ |
| 3 |
|
|
| 4 |
require_once 'image_pub.common.inc'; |
require_once 'image_pub.common.inc'; |
| 5 |
|
|
| 25 |
|
|
| 26 |
define('GR_SERVER_VERSION', '2.15'); |
define('GR_SERVER_VERSION', '2.15'); |
| 27 |
|
|
| 28 |
|
/* |
| 29 |
|
* This module implements version 2 of the Gallery remote application |
| 30 |
|
* protocol. However, the protocol comes in two slightly different |
| 31 |
|
* flavours: that implemented in Gallery 1 (G1) and that implemented |
| 32 |
|
* in Gallery 2 (G2). The differences are evident from whether most of |
| 33 |
|
* the data is wrapped in a g2_form array element. |
| 34 |
|
*/ |
| 35 |
|
|
| 36 |
|
function _image_pub_gr_gallery_version() { |
| 37 |
|
return (isset($_GET['g2_form']) || isset($_POST['g2_form'])) ? 2 : 1; |
| 38 |
|
} |
| 39 |
|
|
| 40 |
function _image_pub_gr_get_albumname($term) { |
function _image_pub_gr_get_albumname($term) { |
| 41 |
return 'Album' . $term->tid; |
if (_image_pub_gr_gallery_version() == 1) { |
| 42 |
|
return 'Album' . $term->tid; |
| 43 |
|
} |
| 44 |
|
else { |
| 45 |
|
return $term->tid; |
| 46 |
|
} |
| 47 |
} |
} |
| 48 |
|
|
| 49 |
function _image_pub_gr_get_albumid($albname) { |
function _image_pub_gr_get_albumid($albname) { |
| 50 |
if (!strncmp($albname, 'Album', 5)) { |
if (_image_pub_gr_gallery_version() == 1) { |
| 51 |
return substr($albname, 5); |
if (!strncmp($albname, 'Album', 5)) { |
| 52 |
|
return substr($albname, 5); |
| 53 |
|
} |
| 54 |
|
else { |
| 55 |
|
return 0; |
| 56 |
|
} |
| 57 |
|
} |
| 58 |
|
else { |
| 59 |
|
return $albname; |
| 60 |
} |
} |
|
return 0; |
|
| 61 |
} |
} |
| 62 |
|
|
| 63 |
|
|
| 74 |
*/ |
*/ |
| 75 |
|
|
| 76 |
function _image_pub_gr_request() { |
function _image_pub_gr_request() { |
| 77 |
if (isset($_POST['cmd'])) { |
if (_image_pub_gr_gallery_version() == 2) { |
| 78 |
$cmd = $_POST['cmd']; |
$g2_form = array(); |
| 79 |
|
if (isset($_POST['g2_form'])) { |
| 80 |
|
$g2_form = array_merge($g2_form, $_POST['g2_form']); |
| 81 |
|
} |
| 82 |
|
if (isset($_GET['g2_form'])) { |
| 83 |
|
$g2_form = array_merge($g2_form, $_GET['g2_form']); |
| 84 |
|
} |
| 85 |
} |
} |
| 86 |
else { |
else { |
| 87 |
$cmd = $_GET['cmd']; |
$g2_form = array_merge($_POST, $_GET); |
| 88 |
} |
} |
|
|
|
| 89 |
$numref = FALSE; |
$numref = FALSE; |
| 90 |
|
|
| 91 |
// watchdog('image_pub', 'Processing command %cmd', array('%cmd' => $cmd)); |
// watchdog('image_pub', 'Processing command %cmd', array('%cmd' => $cmd)); |
| 92 |
|
|
| 93 |
switch ($cmd) { |
switch ($g2_form['cmd']) { |
| 94 |
case 'login': |
case 'login': |
| 95 |
_image_pub_gr_login($_POST['uname'], $_POST['password']); |
_image_pub_gr_login($g2_form['uname'], $g2_form['password']); |
| 96 |
break; |
break; |
| 97 |
|
|
| 98 |
case 'fetch-albums': |
case 'fetch-albums': |
| 99 |
$numref = TRUE; |
$numref = TRUE; |
| 100 |
case 'fetch-albums-prune': |
case 'fetch-albums-prune': |
| 101 |
$check_writeable = ($_POST['check-writeable'] == 'yes') ? TRUE : FALSE; |
$check_writeable = ($g2_form['check-writeable'] == 'yes') ? TRUE : FALSE; |
| 102 |
_image_pub_gr_fetch_albums($numref, $check_writeable); |
_image_pub_gr_fetch_albums($numref, $check_writeable); |
| 103 |
break; |
break; |
| 104 |
|
|
| 105 |
case 'fetch-album-images': |
case 'fetch-album-images': |
| 106 |
$albums_too = ($_POST['albums_too'] == 'yes') ? TRUE : FALSE; |
$albums_too = ($g2_form['albums_too'] == 'yes') ? TRUE : FALSE; |
| 107 |
_image_pub_gr_fetch_album_images($_POST['set_albumName'], |
_image_pub_gr_fetch_album_images($g2_form['set_albumName'], |
| 108 |
$albums_too); |
$albums_too); |
| 109 |
break; |
break; |
| 110 |
|
|
| 111 |
case 'new-album': |
case 'new-album': |
| 112 |
_image_pub_gr_add_album($_POST['set_albumName'], |
_image_pub_gr_add_album($g2_form['set_albumName'], |
| 113 |
$_POST['newAlbumTitle'], |
$g2_form['newAlbumTitle'], |
| 114 |
$_POST['newAlbumDesc']); |
$g2_form['newAlbumDesc']); |
| 115 |
break; |
break; |
| 116 |
|
|
| 117 |
case 'move-album': |
case 'move-album': |
| 118 |
_image_pub_gr_move_album($_POST['set_albumName'], |
_image_pub_gr_move_album($g2_form['set_albumName'], |
| 119 |
$_POST['set_destalbumName']); |
$g2_form['set_destalbumName']); |
| 120 |
break; |
break; |
| 121 |
|
|
| 122 |
case 'add-item': |
case 'add-item': |
| 123 |
_image_pub_gr_add_image($_POST['set_albumName'], |
if (!empty($g2_form['caption'])) { |
| 124 |
$_POST['caption'], |
$caption = $g2_form['caption']; |
| 125 |
$_POST['extrafield_Description']); |
} |
| 126 |
|
else { |
| 127 |
|
$caption = $g2_form['force_filename']; |
| 128 |
|
} |
| 129 |
|
_image_pub_gr_add_image($g2_form['set_albumName'], |
| 130 |
|
$caption, |
| 131 |
|
$g2_form['extrafield_Description'], |
| 132 |
|
(_image_pub_gr_gallery_version() == 2) ? 'g2_userfile' : 'userfile'); |
| 133 |
|
break; |
| 134 |
|
|
| 135 |
|
case 'no-op': |
| 136 |
|
_image_pub_gr_finish(GR_STAT_SUCCESS, '', 'No-op successful'); |
| 137 |
break; |
break; |
| 138 |
|
|
| 139 |
case '': |
case '': |
| 141 |
exit; |
exit; |
| 142 |
|
|
| 143 |
default: |
default: |
| 144 |
_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'])))); |
| 145 |
break; |
break; |
| 146 |
} |
} |
| 147 |
} |
} |
| 385 |
} |
} |
| 386 |
|
|
| 387 |
|
|
| 388 |
function _image_pub_gr_add_image($albname, $caption, $description) { |
function _image_pub_gr_add_image($albname, $caption, $description, $userfile) { |
| 389 |
$body = ''; |
$body = ''; |
| 390 |
$album = _image_pub_album_get(_image_pub_gr_get_albumid($albname)); |
$album = _image_pub_album_get(_image_pub_gr_get_albumid($albname)); |
| 391 |
if (!isset($album)) { |
if (!isset($album)) { |
| 395 |
_image_pub_gr_finish(GR_STAT_NO_ADD_PERMISSION); |
_image_pub_gr_finish(GR_STAT_NO_ADD_PERMISSION); |
| 396 |
} |
} |
| 397 |
|
|
| 398 |
$result = _image_pub_image_add($album, $caption, $description, 'userfile'); |
$result = _image_pub_image_add($album, $caption, $description, $userfile); |
| 399 |
|
|
| 400 |
if (!$result['success']) { |
if (!$result['success']) { |
| 401 |
_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']); |
_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']); |