Recent Topics

1 Jul 02, 2008 09:37    

My b2evolution Version: 2.x

have any plugin can add the password for new post?

user must enter correct password to see the post?

2 Jul 02, 2008 14:03

Welcome to the forums!

I made a hack, you can test it here http://ru.b2evo.net/demo/blogs/blog2.php/2008/07/01/-8
Post password: a02f883f6d5e580f339260fc13dec82d

When you create a post the password is generated from post ID and key phrase and displayed to you. Write it somewhere because this simple hack doesn't store passwords.
Post content should look like

Warning message
<!--more-->
Post content

Warning message will be shown in search and post list modes.

1. Edit file /inc/items/items.ctrl.php line 316

// Execute or schedule notifications & pings:
$edited_Item->handle_post_processing();

$Messages->add( T_('Post has been created.'), 'success' );

// Generate post password
gen_post_password( $edited_Item->ID );

2. Edit skin file. In my case it's /skins/evopress/single.main.php lines 116-122

//Post password hack
param( 'post_password', 'string' );
if( check_post_password( $Item->ID, $post_password ) )
{	// We have a valid password
	// Display post content
	skin_include( '_item_content.inc.php', array(
			'image_size'	=>	'fit-400x320',
		) );
}
else
{	// Display password form
	post_password_form();
}

3. Create new file /conf/_config_TEST.php with this content

$password_key = 'put some random text here';

function check_post_password( $Item_ID, $post_password )
{
	global $password_key;
	
	if( $post_password == md5($Item_ID.$password_key ) )
	{  return true;  }
				
	return false;
}


function gen_post_password( $Item_ID )
{
	global $password_key, $Messages;
	$Messages->add( T_('Post password: ').md5($Item_ID.$password_key), 'success' );
}


function post_password_form()
{
	echo '<div class="error" style="clear:both; margin:50px 0; padding:20px">
			<b>Enter password</b>
			<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
				<input name="post_password" type="password" />
				<input type="submit" value="View post content!" />
			</form></div>';
}

3 Jul 04, 2008 01:25

ok, thx

but if i need to set the password as i like, how to do that?

4 Jul 04, 2008 01:36

If you are going to set one password for all posts it pretty easy, but if you need custom passwords you would have to store them in DB.

This hack does't have to "know" passwords or get them from DB.

If you don't like the length just cut passwords to 4-6 symbols.

5 Jul 04, 2008 01:44

because i want to lock the post with some same password for some people..

so, can i set the password as i like?

thx

sorry for my bad english

6 Jul 04, 2008 05:38

If you want to use custom passwords you have to wait until I make a plugin, it's not going to be soon.

8 Jul 05, 2008 19:26

Does "protected" not work for your needs? A protected post is only visible by people who are registered AND members of the blog the post is in.

9 Jul 05, 2008 19:53

EdB wrote:

Does "protected" not work for your needs? A protected post is only visible by people who are registered AND members of the blog the post is in.

But then you must be logged in to that blog.
You don't see the 'warning 'here is a post' if you are not logged in.

10 Jul 05, 2008 21:13

True, but NoName didn't actually ask for password-protecting only part of a post so I thought maybe the answer here is a bit more complicated than it needs to be.


Form is loading...