Gallery: Use App storage instead of contructing our own path

This commit is contained in:
Bart Visscher 2012-05-09 22:47:57 +02:00
parent c2230580c1
commit 9a66b869c0
6 changed files with 20 additions and 21 deletions

View File

@ -42,7 +42,8 @@ function handleRemove($name) {
function handleGetThumbnails($albumname) {
OCP\Response::enableCaching(3600 * 24); // 24 hour
$thumbnail = OC::$CONFIG_DATADIRECTORY.'/../gallery/'.urldecode($albumname).'.png';
$view = OCP\App::getStorage('gallery');
$thumbnail = $view->fopen(urldecode($albumname).'.png', 'r');
header('Content-Type: '.OC_Image::getMimeTypeForFile($thumbnail));
OCP\Response::sendFile($thumbnail);
}

View File

@ -80,7 +80,8 @@ function handleGetThumbnail($token, $imgpath) {
function handleGetAlbumThumbnail($token, $albumname)
{
$owner = OC_Gallery_Sharing::getTokenOwner($token);
$file = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/'.$albumname.'.png';
$view = OCP\App::getStorage('gallery');
$file = $view->fopen($albumname.'.png', 'r');
$image = new OC_Image($file);
if ($image->valid()) {
$image->centerCrop();
@ -93,7 +94,8 @@ function handleGetAlbumThumbnail($token, $albumname)
function handleGetPhoto($token, $photo) {
$owner = OC_Gallery_Sharing::getTokenOwner($token);
$file = OCP\Config::getSystemValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$owner.'/files'.urldecode($photo);
$view = OCP\App::getStorage('files');
$file = $view->fopen(urldecode($photo), 'r');
header('Content-Type: '.OC_Image::getMimeTypeForFile($file));
OCP\Response::sendFile($file);
}

View File

@ -27,10 +27,6 @@ OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('gallery');
OCP\App::setActiveNavigationEntry( 'gallery_index' );
if (!file_exists(OCP\Config::getSystemValue("datadirectory").'/'. OCP\USER::getUser() .'/gallery')) {
mkdir(OCP\Config::getSystemValue("datadirectory").'/'. OCP\USER::getUser() .'/gallery');
}
if (!isset($_GET['view'])) {
$result = OC_Gallery_Album::find(OCP\USER::getUser());

View File

@ -92,9 +92,8 @@ class OC_Gallery_Album {
}
public static function changeThumbnailPath($oldname, $newname) {
$thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/';
rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
$view = OCP\App::getStorage('gallery');
$view->rename($oldname.'.png', $newname.'.png');
}
public static function getAlbumSize($id){

View File

@ -68,17 +68,17 @@ class OC_Gallery_Photo {
public static function getThumbnail($image_name, $owner = null) {
if (!$owner) $owner = OCP\USER::getUser();
$save_dir = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/';
$save_dir .= dirname($image_name). '/';
$image_path = $image_name;
$thumb_file = $save_dir . basename($image_name);
if (!is_dir($save_dir)) {
mkdir($save_dir, 0777, true);
$view = OCP\App::getStorage('gallery');
$save_dir = dirname($image_name);
if (!$view->is_dir($save_dir)) {
$view->mkdir($save_dir);
}
if (file_exists($thumb_file)) {
$image = new OC_Image($thumb_file);
$view->chroot($view->getRoot().'/'.$save_dir);
$thumb_file = basename($image_name);
if ($view->file_exists($thumb_file)) {
$image = new OC_Image($view->fopen($thumb_file, 'r'));
} else {
$image_path = OC_Filesystem::getLocalFile($image_path);
$image_path = OC_Filesystem::getLocalFile($image_name);
if(!file_exists($image_path)) {
return null;
}
@ -86,7 +86,7 @@ class OC_Gallery_Photo {
if ($image->valid()) {
$image->centerCrop(200);
$image->fixOrientation();
$image->save($thumb_file);
$image->save($view->getLocalFile($thumb_file));
}
}
if ($image->valid()) {

View File

@ -81,7 +81,8 @@ class OC_Gallery_Scanner {
$image->destroy();
}
}
imagepng($thumbnail, OCP\Config::getSystemValue("datadirectory").'/'. OCP\USER::getUser() .'/gallery/' . $albumName.'.png');
$view = OCP\App::getStorage('gallery');
imagepng($thumbnail, $view->getLocalFile($albumName.'.png'));
imagedestroy($thumbnail);
}