diff --git a/php/modules/Album.php b/php/modules/Album.php index e2dec88..6ba81e0 100644 --- a/php/modules/Album.php +++ b/php/modules/Album.php @@ -94,20 +94,14 @@ class Album extends Module { $previousPhotoID = ''; while ($photo = $photos->fetch_assoc()) { - # Parse - $photo['sysdate'] = date('d F Y', substr($photo['id'], 0, -4)); - $photo['previousPhoto'] = $previousPhotoID; - $photo['nextPhoto'] = ''; - $photo['thumbUrl'] = LYCHEE_URL_UPLOADS_THUMB . $photo['thumbUrl']; + # Turn data from the database into a front-end friendly format + $photo = Photo::prepareData($photo); - # Parse url - $photo['url'] = LYCHEE_URL_UPLOADS_BIG . $photo['url']; - - if (isset($photo['takestamp'])&&$photo['takestamp']!=='0') { - $photo['cameraDate'] = 1; - $photo['sysdate'] = date('d F Y', $photo['takestamp']); - } + # Set previous and next photoID for navigation purposes + $photo['previousPhoto'] = $previousPhotoID; + $photo['nextPhoto'] = ''; + # Set current photoID as nextPhoto of previous photo if ($previousPhotoID!=='') $return['content'][$previousPhotoID]['nextPhoto'] = $photo['id']; $previousPhotoID = $photo['id']; @@ -183,18 +177,19 @@ class Album extends Module { $album['password'] = ($album['password']=='' ? '0' : '1'); # Thumbs - if (($public===true&&$album['password']==='0')||($public===false)) { + if (($public===true&&$album['password']==='0')|| + ($public===false)) { - # Execute query - $query = Database::prepare($this->database, "SELECT thumbUrl FROM ? WHERE album = '?' ORDER BY star DESC, " . substr($this->settings['sorting'], 9) . " LIMIT 3", array(LYCHEE_TABLE_PHOTOS, $album['id'])); - $thumbs = $this->database->query($query); + # Execute query + $query = Database::prepare($this->database, "SELECT thumbUrl FROM ? WHERE album = '?' ORDER BY star DESC, " . substr($this->settings['sorting'], 9) . " LIMIT 3", array(LYCHEE_TABLE_PHOTOS, $album['id'])); + $thumbs = $this->database->query($query); - # For each thumb - $k = 0; - while ($thumb = $thumbs->fetch_object()) { - $album["thumb$k"] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; - $k++; - } + # For each thumb + $k = 0; + while ($thumb = $thumbs->fetch_object()) { + $album["thumb$k"] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; + $k++; + } } diff --git a/php/modules/Photo.php b/php/modules/Photo.php index 942c693..8bdd7d4 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -526,6 +526,46 @@ class Photo extends Module { } + public static function prepareData($data) { + + # This function requires the following photo-attributes and turns them + # into a front-end friendly format: id, title, tags, public, star, album, thumbUrl, takestamp, url + # Note that some attributes remain unchanged + + # Init + $photo = null; + + # Set unchanged attribute + $photo['id'] = $data['id']; + $photo['title'] = $data['title']; + $photo['tags'] = $data['tags']; + $photo['public'] = $data['public']; + $photo['star'] = $data['star']; + $photo['album'] = $data['album']; + + # Parse urls + $photo['thumbUrl'] = LYCHEE_URL_UPLOADS_THUMB . $data['thumbUrl']; + $photo['url'] = LYCHEE_URL_UPLOADS_BIG . $data['url']; + + # Use takestamp as sysdate when possible + if (isset($data['takestamp'])&&$data['takestamp']!=='0') { + + # Use takestamp + $photo['cameraDate'] = '1'; + $photo['sysdate'] = date('d F Y', $data['takestamp']); + + } else { + + # Use sysstamp from the id + $photo['cameraDate'] = '0'; + $photo['sysdate'] = date('d F Y', substr($data['id'], 0, -4)); + + } + + return $photo; + + } + public function get($albumID) { # Check dependencies diff --git a/php/modules/misc.php b/php/modules/misc.php index 2094790..462f51e 100755 --- a/php/modules/misc.php +++ b/php/modules/misc.php @@ -21,12 +21,13 @@ function search($database, $settings, $term) { ); # Photos - $query = Database::prepare($database, "SELECT id, title, tags, public, star, album, thumbUrl FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' OR tags LIKE '%?%'", array(LYCHEE_TABLE_PHOTOS, $term, $term, $term)); + $query = Database::prepare($database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' OR tags LIKE '%?%'", array(LYCHEE_TABLE_PHOTOS, $term, $term, $term)); $result = $database->query($query); - while($row = $result->fetch_assoc()) { - $return['photos'][$row['id']] = $row; - $return['photos'][$row['id']]['thumbUrl'] = LYCHEE_URL_UPLOADS_THUMB . $row['thumbUrl']; - $return['photos'][$row['id']]['sysdate'] = date('d M. Y', substr($row['id'], 0, -4)); + while($photo = $result->fetch_assoc()) { + + $photo = Photo::prepareData($photo); + $return['photos'][$photo['id']] = $photo; + } # Albums diff --git a/src/scripts/build.js b/src/scripts/build.js index 1f8aa3b..565eec4 100644 --- a/src/scripts/build.js +++ b/src/scripts/build.js @@ -124,7 +124,7 @@ build.photo = function(data) {