Pastoid

Private Posts Plugin for Habari

The page you are looking at now is at this URL: http://pastoid.com/bnz

This paste was last updated on January 30, 2009 at 1:01 am.

simple_private_posts.plugin.phpraw

<?php
 
class SimplePrivatePosts extends Plugin
{
	/**
	 * function info
	 * Returns information about this plugin
	 * @return array Plugin info array
	 **/
	function info()
	{
		return array (
			'name' => 'Simple Private Posts',
			'url' => 'http://habariproject.org/',
			'author' => 'Owen Winkler',
			'authorurl' => 'http://asymptomatic.net/',
			'version' => '1.0',
			'description' => 'Mark posts as private so that only authenticated users who have read access to the "private" token can read them',
			'license' => 'Apache License 2.0',
		);
	}
 
	public function help()
	{
		return <<< END_HELP
<p>You must select a group to deny permission to posts with the "private" token.  Do this on the groups page.  Usually, you'll want to <em>deny</em> the "private" token to the "Anonymous" group, to prevent users in the Anonymous group from seeing posts with the private token.</p>
<p>On the post creation page, a new checkbox labeled "Private Post" will appear in the settings area.  Check this box to make the post private.</p>
END_HELP;
	}
 
	public function action_plugin_activation( )
	{
		ACL::create_token('private', 'Permissions on posts marked as "private"');
	}
 
	public function action_plugin_deactivation( $plugin_file )
	{
		if( Plugins::id_from_file(__FILE__) == Plugins::id_from_file($plugin_file) ) {
			ACL::destroy_token('private');
		}
	}
 
	public function action_form_publish($form, $post)
	{
		if($post->content_type == Post::type('entry')) {
			$form->settings->append('checkbox', 'private_post', 'null:null', _t('Private Post'), 'tabcontrol_checkbox');
			if($post->has_tokens('private')) {
				$form->private_post->value = true;
			}
		}
	}
 
	public function action_publish_post($post, $form)
	{
		if($post->content_type == Post::type('entry')) {
			if(	$form->private_post->value == true) {
				$post->add_tokens('private');
			}
			else {
				$post->remove_tokens('private');
			}
		}
	}
 
}
?>

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 83
search.live.com 2
www.google.com.au 2
mibbit.com 1
search.twitter.com 1
Is this paste spam?
<Hide