コード例 #1
0
ファイル: Database.php プロジェクト: windhamdavid/Lychee
 /**
  * Exits on error.
  * @return boolean Returns true when successful.
  */
 private function __construct($host, $user, $password, $name = 'lychee', $dbTablePrefix)
 {
     // Check dependencies
     Validator::required(isset($host, $user, $password, $name), __METHOD__);
     // Define the table prefix
     defineTablePrefix($dbTablePrefix);
     // Open a new connection to the MySQL server
     $connection = self::connect($host, $user, $password);
     // Check if the connection was successful
     if ($connection === false) {
         Response::error(self::connect_error());
     }
     if (self::setCharset($connection) === false) {
         Response::error('Could not set database charset!');
     }
     // Create database
     if (self::createDatabase($connection, $name) === false) {
         Response::error('Could not create database!');
     }
     // Create tables
     if (self::createTables($connection) === false) {
         Response::error('Could not create tables!');
     }
     // Update database
     if (self::update($connection, $name) === false) {
         Response::error('Could not update database and tables!');
     }
     $this->connection = $connection;
     return true;
 }
コード例 #2
0
ファイル: update_030000.php プロジェクト: windhamdavid/Lychee
<?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!');
}
コード例 #3
0
ファイル: Installation.php プロジェクト: windhamdavid/Lychee
 private static function initAction()
 {
     $return = array('status' => LYCHEE_STATUS_NOCONFIG);
     Response::json($return);
 }
コード例 #4
0
ファイル: Access.php プロジェクト: windhamdavid/Lychee
 protected static final function fnNotFound()
 {
     Response::error('Function not found! Please check the spelling of the called function.');
 }
コード例 #5
0
ファイル: Guest.php プロジェクト: windhamdavid/Lychee
 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!');
     }
 }
コード例 #6
0
ファイル: index.php プロジェクト: windhamdavid/Lychee
    if (isset($_POST['photoID']) && Validator::isPhotoID($_POST['photoID']) == false) {
        Response::error('Wrong parameter type for photoID!');
    }
    // Check if a configuration exists
    if (Config::exists() === false) {
        /**
         * Installation Access
         * Limited access to configure Lychee. Only available when the config.php file is missing.
         */
        Installation::init($fn);
        exit;
    }
    // Check if user is logged
    if (isset($_SESSION['login']) && $_SESSION['login'] === true && (isset($_SESSION['identifier']) && $_SESSION['identifier'] === Settings::get()['identifier'])) {
        /**
         * Admin Access
         * Full access to Lychee. Only with correct password/session.
         */
        Admin::init($fn);
        exit;
    } else {
        /**
         * Guest Access
         * Access to view all public folders and photos in Lychee.
         */
        Guest::init($fn);
        exit;
    }
} else {
    Response::error('No API function specified!');
}
コード例 #7
0
ファイル: Admin.php プロジェクト: windhamdavid/Lychee
 private static function setDropboxKeyAction()
 {
     Validator::required(isset($_POST['key']), __METHOD__);
     Response::json(Settings::setDropboxKey($_POST['key']));
 }
コード例 #8
0
ファイル: Photo.php プロジェクト: worksmarter/Lychee
 /**
  * Creats new photo(s).
  * Exits on error.
  * Use $returnOnError if you want to handle errors by your own.
  * @return string|false ID of the added photo.
  */
 public function add(array $files, $albumID = 0, $returnOnError = false)
 {
     // Check permissions
     if (hasPermissions(LYCHEE_UPLOADS) === false || hasPermissions(LYCHEE_UPLOADS_BIG) === false || hasPermissions(LYCHEE_UPLOADS_THUMB) === false) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'An upload-folder is missing or not readable and writable');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('An upload-folder is missing or not readable and writable!');
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     switch ($albumID) {
         case 's':
             // s for public (share)
             $public = 1;
             $star = 0;
             $albumID = 0;
             break;
         case 'f':
             // f for starred (fav)
             $star = 1;
             $public = 0;
             $albumID = 0;
             break;
         case 'r':
             // r for recent
             $public = 0;
             $star = 0;
             $albumID = 0;
             break;
         default:
             $star = 0;
             $public = 0;
             break;
     }
     // Only process the first photo in the array
     $file = $files[0];
     // Check if file exceeds the upload_max_filesize directive
     if ($file['error'] === UPLOAD_ERR_INI_SIZE) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'The uploaded file exceeds the upload_max_filesize directive in php.ini');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('The uploaded file exceeds the upload_max_filesize directive in php.ini!');
     }
     // Check if file was only partially uploaded
     if ($file['error'] === UPLOAD_ERR_PARTIAL) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'The uploaded file was only partially uploaded');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('The uploaded file was only partially uploaded!');
     }
     // Check if writing file to disk failed
     if ($file['error'] === UPLOAD_ERR_CANT_WRITE) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Failed to write photo to disk');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('Failed to write photo to disk!');
     }
     // Check if a extension stopped the file upload
     if ($file['error'] === UPLOAD_ERR_EXTENSION) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'A PHP extension stopped the file upload');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('A PHP extension stopped the file upload!');
     }
     // Check if the upload was successful
     if ($file['error'] !== UPLOAD_ERR_OK) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Upload contains an error (' . $file['error'] . ')');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('Upload failed!');
     }
     // Verify extension
     $extension = getExtension($file['name'], false);
     if (!in_array(strtolower($extension), self::$validExtensions, true)) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Photo format not supported');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('Photo format not supported!');
     }
     // Verify image
     $type = @exif_imagetype($file['tmp_name']);
     if (!in_array($type, self::$validTypes, true)) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Photo type not supported');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('Photo type not supported!');
     }
     // Generate id
     $id = generateID();
     // Set paths
     $tmp_name = $file['tmp_name'];
     $photo_name = md5($id) . $extension;
     $path = LYCHEE_UPLOADS_BIG . $photo_name;
     // Calculate checksum
     $checksum = sha1_file($tmp_name);
     if ($checksum === false) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Could not calculate checksum for photo');
         if ($returnOnError === true) {
             return false;
         }
         Response::error('Could not calculate checksum for photo!');
     }
     // Check if image exists based on checksum
     if ($checksum === false) {
         $checksum = '';
         $exists = false;
     } else {
         $exists = $this->exists($checksum);
         if ($exists !== false) {
             $photo_name = $exists['photo_name'];
             $path = $exists['path'];
             $path_thumb = $exists['path_thumb'];
             $medium = $exists['medium'] === '1' ? 1 : 0;
             $exists = true;
         }
     }
     if ($exists === false) {
         // Import if not uploaded via web
         if (!is_uploaded_file($tmp_name)) {
             if (!@copy($tmp_name, $path)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not copy photo to uploads');
                 if ($returnOnError === true) {
                     return false;
                 }
                 Response::error('Could not copy photo to uploads!');
             } else {
                 @unlink($tmp_name);
             }
         } else {
             if (!@move_uploaded_file($tmp_name, $path)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not move photo to uploads');
                 if ($returnOnError === true) {
                     return false;
                 }
                 Response::error('Could not move photo to uploads!');
             }
         }
     } else {
         // Photo already exists
         // Check if the user wants to skip duplicates
         if (Settings::get()['skipDuplicates'] === '1') {
             Log::notice(Database::get(), __METHOD__, __LINE__, 'Skipped upload of existing photo because skipDuplicates is activated');
             if ($returnOnError === true) {
                 return false;
             }
             Response::warning('This photo has been skipped because it\'s already in your library.');
         }
     }
     // Read infos
     $info = $this->getInfo($path);
     // Use title of file if IPTC title missing
     if ($info['title'] === '') {
         $info['title'] = substr(basename($file['name'], $extension), 0, 30);
     }
     if ($exists === false) {
         // Set orientation based on EXIF data
         if ($file['type'] === 'image/jpeg' && isset($info['orientation']) && $info['orientation'] !== '') {
             $adjustFile = $this->adjustFile($path, $info);
             if ($adjustFile !== false) {
                 $info = $adjustFile;
             } else {
                 Log::notice(Database::get(), __METHOD__, __LINE__, 'Skipped adjustment of photo (' . $info['title'] . ')');
             }
         }
         // Set original date
         if ($info['takestamp'] !== '' && $info['takestamp'] !== 0) {
             @touch($path, $info['takestamp']);
         }
         // Create Thumb
         if (!$this->createThumb($path, $photo_name, $info['type'], $info['width'], $info['height'])) {
             Log::error(Database::get(), __METHOD__, __LINE__, 'Could not create thumbnail for photo');
             if ($returnOnError === true) {
                 return false;
             }
             Response::error('Could not create thumbnail for photo!');
         }
         // Create Medium
         if ($this->createMedium($path, $photo_name, $info['width'], $info['height'])) {
             $medium = 1;
         } else {
             $medium = 0;
         }
         // Set thumb url
         $path_thumb = md5($id) . '.jpeg';
     }
     $values = array(LYCHEE_TABLE_PHOTOS, $id, $info['title'], $photo_name, $info['description'], $info['tags'], $info['type'], $info['width'], $info['height'], $info['size'], $info['iso'], $info['aperture'], $info['make'], $info['model'], $info['shutter'], $info['focal'], $info['takestamp'], $path_thumb, $albumID, $public, $star, $checksum, $medium);
     $query = Database::prepare(Database::get(), "INSERT INTO ? (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum, medium) VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')", $values);
     $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     if ($result === false) {
         if ($returnOnError === true) {
             return false;
         }
         Response::error('Could not save photo in database!');
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     return $id;
 }