예제 #1
0
 /**
  * @return object|false Returns the results on success.
  */
 public static function execute($connection, $query, $function, $line)
 {
     // Check dependencies
     Validator::required(isset($connection, $query), __METHOD__);
     // Only activate logging when $function and $line is set
     $logging = $function === null || $line === null ? false : true;
     // Execute query
     $result = $connection->query($query);
     // Check if execution failed
     if ($result === false) {
         if ($logging === true) {
             Log::error($connection, $function, $line, $connection->error);
         }
         return false;
     }
     return $result;
 }
예제 #2
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;
 }
예제 #3
0
 private static function configCreateAction()
 {
     Validator::required(isset($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName'], $_POST['dbTablePrefix']), __METHOD__);
     Response::json(Config::create($_POST['dbHost'], $_POST['dbUser'], $_POST['dbPassword'], $_POST['dbName'], $_POST['dbTablePrefix']));
 }
예제 #4
0
 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!');
     }
 }
예제 #5
0
// Check if a function has been specified
if (!empty($fn)) {
    // Start the session and set the default timezone
    session_start();
    date_default_timezone_set('UTC');
    // Validate parameters
    if (isset($_POST['albumIDs']) && Validator::isAlbumIDs($_POST['albumIDs']) === false) {
        Response::error('Wrong parameter type for albumIDs!');
    }
    if (isset($_POST['photoIDs']) && Validator::isPhotoIDs($_POST['photoIDs']) === false) {
        Response::error('Wrong parameter type for photoIDs!');
    }
    if (isset($_POST['albumID']) && Validator::isAlbumID($_POST['albumID']) == false) {
        Response::error('Wrong parameter type for albumID!');
    }
    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
예제 #6
0
 private static function getPhotoArchiveAction()
 {
     Validator::required(isset($_GET['photoID']), __METHOD__);
     $photo = new Photo($_GET['photoID']);
     $photo->getArchive();
 }
예제 #7
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;
 }