small fixes in merge request 104, use OCP\Files::getStorage

This commit is contained in:
Jörn Friedrich Dreyer 2012-07-11 02:32:17 +02:00
parent 0b14b4e3e8
commit ca8028bd73
4 changed files with 80 additions and 77 deletions

View File

@ -20,8 +20,6 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
OCP\JSON::checkLoggedIn(); OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('gallery'); OCP\JSON::checkAppEnabled('gallery');

View File

@ -71,9 +71,9 @@ class ThumbnailsManager {
} }
public function getThumbnail($path) { public function getThumbnail($path) {
$gallery_path = \OCP\Config::getSystemValue( 'datadirectory' ).'/'.\OC_User::getUser().'/gallery'; $gallery_storage = \OCP\Files::getStorage('gallery');
if (file_exists($gallery_path.$path)) { if ($gallery_storage->file_exists($path)) {
return new \OC_Image($gallery_path.$path); return new \OC_Image($gallery_storage->getLocalFile($path));
} }
if (!\OC_Filesystem::file_exists($path)) { if (!\OC_Filesystem::file_exists($path)) {
\OC_Log::write(self::TAG, 'File '.$path.' don\'t exists', \OC_Log::WARN); \OC_Log::write(self::TAG, 'File '.$path.' don\'t exists', \OC_Log::WARN);
@ -92,8 +92,9 @@ class ThumbnailsManager {
unset($image); unset($image);
return false; return false;
} }
$l = $gallery_storage->getLocalFile($path);
$image->save($gallery_path.'/'.$path); $image->save($l);
return $image; return $image;
} }
@ -122,9 +123,9 @@ class ThumbnailsManager {
} }
public function delete($path) { public function delete($path) {
$thumbnail = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/gallery".$path; $thumbnail_storage = \OCP\Files::getStorage('gallery');
if (file_exists($thumbnail)) { if ($thumbnail_storage->file_exists($path)) {
unlink($thumbnail); $thumbnail_storage->unlink($path);
} }
} }

View File

@ -20,12 +20,13 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
class OC_Gallery_Photo { class OC_Gallery_Photo {
public static function create($albumId, $img) { public static function create($albumId, $img) {
$stmt = OCP\DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)'); $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
$stmt->execute(array($albumId, $img)); $stmt->execute(array($albumId, $img));
} }
public static function find($albumId, $img = null) { public static function find($albumId, $img = null) {
$sql = 'SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?'; $sql = 'SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?';
$args = array($albumId); $args = array($albumId);
@ -36,6 +37,7 @@ class OC_Gallery_Photo {
$stmt = OCP\DB::prepare($sql); $stmt = OCP\DB::prepare($sql);
return $stmt->execute($args); return $stmt->execute($args);
} }
public static function findForAlbum($owner, $album_name) { public static function findForAlbum($owner, $album_name) {
$stmt = OCP\DB::prepare('SELECT *' $stmt = OCP\DB::prepare('SELECT *'
.' FROM *PREFIX*gallery_photos photos,' .' FROM *PREFIX*gallery_photos photos,'
@ -67,7 +69,8 @@ class OC_Gallery_Photo {
} }
public static function getThumbnail($image_name, $owner = null) { public static function getThumbnail($image_name, $owner = null) {
if (!$owner) $owner = OCP\USER::getUser(); if (!$owner)
$owner = OCP\USER::getUser();
$view = OCP\Files::getStorage('gallery'); $view = OCP\Files::getStorage('gallery');
$save_dir = dirname($image_name); $save_dir = dirname($image_name);
if (!$view->is_dir($save_dir)) { if (!$view->is_dir($save_dir)) {
@ -99,7 +102,7 @@ class OC_Gallery_Photo {
public static function getViewImage($image_name, $owner = null) { public static function getViewImage($image_name, $owner = null) {
if (!$owner) $owner = OCP\USER::getUser(); if (!$owner) $owner = OCP\USER::getUser();
$save_dir = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/'; $save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery';
$save_dir .= dirname($image_name) . '/view/'; $save_dir .= dirname($image_name) . '/view/';
$image_path = $image_name; $image_path = $image_name;
$view_file = $save_dir . basename($image_name); $view_file = $save_dir . basename($image_name);
@ -131,4 +134,5 @@ class OC_Gallery_Photo {
public static function getGalleryRoot() { public static function getGalleryRoot() {
return OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', ''); return OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '');
} }
} }

View File

@ -95,7 +95,7 @@ class TileSingle extends TileBase {
public function get($extra = '') { public function get($extra = '') {
// !HACK! file path needs to be encoded twice because files app decode twice url, so any special chars like + or & in filename // !HACK! file path needs to be encoded twice because files app decode twice url, so any special chars like + or & in filename
// !HACK! will result in failing of opening them // !HACK! will result in failing of opening them
return '<a rel="images" title="'.htmlentities(basename($this->getPath())).'" href="'.\OCP\Util::linkTo('files', 'download.php').'?file='.urlencode(urlencode($this->getPath())).'"><img rel="images" src="'.\OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath()).'" '.$extra.'></a>'; return '<a rel="images" title="'.htmlentities(basename($this->getPath())).'" href="'.\OCP\Util::linkTo('gallery','ajax/viewImage.php').'?img='.urlencode(urlencode($this->getPath())).'"><img rel="images" src="'.\OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath()).'" '.$extra.'></a>';
} }
public function getMiniatureSrc() { public function getMiniatureSrc() {