function getGraphHeader($photoID) { $photo = new Photo($photoID); if ($photo->getPublic('') === false) { return false; } $query = Database::prepare(Database::get(), "SELECT title, description, url, medium FROM ? WHERE id = '?'", array(LYCHEE_TABLE_PHOTOS, $photoID)); $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__); if ($result === false) { return false; } $row = $result->fetch_object(); if ($row === null) { Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find photo in database'); return false; } if ($row->medium === '1') { $dir = 'medium'; } else { $dir = 'big'; } $parseUrl = parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $url = '//' . $parseUrl['host'] . $parseUrl['path'] . '?' . $parseUrl['query']; $picture = '//' . $parseUrl['host'] . $parseUrl['path'] . '/../uploads/' . $dir . '/' . $row->url; $url = htmlentities($url); $picture = htmlentities($picture); $row->title = htmlentities($row->title); $row->description = htmlentities($row->description); $return = '<!-- General Meta Data -->'; $return .= '<meta name="title" content="' . $row->title . '">'; $return .= '<meta name="description" content="' . $row->description . ' - via Lychee">'; $return .= '<link rel="image_src" type="image/jpeg" href="' . $picture . '">'; $return .= '<!-- Twitter Meta Data -->'; $return .= '<meta name="twitter:card" content="photo">'; $return .= '<meta name="twitter:title" content="' . $row->title . '">'; $return .= '<meta name="twitter:image:src" content="' . $picture . '">'; $return .= '<!-- Facebook Meta Data -->'; $return .= '<meta property="og:title" content="' . $row->title . '">'; $return .= '<meta property="og:description" content="' . $row->description . ' - via Lychee">'; $return .= '<meta property="og:image" content="' . $picture . '">'; $return .= '<meta property="og:url" content="' . $url . '">'; return $return; }
/** * @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 boolean Returns true when successful. */ public function delete() { // Check dependencies Validator::required(isset($this->albumIDs), __METHOD__); // Call plugins Plugins::get()->activate(__METHOD__, 0, func_get_args()); // Init vars $photoIDs = array(); // Execute query $query = Database::prepare(Database::get(), "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs)); $photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__); if ($photos === false) { return false; } // Only delete photos when albums contain photos if ($photos->num_rows > 0) { // Add each id to photoIDs while ($row = $photos->fetch_object()) { $photoIDs[] = $row->id; } // Convert photoIDs to a string $photoIDs = implode(',', $photoIDs); // Delete all photos $photo = new Photo($photoIDs); if ($photo->delete() !== true) { return false; } } // Delete albums $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs)); $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__); // Call plugins Plugins::get()->activate(__METHOD__, 1, func_get_args()); if ($result === false) { return false; } return true; }
private static function getPhotoArchiveAction() { Validator::required(isset($_GET['photoID'], $_GET['password']), __METHOD__); $photo = new Photo($_GET['photoID']); $pgP = $photo->getPublic($_GET['password']); // Photo Download if ($pgP === 2) { // Photo Public $photo->getArchive(); } else { // Photo Private Response::warning('Photo private or password incorrect!'); } }
private static function getPhotoArchiveAction() { Validator::required(isset($_GET['photoID']), __METHOD__); $photo = new Photo($_GET['photoID']); $photo->getArchive(); }