search.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. function search($term) {
  3. $return['albums'] = '';
  4. # Initialize return var
  5. $return = array(
  6. 'photos' => null,
  7. 'albums' => null,
  8. 'hash' => ''
  9. );
  10. ###
  11. # Photos
  12. ###
  13. $query = Database::prepare(Database::get(), "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));
  14. $result = Database::get()->query($query);
  15. while($photo = $result->fetch_assoc()) {
  16. $photo = Photo::prepareData($photo);
  17. $return['photos'][$photo['id']] = $photo;
  18. }
  19. ###
  20. # Albums
  21. ###
  22. $query = Database::prepare(Database::get(), "SELECT id, title, public, sysstamp, password FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%'", array(LYCHEE_TABLE_ALBUMS, $term, $term));
  23. $result = Database::get()->query($query);
  24. while($album = $result->fetch_assoc()) {
  25. # Turn data from the database into a front-end friendly format
  26. $album = Album::prepareData($album);
  27. # Thumbs
  28. $query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'] . " LIMIT 0, 3", array(LYCHEE_TABLE_PHOTOS, $album['id']));
  29. $thumbs = Database::get()->query($query);
  30. # For each thumb
  31. $k = 0;
  32. while ($thumb = $thumbs->fetch_object()) {
  33. $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
  34. $k++;
  35. }
  36. # Add to return
  37. $return['albums'][$album['id']] = $album;
  38. }
  39. # Hash
  40. $return['hash'] = md5(json_encode($return));
  41. return $return;
  42. }
  43. ?>