diff --git a/app/Http/Controllers/Admin/AlbumController.php b/app/Http/Controllers/Admin/AlbumController.php index 941298c..eadd5be 100644 --- a/app/Http/Controllers/Admin/AlbumController.php +++ b/app/Http/Controllers/Admin/AlbumController.php @@ -494,6 +494,20 @@ class AlbumController extends Controller // Re-generate the URL path to ensure it's correct if the parent has changed if ($currentParentID != $album->parent_album_id) { + // Create a redirect if required + $redirectData = [ + 'album_id' => $album->id, + 'source_url' => sprintf('/%s', $album->url_path) + ]; + + if (strtolower($request->get('preserve_url_redirect')) == 'on' && AlbumRedirect::where($redirectData)->count() == 0) + { + $redirect = new AlbumRedirect(); + $redirect->fill($redirectData); + $redirect->save(); + } + + // Update the URL path $album->generateUrlPath(); } diff --git a/app/Http/Requests/StoreAlbumRedirectRequest.php b/app/Http/Requests/StoreAlbumRedirectRequest.php index 2607f07..236189d 100644 --- a/app/Http/Requests/StoreAlbumRedirectRequest.php +++ b/app/Http/Requests/StoreAlbumRedirectRequest.php @@ -16,6 +16,13 @@ class StoreAlbumRedirectRequest extends FormRequest return true; } + public function messages() + { + return [ + 'regex' => trans('validation.redirect_url_format') + ]; + } + /** * Get the validation rules that apply to the request. * @@ -24,7 +31,7 @@ class StoreAlbumRedirectRequest extends FormRequest public function rules() { return [ - 'source_url' => 'required|unique:album_redirects|max:255' + 'source_url' => 'required|unique:album_redirects|max:255|regex:/^\/[a-z0-9\-]+$/i' ]; } } \ No newline at end of file diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index fcec7c2..2c67ba7 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -82,6 +82,7 @@ return [ 'delete_user_warning' => 'This is a permanent action that cannot be reversed!', 'edit_album' => 'Edit photo album: :album_name', 'edit_album_action' => 'Edit album details', + 'edit_album_change_parent_add_alias' => 'Add a redirect to this album to prevent old links breaking.', 'edit_album_change_parent_warning' => 'Changing this album\'s parent will change the address used to access this album. This may break any bookmarks or links used by your visitors or search engines.', 'edit_album_intro' => 'Photo albums contain individual photographs in the same way as a physical photo album or memory book.', 'edit_album_intro2' => 'Complete the form below to edit the properties of the album: :album_name.', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 55ccb52..7716b02 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -116,5 +116,6 @@ return [ 'dir_empty' => 'The path must be an empty folder.', 'is_dir' => 'The folder must be a valid directory.', 'is_writeable' => 'Unable to write to this folder - please check permissions.', - 'photo_name_required' => 'The name field is required.' + 'photo_name_required' => 'The name field is required.', + 'redirect_url_format' => 'The URL must begin with a forward-slash and only contain a-z, A-Z, 0-9 and hyphens.' ]; diff --git a/resources/views/themes/base/admin/edit_album.blade.php b/resources/views/themes/base/admin/edit_album.blade.php index f95b938..a69dc65 100644 --- a/resources/views/themes/base/admin/edit_album.blade.php +++ b/resources/views/themes/base/admin/edit_album.blade.php @@ -54,8 +54,16 @@ -