From 99ed3cc12ecc58a1e7f62ab77240d1886775a98f Mon Sep 17 00:00:00 2001 From: Byrne Date: Fri, 22 Oct 2010 22:21:51 -0700 Subject: [PATCH] [#371 state:resolved] Updated to the latest version of Config Assistant to squash deprecation warnings. --- addons/ConfigAssistant.plugin/config.yaml | 6 +- .../lib/ConfigAssistant/Init.pm | 62 +++++++--- .../lib/ConfigAssistant/Plugin.pm | 113 +++++++++++++++--- .../lib/ConfigAssistant/Prefs.pm | 18 +-- .../lib/ConfigAssistant/Static.pm | 25 ++-- .../lib/ConfigAssistant/Util.pm | 2 +- 6 files changed, 174 insertions(+), 52 deletions(-) diff --git a/addons/ConfigAssistant.plugin/config.yaml b/addons/ConfigAssistant.plugin/config.yaml index fb0dd47d6..22a8410af 100644 --- a/addons/ConfigAssistant.plugin/config.yaml +++ b/addons/ConfigAssistant.plugin/config.yaml @@ -4,7 +4,7 @@ key: ConfigAssistant author_link: http://www.majordojo.com/ author_name: Byrne Reese description: This plugin provides a simple YAML based framework for creating plugin and theme configuration options. -version: 2.0.1 +version: 2.1.3 static_version: 4 schema_version: 2 @@ -63,8 +63,12 @@ config_types: handler: $ConfigAssistant::ConfigAssistant::Plugin::type_link_group category: handler: $ConfigAssistant::ConfigAssistant::Plugin::type_category + category_list: + handler: $ConfigAssistant::ConfigAssistant::Plugin::type_category_list folder: handler: $ConfigAssistant::ConfigAssistant::Plugin::type_folder + folder_list: + handler: $ConfigAssistant::ConfigAssistant::Plugin::type_folder_list upgrade_functions: static_copy: diff --git a/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Init.pm b/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Init.pm index 62d9f5be5..13d708583 100644 --- a/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Init.pm +++ b/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Init.pm @@ -36,7 +36,8 @@ sub init_app { # runs it sees it and will run the upgrade_function. # If this isn't the upgrade screen, just quit. my $cfg = MT->config('PluginSchemaVersion'); - if ( $cfg->{$plugin->id} eq '' ) { + # $cfg->{$plugin->id} = '0.1'; ### UNCOMMENT TO TEST UPGRADE ### + if ( ($cfg->{$plugin->id}||'') eq '' ) { # There is no schema version set. Set one! $cfg->{$plugin->id} = '0.1'; } @@ -197,33 +198,32 @@ sub load_tags { # First initialize all the tags associated with themes my @sets = keys %{ $r->{'template_sets'} }; foreach my $set (@sets) { - if ( $r->{'template_sets'}->{$set}->{'options'} ) { + if ( $obj->registry('template_sets', $set, 'options') ) { foreach my $opt ( - keys %{ $r->{'template_sets'}->{$set}->{'options'} } ) + keys %{ $obj->registry('template_sets', $set, 'options') } ) { - my $option = - $r->{'template_sets'}->{$set}->{'options'}->{$opt}; + my $option = $obj->registry('template_sets', $set, 'options', $opt); # If the option does not define a tag name, # then there is no need to register one next if ( !defined( $option->{tag} ) ); my $tag = $option->{tag}; - # TODO - there is the remote possibility that a template set - # will attempt to register a duplicate tag. This case needs to be - # handled properly. Or does it? - # Note: the tag handler takes into consideration the blog_id, the - # template set id and the option/setting name. + # TODO - there is the remote possibility that a template set + # will attempt to register a duplicate tag. This case needs to be + # handled properly. Or does it? + # Note: the tag handler takes into consideration the blog_id, the + # template set id and the option/setting name. if ( $tag =~ s/\?$// ) { $tags->{block}->{$tag} = sub { my $blog = $_[0]->stash('blog'); my $bset = $blog->template_set; $_[0]->stash( 'field', $bset . '_' . $opt ); $_[0]->stash( 'plugin_ns', - find_theme_plugin($bset)->id ); + find_theme_plugin($bset)->id ); $_[0]->stash( 'scope', 'blog' ); runner( '_hdlr_field_cond', - 'ConfigAssistant::Plugin', @_ ); + 'ConfigAssistant::Plugin', @_ ); }; } elsif ( $tag ne '' ) { @@ -279,9 +279,25 @@ sub load_tags { $_[0]->stash( 'plugin_ns', find_theme_plugin($bset)->id ); $_[0]->stash( 'scope', 'blog' ); + $_[0]->stash( 'show_children', (defined $option->{show_children} ? $option->{show_children} : 1 ) ); runner( '_hdlr_field_link_group', 'ConfigAssistant::Plugin', @_ ); }; + } elsif ($option->{'type'} eq 'category_list' or $option->{'type'} eq 'folder_list') { + my $t = $option->{'type'}; + my $tag_type = $t eq 'category_list' ? 'Categories' : 'Folders'; + my $obj_class = substr($t, 0, index($t, '_list')); + $tags->{block}->{$tag . $tag_type} = sub { + $_[0]->stash('obj_class', $obj_class); + my $blog = $_[0]->stash('blog'); + my $bset = $blog->template_set; + $_[0]->stash( 'field', $bset . '_' . $opt ); + $_[0]->stash( 'plugin_ns', + find_theme_plugin($bset)->id ); + $_[0]->stash( 'scope', 'blog' ); + runner( '_hdlr_field_category_list', + 'ConfigAssistant::Plugin', @_ ); + }; } } } @@ -340,7 +356,6 @@ sub load_tags { 'ConfigAssistant::Plugin', @_ ); }; - } elsif ($option->{'type'} eq 'file') { $tags->{block}->{$tag . 'Asset'} = sub { my $blog = $_[0]->stash('blog'); @@ -352,6 +367,7 @@ sub load_tags { runner( '_hdlr_field_asset', 'ConfigAssistant::Plugin', @_ ); }; + } elsif ($option->{'type'} eq 'link-group') { $tags->{block}->{$tag . 'Links'} = sub { my $blog = $_[0]->stash('blog'); @@ -363,12 +379,28 @@ sub load_tags { runner( '_hdlr_field_link_group', 'ConfigAssistant::Plugin', @_ ); }; + + } elsif ($option->{'type'} eq 'category_list' or $option->{'type'} eq 'folder_list') { + my $t = $option->{'type'}; + my $tag_type = $t eq 'category_list' ? 'Categories' : 'Folders'; + my $obj_class = substr($t, 0, index($t, '_list')); + $tags->{block}->{$tag . $tag_type} = sub { + $_[0]->stash('obj_class', $obj_class); + my $blog = $_[0]->stash('blog'); + my $bset = $blog->template_set; + $_[0]->stash( 'field', $bset . '_' . $opt ); + $_[0]->stash( 'plugin_ns', + find_theme_plugin($bset)->id ); + $_[0]->stash( 'scope', 'blog' ); + runner( '_hdlr_field_category_list', + 'ConfigAssistant::Plugin', @_ ); + }; } } } # Create plugin-specific tags to the static content - if ( $r->{'static_version'} ) { + if ( $r && $r->{'static_version'} ) { # Create the plugin-specific static file path tag, such as "ConfigAssistantStaticFilePath." my $tag; $tag = $obj->id . 'StaticFilePath'; @@ -382,7 +414,7 @@ sub load_tags { }; # Create the plugin-specific static web path tag, such as "ConfigAssistantStaticWebPath." $tag = $obj->id . 'StaticWebPath'; - my $url = $app->config('StaticWebPath'); + my $url = $app->static_path; $url .= '/' unless $url =~ m!/$!; $url .= 'support/plugins/'.$obj->id.'/'; $tags->{function}->{$tag} = sub { diff --git a/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Plugin.pm b/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Plugin.pm index b7470bb32..c0b0c7034 100644 --- a/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Plugin.pm +++ b/addons/ConfigAssistant.plugin/lib/ConfigAssistant/Plugin.pm @@ -22,7 +22,7 @@ sub tag_plugin_static_web_path { $ctx->stash('tag'), $sig) ); } elsif ( $obj->registry('static_version') ) { - my $url = MT->config('StaticWebPath'); + my $url = MT->instance->static_path; $url .= '/' unless $url =~ m!/$!; $url .= 'support/plugins/'.$obj->id.'/'; return $url; @@ -45,8 +45,8 @@ sub tag_plugin_static_file_path { $ctx->stash('tag'), $sig) ); } elsif ( $obj->registry('static_version') ) { - my $url = File::Spec->catdir( MT->config('StaticFilePath'), 'support', 'plugins', $obj->id ); - return $url; + return File::Spec->catdir( + MT->instance->static_file_path, 'support', 'plugins', $obj->id ); } else { return $ctx->error( MT->translate( @@ -60,7 +60,7 @@ sub tag_plugin_static_file_path { sub theme_options { my $app = shift; my ($param) = @_; - my $q = $app->{query}; + my $q = $app->can('query') ? $app->query : $app->param; my $blog = $app->blog; $param ||= {}; @@ -115,6 +115,15 @@ sub theme_options { } next unless $cond->(); } + if (!$field->{'type'}) { + MT->log( + { + message => "Option '$optname' in template set '$ts' did not declare a type. Skipping" + } + ); + next; + } + my $field_id = $ts . '_' . $optname; @@ -258,7 +267,7 @@ sub theme_options { # Code for this method taken from MT::CMS::Plugin sub save_config { my $app = shift; - my $q = $app->param; + my $q = $app->can('query') ? $app->query : $app->param; my $plugin_sig = $q->param('plugin_sig'); my $profile = $MT::Plugins{$plugin_sig}; my $blog_id = $q->param('blog_id'); @@ -443,7 +452,7 @@ sub type_colorpicker { sub type_link_group { my $app = shift; my ( $ctx, $field_id, $field, $value ) = @_; - my $static = $app->config->StaticWebPath; + my $static = $app->static_path; $value = '"[]"' if (!$value || $value eq ''); eval "\$value = $value"; if ($@) { $value = '"[]"'; } @@ -673,7 +682,7 @@ sub type_radio_image { my $app = shift; my ( $ctx, $field_id, $field, $value ) = @_; my $out; - my $static = $app->config->StaticWebPath; + my $static = $app->static_path; $out .= "