Skip to content

Commit

Permalink
[jan] Keep original file names when PUTing images via WebDAV.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 5, 2015
1 parent 60c058b commit 946f6a1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions ansel/docs/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
v3.0.2-git
----------

[jan] Keep original file names when PUTing images via WebDAV.
[jan] Fix closure compiler errors (Bug #13596).
[jan] Return ETags with browse() API method.
[mjr] Fix fatal divide by zero error due to incorrectly named variable.
Expand Down
31 changes: 26 additions & 5 deletions ansel/lib/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public function browse($path = '', array $properties = array())
}
return $results;
} else {
$dav = $injector->getInstance('Horde_Dav_Storage');
$object = end($parts);
try {
$object = $dav->getInternalObjectId($object, $parts[count($parts) - 2])
?: $object;
} catch (Horde_Dav_Exception $e) {
}
if (count($parts) == 1) {
// This request is for all galleries owned by the requested
// user.
Expand All @@ -86,7 +93,7 @@ public function browse($path = '', array $properties = array())

} elseif (count($parts) > 2 &&
$this->galleryExists($parts[count($parts) - 2]) &&
($image = $injector->getInstance('Ansel_Storage')->getImage(end($parts)))) {
($image = $injector->getInstance('Ansel_Storage')->getImage($object))) {

return array(
'data' => $image->raw(),
Expand Down Expand Up @@ -117,7 +124,12 @@ public function browse($path = '', array $properties = array())
}
}

$dav = $injector->getInstance('Horde_Dav_Storage');
foreach ($images as $imageId => $image) {
try {
$imageId = $dav->getExternalObjectId($imageId, $parts[count($parts) - 1]) ?: $imageId;
} catch (Horde_Dav_Exception $e) {
}
$retpath = 'ansel/' . implode('/', $parts) . '/' . $imageId;
if (in_array('name', $properties)) {
$results[$retpath]['name'] = $image['name'];
Expand Down Expand Up @@ -164,6 +176,8 @@ public function browse($path = '', array $properties = array())
*/
public function put($path, $content, $content_type)
{
global $injector, $registry;

if (substr($path, 0, 5) == 'ansel') {
$path = substr($path, 9);
}
Expand All @@ -175,19 +189,26 @@ public function put($path, $content, $content_type)
}
$image_name = array_pop($parts);
$gallery_id = end($parts);
if (!$GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($gallery_id)) {
$dav = $injector->getInstance('Horde_Dav_Storage');
$gallery_id = $dav->getInternalCollectionId($gallery_id, 'ansel')
?: $gallery_id;
$storage = $injector->getInstance('Ansel_Storage');
if (!$storage->galleryExists($gallery_id)) {
throw new Horde_Exception_NotFound("Gallery does not exist");
}
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
$gallery = $storage->getGallery($gallery_id);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
throw new Horde_Exception_PermissionDenied(_("Access denied adding photos to this gallery."));
}

return $gallery->addImage(array(
$id = $gallery->addImage(array(
'image_type' => $content_type,
'image_filename' => $image_name,
'image_caption' => '',
'data' => $content));
$dav->addObjectMap($id, $image_name, $gallery_id);

return $id;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ansel/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Keep original file names when PUTing images via WebDAV.
* [jan] Fix closure compiler errors (Bug #13596).
* [jan] Return ETags with browse() API method.
* [mjr] Fix fatal divide by zero error due to incorrectly named variable.
Expand Down Expand Up @@ -1348,6 +1349,7 @@
<date>2014-02-24</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Keep original file names when PUTing images via WebDAV.
* [jan] Fix closure compiler errors (Bug #13596).
* [jan] Return ETags with browse() API method.
* [mjr] Fix fatal divide by zero error due to incorrectly named variable.
Expand Down

0 comments on commit 946f6a1

Please sign in to comment.