Skip to content

Commit

Permalink
Updated Config Assistant from version 2.1.9 to version 2.1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
jayallen committed Jan 25, 2011
1 parent 5a4d6c9 commit d3948f2
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 103 deletions.
6 changes: 3 additions & 3 deletions addons/ConfigAssistant.pack/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
60 changes: 26 additions & 34 deletions addons/ConfigAssistant.pack/lib/ConfigAssistant/Init.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -99,7 +91,7 @@ sub init_options {
else {

# if ( my $default = $option->{default} ) {
# if ( !ref($default)
# if ( !ref($default)
# && ( $default =~ /^\s*sub/
# || $default =~ /^\$/)) {
# $default
Expand All @@ -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)
Expand Down Expand Up @@ -192,7 +184,7 @@ sub load_tags {
class => 'system',
category => 'plugin',
level => MT::Log::ERROR(),
}
}
);
}
}
Expand Down
90 changes: 47 additions & 43 deletions addons/ConfigAssistant.pack/lib/ConfigAssistant/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 "
. "<mt:StaticWebPath> instead.",
$ctx->stash('tag'),
$sig
)
MT->translate(
"The plugin you specified '[_2]' in '[_1]' has not"
. "registered a static directory. Please use "
. "<mt:StaticWebPath> instead.",
$ctx->stash('tag'),
$sig
)
);
}
} ## end sub tag_plugin_static_web_path
Expand All @@ -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 "
. "<mt:StaticFilePath> instead.",
$_[0]->stash('tag')
)
MT->translate(
"The plugin you specified in '[_1]' has not "
. "registered a static directory. Please use "
. "<mt:StaticFilePath> instead.",
$_[0]->stash('tag')
)
);
}
} ## end sub tag_plugin_static_file_path
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand All @@ -460,14 +459,19 @@ sub type_file {
. ( $asset->label ? $asset->label : $asset->file_name )
. " <a target=\"_new\" href=\""
. $asset->url
. "\">view</a></p>";
. "\">view</a> | <a href=\"javascript:void(0)\" class=\"remove\">remove</a></p>";
}
else {
$html .= "<p>File not found.</p>";
}
}
$html
.= " <input type=\"file\" name=\"$field_id\" class=\"full-width\" />\n";
$html .= " <input type=\"file\" name=\"$field_id\" class=\"full-width\" />\n" .
" <input type=\"hidden\" name=\"$field_id-clear\" value=\"0\" class=\"clear-file\" />\n";

$html .= "<script type=\"text/javascript\">\n";
$html .= " \$('#field-".$field_id." a.remove').click( handle_remove_file );\n";
$html .= "</script>\n";

return $html;
} ## end sub type_file

Expand Down Expand Up @@ -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 } );
Expand Down
15 changes: 7 additions & 8 deletions addons/ConfigAssistant.pack/lib/ConfigAssistant/Static.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 20 additions & 3 deletions addons/ConfigAssistant.pack/lib/ConfigAssistant/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 ) = @_;
Expand Down
22 changes: 14 additions & 8 deletions addons/ConfigAssistant.pack/static/js/app.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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();
});
});
Loading

0 comments on commit d3948f2

Please sign in to comment.