search.php 1.5 KB

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