root/trunk/CommunityEdit/CommunityEdit.pl

Revision 770, 3.3 kB (checked in by arvind, 5 months ago)

Importing CommunityEdit? - an MTCS plugin that allows members to edit entries they have submitted

Line 
1 package MT::Plugin::CommunityEdit;
2
3 use strict;
4 use MT 4.0;
5 use base qw( MT::Plugin );
6
7 # Define $DISPLAY_NAME only if different from package ending (i.e. TestPlugin)
8 our $DISPLAY_NAME = '';
9 our $VERSION = '1.0';
10
11 our ($plugin, $PLUGIN_MODULE, $PLUGIN_KEY);
12 MT->add_plugin($plugin = __PACKAGE__->new({
13    id          => plugin_module(),
14    key         => plugin_key(),
15    name        => plugin_name(),
16    description => "Allows your readers to edit entries they have submitted",
17    version     => $VERSION,
18    author_name => "Six Apart",
19    author_link => "http://sixapart.com/",
20    # plugin_link => "[link to plugin's homepage]",
21 }));
22 sub init_registry {
23     my $plugin = shift;
24     $plugin->registry({
25         default_templates => {
26             base_path => 'templates/global',
27             'global:system' => {
28                 edit_entry => {
29                     label => 'Create/Edit Entry'
30                 }
31             }
32         },
33         applications => {
34             community => {
35                 methods => {
36                     edit_entry => '$CommunityEdit::MT::App::CommunityEdit::edit_entry',
37                     save_entry => '$CommunityEdit::MT::App::CommunityEdit::save_entry'
38                 }
39             }
40         },
41         tags => {
42             function => {
43                 'CustomFieldSuperHTML' => \&_hdlr_customfield_super_html # Because MTCustomFieldHTML doesn't use field_value
44             }
45         }
46     });
47 }
48
49 sub plugin_name     { return ($DISPLAY_NAME || plugin_module()) }
50 sub plugin_module   {
51     $PLUGIN_MODULE or ($PLUGIN_MODULE = __PACKAGE__) =~ s/^MT::Plugin:://;
52     return $PLUGIN_MODULE;
53 }
54 sub plugin_key      {
55     $PLUGIN_KEY or ($PLUGIN_KEY = lc(plugin_module())) =~ s/\s+//g;
56     return $PLUGIN_KEY
57 }
58
59 sub _hdlr_customfield_super_html {
60     my ($ctx, $args) = shift;
61     my $plugin = MT->component("Commercial");
62     my $field = $ctx->stash('field')
63         or return _no_field($ctx);
64
65     my ($type, $basename) = ($field->type, $field->basename);
66     my $type_obj = MT->registry('customfield_types', $type);
67    
68     require CustomFields::Template::ContextHandlers;
69     my $value = CustomFields::Template::ContextHandlers::_hdlr_customfield_value($plugin, $ctx, $args);
70
71     my $row = $field->column_values();
72     $row->{blog_id} ||= 0;
73     $row->{value} = $value || $field->default;     
74     if($type_obj->{options_delimiter}) {
75         my @option_loop;
76         my $expr = '\s*' . quotemeta($type_obj->{options_delimiter}) . '\s*';
77         my @options = split /$expr/, $field->options;
78         foreach my $option (@options) {
79             my $option_row = { option => $option };
80             $option_row->{is_selected} = defined $row->{value} ? ($row->{value} eq $option) : 0;           
81             push @option_loop, $option_row;
82         }
83         $row->{option_loop} = \@option_loop;
84     }
85     $row->{show_field} = ($field->obj_type eq 'entry') ? 0 : 1;
86     $row->{show_hint} = $type ne 'checkbox' ? 1 : 0;
87     $row->{field_id} = $row->{field_name} = "customfield_$basename";
88     $row->{field_value} = $row->{value};
89     $row->{simple} = 1;         # it's for asset-chooser.tmpl
90    
91     # Send through variables set before calling this tag
92     my $vars = $ctx->stash('vars');
93     foreach my $var (keys %$vars) {
94         $row->{$var} = $vars->{$var};
95     }
96
97     require CustomFields::Util;
98     return CustomFields::Util::_get_html($type, 'field_html', $row);
99 }
100
101 1;
Note: See TracBrowser for help on using the browser.