Exemple #1
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;
}
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;
}
Exemple #3
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;
}
<?php

/**
 * Update to version 3.0.0
 */
use Lychee\Modules\Database;
use Lychee\Modules\Response;
// Remove login
// Login now saved as crypt without md5. Legacy code has been removed.
$query = Database::prepare($connection, "UPDATE `?` SET `value` = '' WHERE `key` = 'username' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030000', __LINE__);
if ($result === false) {
    Response::error('Could not reset username in database!');
}
$query = Database::prepare($connection, "UPDATE `?` SET `value` = '' WHERE `key` = 'password' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030000', __LINE__);
if ($result === false) {
    Response::error('Could not reset password in database!');
}
// Make public albums private and reset password
// Password now saved as crypt without md5. Legacy code has been removed.
$query = Database::prepare($connection, "UPDATE `?` SET `public` = 0, `password` = NULL", array(LYCHEE_TABLE_ALBUMS));
$result = Database::execute($connection, $query, 'update_030000', __LINE__);
if ($result === false) {
    Response::error('Could not reset publicity of photos in database!');
}
// Set version
if (Database::setVersion($connection, '030000') === false) {
    Response::error('Could not update version of database!');
}
Exemple #5
0
 /**
  * @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;
 }
 function getAllPhotos()
 {
     # Functions returns the list of photos
     global $newWidth;
     global $newHeight;
     # Get photos that do not have a medium size photo
     $query = Database::prepare(Database::get(), "SELECT id, width, height, url, medium FROM ? WHERE medium=0 AND (width > ? OR height > ?)", array(LYCHEE_TABLE_PHOTOS, $newWidth, $newHeight));
     $photos = Database::get()->query($query);
     $data = array();
     while ($photo = $photos->fetch_assoc()) {
         # Parse photo
         $photo['filename'] = $photo['url'];
         $photo['url'] = LYCHEE_URL_UPLOADS_BIG . $photo['url'];
         $data[] = $photo;
     }
     return $data;
 }
Exemple #7
0
require $lychee . 'php/define.php';
require $lychee . 'php/autoload.php';
// Start the session
session_start();
// Set content
header('content-type: text/plain');
// Load config
if (!file_exists(LYCHEE_CONFIG_FILE)) {
    exit('Error 001: Configuration not found. Please install Lychee first.');
}
require LYCHEE_CONFIG_FILE;
// Ensure that user is logged in
if (isset($_SESSION['login']) && $_SESSION['login'] === true && (isset($_SESSION['identifier']) && $_SESSION['identifier'] === Settings::get()['identifier'])) {
    // Result
    $query = Database::prepare(Database::get(), "SELECT FROM_UNIXTIME(time), type, function, line, text FROM ?", array(LYCHEE_TABLE_LOG));
    $result = Database::get()->query($query);
    // Output
    if ($result->num_rows === 0) {
        echo 'Everything looks fine, Lychee has not reported any problems!';
    } else {
        while ($row = $result->fetch_row()) {
            // Encode result before printing
            $row = array_map('htmlentities', $row);
            // Format: time TZ - type - function(line) - text
            printf("%s - %s - %s (%s) \t- %s\n", $row[0], $row[1], $row[2], $row[3], $row[4]);
        }
    }
} else {
    // Don't go further if the user is not logged in
    exit('You have to be logged in to see the log.');
}
Exemple #8
0
 /**
  * Deletes a photo with all its data and files.
  * @return boolean Returns true when successful.
  */
 public function delete()
 {
     // Check dependencies
     Validator::required(isset($this->photoIDs), __METHOD__);
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     // Init vars
     $error = false;
     // Get photos
     $query = Database::prepare(Database::get(), "SELECT id, url, thumbUrl, checksum FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->photoIDs));
     $photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     if ($photos === false) {
         return false;
     }
     // For each photo
     while ($photo = $photos->fetch_object()) {
         // Check if other photos are referring to this images
         // If so, only delete the db entry
         if ($this->exists($photo->checksum, $photo->id) === false) {
             // Get retina thumb url
             $thumbUrl2x = explode(".", $photo->thumbUrl);
             $thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
             // Delete big
             if (file_exists(LYCHEE_UPLOADS_BIG . $photo->url) && !unlink(LYCHEE_UPLOADS_BIG . $photo->url)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete photo in uploads/big/');
                 $error = true;
             }
             // Delete medium
             if (file_exists(LYCHEE_UPLOADS_MEDIUM . $photo->url) && !unlink(LYCHEE_UPLOADS_MEDIUM . $photo->url)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete photo in uploads/medium/');
                 $error = true;
             }
             // Delete thumb
             if (file_exists(LYCHEE_UPLOADS_THUMB . $photo->thumbUrl) && !unlink(LYCHEE_UPLOADS_THUMB . $photo->thumbUrl)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete photo in uploads/thumb/');
                 $error = true;
             }
             // Delete thumb@2x
             if (file_exists(LYCHEE_UPLOADS_THUMB . $thumbUrl2x) && !unlink(LYCHEE_UPLOADS_THUMB . $thumbUrl2x)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete high-res photo in uploads/thumb/');
                 $error = true;
             }
         }
         // Delete db entry
         $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id = '?'", array(LYCHEE_TABLE_PHOTOS, $photo->id));
         $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
         if ($result === false) {
             $error = true;
         }
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     if ($error === true) {
         return false;
     }
     return true;
 }