function search($database, $settings, $term) { if (!isset($database, $settings, $term)) { return false; } $return['albums'] = ''; # Initialize return var $return = array('photos' => null, 'albums' => null, 'hash' => ''); ### # Photos ### // Photos if ($database->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { $stmtP = $database->prepare("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE title LIKE ? OR description LIKE ? OR tags LIKE ?"); } else { if ($database->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { $stmtP = $database->prepare("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE title ILIKE ? OR description ILIKE ? OR tags ILIKE ?"); } else { $stmtP = $database->prepare("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE title LIKE ? OR description LIKE ? OR tags LIKE ?"); Log::error($this->database, __METHOD__, __LINE__, 'Unknown database driver: ' . $database->getAttribute(PDO::ATTR_DRIVER_NAME)); } } $result = $stmtP->execute(array('%' . $term . '%', '%' . $term . '%', '%' . $term . '%')); while ($photo = $stmtP->fetch(PDO::FETCH_ASSOC)) { $photo = Photo::prepareData($photo); $return['photos'][$photo['id']] = $photo; } ### # Albums ### if ($database->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { $stmtA = $database->prepare("SELECT id, title, public, sysstamp, password FROM " . LYCHEE_TABLE_ALBUMS . " WHERE title LIKE ? OR description LIKE ?"); } else { if ($database->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { $stmtA = $database->prepare("SELECT id, title, public, sysstamp, password FROM " . LYCHEE_TABLE_ALBUMS . " WHERE title ILIKE ? OR description ILIKE ?"); } else { Log::error($this->database, __METHOD__, __LINE__, 'Unknown database driver: ' . $database->getAttribute(PDO::ATTR_DRIVER_NAME)); } } $result = $stmtA->execute(array('%' . $term . '%', '%' . $term . '%')); while ($album = $stmtA->fetch(PDO::FETCH_ASSOC)) { # Turn data from the database into a front-end friendly format $album = Album::prepareData($album); // Thumbs $stmtT = $database->prepare("SELECT thumburl FROM " . LYCHEE_TABLE_PHOTOS . " WHERE album = ? " . $settings['sortingPhotos'] . " LIMIT 3 OFFSET 0"); $result2 = $stmtT->execute(array($album['id'])); $k = 0; while ($thumb = $stmtT->fetchObject()) { $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; }
function search($settings, $term) { if (!isset($settings, $term)) { return false; } $return['albums'] = ''; # Initialize return var $return = array('photos' => null, 'albums' => null, 'hash' => ''); ### # Photos ### $pterm = pg_escape_string($term); $sql = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM photos WHERE title ILIKE '%" . $pterm . "%' OR description ILIKE '%" . $pterm . "%' OR tags ILIKE '%" . $pterm . "%'"; $res = pg_query($db, $sql); while ($row = pg_fetch_array($res)) { $photo = Photo::prepareData($row); $return['photos'][$photo['id']] = $photo; } pg_free_result($res); ### # Albums ### $sql = "SELECT id, title, public, sysstamp, \"password\" FROM albums WHERE title ILIKE '%" . $pterm . "%' OR description ILIKE '%" . $pterm . "%'"; $res = pg_query($db, $sql); while ($row = pg_fetch_array($res)) { # Turn data from the database into a front-end friendly format $album = Album::prepareData($row); $sql = "SELECT thumUrl FROM photos WHERE album=" . $album['id'] . " " . $settings['sortingPhotos']; $nres = pg_query($db, $sql); $k = 0; while ($nrow = pg_fetch_array($nres)) { $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $nrow['thumbUrl']; $k++; } pg_free_result($nres); # Add to return $return['albums'][$album['id']] = $album; } pg_free_result($res); # Hash $return['hash'] = hash('sha256', json_encode($return), false); return $return; }
function search($database, $settings, $term) { if (!isset($database, $settings, $term)) { return false; } $return['albums'] = ''; # Initialize return var $return = array('photos' => null, 'albums' => null, 'hash' => ''); ### # Photos ### $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 ($photo = $result->fetch_assoc()) { $photo = Photo::prepareData($photo); $return['photos'][$photo['id']] = $photo; } ### # Albums ### $query = Database::prepare($database, "SELECT id, title, public, sysstamp, password FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%'", array(LYCHEE_TABLE_ALBUMS, $term, $term)); $result = $database->query($query); 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, "SELECT thumbUrl FROM ? WHERE album = '?' " . $settings['sortingPhotos'] . " LIMIT 0, 3", array(LYCHEE_TABLE_PHOTOS, $album['id'])); $thumbs = $database->query($query); # 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; }
public function get() { # Check dependencies self::dependencies(isset($this->database, $this->settings, $this->albumIDs)); # Call plugins $this->plugins(__METHOD__, 0, func_get_args()); # Get album information switch ($this->albumIDs) { case 'f': $return['public'] = '0'; $photos = $this->database->query("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE star = 1 " . $this->settings['sortingPhotos']); break; case 's': $return['public'] = '0'; $photos = $this->database->query("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE public = 1 " . $this->settings['sortingPhotos']); break; case 'r': $return['public'] = '0'; if ($this->database->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { $photos = $this->database->query("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . $this->settings['sortingPhotos']); } else { if ($this->database->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { $photos = $this->database->query("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE id >= extract(epoch FROM NOW() - INTERVAL '1' DAY)*10000 " . $this->settings['sortingPhotos']); } else { Log::error($this->database, __METHOD__, __LINE__, 'Unknown database driver: ' . $this->database->getAttribute(PDO::ATTR_DRIVER_NAME)); } } break; case '0': $return['public'] = '0'; $photos = $this->database->query("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE album = '0' " . $this->settings['sortingPhotos']); break; default: $stmt = $this->database->prepare("SELECT * FROM " . LYCHEE_TABLE_ALBUMS . " WHERE id = ? LIMIT 1"); $albums = $stmt->execute(array($this->albumIDs)); $return = $stmt->fetch(PDO::FETCH_ASSOC); # fix public, visible, downloadable $return['public'] = $return['public'] == 1 ? '1' : '0'; $return['visible'] = $return['visible'] == 1 ? '1' : '0'; $return['downloadable'] = $return['downloadable'] == 1 ? '1' : '0'; # $return['sysdate'] = date('d M. Y', $return['sysstamp']); $return['password'] = $return['password'] == '' ? '0' : '1'; $stmt = $this->database->prepare("SELECT id, title, tags, public, star, album, thumburl, takestamp, url FROM " . LYCHEE_TABLE_PHOTOS . " WHERE album = ? " . $this->settings['sortingPhotos']); $photos = $stmt->execute(array($this->albumIDs)); $photos = $stmt; break; } # Get photos $previousPhotoID = ''; while ($photo = $photos->fetch(PDO::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->rowCount() === 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->rowCount(); # Call plugins $this->plugins(__METHOD__, 1, func_get_args()); return $return; }
public function get() { # Check dependencies self::dependencies(isset($this->database, $this->settings, $this->albumIDs)); # Call plugins $this->plugins(__METHOD__, 0, func_get_args()); # Get album information switch ($this->albumIDs) { case 'f': $return['public'] = '0'; $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE star = 1 " . $this->settings['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; case 's': $return['public'] = '0'; $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE public = 1 " . $this->settings['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; case 'r': $return['public'] = '0'; $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . $this->settings['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; case '0': $return['public'] = '0'; $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = 0 " . $this->settings['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS)); break; default: $query = Database::prepare($this->database, "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs)); $albums = $this->database->query($query); $return = $albums->fetch_assoc(); $return = Album::prepareData($return); $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . $this->settings['sortingPhotos'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs)); break; } # Get photos $photos = $this->database->query($query); $previousPhotoID = ''; 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 $this->plugins(__METHOD__, 1, func_get_args()); return $return; }
public function get() { # Check dependencies self::dependencies(isset($this->settings, $this->albumIDs)); # Get album information switch ($this->albumIDs) { case 'f': $return['public'] = '0'; $sql = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM photos WHERE star = 1 " . $this->settings['sortingPhotos']; break; case 's': $return['public'] = '0'; $sql = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM photos WHERE public = 1 " . $this->settings['sortingPhotos']; break; case 'r': $return['public'] = '0'; $check = strtotime('-24 Hours'); $sql = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM photos WHERE takestamp> " . $check . " " . $this->settings['sortingPhotos']; break; case '0': $return['public'] = '0'; $sql = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM photos WHERE album = 0 " . $this->settings['sortingPhotos']; break; default: $sql = "SELECT * FROM albums id = " . intval($this->albumIDs); $res = pg_query($db, $sql); $row = pg_fetch_array($res); $return = $row; $return['sysdate'] = date('d M. Y', $return['sysstamp']); $return['password'] = $return['password'] == '' ? '0' : '1'; pg_free_result($res); $sql = "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM photos WHERE album = " . intval($this->albumIDs) . " " . $this->settings['sortingPhotos']; break; } # Get photos $res = pg_query($db, $sql); $previousPhotoID = ''; while ($row = pg_fetch_array($res)) { # Turn data from the database into a front-end friendly format $photo = Photo::prepareData($row); # 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 (pg_num_rows($res) < 1) { # 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'] = pg_num_rows($res); pg_free_result($res); return $return; }