/** * @return array|false Returns an array with albums and photos. */ function search($term) { // Initialize return var $return = array('photos' => null, 'albums' => null, 'hash' => ''); /** * Photos */ $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)); $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__); if ($result === false) { return false; } while ($photo = $result->fetch_assoc()) { $photo = Photo::prepareData($photo); $return['photos'][$photo['id']] = $photo; } /** * Albums */ $query = Database::prepare(Database::get(), "SELECT id, title, public, sysstamp, password FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%'", array(LYCHEE_TABLE_ALBUMS, $term, $term)); $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__); if ($result === false) { return false; } while ($album = $result->fetch_assoc()) { // Turn data from the database into a front-end friendly format $album = Album::prepareData($album); // Thumbs $query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'] . " LIMIT 0, 3", array(LYCHEE_TABLE_PHOTOS, $album['id'])); $thumbs = Database::execute(Database::get(), $query, __METHOD__, __LINE__); if ($thumbs === false) { return false; } // For each thumb $k = 0; while ($thumb = $thumbs->fetch_object()) { $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; $k++; } // Add to return $return['albums'][$album['id']] = $album; } // Hash $return['hash'] = md5(json_encode($return)); return $return; }
/** * @return array|false Returns an array of photos and album information or false on failure. */ public function get() { // Check dependencies Validator::required(isset($this->albumIDs), __METHOD__); // Call plugins Plugins::get()->activate(__METHOD__, 0, func_get_args()); // Get album information switch ($this->albumIDs) { case 'f': $return['public'] = '0'; $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE star = 1 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; case 's': $return['public'] = '0'; $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE public = 1 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; case 'r': $return['public'] = '0'; $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; case '0': $return['public'] = '0'; $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = 0 " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; default: $query = Database::prepare(Database::get(), "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs)); $albums = Database::execute(Database::get(), $query, __METHOD__, __LINE__); $return = $albums->fetch_assoc(); $return = Album::prepareData($return); $query = Database::prepare(Database::get(), "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . Settings::get()['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs)); break; } // Get photos $photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__); $previousPhotoID = ''; if ($photos === false) { return false; } while ($photo = $photos->fetch_assoc()) { // Turn data from the database into a front-end friendly format $photo = Photo::prepareData($photo); // 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']; // Add to return $return['content'][$photo['id']] = $photo; } if ($photos->num_rows === 0) { // Album empty $return['content'] = false; } else { // Enable next and previous for the first and last photo $lastElement = end($return['content']); $lastElementId = $lastElement['id']; $firstElement = reset($return['content']); $firstElementId = $firstElement['id']; if ($lastElementId !== $firstElementId) { $return['content'][$lastElementId]['nextPhoto'] = $firstElementId; $return['content'][$firstElementId]['previousPhoto'] = $lastElementId; } } $return['id'] = $this->albumIDs; $return['num'] = $photos->num_rows; // Call plugins Plugins::get()->activate(__METHOD__, 1, func_get_args()); return $return; }