This is a little something I did for fun as a companion to the ScriptyGoddess Restricted Access Posts hack.
Due to a situation I won't bother going into detail on, I started thinking about how I might protect certain text within the entries on my journal. I already use the SG hack to protect entries which I place in a restricted category, so I began looking at that code to see how I could adapt it to recognize that I wanted certain pieces of text within an otherwise unrestricted entry to not display unless the user already had access to the completely restricted entries on my site.
Are you with me so far? Say I have an entry with text like this:
There are a lot of coworkers who I do not like.Maybe I don't want just anyone who runs across my journal to see my statement about Angela (especially Angela if she knows her way around Google).
For example, that bitch Angela drives me nuts.
But I have learned to get along with everyone.
So this is what I came up with.
Required: the Process Tags plugin (and of course, the aforementioned SG hack already installed on your site)
I first created two new Template Modules, begin_restricted and end_restricted:
begin_restricted
$accessallowed = FALSE;
if (in_array($ip, $array, TRUE) || in_array($cookievalue, $array, TRUE))
{
$accessallowed = TRUE;
}
if ($accessallowed)
{
PRINT "
end_restricted
} ?>
These are the pieces of code taken (and modified) from the SG hack.
Then, I invoked the process tags plugin within the Individual Entry Archive:
<MTEntryMore process_tags="1">
The only thing left to do is call the modules in my entry around the restricted text:
There are a lot of coworkers who I do not like.Now, when I publish the entry, the Process Tags plugin pulls in the necessary PHP code to block the display of my insult to Angela if the reader doesn't have the cookie from the SG hack which gives them full access to my journal:
<MTInclude module="begin_restricted">
For example, that bitch Angela drives me nuts.
<MTInclude module="end_restricted">
But I have learned to get along with everyone.
There are a lot of coworkers who I do not like.That's all they see. View Source merely displays some empty <p> and </p> tags, due to MT's Convert Breaks formatting option.
But I have learned to get along with everyone.
I could probably also use an ELSE statement to alert them to the restriction, offer access, etc., but I think that's more distraction than I want to insert into my entries. Perhaps for larger blocks of text, I'll create some alternate modules with these options; or explain elsewhere on my site about the restricted access feature.
Also, I could have avoided the plugin altogether and just used PHP includes for the two pieces of code, but I decided it would be easier to remember the module names than the full path to the files every time I wanted to use them.
I do have to be careful with this, of course - blocking too much might cause the entry to not make sense to the reader who doesn't have full access. But I just wanted to see if I could figure out how to do it; whether I actually make use of it or not remains to be seen.
Perhaps there's a way to achieve this purely in PHP. But being a neophyte in that area, I have no idea how to mark the sections of code I want to be restricted in a way that the script will recognize them, and maybe doing so is more trouble than it's worth. So anyone who does know PHP would really tickle my fancy if they could show me another way to do this.
P.S. I don't really have a co-worker named Angela. =)
Update 11.08.03: I have modified the code for the begin_restricted module above to make it a little less redundant (I was repeating some variables and code unnecessarily).

