diff options
author | Bartek Przybylski <bart.p.pl@gmail.com> | 2011-12-21 18:35:29 +0100 |
---|---|---|
committer | Bartek Przybylski <bart.p.pl@gmail.com> | 2011-12-21 18:35:29 +0100 |
commit | 3c428671090e2bd3d46d76567a45c2a9e1639127 (patch) | |
tree | 785f2821086745b4bbef1bc01e4fb111c961dc83 /apps/gallery | |
parent | 865be6064a1f2f896ca3657fa6eef590748a4e39 (diff) | |
parent | e1b9b65e4159bdd6e0ed81c8cd6b588f03b3a018 (diff) | |
download | nextcloud-server-3c428671090e2bd3d46d76567a45c2a9e1639127.tar.gz nextcloud-server-3c428671090e2bd3d46d76567a45c2a9e1639127.zip |
merged
Diffstat (limited to 'apps/gallery')
-rw-r--r-- | apps/gallery/ajax/createAlbum.php | 3 | ||||
-rw-r--r-- | apps/gallery/ajax/getAlbums.php | 7 | ||||
-rw-r--r-- | apps/gallery/ajax/getCovers.php | 16 | ||||
-rw-r--r-- | apps/gallery/ajax/scanForAlbums.php | 6 | ||||
-rw-r--r-- | apps/gallery/ajax/thumbnail.php | 17 | ||||
-rw-r--r-- | apps/gallery/appinfo/app.php | 4 | ||||
-rw-r--r-- | apps/gallery/css/styles.css | 14 | ||||
-rw-r--r-- | apps/gallery/index.php | 7 | ||||
-rw-r--r-- | apps/gallery/js/albums.js | 2 | ||||
-rw-r--r-- | apps/gallery/lib/album.php | 18 | ||||
-rw-r--r-- | apps/gallery/lib/photo.php | 28 | ||||
-rw-r--r-- | apps/gallery/lib/scanner.php (renamed from apps/gallery/lib_scanner.php) | 24 | ||||
-rw-r--r-- | apps/gallery/templates/view_album.php | 10 |
13 files changed, 111 insertions, 45 deletions
diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php index 610f761b72a..9413b54718a 100644 --- a/apps/gallery/ajax/createAlbum.php +++ b/apps/gallery/ajax/createAlbum.php @@ -3,8 +3,7 @@ require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); -$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES ("'.OC_User::getUser().'", "'.$_GET['album_name'].'")'); -$stmt->execute(array()); +OC_Gallery_Album::create(OC_User::getUser(), $_GET['album_name']); OC_JSON::success(array('name' => $_GET['album_name'])); diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php index 98d92c5f31a..7454b18edab 100644 --- a/apps/gallery/ajax/getAlbums.php +++ b/apps/gallery/ajax/getAlbums.php @@ -4,13 +4,12 @@ OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); $a = array(); -$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner LIKE ?'); -$result = $stmt->execute(array(OC_User::getUser())); +$result = OC_Gallery_Album::find(OC_User::getUser()); while ($r = $result->fetchRow()) { $album_name = $r['album_name']; - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?'); - $tmp_res = $stmt->execute(array($r['album_id'])); + $tmp_res = OC_Gallery_Photo::find($r['album_id']); + $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10), 'bgPath' => OC::$WEBROOT.'/data/'.OC_User::getUser().'/gallery/'.$album_name.'.png'); } diff --git a/apps/gallery/ajax/getCovers.php b/apps/gallery/ajax/getCovers.php index b9c7558a53c..db7c8e9fcde 100644 --- a/apps/gallery/ajax/getCovers.php +++ b/apps/gallery/ajax/getCovers.php @@ -18,7 +18,7 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $ default: exit(); } - if(!$myImage) exit(); + if(!$myImage) exit(); $ratio_orig = $width_orig/$height_orig; if ($thumbnail_width/$thumbnail_height > $ratio_orig) { @@ -44,15 +44,19 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $ $box_size = 200; $album_name= $_GET['album_name']; -$stmt = OC_DB::prepare('SELECT `file_path` FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.`uid_owner` = ? AND `album_name` = ? AND *PREFIX*gallery_photos.`album_id` = *PREFIX*gallery_albums.`album_id`'); -$result = $stmt->execute(array(OC_User::getUser(), $album_name)); +$result = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $album_name); $numOfItems = min($result->numRows(),10); -$targetImg = imagecreatetruecolor($numOfItems*$box_size, $box_size); +if ($numOfItems){ + $targetImg = imagecreatetruecolor($numOfItems*$box_size, $box_size); +} +else{ + $targetImg = imagecreatetruecolor($box_size, $box_size); +} $counter = 0; while (($i = $result->fetchRow()) && $counter < $numOfItems) { - $imagePath = OC::$CONFIG_DATADIRECTORY . $i['file_path']; + $imagePath = OC_Filesystem::getLocalFile($i['file_path']); if(file_exists($imagePath)) { CroppedThumbnail($imagePath, $box_size, $box_size, $targetImg, $counter*$box_size); @@ -65,7 +69,7 @@ header('Content-Type: image/png'); $offset = 3600 * 24; // calc the string in GMT not localtime and add the offset header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); -header('Cache-Control: max-age=3600, must-revalidate'); +header('Cache-Control: max-age='.$offset.', must-revalidate'); header('Pragma: public'); imagepng($targetImg); diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php index bdd591d0422..f603cbb4971 100644 --- a/apps/gallery/ajax/scanForAlbums.php +++ b/apps/gallery/ajax/scanForAlbums.php @@ -3,10 +3,8 @@ require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); -require_once('../lib_scanner.php'); -OC_GALLERY_SCANNER::cleanUp(); -OC_JSON::success(array('albums' => OC_GALLERY_SCANNER::scan(''))); -//OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa'))))); +OC_Gallery_Scanner::cleanUp(); +OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan(''))); ?> diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php index a1416452932..d937691fa03 100644 --- a/apps/gallery/ajax/thumbnail.php +++ b/apps/gallery/ajax/thumbnail.php @@ -49,12 +49,19 @@ function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSr $box_size = 200; $img = $_GET['img']; -$tmp = OC::$CONFIG_DATADIRECTORY . $img; +$imagePath = OC_Filesystem::getLocalFile($img); -if(file_exists($tmp)) +if(file_exists($imagePath)) { - header('Content-Type: image/png'); - $image = CroppedThumbnail($tmp, $box_size, $box_size); + $image = CroppedThumbnail($imagePath, $box_size, $box_size); + + header('Content-Type: image/png'); + $offset = 3600 * 24; + // calc the string in GMT not localtime and add the offset + header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); + header('Cache-Control: max-age='.$offset.', must-revalidate'); + header('Pragma: public'); + imagepng($image); imagedestroy($image); -}
\ No newline at end of file +} diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php index 8f855c470e5..2b1ab857afc 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -1,4 +1,8 @@ <?php +OC::$CLASSPATH['OC_Gallery_Album'] = 'apps/gallery/lib/album.php'; +OC::$CLASSPATH['OC_Gallery_Photo'] = 'apps/gallery/lib/photo.php'; +OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php'; + OC_App::register(array( 'order' => 20, 'id' => 'gallery', diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css index 03b179138e6..e23d822fec7 100644 --- a/apps/gallery/css/styles.css +++ b/apps/gallery/css/styles.css @@ -1,13 +1,22 @@ div#gallery_list { margin: 90pt 20pt; } +div#gallery_list.leftcontent { + padding-top: 15px; + margin: 0; + text-align: center; +} div#gallery_album_box { width: 200px; text-align: center; border: 0; - float: left; + display: inline-block; margin: 5pt; + vertical-align: top; +} +.leftcontent div#gallery_album_box { + margin: 5px; } div#gallery_album_box h1 { @@ -21,3 +30,6 @@ div#gallery_album_cover { border: solid 1px black; } +#gallery_images { +padding:10px 5px; +} diff --git a/apps/gallery/index.php b/apps/gallery/index.php index cb567e3c8f6..0cd795bac01 100644 --- a/apps/gallery/index.php +++ b/apps/gallery/index.php @@ -13,8 +13,7 @@ if (!file_exists(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .' } if (!isset($_GET['view'])) { - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'); - $result = $stmt->execute(array(OC_User::getUser())); + $result = OC_Gallery_Album::find(OC_User::getUser()); $r = array(); while ($row = $result->fetchRow()) @@ -24,9 +23,7 @@ if (!isset($_GET['view'])) { $tmpl->assign('r', $r); $tmpl->printPage(); } else { - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos, *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name = ? AND *PREFIX*gallery_albums.album_id = *PREFIX*gallery_photos.album_id'); - - $result = $stmt->execute(array(OC_User::getUser(), $_GET['view'])); + $result = OC_Gallery_Photo::findForAlbum(OC_User::getUser(), $_GET['view']); $photos = array(); while ($p = $result->fetchRow()) diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js index a8e317159d5..387cc611d5f 100644 --- a/apps/gallery/js/albums.js +++ b/apps/gallery/js/albums.js @@ -69,7 +69,7 @@ Albums={ if (albumMetadata == undefined) { return; } - var x = Math.min(Math.floor((e.clientX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers)), albumMetadata.numOfCovers-1); + var x = Math.min(Math.floor((e.layerX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers)), albumMetadata.numOfCovers-1); x *= this.offsetWidth; $(this).css('background-position', -x+'px 0'); }); diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php new file mode 100644 index 00000000000..6ddfe46de3d --- /dev/null +++ b/apps/gallery/lib/album.php @@ -0,0 +1,18 @@ +<?php + +class OC_Gallery_Album{ + public static function create($owner, $name){ + $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name) VALUES (?, ?)'); + $stmt->execute(array($owner, $name)); + } + public static function find($owner, $name=null){ + $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'; + $args = array($owner); + if (!is_null($name)){ + $sql .= ' AND album_name = ?'; + $args[] = $name; + } + $stmt = OC_DB::prepare($sql); + return $stmt->execute($args); + } +} diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php new file mode 100644 index 00000000000..97d159935f5 --- /dev/null +++ b/apps/gallery/lib/photo.php @@ -0,0 +1,28 @@ +<?php + +class OC_Gallery_Photo{ + public static function create($albumId, $img){ + $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)'); + $stmt->execute(array($albumId, $img)); + } + public static function find($albumId, $img=null){ + $sql = 'SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?'; + $args = array($albumId); + $args = array($albumId); + if (!is_null($img)){ + $sql .= ' AND file_path = ?'; + $args[] = $img; + } + $stmt = OC_DB::prepare($sql); + return $stmt->execute($args); + } + public static function findForAlbum($owner, $album_name){ + $stmt = OC_DB::prepare('SELECT *' + .' FROM *PREFIX*gallery_photos photos,' + .' *PREFIX*gallery_albums albums' + .' WHERE albums.uid_owner = ?' + .' AND albums.album_name = ?' + .' AND photos.album_id = albums.album_id'); + return $stmt->execute(array($owner, $album_name)); + } +} diff --git a/apps/gallery/lib_scanner.php b/apps/gallery/lib/scanner.php index f72d54777a7..ef210327966 100644 --- a/apps/gallery/lib_scanner.php +++ b/apps/gallery/lib/scanner.php @@ -1,9 +1,9 @@ <?php require_once('base.php'); // base lib -require_once('lib/images_utils.php'); +require_once('images_utils.php'); -class OC_GALLERY_SCANNER { +class OC_Gallery_Scanner { public static function scan($root) { $albums = array(); @@ -36,22 +36,18 @@ class OC_GALLERY_SCANNER { } $current_album['imagesCount'] = count($current_album['images']); $albums[] = $current_album; - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner LIKE ? AND album_name LIKE ?'); - $result = $stmt->execute(array(OC_User::getUser(), $current_album['name'])); + + $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']); if ($result->numRows() == 0 && count($current_album['images'])) { - $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name) VALUES (?, ?)'); - $stmt->execute(array(OC_User::getUser(), $current_album['name'])); + OC_Gallery_Album::create(OC_User::getUser(), $current_album['name']); + $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']); } - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner LIKE ? AND album_name LIKE ?'); - $result = $stmt->execute(array(OC_User::getUser(), $current_album['name'])); - $albumId = $result->fetchAll(); - $albumId = $albumId[0]['album_id']; + $albumId = $result->fetchRow(); + $albumId = $albumId['album_id']; foreach ($current_album['images'] as $img) { - $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ? AND file_path LIKE ?'); - $result = $stmt->execute(array($albumId, $img)); + $result = OC_Gallery_Photo::find($albumId, $img); if ($result->numRows() == 0) { - $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)'); - $stmt->execute(array($albumId, $img)); + OC_Gallery_Photo::create($albumId, $img); } } if (count($current_album['images'])) { diff --git a/apps/gallery/templates/view_album.php b/apps/gallery/templates/view_album.php index 230e2a5c21d..ae43e2fc557 100644 --- a/apps/gallery/templates/view_album.php +++ b/apps/gallery/templates/view_album.php @@ -1,5 +1,6 @@ <?php OC_Util::addStyle('gallery', 'styles'); +OC_Util::addScript('gallery', 'albums'); OC_Util::addScript('gallery', 'album_cover'); OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack'); OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack'); @@ -16,13 +17,16 @@ OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' ); <div id="controls"> <a href="?"><input type="button" value="Back" /></a><br/> </div> -<div id="gallery_list"> + +<div id="gallery_list" class="leftcontent"> +</div> + +<div id="gallery_images" class="rightcontent"> <?php foreach ($_['photos'] as $a) { ?> -<a rel="images" href="../../files/ajax/download.php?files=<?php echo $a; ?>"><img src="ajax/thumbnail.php?img=<?php echo $a ?>"></a> +<a rel="images" href="../../files/download.php?file=<?php echo urlencode($a); ?>"><img src="ajax/thumbnail.php?img=<?php echo urlencode($a) ?>"></a> <?php } ?> - </div> |