Example #1
0
function getPhoto($database, $type, $photoUrl, $isAdmin)
{
    $retinaSuffix = '@2x';
    $urlParts = explode('.', $photoUrl);
    $dbUrl = $photoUrl;
    # If the filename ends in $retinaSuffix, remove it for the database query
    if (substr_compare($urlParts[0], $retinaSuffix, strlen($urlParts[0]) - strlen($retinaSuffix), strlen($retinaSuffix)) === 0) {
        $dbUrl = substr($urlParts[0], 0, -strlen($retinaSuffix)) . '.' . $urlParts[1];
    }
    # Get photo
    if ($type == 'thumb') {
        $query = Database::prepare($database, "SELECT * FROM ? WHERE thumbUrl = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $dbUrl));
    } else {
        $query = Database::prepare($database, "SELECT * FROM ? WHERE url = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $dbUrl));
    }
    $photos = Database::execute($database, $query, __METHOD__, __LINE__);
    $photo = $photos->fetch_object();
    if ($photo === null) {
        http_response_code(404);
        exit('Photo not found');
    }
    # Check if public
    if ($isAdmin === true || $photo->public === '1') {
        # Photo public
        return $photo;
    } else {
        # Check if album public
        $album = new Album($database, null, null, $photo->album);
        $agP = $album->getPublic();
        if ($agP === true) {
            return $photo;
        }
    }
    # Photo private
    return false;
}
Example #2
0
/**
 * @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;
}
Example #3
0
 /**
  * @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;
 }
Example #4
0
 private static function getAlbumArchiveAction()
 {
     Validator::required(isset($_GET['albumID'], $_GET['password']), __METHOD__);
     $album = new Album($_GET['albumID']);
     if ($album->getPublic() && $album->getDownloadable()) {
         // Album Public
         if ($album->checkPassword($_GET['password'])) {
             $album->getArchive();
         } else {
             Response::warning('Wrong password!');
         }
     } else {
         // Album Private
         Response::warning('Album private or not downloadable!');
     }
 }
Example #5
0
 private static function getAlbumArchiveAction()
 {
     Validator::required(isset($_GET['albumID']), __METHOD__);
     $album = new Album($_GET['albumID']);
     $album->getArchive();
 }
Example #6
0
 /**
  * Checks if photo or parent album is public.
  * @return integer 0 = Photo private and parent album private
  *                 1 = Album public, but password incorrect
  *                 2 = Photo public or album public and password correct
  */
 public function getPublic($password)
 {
     // Check dependencies
     Validator::required(isset($this->photoIDs), __METHOD__);
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     // Get photo
     $query = Database::prepare(Database::get(), "SELECT public, album FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_PHOTOS, $this->photoIDs));
     $photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     if ($photos === false) {
         return 0;
     }
     // Get photo object
     $photo = $photos->fetch_object();
     // Photo not found?
     if ($photo === null) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified photo');
         return false;
     }
     // Check if public
     if ($photo->public === '1') {
         // Photo public
         return 2;
     } else {
         // Check if album public
         $album = new Album($photo->album);
         $agP = $album->getPublic();
         $acP = $album->checkPassword($password);
         // Album public and password correct
         if ($agP === true && $acP === true) {
             return 2;
         }
         // Album public, but password incorrect
         if ($agP === true && $acP === false) {
             return 1;
         }
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     // Photo private
     return 0;
 }