Example #1
0
 public static function get()
 {
     if (!self::$instance) {
         $files = Settings::get()['plugins'];
         self::$instance = new self($files);
     }
     return self::$instance;
 }
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
$type = $_GET['type'];
$url = $_GET['url'];
# Usual startup (taken from php/index.php file)
use Lychee\Modules\Album;
use Lychee\Modules\Config;
use Lychee\Modules\Settings;
use Lychee\Modules\Database;
require __DIR__ . '/../../php/define.php';
require __DIR__ . '/../../php/autoload.php';
session_start();
date_default_timezone_set('UTC');
if (Config::exists() === false) {
    exit('Error: no config file.');
}
$isAdmin = false;
if (isset($_SESSION['login']) && $_SESSION['login'] === true && (isset($_SESSION['identifier']) && $_SESSION['identifier'] === Settings::get()['identifier'])) {
    $isAdmin = true;
}
# end of startup
$database = Database::get();
# return the photo if the current user has acces to it or false otherwise (taken from php/module/photo.php)
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
Example #5
0
 private static function setDropboxKeyAction()
 {
     Validator::required(isset($_POST['key']), __METHOD__);
     Response::json(Settings::setDropboxKey($_POST['key']));
 }
Example #6
0
 /**
  * Rotates and flips a photo based on its EXIF orientation.
  * @return array|false Returns an array with the new orientation, width, height or false on failure.
  */
 public function adjustFile($path, array $info)
 {
     // Excepts the following:
     // (string) $path = Path to the photo-file
     // (array) $info = ['orientation', 'width', 'height']
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     $swapSize = false;
     if (extension_loaded('imagick') && Settings::get()['imagick'] === '1') {
         $image = new Imagick();
         $image->readImage($path);
         $orientation = $image->getImageOrientation();
         switch ($orientation) {
             case Imagick::ORIENTATION_TOPLEFT:
                 return false;
                 break;
             case Imagick::ORIENTATION_TOPRIGHT:
                 $image->flopImage();
                 break;
             case Imagick::ORIENTATION_BOTTOMRIGHT:
                 $image->rotateImage(new ImagickPixel(), 180);
                 break;
             case Imagick::ORIENTATION_BOTTOMLEFT:
                 $image->flopImage();
                 $image->rotateImage(new ImagickPixel(), 180);
                 break;
             case Imagick::ORIENTATION_LEFTTOP:
                 $image->flopImage();
                 $image->rotateImage(new ImagickPixel(), -90);
                 $swapSize = true;
                 break;
             case Imagick::ORIENTATION_RIGHTTOP:
                 $image->rotateImage(new ImagickPixel(), 90);
                 $swapSize = true;
                 break;
             case Imagick::ORIENTATION_RIGHTBOTTOM:
                 $image->flopImage();
                 $image->rotateImage(new ImagickPixel(), 90);
                 $swapSize = true;
                 break;
             case Imagick::ORIENTATION_LEFTBOTTOM:
                 $image->rotateImage(new ImagickPixel(), -90);
                 $swapSize = true;
                 break;
             default:
                 return false;
                 break;
         }
         // Adjust photo
         $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
         $image->writeImage($path);
         // Free memory
         $image->clear();
         $image->destroy();
     } else {
         $newWidth = $info['width'];
         $newHeight = $info['height'];
         $sourceImg = imagecreatefromjpeg($path);
         switch ($info['orientation']) {
             case 1:
                 // do nothing
                 return false;
                 break;
             case 2:
                 // mirror
                 // not yet implemented
                 return false;
                 break;
             case 3:
                 $sourceImg = imagerotate($sourceImg, -180, 0);
                 break;
             case 4:
                 // rotate 180 and mirror
                 // not yet implemented
                 return false;
                 break;
             case 5:
                 // rotate 90 and mirror
                 // not yet implemented
                 return false;
                 break;
             case 6:
                 $sourceImg = imagerotate($sourceImg, -90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 $swapSize = true;
                 break;
             case 7:
                 // rotate -90 and mirror
                 // not yet implemented
                 return false;
                 break;
             case 8:
                 $sourceImg = imagerotate($sourceImg, 90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 $swapSize = true;
                 break;
             default:
                 return false;
                 break;
         }
         // Recreate photo
         // In this step the photos also loses its metadata :(
         $newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
         imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
         imagejpeg($newSourceImg, $path, 100);
         // Free memory
         imagedestroy($sourceImg);
         imagedestroy($newSourceImg);
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     // SwapSize should be true when the image has been rotated
     // Return new dimensions in this case
     if ($swapSize === true) {
         $swapSize = $info['width'];
         $info['width'] = $info['height'];
         $info['height'] = $swapSize;
     }
     return $info;
 }
Example #7
0
}
// Config
if (!isset($dbName) || $dbName === '') {
    $error .= 'Error: No property for $dbName in config.php' . PHP_EOL;
}
if (!isset($dbUser) || $dbUser === '') {
    $error .= 'Error: No property for $dbUser in config.php' . PHP_EOL;
}
if (!isset($dbPassword)) {
    $error .= 'Error: No property for $dbPassword in config.php' . PHP_EOL;
}
if (!isset($dbHost) || $dbHost === '') {
    $error .= 'Error: No property for $dbHost in config.php' . PHP_EOL;
}
// Load settings
$settings = Settings::get();
// Settings
if (!isset($settings['username']) || $settings['username'] == '') {
    $error .= 'Error: Username empty or not set in database' . PHP_EOL;
}
if (!isset($settings['password']) || $settings['password'] == '') {
    $error .= 'Error: Password empty or not set in database' . PHP_EOL;
}
if (!isset($settings['sortingPhotos']) || $settings['sortingPhotos'] == '') {
    $error .= 'Error: Wrong property for sortingPhotos in database' . PHP_EOL;
}
if (!isset($settings['sortingAlbums']) || $settings['sortingAlbums'] == '') {
    $error .= 'Error: Wrong property for sortingAlbums in database' . PHP_EOL;
}
if (!isset($settings['plugins'])) {
    $error .= 'Error: No property for plugins in database' . PHP_EOL;
Example #8
0
 /**
  * Rotates and flips a photo based on its EXIF orientation.
  * @return array|false Returns an array with the new orientation, width, height or false on failure.
  */
 public function adjustFile($path, array $info)
 {
     // Excepts the following:
     // (string) $path = Path to the photo-file
     // (array) $info = ['orientation', 'width', 'height']
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     $swapSize = false;
     if (extension_loaded('imagick') && Settings::get()['imagick'] === '1') {
         switch ($info['orientation']) {
             case 3:
                 $rotateImage = 180;
                 break;
             case 6:
                 $rotateImage = 90;
                 $swapSize = true;
                 break;
             case 8:
                 $rotateImage = 270;
                 $swapSize = true;
                 break;
             default:
                 return false;
                 break;
         }
         if ($rotateImage !== 0) {
             $image = new Imagick();
             $image->readImage($path);
             $image->rotateImage(new ImagickPixel(), $rotateImage);
             $image->setImageOrientation(1);
             $image->writeImage($path);
             $image->clear();
             $image->destroy();
         }
     } else {
         $newWidth = $info['width'];
         $newHeight = $info['height'];
         $sourceImg = imagecreatefromjpeg($path);
         switch ($info['orientation']) {
             case 2:
                 // mirror
                 // not yet implemented
                 return false;
                 break;
             case 3:
                 $sourceImg = imagerotate($sourceImg, -180, 0);
                 break;
             case 4:
                 // rotate 180 and mirror
                 // not yet implemented
                 return false;
                 break;
             case 5:
                 // rotate 90 and mirror
                 // not yet implemented
                 return false;
                 break;
             case 6:
                 $sourceImg = imagerotate($sourceImg, -90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 $swapSize = true;
                 break;
             case 7:
                 // rotate -90 and mirror
                 // not yet implemented
                 return false;
                 break;
             case 8:
                 $sourceImg = imagerotate($sourceImg, 90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 $swapSize = true;
                 break;
             default:
                 return false;
                 break;
         }
         // Recreate photo
         $newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
         imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
         imagejpeg($newSourceImg, $path, 100);
         // Free memory
         imagedestroy($sourceImg);
         imagedestroy($newSourceImg);
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     // SwapSize should be true when the image has been rotated
     // Return new dimensions in this case
     if ($swapSize === true) {
         $swapSize = $info['width'];
         $info['width'] = $info['height'];
         $info['height'] = $swapSize;
     }
     return $info;
 }