00001 <?php
00002
00003 namespace Habari;
00004
00005 if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); }
00006
00007 class SimplePrivatePosts extends Plugin
00008 {
00009
00010 public function action_plugin_activation()
00011 {
00012 ACL::create_token('private', 'Permission to read posts marked as "private"', 'Private Posts');
00013
00014
00015 $anon = UserGroup::get('anonymous');
00016 if ( false != $anon ) {
00017 $anon->deny('private');
00018 }
00019 }
00020
00027 public function filter_token_description_display( $token )
00028 {
00029 $desc = array(
00030 'private' => _t( 'Permission to read posts marked as "private"' ),
00031 );
00032 return isset( $desc[$token] ) ? $desc[$token] : $token;
00033 }
00034
00041 public function filter_token_group_display( $group )
00042 {
00043 $name = array(
00044 'Private Posts' => _t( 'Private Posts' ),
00045 );
00046 return isset( $name[$group] ) ? $name[$group] : $group;
00047 }
00048
00049 public function action_plugin_deactivation( $plugin_file )
00050 {
00051 if ( Plugins::id_from_file(__FILE__) == Plugins::id_from_file($plugin_file) ) {
00052 ACL::destroy_token('private');
00053 }
00054 }
00055
00056 public function action_form_publish($form, $post)
00057 {
00059 $private_post = FormControlCheckbox::create('private_post');
00060 $private_post->set_returned_value(true);
00061 $form->post_settings->append($private_post->label( _t('Private Post') ));
00062 if ( $post->has_tokens('private') ) {
00063 $private_post->set_value(true);
00064 }
00065 else {
00066 $private_post->set_value(false);
00067 }
00068 }
00069
00070 public function action_publish_post($post, $form)
00071 {
00072 if ( $form->private_post->value == true ) {
00073 $post->add_tokens('private');
00074 }
00075 else {
00076 $post->remove_tokens('private');
00077 }
00078 }
00079
00080 }
00081 ?>