search.php 1.8 KB

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