📄 plugin.pm
字号:
# Copyright 2001-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: Plugin.pm 12538 2005-05-26 19:12:57Z ezra $package MT::Plugin;use strict;use MT::ErrorHandler;@MT::Plugin::ISA = qw( MT::ErrorHandler );sub new { my $class = shift; my ($this) = ref$_[0] ? @_ : {@_}; bless $this, $class;}sub name { my $this = shift; my ($new_name) = @_; $this->{name} = $new_name if ($new_name); return $this->{name};}sub config_link { my $this = shift; my ($new_config_link) = @_; $this->{config_link} = $new_config_link if ($new_config_link); return $this->{config_link};}sub doc_link { my $this = shift; my ($new_doc_link) = @_; $this->{doc_link} = $new_doc_link if ($new_doc_link); return $this->{doc_link};}sub description { my $this = shift; my ($new_desc) = @_; $this->{description} = $new_desc if ($new_desc); return $this->{description};}sub envelope { my $this = shift; my ($new_envelope) = @_; $this->{envelope} = $new_envelope if ($new_envelope); return $this->{envelope};}sub set_config_value { my $this = shift; my ($variable, $value) = @_; use MT::PluginData; my $pdata_obj = MT::PluginData->load({plugin => $this->name(), key => 'configuration'}); if (!$pdata_obj) { $pdata_obj = MT::PluginData->new(); $pdata_obj->plugin($this->name()); $pdata_obj->key('configuration'); } my $configuration = $pdata_obj->data(); $configuration->{$variable} = $value; $pdata_obj->data($configuration); $pdata_obj->save();}sub get_config_hash { my $this = shift; require MT::PluginData; my $pdata_obj = MT::PluginData->load({plugin => $this->name(), key => 'configuration'}); return $pdata_obj && $pdata_obj->data() ? $pdata_obj->data() : undef;}sub get_config_value { my $this = shift; my $config = $this->get_config_hash(); return $config ? $config->{$_[0]} : undef;}1;__END__=head1 NAMEMT::Plugin - Movable Type class holding information that describes aplugin=head1 SYNOPSIS $plugin = new MT::Plugin({name => "Example Plugin", description => "Frobnazticates all Diffyhorns", config_link => <configuration URL>, doc_link => <documentation URL>});=head1 DESCRIPTIONAn I<MT::Plugin> object holds data about a plugin which is used to helpusers understand what the plugin does and let them configure theplugin.Normally, a plugin will construct an I<MT::Plugin> object and pass itto the C<add_plugin> method of the I<MT> class: MT->add_plugin($plugin);This will insert a slug for that plugin on the main MT page; the sluggives the name and description and provides links to the documentationand configuration pages, if any.When adding callbacks, you will use the plugin object as well; thisobject is used to help the user identify errors that arise inexecuting the callback. For example, to add a callback which isexecuted before the I<MT::Foo> object is saved to the database, you mightmake a call like this: MT::Foo->add_callback("pre_save", 10, $plugin, \&callback_function);This call will tell I<MT::Foo> to call the functionC<callback_function> just before executing any C<save> operation. Thenumber '10' is signalling the priority, which controls the order inwhich various plugins are called. Lower number callbacks are calledfirst.=head1 ARGUMENTS=over 4=item * nameA human-readable string identifying the plugin. This will be displayedin the plugin's slug on the MT front page.=item * description (optional)A longer string giving a brief description of what the plugin does.=item * doc_link (optional)A URL pointing to some documentation for the plugin. This can be arelative path, in which case it identifies documentation within theplugin's distribution, or it can be an absolute URL, pointing atoff-site documentation.=item * config_link (optional)The relative path of a CGI script or some other configurationinterface for the plugin. This is relative to the "pluginenvelope"--that is, the directory underneath C<mt/plugins> where allyour plugin files live.=head1 MethodsEach of the above arguments to the constructor is also a 'getter'method that returns the corresponding value. C<MT::Plugin> also offersthe following methods:=item * envelopeReturns the path to the plugin, relative to the MT directory. This isdetermined automatically when the plugin is loaded.=item * set_config_value=item * get_config_valueThese routines facilitate easy storage of simple configurationoptions. They make use of the PluginData table in the database tostore a set of key-value pairs for each plugin. Call them as follows: $plugin->set_config_value($key, $value); $value = $plugin->get_config_value($key);The C<name> field of the plugin object is used as the namespace forthe keys. Thus it would not be wise for one plugin to use thesame C<name> as a different plugin.=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 + -