Page 1 of 1
help with plugin to display only posts by specific UserGroup
Posted: Mon Dec 07, 2009 8:42 pm
by perlnerd
I am working on getting a version of Serendipity 1.5-beta1 running which supports self registration of multiple users. I have already written or modified several plugins to do what I want, but I am stuck right now.
I'm having a hard time figuring out how to hook into the default display of Entires on the blog index page and have it only display entries by members of a specific Group.
Any pointers, insights, hints, or code snippets appreciated.
Thanks
Clint
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 11:38 am
by garvinhicking
Hi!
For that, you would need to add the specific ACL parts to the main SQL query. You could have a look at the entryproperties plugin, it does a similar query already to only displays entries for all groups that a user is member of on which he has read privileges on a blog entries' category.
You would need to write a SQL subquery/join that combines the blog entries on the authorid column, and filters out only those, that have a group membership that intersects with the authorgroups of the currently logged in user.
However, I personally wouldn't do it this way; I would try to create categories that match your usergroups, and then simply forward the user to the category overview page of his primary group membership. This way, you'd have proper read+write privileges of blog categories, and wouldn't need to write any SQL code...
HTH,
Garvin
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 2:32 pm
by perlnerd
Garvin,
Thanks for the info. What I want is for the blog index and subsequent pages to only feature posts by a specific group but anyone can see them. On our site any registered user will be able to have a blog but only a select group of bloggers will have their entries show up on the main page. It's somewhat reminiscent of how daily kos does things.
garvinhicking wrote:Hi!
You would need to write a SQL subquery/join that combines the blog entries on the authorid column, and filters out only those, that have a group membership that intersects with the authorgroups of the currently logged in user.
.
I agree, that I need a subquery/join, but I don't need to restrict viewing by the authorgroup of the current user. In the most basic sense I need to add something like this to the where clause of the default query.
Code: Select all
//very simplistic but the basic idea of what I want to do
where ... AND (serendipity_authorgroups.authorid = serendipity_entries.authorid AND serendipity_authorgroups.groupid = 5)
// 5 is the id of the group which will have it's posts featured.
I'm just not sure how to get that into the default query.
Regular user's posts will be accessible via links in sidebar plugins I have already written.
I won't need near the functionality of the entryproperties plugin, but I'll have a good look at it to see if I can find a chunk that will do what I need.
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 2:41 pm
by garvinhicking
Hi!
Hm, in that case, I'd really suggest you make use of the existing category views to group entries. Making it based on usergroups is possible, but really a lot of work
So it would be easier to create a plugin that automatically selects a specific category for a blogposting, basted on the usergroup membership?!
As for the plugin, you need to hook into the event 'frontend_fetchentries' and add to $eventData['and']. That's a variable that holds a SQL string that is added to the "WHERE" part. Have a look into include/functions_entries.inc.php, serendipity_fetchEntries() where $cond is filled and used.
(The entryproperties plugin actually does it in a similar fashion, so that's a good plugin to look into for you, right now)
HTH,
Garvin
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 2:54 pm
by perlnerd
Thanks Garvin,
Ok, what I want to do is a little (a lot?) more difficult than I had anticipated. It looks like I could create a category that only the featured bloggers can write to, and then only display that category on the main index (using serendipity_event_startcat).
We weren't going to have categories on the blog, but one for the featured bloggers and one for everyone else would be fine. Is there a way to force a blog post to a specific category?
Clint
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 2:58 pm
by garvinhicking
Hi!
You could also hide the sidebar category plugin, and could edit the entries.tpl template to remove all references to categories, then all would appear as being not category related?
You can force a blog post to a category, have a look at the serendipity_event_entrycheck plugin. You could borrow from that code to make it fix a category to a specific one (i.e. dependant on the user author group).
HTH,
Garvin
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 3:10 pm
by perlnerd
garvinhicking wrote:You could also hide the sidebar category plugin, and could edit the entries.tpl template to remove all references to categories, then all would appear as being not category related?
Yes, exactly. Now that I think about it this is definitely the way to go. Serendipity is so powerful, that it was making this more difficult than it needed to be. Thanks so much for the nudge in the right direction.
garvinhicking wrote:You can force a blog post to a category, have a look at the serendipity_event_entrycheck plugin. You could borrow from that code to make it fix a category to a specific one (i.e. dependant on the user author group).
I'll have a look at that plugin. I think I'll just have the regular users not have any category and the special users will have the option of choosing their special category or none at all.
Thanks again.
Clint
Re: help with plugin to display only posts by specific UserGroup
Posted: Tue Dec 08, 2009 3:25 pm
by garvinhicking
Hi!
No problem, I'm glad that the category solution seems a doable approach to be. If you face any trouble with that route, let me know, and we'll try to work out the kinks together.
Best regards,
Garvin