Recent Topics

1 Sep 07, 2005 23:27    

It works on version 0.9.0.12/0.9.1

Some words in advance, I am totally new in PHP and any other language. All I done is copy and combine different mods and hark. I just wanna link some useful function togather.

In b2evo, there is a function allows users registering by themselves. Well that seems good but for nothing as users have to wait for admin's permission. Another dispointment is that, as long as an user was assigned right to write/edit, he was also given the right to edit other people's articles, including admin's.
Simple steps solve the two problem:

The first hark is from Barkingstar's original version,but work perfectly with b2evo 0.9.0.12 (http://forums.b2evolution.net/viewtopic.php?t=2952&highlight=allowing+post+blogs+registering)

Step1,
Open /blogs/htsrv/register.php and go down to this bit (around line 130) find out this code:

send_mail( $admin_email, T_('new user registration on your blog'), $message, $notify_from );

       locale_restore_previous(); 

      // Display confirmation screen: 
      require( dirname(__FILE__).'/_reg_complete.php' ); 
      exit(); 
      break; // case 'register' 

Now insert the following code like so:

send_mail( $admin_email, T_('new user registration on your blog'), $message, $notify_from );

		locale_restore_previous();


		
		// HORRIBLE CLUDGE

      $loginid = $DB->get_var( "SELECT ID FROM evo_users WHERE user_login='$login'" );
      $DB->query( "INSERT INTO evo_blogusers (bloguser_blog_id,bloguser_user_id,bloguser_perm_poststatuses,bloguser_ismember) VALUES('1','$loginid','published','1')" );
      $DB->query( "INSERT INTO evo_blogusers (bloguser_blog_id,bloguser_user_id,bloguser_perm_poststatuses,bloguser_ismember) VALUES('2','$loginid','published','1')" );
      $DB->query( "INSERT INTO evo_blogusers (bloguser_blog_id,bloguser_user_id,bloguser_perm_poststatuses,bloguser_ismember) VALUES('3','$loginid','published','1')" );
      $DB->query( "INSERT INTO evo_blogusers (bloguser_blog_id,bloguser_user_id,bloguser_perm_poststatuses,bloguser_ismember) VALUES('4','$loginid','published','1')" );
      $DB->query( "INSERT INTO evo_blogusers (bloguser_blog_id,bloguser_user_id,bloguser_perm_poststatuses,bloguser_ismember) VALUES('5','$loginid','published','1')" );
      $DB->query( "INSERT INTO evo_blogusers (bloguser_blog_id,bloguser_user_id,bloguser_perm_poststatuses,bloguser_ismember) VALUES('6','$loginid','published','1')" );

// END HORRIBLE CLUDGE



		
		// Display confirmation screen:
		require( dirname(__FILE__).'/_reg_complete.php' );
		exit();
		break; // case 'register'

I made some changes according to my board needs. The number that immediately follows VALUES is the ID number of the blog you want users to have access to. As you can see in the above example, I'm giving my users write access to six of my blogs (blog number 1,2,3,4,5 and 6). If I had even more blogs to give access to that I'd just add more of those INSERT lines with the extra ID numbers.
Now new users can register and write anything without any waiting.

Second part from Wonderwinds.com(http://wonderwinds.com/hackblog.php/2005/01/31/lim_iting_who_can_delete_edit_publish_po
Step2,
Open up b2evocore/_class_item in your favorite editor and scroll down until you find function delete_link. A few lines inside that function you will see this:

if( ! $current_User->check_perm( 'blog_del_post', 'any', false, $this->blog_ID ) )
{ // User has right to delete this post
return false;
}

Further down the file you will see a similar block for edit_link function and another similar block for publish_link function. After the permission of edit_link checks you will want to add the following:

// only the author (or admin) can delete posts
if( $current_User->get( 'ID' ) != $this->Author->get( 'ID' )  )
{ // test for author
if( $current_User->get( 'ID' ) != 1 )
{ // test for admin
return false;
}
}

As my own board, it looks like:

	function edit_link( $before = ' ', $after = ' ', $text = '#', $title = '#', $class = '', $glue = '&' )


	{
		global $current_User, $admin_url;
		
		if( ! is_logged_in() ) return false;

		if( ! $current_User->check_perm( 'blog_post_statuses', $this->status, false,
																			$this->blog_ID ) )
		{	// User has no right to edit this post
			return false;
		}



       // only the author (or admin) can edit posts
        if( $current_User->get( 'ID' ) != $this->Author->get( 'ID' )  )
        { // test for author
        if( $current_User->get( 'ID' ) != 1 )
        { // test for admin
        return false;
        }
        }



		if( $text == '#' ) $text = T_('Edit');
		if( $title == '#' ) $title = T_('Edit this post');

		echo $before;
		echo '<a href="'.$admin_url.'/b2edit.php?action=edit'.$glue.'post='.$this->ID;
		echo '" title="'.$title.'"';
		if( !empty( $class ) ) echo ' class="'.$class.'"';
		echo '>'.$text.'</a>';
		echo $after;

		return true;
	}


Thats it! The two hack works fine together. Hope it help someone. If u wanna make further change about new user permission, just follow the second Url from Wonderwinds.com. NB. Im not ads here. :)

2 Sep 07, 2005 23:52

I wonder will someone take further consideration? Step 1 just allow new users to write and edit articles. How to change the code if we wnnna give more access right (likes 'Protected', 'Private', 'Draft' and 'Delete', at lease a writer has the right to del his works)to users when they sign up instead of promote them in the board one by one.

If somebody done that it will be much more perfect! What a shame I got no idea about PHP, or I can do it myself. >:(

3 Sep 08, 2005 00:16

I've done [url=http://wonderwinds.com/hackblog.php/2005/08/14/automatically_create_a_blog_for_a_new_bl]autoblog[/url] which gives a new blogger an automatic blog upon registration. What I think I need to do is fill it full of comments to explain how to do some of the things you say. Not only what type of post they can make, but what about the specific group and level you put them in and give them? I've got a project going on that gives the new blogger a blog and a linkblog, but doesn't automatically create a category for the new linkblog. "Figure that one out" is my theory... Another simple thing I'm doing is requiring a comment along with registration. This way if there is no comment the admin can decide rather quickly to delete the new user (and associated blog). Anyway I really should go down the comment path so that the admin can see how to customize autoblog for their own specific needs.

BTW autoblog is kinda risky. Once a long time ago I had a porno site register for a blog of mine. It never updated it's profile, and back then it couldn't automatically post, so why it registered is beyond me. Nonetheless it did. Something to think about when you give a blog upon registration. I should probably have set it up so that when the admin gets the "new user registered" email they get the comment, and then decide to trigger the autoblog routine. A minor inconvenience to the admin that ensures you are not giving porno sites the right to post on your blog. One step at a time though!

4 Sep 08, 2005 19:02

That's absolutely a brilliance job. It's that perfect for someone really needed. Currently I prefer to let users auto-register and get post. That will be enought for me cause there are numberless free nice blog offers to people that people might not want their blogs holded on my site :'( .

Anyway, people need it will appreciate for that huge. One day if I change my mind I will patch up that hark. Thanks EdB!

5 Sep 12, 2005 11:06

Ed that looks kick arse. It's kind of what I've been waiting for. Yeah, Admin notification on blog creation would be icing on the cake.


Form is loading...