⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 permission.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
# Copyright 2001-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: Permission.pm 10197 2005-03-09 00:27:57Z ezra $package MT::Permission;use strict;use MT::Object;@MT::Permission::ISA = qw( MT::Object );__PACKAGE__->install_properties({    columns => [        'id', 'author_id', 'blog_id', 'role_mask', 'entry_prefs',    ],    indexes => {        blog_id => 1,        author_id => 1,    },    datasource => 'permission',    primary_key => 'id',});{    my @Perms = (        [ 1, 'comment', 'Post Comments', ],        [ 2, 'post', 'Post', ],        [ 4, 'upload', 'Upload File', ],        [ 8, 'edit_all_posts', 'Edit All Posts', ],        [ 16, 'edit_templates', 'Edit Templates', ],        [ 32, 'edit_authors', 'Edit Authors & Permissions', ],        [ 64, 'edit_config', 'Configure Weblog', ],        [ 128, 'rebuild', 'Rebuild Files', ],        [ 256, 'send_notifications', 'Send Notifications', ],        [ 512, 'edit_categories', 'Edit Categories', ],        [ 1024, 'edit_notifications', 'Edit Address Book' ],	[ 2048, 'not_comment', ''],  # not a real permission but a denial thereeof    );    sub set_full_permissions {        my $perms = shift;        my $mask = 0;        for my $ref (@Perms) {	    next if ($ref->[1] =~ /^not_/);            $mask += $ref->[0];        }        $perms->role_mask($mask);    }    sub perms { \@Perms }    no strict 'refs';    for my $ref (@Perms) {        my $mask = $ref->[0];        my $meth = 'can_' . $ref->[1];        *$meth = sub {            my $flags = $_[0]->role_mask || 0;            if (@_ == 2) {                $flags = $_[1] ? ($flags | $mask) :                                 ($flags & ~$mask);                $_[0]->role_mask($flags);            }            $flags & $mask;        };    }}sub can_edit_entry {    my $perms = shift;    my($entry, $author) = @_;    $perms->can_edit_all_posts ||	($perms->can_post &&	 $entry->author_id == $author->id);}1;__END__=head1 NAMEMT::Permission - Movable Type permissions record=head1 SYNOPSIS    use MT::Permission;    my $perms = MT::Permission->load({ blog_id => $blog->id,                                       author_id => $author->id })        or die "Author has no permissions for blog";    $perms->can_post        or die "Author cannot post to blog";    $perms->can_edit_config(0);    $perms->save        or die $perms->errstr;=head1 DESCRIPTIONAn I<MT::Permission> object represents the permissions settings for an authorin a particular blog. Permissions are set on a role basis, and each permissionis either on or off for an author-blog combination; permissions are stored asa bitmask.=head1 USAGEAs a subclass of I<MT::Object>, I<MT::Permission> inherits all of thedata-management and -storage methods from that class; thus you should lookat the I<MT::Object> documentation for details about creating a new object,loading an existing object, saving an object, etc.The following methods are unique to the I<MT::Permission> interface. Each ofthese methods, B<except> for I<set_full_permissions>, can be called with anoptional argument to turn the permission on or off. If the argument is sometrue value, the permission is enabled; otherwise, the permission is disabled.If no argument is provided at all, the existing permission setting isreturned.=head2 $perms->set_full_permissionsTurns on all permissions for the author and blog represented by I<$perms>.=head2 $perms->can_postReturns true if the author can post to the blog, and edit the entries thathe/she has posted; false otherwise.=head2 $perms->can_uploadReturns true if the author can upload files to the blog directories specifiedfor this blog, false otherwise.=head2 $perms->can_edit_all_postsReturns true if the author can edit B<all> entries posted to this blog (evenentries that he/she did not write), false otherwise.=head2 $perms->can_edit_templatesReturns true if the author can edit the blog's templates, false otherwise.=head2 $perms->can_send_notificationsReturns true if the author can send messages to the notification list, falseotherwise.=head2 $perms->can_edit_categoriesReturns true if the author can edit the categories defined for the blog, falseotherwise.=head2 $perms->can_edit_notificationsReturns true if the author can edit the notification list for the blog, falseotherwise.=head2 $perms->can_edit_authorsReturns true if the author can edit author permissions for the blog, and addnew authors who have access to the blog; false otherwise.Note: you should be very careful when giving this permission to authors,because an author could easily then block your access to the blog.=head2 $perms->can_edit_configReturns true if the author can edit the blog configuration, false otherwise.Note that this setting also controls whether the author can import entriesto the blog, and export entries from the blog.=head1 DATA ACCESS METHODSThe I<MT::Comment> object holds the following pieces of data. These fields canbe accessed and set using the standard data access methods described in theI<MT::Object> documentation.=over 4=item * idThe numeric ID of this permissions record.=item * author_idThe numeric ID of the author associated with this permissions record.=item * blog_idThe numeric ID of the blog associated with this permissions record.=item * role_maskThe permissions bitmask. You should not access this value directly; insteaduse the I<can_*> methods, above.=back=head1 DATA LOOKUPIn addition to numeric ID lookup, you can look up or sort records by anycombination of the following fields. See the I<load> documentation inI<MT::Object> for more information.=over 4=item * blog_id=item * author_id=back=head1 AUTHOR & COPYRIGHTSPlease see the I<MT> manpage for author, copyright, and license information.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -