Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * @return boolean Returns when album is public.
  */
 public function checkPassword($password)
 {
     // Check dependencies
     Validator::required(isset($this->albumIDs), __METHOD__);
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     // Execute query
     $query = Database::prepare(Database::get(), "SELECT password FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
     $albums = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     if ($albums === false) {
         return false;
     }
     // Get album object
     $album = $albums->fetch_object();
     // Album not found?
     if ($album === null) {
         Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find specified album');
         return false;
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     // Check if password is correct
     if ($album->password == '') {
         return true;
     }
     if ($album->password === crypt($password, $album->password)) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
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;
 }