From d3948f2c172f67a95ecd0c9bdb6635981abf33ab Mon Sep 17 00:00:00 2001 From: Jay Allen Date: Mon, 24 Jan 2011 18:46:26 -0800 Subject: [PATCH] Updated Config Assistant from version 2.1.9 to version 2.1.15 --- addons/ConfigAssistant.pack/config.yaml | 6 +- .../lib/ConfigAssistant/Init.pm | 60 +++--- .../lib/ConfigAssistant/Plugin.pm | 90 ++++---- .../lib/ConfigAssistant/Static.pm | 15 +- .../lib/ConfigAssistant/Util.pm | 23 ++- addons/ConfigAssistant.pack/static/js/app.js | 22 +- .../static/js/jquery.history.js | 194 ++++++++++++++++++ .../ConfigAssistant.pack/static/js/options.js | 4 + .../tmpl/prefs_chooser.mtml | 4 +- .../tmpl/theme_options.mtml | 3 +- 10 files changed, 318 insertions(+), 103 deletions(-) create mode 100644 addons/ConfigAssistant.pack/static/js/jquery.history.js diff --git a/addons/ConfigAssistant.pack/config.yaml b/addons/ConfigAssistant.pack/config.yaml index 8685531da..7524424e1 100644 --- a/addons/ConfigAssistant.pack/config.yaml +++ b/addons/ConfigAssistant.pack/config.yaml @@ -4,9 +4,9 @@ key: ConfigAssistant author_link: http://openmelody.org/ author_name: "Byrne Reese, Open Melody Software Group" description: This plugin provides a simple YAML based framework for creating plugin and theme configuration options. -version: 2.1.9 -static_version: 4 -schema_version: 2 +version: 2.1.15 +static_version: 7 +schema_version: 3 applications: cms: diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm index 6f44fc117..932aa6943 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm @@ -14,45 +14,37 @@ sub plugin { sub init_app { my $plugin = shift; - my ($app) = @_; + my ($app) = @_; + my $cfg = $app->config; return if $app->id eq 'wizard'; - # Disable the AutoPrefs plugin if it's installed. (AutoPrefs has been - # merged with Config Assistant, so is not needed anymore.) - my $switch = MT->config('PluginSwitch') || {}; - unless ( ( $switch->{'AutoPrefs'} || '' ) eq '0' ) { - $switch->{'AutoPrefs'} = 0; - MT->config( 'PluginSwitch', $switch, 1 ); - MT->config->save_config(); - } + # Disable the AutoPrefs plugin if it's still installed. (AutoPrefs has + # been merged with Config Assistant, so is not needed anymore.) + my $switch = $cfg->PluginSwitch || {}; + $switch->{'AutoPrefs/config.yaml'} = $switch->{'AutoPrefs'} = 0; + $cfg->PluginSwitch( $switch ); + # FIXME This needs some commentary... init_options($app); - my $r = $plugin->registry; - $r->{tags} = sub { load_tags( $app, $plugin ) }; + + # FIXME This looks fishy... Pretty sure we shouldn't be accessing the registry as a hash but instead $plugin->registry('tags', sub { ... }) + my $r = $plugin->registry->{tags} = sub { load_tags( $app, $plugin ) }; # Static files only get copied during an upgrade. if ( $app->id eq 'upgrade' ) { - - # Because no schema version is set, the upgrade process doesn't run - # during the plugin's initial install. But, we need it to so that - # static files will get copied. Check if PluginschemaVersion has been - # set for Config Assistant. If not, set it. That way, when the upgrade - # runs it sees it and will run the upgrade_function. - # If this isn't the upgrade screen, just quit. - my $cfg = MT->config('PluginSchemaVersion'); - - # $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'; - } + # Because no schema version is set, the upgrade process does nothing + # during the plugin's initial install. So, in order to copy static + # files on first run, we set an initial schema version which triggers + # the framework. + my $schemas = $cfg->PluginSchemaVersion || {}; + $schemas->{ $plugin->id } ||= '0.1'; + # $schemas->{$plugin->id} = '0.1'; ## UNCOMMENT TO TEST UPGRADE ## + $cfg->PluginSchemaVersion( $schemas ); } - require Sub::Install; - # TODO - This should not have to reinstall a subroutine. It should invoke # a callback. + require Sub::Install; Sub::Install::reinstall_sub( { code => \&needs_upgrade, into => 'MT::Component', @@ -87,9 +79,9 @@ sub init_options { my $option = $r->{'template_sets'}->{$set}->{'options'}->{$opt}; - # To avoid option names that may collide with other - # options in other template sets settings are derived - # by combining the name of the template set and the + # To avoid option names that may collide with other + # options in other template sets settings are derived + # by combining the name of the template set and the # option's key. my $optname = $set . '_' . $opt; if ( _option_exists( $sig, $optname ) ) { @@ -99,7 +91,7 @@ sub init_options { else { # if ( my $default = $option->{default} ) { - # if ( !ref($default) + # if ( !ref($default) # && ( $default =~ /^\s*sub/ # || $default =~ /^\$/)) { # $default @@ -118,7 +110,7 @@ sub init_options { $obj->{'registry'}->{'settings'}->{$optname} = { scope => 'blog', %$option, }; } - } ## end else [ if ( _option_exists( $sig...))] + } } ## end foreach my $opt ( keys %{ $r...}) } ## end if ( $r->{'template_sets'...}) } # end foreach (@sets) @@ -192,7 +184,7 @@ sub load_tags { class => 'system', category => 'plugin', level => MT::Log::ERROR(), - } + } ); } } diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm index 563d9922e..e69d6b3be 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm @@ -5,12 +5,12 @@ use warnings; use Carp qw( croak ); use MT::Util qw( relative_date offset_time offset_time_list epoch2ts - ts2epoch format_ts encode_html decode_html dirify ); + ts2epoch format_ts encode_html decode_html dirify ); use ConfigAssistant::Util qw( find_theme_plugin find_template_def find_option_def - find_option_plugin process_file_upload ); + find_option_plugin process_file_upload + plugin_static_web_path plugin_static_file_path ); use JSON; - # use MT::Log::Log4perl qw( l4mtdump ); use Log::Log4perl qw( :resurrect ); our $logger; @@ -21,32 +21,29 @@ sub tag_plugin_static_web_path { if ( !$obj ) { return $ctx->error( - MT->translate( - "The plugin you specified '[_2]' in '[_1]' " - . "could not be found.", - $ctx->stash('tag'), - $sig - ) + MT->translate( + "The plugin you specified '[_2]' in '[_1]' " + . "could not be found.", + $ctx->stash('tag'), + $sig + ) ); } elsif ( $obj->registry('static_version') ) { - my $url = MT->instance->static_path; - $url .= '/' unless $url =~ m!/$!; - $url .= 'support/plugins/' . $obj->id . '/'; - return $url; + return plugin_static_web_path($obj); } else { # TODO - perhaps this should default to: mt-static/plugins/$sig? return $ctx->error( - MT->translate( - "The plugin you specified '[_2]' in '[_1]' has not" - . "registered a static directory. Please use " - . " instead.", - $ctx->stash('tag'), - $sig - ) + MT->translate( + "The plugin you specified '[_2]' in '[_1]' has not" + . "registered a static directory. Please use " + . " instead.", + $ctx->stash('tag'), + $sig + ) ); } } ## end sub tag_plugin_static_web_path @@ -58,28 +55,26 @@ sub tag_plugin_static_file_path { if ( !$obj ) { return $ctx->error( - MT->translate( - "The plugin you specified '[_2]' in '[_1]' " - . "could not be found.", - $ctx->stash('tag'), - $sig - ) + MT->translate( + "The plugin you specified '[_2]' in '[_1]' " + . "could not be found.", + $ctx->stash('tag'), + $sig + ) ); } elsif ( $obj->registry('static_version') ) { - return - File::Spec->catdir( MT->instance->static_file_path, - 'support', 'plugins', $obj->id ); + return plugin_static_file_path($obj); } else { return $ctx->error( - MT->translate( - "The plugin you specified in '[_1]' has not " - . "registered a static directory. Please use " - . " instead.", - $_[0]->stash('tag') - ) + MT->translate( + "The plugin you specified in '[_1]' has not " + . "registered a static directory. Please use " + . " instead.", + $_[0]->stash('tag') + ) ); } } ## end sub tag_plugin_static_file_path @@ -369,9 +364,13 @@ sub save_config { return $app->error( "Error uploading file: " . $result->{message} ); } - next - if ( - $result->{status} == ConfigAssistant::Util::NO_UPLOAD ); + if ( $result->{status} == ConfigAssistant::Util::NO_UPLOAD ) { + if ($param->{$var.'-clear'} && $data->{$var}) { + my $old = MT->model('asset')->load( $data->{$var} ); + $old->remove if $old; + } + next; + } if ( $data->{$var} ) { my $old = MT->model('asset')->load( $data->{$var} ); $old->remove if $old; @@ -435,7 +434,7 @@ sub save_config { } } ## end if ( $profile && $profile...) - $app->add_return_arg( saved => 1 ); + $app->add_return_arg( saved => $profile->{object}->id ); $app->call_return; } ## end sub save_config @@ -460,14 +459,19 @@ sub type_file { . ( $asset->label ? $asset->label : $asset->file_name ) . " url - . "\">view

"; + . "\">view | remove

"; } else { $html .= "

File not found.

"; } } - $html - .= " \n"; + $html .= " \n" . + " \n"; + + $html .= "\n"; + return $html; } ## end sub type_file @@ -1011,7 +1015,7 @@ sub _hdlr_field_category_list { my ( $ctx, $args, $cond ) = @_; my $field = $ctx->stash('field') or return _no_field($ctx); my $value = _get_field_value($ctx); - my @ids = ref($value) eq 'ARRAY' ? @$value : ($value); + my @ids = ref($value) eq 'ARRAY' ? @$value : ($value); my $class = $ctx->stash('obj_class'); my @categories = MT->model($class)->load( { id => \@ids } ); diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm index aaf348285..51f67bee9 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm @@ -28,7 +28,6 @@ sub upgrade { # The saved version my $ver = MT->config('PluginStaticVersion'); - # $ver = undef; ### UNCOMMENT TO TEST STATIC UPGRADE ### # Check to see if $plugin->id is valid. If it's not, we need to @@ -69,13 +68,13 @@ sub upgrade { $cfg->set( 'PluginStaticVersion', $plugin_id . '=' . $static_version, 1 ); $self->progress( - $self->translate_escape( - "Plugin '[_1]' upgraded successfully to " - . "version [_2] (static version [_3]).", - $plugin->label, - $plugin->version || '-', - $static_version - ) + $self->translate_escape( + "Plugin '[_1]' upgraded successfully to " + . "version [_2] (static version [_3]).", + $plugin->label, + $plugin->version || '-', + $static_version + ) ); } ## end if ( $static_version >...) } ## end for my $sig ( keys %MT::Plugins) diff --git a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm index 08aecb756..78f03169c 100644 --- a/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm +++ b/addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm @@ -3,9 +3,11 @@ package ConfigAssistant::Util; use strict; use warnings; use base 'Exporter'; -our @EXPORT_OK = qw( find_theme_plugin find_template_def find_option_def - find_option_plugin process_file_upload - ERROR SUCCESS OVERWRITE NO_UPLOAD ); +our @EXPORT_OK + = qw( find_theme_plugin find_template_def find_option_def + find_option_plugin process_file_upload + plugin_static_web_path plugin_static_file_path + ERROR SUCCESS OVERWRITE NO_UPLOAD ); use MT::Util qw( encode_url ); @@ -14,6 +16,21 @@ sub SUCCESS () {1} sub OVERWRITE () {2} sub NO_UPLOAD () {3} +sub plugin_static_web_path { + my ($plugin) = @_; + my $url = MT->instance->static_path; + $url .= '/' unless $url =~ m!/$!; + $url .= 'support/plugins/' . $plugin->id . '/'; + return $url; +} + +sub plugin_static_file_path { + my ($plugin) = @_; + return File::Spec->catdir( MT->instance->static_file_path, + 'support', 'plugins', $plugin->id ); + +} + sub process_file_upload { my $app = shift; my ( $param_name, $scope, $extra_path, %upload_param ) = @_; diff --git a/addons/ConfigAssistant.pack/static/js/app.js b/addons/ConfigAssistant.pack/static/js/app.js index 34d935862..bceebfae4 100644 --- a/addons/ConfigAssistant.pack/static/js/app.js +++ b/addons/ConfigAssistant.pack/static/js/app.js @@ -1,19 +1,19 @@ $(document).ready( function() { - var active = $('#content-nav ul li.active a').attr('id'); - $('#' + active + '-content').show(); $('h2#page-title span').html( $('#content-nav ul li.active a b').html() ); $('#fieldsets input, #fieldsets select, #fieldsets textarea').change( function () { var changed = $(this).parent().parent().parent().attr('id'); $('#content-nav ul li.'+changed).addClass('changed'); }); $('#content-nav ul li a').click( function() { - var newactive = $(this).attr('id'); + var active = $(this).parents('ul').find('li.active a').attr('id').replace(/-tab$/,''); + var newactive = $(this).attr('id').replace(/-tab$/,''); $('#content-nav li.active').removeClass('active'); - $('#' + active + '-content').hide(); - $('#content-nav li.' + newactive).addClass('active'); - $('#' + newactive + '-content').show(); - $('h2#page-title span').html( $('#content-nav ul li.'+newactive+' a b').html() ); - active = newactive; + $('#' + active + '-tab-content').hide(); + $('#content-nav li.' + newactive+'-tab').addClass('active'); + $('#' + newactive + '-tab-content').show(); + $('h2#page-title span').html( $('#content-nav ul li.'+newactive+'-tab a b').html() ); + document.title = $(this).attr('title'); + window.location.hash = newactive; }); $('.field-type-radio-image li input:checked').each( function() { $(this).parent().addClass('selected'); }); $('.field-type-radio-image li').click( function() { @@ -24,4 +24,10 @@ $(document).ready( function() { var changed = $(this).parent().parent().parent().parent().attr('id'); $('#content-nav ul li.'+changed).addClass('changed'); }); + $.history.init(function(hash){ + if (hash == "") { + hash = $('#content-nav ul li:first-child a').attr('id').replace(/-tab$/,''); + } + $('#content-nav ul li.'+hash+'-tab a').click(); + }); }); diff --git a/addons/ConfigAssistant.pack/static/js/jquery.history.js b/addons/ConfigAssistant.pack/static/js/jquery.history.js new file mode 100644 index 000000000..7f91079d4 --- /dev/null +++ b/addons/ConfigAssistant.pack/static/js/jquery.history.js @@ -0,0 +1,194 @@ +/* + * jQuery history plugin + * + * The MIT License + * + * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari) + * Copyright (c) 2010 Takayuki Miwa + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +(function($) { + var locationWrapper = { + put: function(hash, win) { + (win || window).location.hash = this.encoder(hash); + }, + get: function(win) { + var hash = ((win || window).location.hash).replace(/^#/, ''); + try { + return $.browser.mozilla ? hash : decodeURIComponent(hash); + } + catch (error) { + return hash; + } + }, + encoder: encodeURIComponent + }; + + var iframeWrapper = { + id: "__jQuery_history", + init: function() { + var html = '