package MT::Plugin::CommunityEdit; use strict; use MT 4.0; use base qw( MT::Plugin ); # Define $DISPLAY_NAME only if different from package ending (i.e. TestPlugin) our $DISPLAY_NAME = ''; our $VERSION = '1.0'; our ($plugin, $PLUGIN_MODULE, $PLUGIN_KEY); MT->add_plugin($plugin = __PACKAGE__->new({ id => plugin_module(), key => plugin_key(), name => plugin_name(), description => "Allows your readers to edit entries they have submitted", version => $VERSION, author_name => "Six Apart", author_link => "http://sixapart.com/", # plugin_link => "[link to plugin's homepage]", })); sub init_registry { my $plugin = shift; $plugin->registry({ default_templates => { base_path => 'templates/global', 'global:system' => { edit_entry => { label => 'Create/Edit Entry' } } }, applications => { community => { methods => { edit_entry => '$CommunityEdit::MT::App::CommunityEdit::edit_entry', save_entry => '$CommunityEdit::MT::App::CommunityEdit::save_entry' } } }, tags => { function => { 'CustomFieldSuperHTML' => \&_hdlr_customfield_super_html # Because MTCustomFieldHTML doesn't use field_value } } }); } sub plugin_name { return ($DISPLAY_NAME || plugin_module()) } sub plugin_module { $PLUGIN_MODULE or ($PLUGIN_MODULE = __PACKAGE__) =~ s/^MT::Plugin:://; return $PLUGIN_MODULE; } sub plugin_key { $PLUGIN_KEY or ($PLUGIN_KEY = lc(plugin_module())) =~ s/\s+//g; return $PLUGIN_KEY } sub _hdlr_customfield_super_html { my ($ctx, $args) = shift; my $plugin = MT->component("Commercial"); my $field = $ctx->stash('field') or return _no_field($ctx); my ($type, $basename) = ($field->type, $field->basename); my $type_obj = MT->registry('customfield_types', $type); require CustomFields::Template::ContextHandlers; my $value = CustomFields::Template::ContextHandlers::_hdlr_customfield_value($plugin, $ctx, $args); my $row = $field->column_values(); $row->{blog_id} ||= 0; $row->{value} = $value || $field->default; if($type_obj->{options_delimiter}) { my @option_loop; my $expr = '\s*' . quotemeta($type_obj->{options_delimiter}) . '\s*'; my @options = split /$expr/, $field->options; foreach my $option (@options) { my $option_row = { option => $option }; $option_row->{is_selected} = defined $row->{value} ? ($row->{value} eq $option) : 0; push @option_loop, $option_row; } $row->{option_loop} = \@option_loop; } $row->{show_field} = ($field->obj_type eq 'entry') ? 0 : 1; $row->{show_hint} = $type ne 'checkbox' ? 1 : 0; $row->{field_id} = $row->{field_name} = "customfield_$basename"; $row->{field_value} = $row->{value}; $row->{simple} = 1; # it's for asset-chooser.tmpl # Send through variables set before calling this tag my $vars = $ctx->stash('vars'); foreach my $var (keys %$vars) { $row->{$var} = $vars->{$var}; } require CustomFields::Util; return CustomFields::Util::_get_html($type, 'field_html', $row); } 1;