This project is read-only.

Some Post As Private but Not All

Aug 30, 2010 at 3:02 AM

With the ability to make the blog private is there a way to make some post private but not all post?  My site is family blog and some of the post we like to reserve for family members only.  

Is this possible?

Aug 31, 2010 at 4:28 AM

I know I am asking a lot but does anyone have any ideas?

Aug 31, 2010 at 8:59 AM

I would consider making a private instance and a public instance of BlogEngine. And use Windows Live Writer to publish the same post to the two instances. You would then have to write the post only once, but publish it twice. I have written a post about multiple instances of BlogEngine here.

Aug 31, 2010 at 9:37 AM

One approach is to create a role (e.g. Family), and then create a Category (e.g. Family).  You can assign family members to the Family role (after you create an account for them), and then assign the "family" posts to the Family category (you could alternatively use Tags).

With the new version of BE you're using, you can easily create a new role on the Users tab in the control panel (right hand side is a link for Roles).  Once the role is created, you can assign users to the role.

To enforce the role, there's a couple of ways to do it, but I think the easiest would be to modify the "IsVisible" property in the Post class (in the BE core).  If you modified it to what's below, it would ensure that posts tied to the Family category can only be seen by users in the Family role.  After making this modification, recompiling the BE core would be required.

public bool IsVisible
		if (IsAuthenticated || (IsPublished && DateCreated <= DateTime.Now.AddHours(BlogSettings.Instance.Timezone)))
			bool isFamilyPost = Categories.Find(delegate(Category c)
				return c.Title.Equals("family", StringComparison.OrdinalIgnoreCase);
			}) != null;

			if (isFamilyPost)
				return Thread.CurrentPrincipal.IsInRole("Family");

			return true;

		return false;

Aug 31, 2010 at 10:25 PM

Can you suggest a way to keep the modified source code in sync with the official version ?

Sep 1, 2010 at 10:29 AM

It's not usually easy to do, but it also depends on the particular modifications.

It's good to always at least record/log what changes you've made, so you can re-implement those changes when updating to a newer version of BE.  If you don't have the changes logged somewhere, a program Beyond Compare is really helpful for comparing two folders to see which files are different, and the specific changes within each file.  With this, you would be comparing your modified version to the original version you started from to see what changes you previously made (if you don't remember what changes you made).

If you're looking to add additional functionality, that functionality can either be in a new class, or in some cases if the class within BE is a "partial class", then you can create your own partial class (for the same object), and add your additional functionality in that.  The two (or more) partial classes get merged into one class when compiled.  Probably for a lot of modification types, this scenario doesn't apply (but does in some cases).

Obviously it's best to try and make as many of the modifications within your own theme.  For example, I have a JS file in my theme that removes/hides some elements on pages that are outside of the theme.  So when these non-theme pages are loaded in the browser, the JS modifies/removes/changes some of the layout on those non-theme pages.  It's a little hacky :)

Right now I don't have any modifications outside my blog theme.  This is the ultimate for making upgrades thoughtless.

In some cases, if you have a request, we can modify BE to make something configurable or easier to modify from the outside so you don't need to re-add your modifications every time.

Sep 6, 2010 at 2:25 PM

Creating an instance of BlogEngine per target audience will allow you to select a theme that matches to that audience. What would you recommend modifying if you wanted to associate a theme to a Category ?

Sep 7, 2010 at 12:05 AM

The theme can be dynamically set in BlogBasePage as demonstrated here.  In OnPreInit, you can check what the current category is (by looking at the URL), and dynamically choose a theme based on that.