Sorry, I thought I had solved this but the problem is still there.
I've updated october to build 428, and also updated all the plugins. Then I've noticed that unpublished blog posts are showing on the frontend.
I have all my plugins as git submodules. How can I fix this?
@rangrage for future reference it's not helpful to edit an issue removing all information about it because some people in the future may have the same issue as you. Instead, post what you did to fix it.
In regards to this issue as it stands right now, there is not enough information here to do anything about. Please post your octobercms build version and your plugin versions and then provide as much information as possible on the problem. Help us help you.
@LukeTowers sorry about that, will do in future. Thanks.
I am currently on build 428
Rainlab Blog plugin version 1.2.19
I pulled the octobercms repo, ran composer update, which set the PHP version to 7.0 and Laravel 5.5.
Then updated all plugins via git submodule update.
Then ran php artisan october:update
Finally tested all plugins on the site backend and frontend, everything is working as expected, however I've noticed that the unpublished blog posts are now showing on the frontend.
Please let me know if you required any additional information.
Thanks,
@rangrage what code do you use to display the posts on the frontend?
I'm using the blogPosts component
[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "{{ :slug }}"
postsPerPage = 12
noPostsMessage = "There are currently no items to display!"
sortOrder = "published_at desc"
categoryPage = "news"
postPage = "news-post"
And in the html
{% for post in posts %}
<div>
<div class="uk-card bg-comm-green text-white mylink">
<a href="{{ post.url }}">
<div class="uk-card-media-top">
<img src="
{% if post.featured_images.isEmpty() %}
{{ "site/placeholder.jpg"|media }}
{% else %}
{{ post.featured_images.first().getPath() }}
{% endif %}
" class="uk-width-1-1">
</div>
</a>
<div class="uk-card-body uk-padding-small">
<a href="{{ post.url }}"><h3 class="text-white">{{ post.title }}</h3></a>
<hr>
<br>
<div class="uk-position-bottom mylink">
<p class="uk-text-small uk-text-right" style="padding-right:15px;">
Posted
{% if post.categories.count %} in {% endif %}
{% for category in post.categories %}
<a href="{{ category.url }}">{{ category.name }}</a>{% if not loop.last %}, {% endif %}
{% endfor %}
on {{ post.published_at|date('M d, Y') }}
</p>
</div>
</div>
</div>
</div>
{% endfor %}
@rangrage are you able to take a look at the blogPosts component to figure out why this is happening?
@LukeTowers this seems to be causing the issue, not sure why it was added here and can't see what's the relation to the checkEditor() function at line 218;
protected function listPosts()
{
$category = $this->category ? $this->category->id : null;
/*
* List all the posts, eager load their categories
*/
$isPublished = !$this->checkEditor();
$posts = BlogPost::with('categories')->listFrontEnd([
'page' => $this->property('pageNumber'),
'sort' => $this->property('sortOrder'),
'perPage' => $this->property('postsPerPage'),
'search' => trim(input('search')),
'category' => $category,
'published' => $isPublished,
'exceptPost' => $this->property('exceptPost'),
]);
Removing the $isPublished fixes the problem. This is already handled by the Model so I can't understand the need for it here.
Fixed here
protected function listPosts()
{
$category = $this->category ? $this->category->id : null;
/*
* List all the posts, eager load their categories
*/
$posts = BlogPost::with('categories')->listFrontEnd([
'page' => $this->property('pageNumber'),
'sort' => $this->property('sortOrder'),
'perPage' => $this->property('postsPerPage'),
'search' => trim(input('search')),
'category' => $category,
'exceptPost' => $this->property('exceptPost'),
]);
@rangrage ah, I see what the issue is. Try viewing your site in incognito mode or when not logged in. https://github.com/rainlab/blog-plugin/pull/316 changed it so that backend users that are logged in can view the unpublished post in order to preview it before making it live.
Aah! so the bug turns out to be a feature actually.
Yes, I've tested this and confirm it's only view-able when logged in.
Thanks for your assistance @LukeTowers :)
Not a problem @rangrage :)
Is this problem fixed yet? Doesn't seem like it has been since I'm updated to the latest revision and still face this. I think a version bump may be needed?
@SaifurRahmanMohsin yes it is fixed. If you read the comments above from LukeTowers, this is actually a feature for logged-in backend users to view unpublished posts before making them live.
Wow. That is actually handy. I think it would be a good idea to have a message below in logged in mode alone to show that it shows up only when logged in and a button to jump directly into the publish tab of that post in the backend.
@SaifurRahmanMohsin see suggestion from @daftspunk here: https://github.com/rainlab/blog-plugin/pull/316#issuecomment-304833622. Feel free to make a PR to improve the UX of logged in backend users previewing the posts.
@LukeTowers said:
@rangrage ah, I see what the issue is. Try viewing your site in incognito mode or when not logged in. #316 changed it so that backend users that are logged in can view the unpublished post in order to preview it before making it live.
Well, I don't know.
While I understand the necessity to be able to see what unpublished posts look like, it's clearly not the case for Post Lists, and is very confusing.
which is why I opened #359 ...
I ended up overriding the partial for the Post List component to make sure I can program a post to appear automatically on a given time/date. Now I see incognito mode would've worked as well.
For anyone looking for how to do this:
This is the quick tutorial for overriding partials. (it's simply duplicating default.htm to the right partial folder).
Then, just add these two lines after the {% for post in posts %} loop:
{% for post in posts %}
{% if post.published %}
{% if ("now"|date('Y-m-d H:i', "America/Toronto")) > (post.published_at | date('Y-m-d H:i')) %}
<li>
Close your two ifs before the {% else %} tag.
PS. (Remember to replace America/Toronto with your timezone)
For those who look for quick solution (remove confusion for yourself), just use this code for post title with preferred icon:
<h5>
<a href="{{ post.url }}">{{ post.title }}</a>
{{ post.published? '':'<i class="fas fa-lock text-danger pl-2"></i>'|raw }}
</h5>
When you are loggedIn in BackEnd, you can notice the difference easily...
Most helpful comment
@SaifurRahmanMohsin yes it is fixed. If you read the comments above from LukeTowers, this is actually a feature for logged-in backend users to view unpublished posts before making them live.