Show
Ignore:
Timestamp:
04/24/08 09:36:00 (19 months ago)
Author:
fumiakiy
Message:

Integrated Widget Manager to the core. BugId:68750

Now a widgetset is another type of template. The widgets contained in a widgetset is stored in a meta field.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-36/plugins/WidgetManager/WidgetManager.pl

    r1713 r2052  
    1515use base qw( MT::Plugin ); 
    1616use constant DEBUG => 0; 
    17 our $VERSION = '1.0'; 
     17use MT::Template; 
     18use MT::Util qw( escape_unicode ); 
     19use MT::I18N qw( encode_text ); 
     20 
     21our $VERSION = '1.1'; 
    1822 
    1923my $plugin = MT::Plugin::WidgetManager->new({ 
    20     id          => 'WidgetManager', 
    21     name        => 'Widget Manager', 
    22     description => q(<MT_TRANS phrase="Maintain your blog's widget content using a handy drag and drop interface.">), 
    23     version     => $VERSION, 
    24     author_name => 'Six Apart', 
    25     key         => 'widget-manager', 
    26     l10n_class  => 'WidgetManager::L10N', 
     24    id             => 'WidgetManager', 
     25    name           => 'Widget Manager Upgrade Assistant', 
     26    description    => q(<MT_TRANS phrase="Widget Manager version 1.1; This version of the plugin is to upgrade data from older version of Widget Manager that has been shipped with Movable Type to the Movable Type core schema.  No other features are included.  You can safely remove this plugin after installing/upgrading Movable Type.\">), 
     27    version        => $VERSION, 
     28    schema_version => $VERSION, 
     29    author_name    => 'Six Apart, Ltd.', 
     30    key            => 'widget-manager', 
     31    l10n_class     => 'WidgetManager::L10N', 
    2732}); 
    2833MT->add_plugin($plugin); 
     
    3338    my $plugin = shift; 
    3439    $plugin->registry({ 
    35         tags => { 
    36             help_url => sub { MT->translate('http://www.movabletype.org/documentation/appendices/tags/%t.html') }, 
    37             function => { 
    38                 WidgetManager => '$WidgetManager::WidgetManager::Plugin::_hdlr_widget_manager', 
    39                 WidgetSet => '$WidgetManager::WidgetManager::Plugin::_hdlr_widget_manager', 
     40        upgrade_functions => { 
     41            'upgrade_widgetmanagers_nv' => { 
     42                # this is to workaround absence of PluginSchemaVersion 
     43                code => \&upgrade_widgetmanagers, 
    4044            }, 
    41         }, 
    42         callbacks => { 
    43             'clone_blog_widgets' => { 
    44                 callback => 'MT::Blog::post_clone', 
    45                 handler => '$WidgetManager::WidgetManager::Plugin::clone_blog_widgemanagers', 
    46             }, 
    47             'remove_blog_widgets' => { 
    48                 callback => 'MT::Blog::post_remove', 
    49                 handler => '$WidgetManager::WidgetManager::Plugin::remove_blog_widgetmanager', 
    50             }, 
    51             'DefaultTemplateFilter' => '$WidgetManager::MT::Plugin::WidgetManager::default_templates', 
    52             'MT::Blog::post_create_default_templates' => '$WidgetManager::WidgetManager::Plugin::create_default_widgetsets', 
    53             'restore' => '$WidgetManager::WidgetManager::Plugin::restore_widgetmanagers', 
    54         }, 
    55         applications => { 
    56             cms => { 
    57                 methods => { 
    58                     list_widget => '$WidgetManager::WidgetManager::CMS::list', 
    59                     edit_widget => '$WidgetManager::WidgetManager::CMS::edit', 
    60                     delete_widget => '$WidgetManager::WidgetManager::CMS::delete', 
    61                     save_widget => '$WidgetManager::WidgetManager::CMS::save', 
    62                 }, 
    63                 menus => { 
    64                     'design:widgets' => { 
    65                         label => 'Widgets', 
    66                         mode => 'list_widget', 
    67                         order => 200, 
    68                         permission => 'edit_templates', 
    69                         view => "blog", 
    70                     }, 
    71                 }, 
    72                 template_snippets => { 
    73                     'widget_manager' => { 
    74                         label => 'Widget Set', 
    75                         content => '<$mt:WidgetSet name="$0"$>', 
    76                         trigger => 'widget', 
    77                     }, 
    78                 }, 
    79             }, 
     45            'upgrade_widgetmanagers' => { 
     46                version_limit => 1.1, 
     47                code => \&upgrade_widgetmanagers, 
     48            } 
    8049        }, 
    8150    }); 
     51    return 1; 
    8252} 
    8353 
    84 sub load_selected_modules {  
    85     require WidgetManager::Plugin;  
    86     WidgetManager::Plugin::load_selected_modules(@_);  
    87 } 
     54sub _disable_widgetmanager {  
     55    my $switch = MT->config('PluginSwitch') || {};  
     56    $switch->{$plugin->{plugin_sig}} = 0;  
     57    MT->config('PluginSwitch', $switch, 1);  
     58    MT->config->save_config();  
     59}  
    8860 
    89 sub default_templates { 
    90     my $cb = shift; 
    91     my ($tmpl_list) = @_; 
     61sub _translate_escape {  
     62    my $trans = $plugin->translate(@_);  
     63    return $trans if $MT::Upgrade::CLI;  
     64    $trans = MT::I18N::encode_text($trans, undef, 'utf-8');  
     65    return MT::Util::escape_unicode($trans);  
     66}  
    9267 
    93     my $widgetmgr = MT::Plugin::WidgetManager->instance; 
    94     my $widget_tmpls = $widgetmgr->templates(MT->instance); 
    95     push @$tmpl_list, @$widget_tmpls; 
    96 } 
     68sub upgrade_widgetmanagers {  
     69    my $upg = shift;  
    9770 
    98 sub templates { 
    99     my $plugin = shift; 
    100     my ($app) = @_; 
    101     my $default_widget_templates; 
    102  
    103     use File::Spec; 
    104     my $widgets_dir = File::Spec->catfile($plugin->{full_path}, 'default_widgets'); 
    105     my $cfg_file = File::Spec->catfile($widgets_dir, 'widgets.cfg'); 
    106      
    107     local(*FH, $_, $/); 
    108     $/ = "\n"; 
    109     open FH, $cfg_file or 
    110         return $app->error(MT->translate( 
    111                                "Error opening file '[_1]': [_2]", $cfg_file, "$!" )); 
    112     my $cfg = join('',<FH>); 
    113     eval "$cfg;"; 
    114     close FH; 
    115  
    116     my @tmpls; 
    117     require MT::Template; 
    118     foreach (@$default_widget_templates) { 
    119         open(TMPL, File::Spec->catfile($widgets_dir, $_->{template})) or die "Error: $!\n"; 
    120         while (my $line = <TMPL>) { 
    121             $_->{text} .= $line; 
     71    require MT::PluginData; 
     72    my $iter = MT::PluginData->load_iter( 
     73        { plugin => $plugin->key } 
     74    ); 
     75    while ( my $pd = $iter->() ) { 
     76        next unless $plugin->key eq $pd->plugin; 
     77        my ( $blog_id ) = $pd->key =~ /configuration:blog:(\d+)/; 
     78        next unless $blog_id; 
     79        my $config = $pd->data; 
     80        next unless $config; 
     81        my $modulesets = $config->{modulesets}; 
     82        next unless $modulesets; 
     83        foreach my $mod_key ( keys %$modulesets ) { 
     84            $upg->progress(_translate_escape('Moving storage of Widget Manager [_1]...', $mod_key)); 
     85            my $tmpl_ids = $modulesets->{$mod_key}; 
     86            my $tmpl = MT::Template->new; 
     87            $tmpl->blog_id($blog_id); 
     88            $tmpl->name($mod_key); 
     89            $tmpl->type('widgetset'); 
     90            $tmpl->build_dynamic(0); 
     91            $tmpl->rebuild_me(0); 
     92            $tmpl->modulesets($tmpl_ids); 
     93            $tmpl->save_widgetset 
     94                or $upg->progress(_translate_escape('Failed.')), next; 
     95            $upg->progress(_translate_escape('Done.')); 
    12296        } 
    123         close TMPL; 
    124         my $tmpl = MT::Template->new; 
    125         $tmpl->{type} = 'widget'; 
    126         $tmpl->{name} = $plugin->translate($_->{label}); 
    127         $tmpl->{text} = $plugin->translate_templatized($_->{text}); 
    128         push @tmpls, $tmpl; 
     97        $pd->remove; 
    12998    } 
    130     return \@tmpls; 
     99    _disable_widgetmanager; 
    131100} 
    132101