Skip to content

Commit 57ee852

Browse files
committed
ability to remove images
1 parent de6e9ca commit 57ee852

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ After upgraded to latest version follows these steps:
143143

144144

145145
## Version History
146+
- 7.1.8 - ability to remove images from posts (this feature does not work for old posts)
146147
- 7.1.7 - updates CKEditor
147148
- 7.1.5 - minor fix for recent posts
148149
- 7.1.4 - updates fulltext search package which solves the search issue

src/Controllers/BlogEtcAdminController.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,41 @@ public function update_post(UpdateBlogEtcPostRequest $request, $blogPostId)
126126

127127
}
128128

129+
public function remove_photo($postSlug)
130+
{
131+
$post = BlogEtcPost::where("slug", $postSlug)->firstOrFail();
132+
133+
$path = public_path('/' . config("blogetc.blog_upload_dir"));
134+
if (!$this->checked_blog_image_dir_is_writable) {
135+
if (!is_writable($path)) {
136+
throw new \RuntimeException("Image destination path is not writable ($path)");
137+
}
138+
}
139+
140+
$destinationPath = $this->image_destination_path();
141+
142+
if (file_exists($destinationPath.'/'.$post->image_large)) {
143+
unlink($destinationPath.'/'.$post->image_large);
144+
}
145+
146+
if (file_exists($destinationPath.'/'.$post->image_medium)) {
147+
unlink($destinationPath.'/'.$post->image_medium);
148+
}
149+
150+
if (file_exists($destinationPath.'/'.$post->image_thumbnail)) {
151+
unlink($destinationPath.'/'.$post->image_thumbnail);
152+
}
153+
154+
$post->image_large = null;
155+
$post->image_medium = null;
156+
$post->image_thumbnail = null;
157+
$post->save();
158+
159+
Helpers::flash_message("Photo removed");
160+
161+
return redirect($post->edit_url());
162+
}
163+
129164
/**
130165
* Delete a post
131166
*
@@ -176,14 +211,13 @@ protected function processUploadedImages(BaseRequestInterface $request, BlogEtcP
176211
// this image size is enabled, and
177212
// we have an uploaded image that we can use
178213

179-
$uploaded_image = $this->UploadAndResize($new_blog_post, $new_blog_post->title, $image_size_details, $photo);
214+
$uploaded_image = $this->UploadAndResize($new_blog_post, $new_blog_post->slug, $image_size_details, $photo);
180215

181216
$new_blog_post->$size = $uploaded_image['filename'];
182217
$uploaded_image_details[$size] = $uploaded_image;
183218
}
184219
}
185220

186-
187221
// store the image upload.
188222
// todo: link this to the blogetc_post row.
189223
if (count(array_filter($uploaded_image_details))>0) {
@@ -192,9 +226,5 @@ protected function processUploadedImages(BaseRequestInterface $request, BlogEtcP
192226
'uploaded_images' => $uploaded_image_details,
193227
]);
194228
}
195-
196-
197229
}
198-
199-
200230
}

src/Views/blogetc_admin/posts/form.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@
8585

8686

8787
<div class='alert alert-warning'>
88-
If you want to add HTML content to be rendered, click source button at top left, and then paste your HTML snippet.
88+
If you want to add HTML content to be rendered, click source button at top left, and then paste your HTML snippet. (Youtube iFrames)
8989
</div>
9090
</div>
9191

9292

93-
94-
9593
@if(config("blogetc.use_custom_view_files",true))
9694
<div class="form-group">
9795
<label for="blog_use_view_file">Custom View File</label>
@@ -161,7 +159,9 @@
161159
<input class="form-control" type="file" name="{{$size_key}}" id="blog_{{$size_key}}"
162160
aria-describedby="blog_{{$size_key}}_help">
163161

164-
162+
@if($post->has_image($size_info['basic_key']))
163+
<a style="color: darkred" href="{{route("blogetc.admin.remove_photo", $post->slug)}}">Remove Image</a>
164+
@endif
165165
</div>
166166
@endforeach
167167

src/routes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
'BlogEtcAdminController@update_post')
6262
->name('blogetc.admin.update_post');
6363

64+
//Removes post's photo
65+
Route::get('/remove_photo/{slug}',
66+
'BlogEtcAdminController@remove_photo')
67+
->name('blogetc.admin.remove_photo');
6468

6569
Route::group(['prefix' => "image_uploads",], function () {
6670

0 commit comments

Comments
 (0)