diff --git a/dist/main.js b/dist/main.js index e67a346..9f079ff 100644 Binary files a/dist/main.js and b/dist/main.js differ diff --git a/dist/view.js b/dist/view.js index e0630c1..a33cc7e 100644 Binary files a/dist/view.js and b/dist/view.js differ diff --git a/php/modules/Album.php b/php/modules/Album.php index 6ba81e0..dc690b0 100644 --- a/php/modules/Album.php +++ b/php/modules/Album.php @@ -52,6 +52,36 @@ class Album extends Module { } + public static function prepareData($data) { + + # This function requires the following album-attributes and turns them + # into a front-end friendly format: id, title, public, sysstamp, password + # Note that some attributes remain unchanged + + # Check dependencies + self::dependencies(isset($data)); + + # Init + $album = null; + + # Set unchanged attributes + $album['id'] = $data['id']; + $album['title'] = $data['title']; + $album['public'] = $data['public']; + + # Parse date + $album['sysdate'] = date('F Y', $data['sysstamp']); + + # Parse password + $album['password'] = ($data['password']=='' ? '0' : '1'); + + # Set placeholder for thumbs + $album['thumbs'] = array(); + + return $album; + + } + public function get() { # Check dependencies @@ -172,9 +202,8 @@ class Album extends Module { # For each album while ($album = $albums->fetch_assoc()) { - # Parse info - $album['sysdate'] = date('F Y', $album['sysstamp']); - $album['password'] = ($album['password']=='' ? '0' : '1'); + # Turn data from the database into a front-end friendly format + $album = Album::prepareData($album); # Thumbs if (($public===true&&$album['password']==='0')|| @@ -187,7 +216,7 @@ class Album extends Module { # For each thumb $k = 0; while ($thumb = $thumbs->fetch_object()) { - $album["thumb$k"] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; + $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; $k++; } @@ -221,54 +250,87 @@ class Album extends Module { 'recent' => null ); + ### # Unsorted + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE album = 0 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $unsorted = $this->database->query($query); $i = 0; + + $return['unsorted'] = array( + 'thumbs' => array(), + 'num' => $unsorted->num_rows + ); + while($row = $unsorted->fetch_object()) { if ($i<3) { - $return['unsorted']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl; + $return['unsorted']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl; $i++; } else break; } - $return['unsorted']['num'] = $unsorted->num_rows; + ### # Starred + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE star = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $starred = $this->database->query($query); $i = 0; + + $return['starred'] = array( + 'thumbs' => array(), + 'num' => $starred->num_rows + ); + while($row3 = $starred->fetch_object()) { if ($i<3) { - $return['starred']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; + $return['starred']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; $i++; } else break; } - $return['starred']['num'] = $starred->num_rows; + ### # Public + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE public = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $public = $this->database->query($query); $i = 0; + + $return['public'] = array( + 'thumbs' => array(), + 'num' => $public->num_rows + ); + while($row2 = $public->fetch_object()) { if ($i<3) { - $return['public']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl; + $return['public']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl; $i++; } else break; } - $return['public']['num'] = $public->num_rows; + ### # Recent + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $recent = $this->database->query($query); $i = 0; + + $return['recent'] = array( + 'thumbs' => array(), + 'num' => $recent->num_rows + ); + while($row3 = $recent->fetch_object()) { if ($i<3) { - $return['recent']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; + $return['recent']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; $i++; } else break; } - $return['recent']['num'] = $recent->num_rows; + # Return SmartAlbums return $return; } diff --git a/php/modules/Photo.php b/php/modules/Photo.php index 8bdd7d4..c23ad4c 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -532,10 +532,13 @@ class Photo extends Module { # into a front-end friendly format: id, title, tags, public, star, album, thumbUrl, takestamp, url # Note that some attributes remain unchanged + # Check dependencies + self::dependencies(isset($data)); + # Init $photo = null; - # Set unchanged attribute + # Set unchanged attributes $photo['id'] = $data['id']; $photo['title'] = $data['title']; $photo['tags'] = $data['tags']; diff --git a/src/scripts/albums.js b/src/scripts/albums.js index 72dbb81..9db151f 100644 --- a/src/scripts/albums.js +++ b/src/scripts/albums.js @@ -59,13 +59,13 @@ albums.load = function() { albums.parse = function(album) { if (album.password==='1'&&lychee.publicMode===true) { - album.thumb0 = 'src/images/password.svg'; - album.thumb1 = 'src/images/password.svg'; - album.thumb2 = 'src/images/password.svg'; + album.thumbs[0] = 'src/images/password.svg'; + album.thumbs[1] = 'src/images/password.svg'; + album.thumbs[2] = 'src/images/password.svg'; } else { - if (!album.thumb0) album.thumb0 = 'src/images/no_images.svg'; - if (!album.thumb1) album.thumb1 = 'src/images/no_images.svg'; - if (!album.thumb2) album.thumb2 = 'src/images/no_images.svg'; + if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg'; + if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg'; + if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg'; } } @@ -77,9 +77,7 @@ albums._createSmartAlbums = function(data) { title: 'Unsorted', sysdate: data.unsorted.num + ' photos', unsorted: '1', - thumb0: data.unsorted.thumb0, - thumb1: data.unsorted.thumb1, - thumb2: data.unsorted.thumb2 + thumbs: data.unsorted.thumbs }; data.starred = { @@ -87,9 +85,7 @@ albums._createSmartAlbums = function(data) { title: 'Starred', sysdate: data.starred.num + ' photos', star: '1', - thumb0: data.starred.thumb0, - thumb1: data.starred.thumb1, - thumb2: data.starred.thumb2 + thumbs: data.starred.thumbs }; data.public = { @@ -97,9 +93,7 @@ albums._createSmartAlbums = function(data) { title: 'Public', sysdate: data.public.num + ' photos', public: '1', - thumb0: data.public.thumb0, - thumb1: data.public.thumb1, - thumb2: data.public.thumb2 + thumbs: data.public.thumbs }; data.recent = { @@ -107,9 +101,7 @@ albums._createSmartAlbums = function(data) { title: 'Recent', sysdate: data.recent.num + ' photos', recent: '1', - thumb0: data.recent.thumb0, - thumb1: data.recent.thumb1, - thumb2: data.recent.thumb2 + thumbs: data.recent.thumbs }; } diff --git a/src/scripts/build.js b/src/scripts/build.js index 565eec4..159c846 100644 --- a/src/scripts/build.js +++ b/src/scripts/build.js @@ -73,13 +73,13 @@ build.album = function(data) { } - if (data.thumb0.split('.').pop()==='svg') typeThumb = 'nonretina'; + if (data.thumbs[0].split('.').pop()==='svg') typeThumb = 'nonretina'; html = `
- thumb - thumb - thumb + thumb + thumb + thumb

${ title }

${ data.sysdate } diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index 45ed35f..f966643 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -87,9 +87,9 @@ contextMenu.albumTitle = function(albumID, e) { var that = this, title = ''; - if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg'; + if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; - title = "
" + that.title + "
"; + title = "
" + that.title + "
"; if (that.id!=albumID) items.push({ type: 'item', title, fn: function() { lychee.goto(that.id) } }); @@ -224,8 +224,8 @@ contextMenu.move = function(photoIDs, e) { var that = this; - if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg'; - that.title = "
" + that.title + "
"; + if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; + that.title = "
" + that.title + "
"; if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } });