diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index a57b83c..81881b5 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Response; +use Illuminate\Http\Request; use App\Http\Requests; use App\Model\Photo; @@ -32,6 +33,31 @@ class PhotoController extends Controller return redirect()->action('PhotoController@info',[$id]); } + public function duplicates($id=NULL) + { + return view('photo.duplicates', ['photos'=> Photo::notRemove()->where('duplicate',1)->paginate(1)]); + } + + public function duplicatesUpdate(Request $request) + { + foreach ($request->input('photo') as $id) + { + $po = Photo::findOrFail($id); + + // Set if duplicate + $po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL; + + // Set if flag + $po->flag = $request->input('flag.'.$id) ? 1 : NULL; + + // Set if delete + $po->remove = $request->input('remove.'.$id) ? 1 : NULL; + + $po->isDirty() AND $po->save(); + } + + return redirect()->action('PhotoController@duplicates','?page='.$request->input('page')); + } public function info($id) { return view('photo.view', ['photo'=> Photo::findOrFail($id)]); diff --git a/app/Http/routes.php b/app/Http/routes.php index 9d248b4..e05b620 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -19,8 +19,10 @@ Route::get('/', function () { Route::auth(); +Route::get('/duplicates/{id?}', 'PhotoController@duplicates')->where('id', '[0-9]+');; Route::get('/info/{id}', 'PhotoController@info')->where('id', '[0-9]+');; Route::get('/thumbnail/{id}', 'PhotoController@thumbnail')->where('id', '[0-9]+');; Route::get('/view/{id}', 'PhotoController@view')->where('id', '[0-9]+');; Route::post('/delete/{id}', 'PhotoController@delete')->where('id', '[0-9]+');; +Route::post('/duplicates', 'PhotoController@duplicatesUpdate')->where('id', '[0-9]+');; Route::post('/undelete/{id}', 'PhotoController@undelete')->where('id', '[0-9]+');; diff --git a/app/Model/Photo.php b/app/Model/Photo.php index 537770b..584b090 100644 --- a/app/Model/Photo.php +++ b/app/Model/Photo.php @@ -26,7 +26,8 @@ class Photo extends Model */ public function scopeNotRemove($query) { - return $query->where(function($query) { + return $query->where(function($query) + { $query->where('remove','!=',TRUE) ->orWhere('remove','=',NULL); }); @@ -39,20 +40,41 @@ class Photo extends Model */ public function scopeNotDuplicate($query) { - return $query->where(function($query) { + return $query->where(function($query) + { $query->where('duplicate','!=',TRUE) ->orWhere('duplicate','=',NULL); }); } - public function date_taken() { + public function date_taken() + { return $this->date_taken ? (date('Y-m-d H:i:s',$this->date_taken).($this->subsectime ? '.'.$this->subsectime : '')) : 'UNKNOWN'; } + /** + * Return the date of the file + */ + public function file_date($type,$format=FALSE) + { + switch ($type) + { + case 'a': $t = fileatime($this->file_path()); + break; + case 'c': $t = filectime($this->file_path()); + break; + case 'm': $t = filemtime($this->file_path()); + break; + } + + return $format ? date('d-m-Y H:i:s',$t) : $t; + } + /** * Determine the new name for the image */ - public function file_path($short=FALSE,$new=FALSE) { + public function file_path($short=FALSE,$new=FALSE) + { $file = $this->filename; if ($new) @@ -66,21 +88,24 @@ class Photo extends Model /** * Calculate a file path ID based on the id of the file */ - public function file_path_id($sep=3,$depth=9) { + public function file_path_id($sep=3,$depth=9) + { return trim(chunk_split(sprintf("%0{$depth}s",$this->id),$sep,'/'),'/'); } /** * Display the GPS coordinates */ - public function gps() { + public function gps() + { return ($this->gps_lat AND $this->gps_lon) ? sprintf('%s/%s',$this->gps_lat,$this->gps_lon) : 'UNKNOWN'; } /** * Return the image, rotated, minus exif data */ - public function image() { + public function image() + { $imo = $this->io(); if (array_key_exists('exif',$imo->getImageProfiles())) @@ -91,11 +116,17 @@ class Photo extends Model return $imo->getImageBlob(); } + public function info() + { + return $this->io() ? $this->io()->getImageProperties() : []; + } + /** * Return an Imagick object or attribute * */ - public function io($attr=NULL) { + protected function io($attr=NULL) + { if (is_null($this->_io)) $this->_io = new \Imagick($this->file_path()); @@ -105,11 +136,13 @@ class Photo extends Model /** * Calculate the GPS coordinates */ - public static function latlon(array $coordinate,$hemisphere) { + public static function latlon(array $coordinate,$hemisphere) + { if (! $coordinate OR ! $hemisphere) return NULL; - for ($i=0; $i<3; $i++) { + for ($i=0; $i<3; $i++) + { $part = explode('/', $coordinate[$i]); if (count($part) == 1) @@ -134,7 +167,8 @@ class Photo extends Model * * useID boolean Determine if the path is based on the the ID or date */ - public function moveable() { + public function moveable() + { // If the source and target are the same, we dont need to move it if ($this->file_path() == $this->file_path(FALSE,TRUE)) return FALSE; @@ -212,7 +246,7 @@ class Photo extends Model */ public function signature($short=FALSE) { - return $short ? static::signaturetrim($this->io()->getImageSignature()) : $this->io()->getImageSignature(); + return $short ? static::signaturetrim($this->signature) : $this->signature; } public static function signaturetrim($signature,$chars=6) @@ -251,32 +285,38 @@ class Photo extends Model /** * Return the extension of the image */ - public function type($mime=FALSE) { + public function type($mime=FALSE) + { return strtolower($mime ? File::mime_by_ext(pathinfo($this->filename,PATHINFO_EXTENSION)) : pathinfo($this->filename,PATHINFO_EXTENSION)); } /** * Find duplicate images based on some attributes of the current image */ - public function list_duplicate() { + public function list_duplicate($includeme=FALSE) + { $po = DB::table('photo'); - if ($this->id) + if ($this->id AND ! $includeme) $po->where('id','!=',$this->id); // Ignore photo's pending removal. - $po->where(function($query) { + $po->where(function($query) + { $query->where('remove','!=',TRUE) ->orWhere('remove','=',NULL); }); // Where the signature is the same - $po->where(function($query) { + $po->where(function($query) + { $query->where('signature','=',$this->signature); // Or they have the same time taken with the same camera - if ($this->date_taken AND ($this->model OR $this->make)) { - $query->orWhere(function($query) { + if ($this->date_taken AND ($this->model OR $this->make)) + { + $query->orWhere(function($query) + { $query->where('date_taken','=',$this->date_taken ? $this->date_taken : NULL); $query->where('subsectime','=',$this->subsectime ? $this->subsectime : NULL); @@ -290,6 +330,6 @@ class Photo extends Model } }); - return $po; + return $po->pluck('id'); } } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index e15706b..f83ab19 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -47,7 +47,7 @@