View previous topic :: View next topic |
Author |
Message |
MiniSizeIt
Joined: 02 Nov 2002 Posts: 70
|
Posted: Tue Nov 05, 2002 4:52 am Post subject: [Request] People Who Are Not Logged In See Nothing |
|
|
Hello.
I use my weblog as a journal with my g/f, and we are the only two registered people and I have disabled new member registration. I would like a little something to redirect guests to say this weblog is private, please login. This is exactly what I need to have b2 the perfect script for me. Any help or workarounds would be greatly appreciated!
Thanks in advance. |
|
Back to top |
|
 |
MiniSizeIt
Joined: 02 Nov 2002 Posts: 70
|
Posted: Tue Nov 05, 2002 5:22 am Post subject: |
|
|
I have been forced to shut down my b2 because people snooping the site and viewing entries that are private. I'll open it up once I get a workaround or when private entries is included in b2. If that's not soon, I might have to find a totally new service, so please help if you can |
|
Back to top |
|
 |
jasonvelocity
Joined: 10 Feb 2002 Posts: 11 Location: colorado springs - co
|
|
Back to top |
|
 |
michel v Site Admin
Joined: 25 Jan 2002 Posts: 799 Location: Corsica
|
Posted: Thu Nov 07, 2002 3:08 am Post subject: |
|
|
Actually, it so happens that you can protect entries in b2 0.6.1, with this new feature: filter functions!
--
Short intro on filters (I mean to post that as its own thread sometime):
Basically, you can set functions to be run over some template tags before they're displayed, for example like this:
[php:1:b8bb6f2968]<?php
/* this will capitalise all the text displayed by the_content() */
add_filter('the_content', 'strtoupper');
?>[/php:1:b8bb6f2968]
Currently the functions you can use in filters must allow only one argument: a string. They must also return a string.
So what you can do is something like this in your template (after you included blog.header.php):
[php:1:b8bb6f2968]<?php
function b2_private_entry($string) {
$password = 'jesusatemyballs';
if (stristr($string, '<private />')) {
if (trim($_POST['b2_password']) != $password) {
$form = 'This is a private entry.<br />To view private entries on this website, please enter the password in the field below:<br /><form method="POST"><input type="password" name="b2_password" /><input type="submit" value="OK" /></form>';
return $form;
}
}
return preg_replace('#\<private \/\>#is', '', $string);
}
add_filter('the_content', 'b2_private_entry');
?>[/php:1:b8bb6f2968]
Then you'll only need to add the tag <private /> in an entry to make it private, and your visitor would have to enter the password in the form to see your private entries.
You can improve the password handling if you want, add a cookie for it to avoid the visitor to have to enter the password each time.
Note that this doesn't protect the_title() (make a similar filter for it), and the RSS files. For the RSS files you should edit them and add a similar filter (though without the form since aggregators couldn't do anything with it) that would just return 'this is a private entry'.
I hope this helps. I haven't tested it, but it should work.
Update: I have tested it, in a modified manner (it would hide any entry's content that has 'CSS' in it) here: http://tidakada.com/indexjesus.php - password is 'jesusatemyballs' (without the quotes). |
|
Back to top |
|
 |
MiniSizeIt
Joined: 02 Nov 2002 Posts: 70
|
Posted: Thu Nov 07, 2002 6:25 am Post subject: |
|
|
Thanks jason, I already saw that post and since we have numerous categories that need to be private, I'm not sure how easy that'd work out.
michel v, thanks for the great post. I've very new to PHP and don't really understand ways to further the coding you posted. However password protection for posts is a great feature. But I'm still looking for a way to password protect all posts by a certain user or to be able to choose who can view my posts. An option in each Member's Control Panel such as a friends list would be awesome. People I include in my list would have the ability to view my list while all others don't even see them. Plus you could have another option only members could see it, and not guests. And a feature to set it totally public.
Thanks! I appreciate you looking into it for me  |
|
Back to top |
|
 |
michel v Site Admin
Joined: 25 Jan 2002 Posts: 799 Location: Corsica
|
Posted: Thu Nov 07, 2002 3:02 pm Post subject: |
|
|
MiniSizeIt wrote: | But I'm still looking for a way to password protect all posts by a certain user or to be able to choose who can view my posts. An option in each Member's Control Panel such as a friends list would be awesome. People I include in my list would have the ability to view my list while all others don't even see them. Plus you could have another option only members could see it, and not guests. And a feature to set it totally public. |
Errr, I may introduce that kind of feature in 1.0 but... from what you're describing you should just use LiveJournal!
Then again, if someone wants to further the above code, it should be pretty easy to make it password-protect each posts by author X. |
|
Back to top |
|
 |
MiniSizeIt
Joined: 02 Nov 2002 Posts: 70
|
Posted: Thu Nov 07, 2002 9:45 pm Post subject: |
|
|
Yeah I looked into LiveJournal and it's not nearly as cool and as fun to play with compared to b2
I just wish I knew PHP well enough to edit and create new features. I'll try to learn PHP and MySQL in the coming months, and maybe even contribute by making hacks and such. But for now I'm just relying on new features in newer versions or hacks created by users.
If anyone can help me out, I'd love it.
Thanks! |
|
Back to top |
|
 |
Reese
Joined: 07 Sep 2002 Posts: 60
|
Posted: Thu Feb 20, 2003 8:25 pm Post subject: |
|
|
Edit: I got it working, thanks to a lovely person.
However, I'm still curious to figure out how I could add in that cookie feature.
Last edited by Reese on Wed Feb 26, 2003 7:41 am; edited 1 time in total |
|
Back to top |
|
 |
k9underdog
Joined: 25 Feb 2003 Posts: 1
|
Posted: Tue Feb 25, 2003 11:50 pm Post subject: |
|
|
Well... I've came with a much more simpller sollution.
First step: open your b2config.php file and just set
Code: | $users_can_register = 0; |
Second step: edit blog.header.php and on line 2 add:
Code: | if(!isset($_COOKIE['cafeloguser']) || $_COOKIE['cafeloguser'] == '') {
Header('Location: b2login.php');
} |
Since this file is included in every file... it will check if you are logged in, and if you're not, it'll take you to the login page.
You can try mine @ http://www.badmodafocas.com/blog/ although I don't think you'll be able to see anything.
If there are any flaws or any way around this let me know. I just did this, so it's still in "testing" phase.
PS: I also needed it to serve the same purpose =P Good luck with your relationship |
|
Back to top |
|
 |
Reese
Joined: 07 Sep 2002 Posts: 60
|
Posted: Wed Feb 26, 2003 12:45 am Post subject: |
|
|
That would be a good solution for MiniSizeIt...still waiting to figure out where I went wrong, though. |
|
Back to top |
|
 |
nelg
Joined: 06 Mar 2003 Posts: 1
|
Posted: Thu Mar 06, 2003 9:18 am Post subject: Thinking of building this functionality |
|
|
Yeah, it would be really good if users could login and have a list of friends, or friends email addresses, that are allowed to view the blog (and it would automatically authenticate them when they create and account, and cookie it so they don't have to login all the time)
I am thinking of building this, if I can't find a solution for it, as I have private stuff on my blog as well, am thinking a checkbox, or group of users, that I can configure on a post by post basis would be good, as I do have some public posts, and some private.
Comments, and if anyone else is building this, I am happy to give them a hand rather than do it all myself, as I will have to get familular with B2 code.
Cheers
Glen |
|
Back to top |
|
 |
livediary
Joined: 12 Jan 2003 Posts: 15 Location: Austin, TX
|
Posted: Sun Mar 16, 2003 8:51 pm Post subject: cookie feature fixed? |
|
|
So has anyone tried out the cookie feature that michel v mentioned---so that users wouldn't have to enter the password in the form every time? _________________ www.live-diary.com |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1274 Location: Oregon
|
Posted: Mon Mar 17, 2003 4:33 am Post subject: Re: cookie feature fixed? |
|
|
livediary wrote: | So has anyone tried out the cookie feature that michel v mentioned---so that users wouldn't have to enter the password in the form every time? |
Refer to http://www.php.net/manual/en/function.setcookie.php for setcookie function. _________________ Michael P.
 |
|
Back to top |
|
 |
livediary
Joined: 12 Jan 2003 Posts: 15 Location: Austin, TX
|
Posted: Mon Mar 17, 2003 4:37 am Post subject: |
|
|
Thanks, I'll have to check that out.  _________________ www.live-diary.com |
|
Back to top |
|
 |
Gadget Girl
Joined: 25 Jan 2002 Posts: 305 Location: Virginia
|
Posted: Tue Apr 08, 2003 1:41 pm Post subject: .RSS and title |
|
|
Thank you Michel for the modification for the entry, now, how do I and where do I place what for the .RSS and the title?
Thanks,
Sara |
|
Back to top |
|
 |
|