Skip to content

Commit

Permalink
[#975 state:resolved] Updating Theme Manager to v0.10.24 (from v0.10.…
Browse files Browse the repository at this point in the history
  • Loading branch information
jayallen committed Jul 13, 2011
1 parent bb1459a commit 5867b84
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 132 deletions.
4 changes: 2 additions & 2 deletions addons/ThemeManager.plugin/config.yaml
Expand Up @@ -4,7 +4,7 @@ key: ThemeManager
author_link: http://endevver.com/
author_name: Endevver
description: 'A comprehensive theme management plugin!'
version: 0.10.23
version: 0.10.24
schema_version: 7
static_version: 7
l10n_class: ThemeManager::L10N
Expand Down Expand Up @@ -42,7 +42,7 @@ callbacks:
template_param.edit_blog: $ThemeManager::ThemeManager::TemplateInstall::xfrm_param_add_language

init_app: $ThemeManager::ThemeManager::Init::init_app

object_types:
theme: ThemeManager::Theme
blog:
Expand Down
@@ -1,7 +1,7 @@
package ThemeManager::DashboardWidget;

use ThemeManager::Util qw( theme_label theme_description theme_author_name
theme_author_link theme_version theme_link theme_doc_link theme_docs
theme_author_link theme_version theme_link theme_doc_link theme_documentation
);

use strict;
Expand Down
94 changes: 66 additions & 28 deletions addons/ThemeManager.plugin/lib/ThemeManager/Plugin.pm
Expand Up @@ -5,7 +5,7 @@ use ConfigAssistant::Util qw( find_theme_plugin );
use ThemeManager::Util qw( theme_label theme_thumbnail_url theme_preview_url
theme_description theme_author_name theme_author_link
theme_paypal_email theme_version theme_link theme_doc_link
theme_about_designer theme_docs theme_thumb_path theme_thumb_url
theme_about_designer theme_documentation theme_thumb_path theme_thumb_url
prepare_theme_meta );
use MT::Util qw(caturl dirify offset_time_list);
use MT;
Expand Down Expand Up @@ -41,7 +41,27 @@ sub update_menus {
order => 1,
mode => 'theme_dashboard',
view => 'blog',
permission => 'edit_templates',
},

# Add the theme documentation to the menu to make it more prominent,
# if documentation is provided with this theme.
'design:theme_documentation' => {
label => 'Theme Documentation',
order => 2,
view => 'blog',
link => sub {

# @_ contains... something. It's not an $app
# reference, and doesn't appear to directly have
# a blog object or the blog ID available. So, grab
# a new instance.
my $app = MT->instance;
return
$app->uri(
mode => 'theme_dashboard',
args => { blog_id => $app->blog->id, },
) . '#docs'; # Go to Documentation.
},
},

# Add the new template menu option, which is actually a link to the
Expand Down Expand Up @@ -225,25 +245,7 @@ sub theme_dashboard {
# use because it was previously sanitized through the Util methods (such
# as theme_label and theme_description). But if the user is in Designer
# Mode, we want to ensure that fallback values are used if necessary.
# TODO Refactor this into a single method call where you pass in $theme_meta and get out a parameter hash ref.
$param->{theme_label} = theme_label( $theme_meta->{label}, $plugin );
$param->{theme_description}
= theme_description( $theme_meta->{description}, $plugin );
$param->{theme_author_name}
= theme_author_name( $theme_meta->{author_name}, $plugin );
$param->{theme_author_link}
= theme_author_link( $theme_meta->{author_link}, $plugin );
$param->{theme_link} = theme_link( $theme_meta->{link}, $plugin );
$param->{theme_doc_link}
= theme_doc_link( $theme_meta->{doc_link}, $plugin );
$param->{theme_version}
= theme_version( $theme_meta->{version}, $plugin );
$param->{paypal_email}
= theme_paypal_email( $theme_meta->{paypal_email}, $plugin );
$param->{about_designer}
= theme_about_designer( $theme_meta->{about_designer}, $plugin );
$param->{theme_docs}
= theme_docs( $theme_meta->{documentation}, $plugin );
$param = _populate_theme_dashboard($param, $theme_meta, $plugin);

# Grab the template set language, or fall back to the blog language.
my $template_set_language = $blog->template_set_language
Expand Down Expand Up @@ -283,6 +285,17 @@ sub theme_dashboard {
$param->{custom_fields_refreshed} = $q->param('custom_fields_refreshed');
$param->{fd_fields_refreshed} = $q->param('fd_fields_refreshed');

# Grab the user's permissions to decide what tabs and content to display
# on the theme dashboard.
my $perms = $app->blog ? $app->permissions : $app->user->permissions;
return $app->return_to_dashboard( redirect => 1 )
unless $perms || $app->user->is_superuser;

# If adequate permissions, return true; else false.
$param->{has_permission} = ( $perms && $perms->can_edit_templates )
? 1 : 0;


my $tmpl = $tm->load_tmpl('theme_dashboard.mtml');
return $app->listing( {
type => 'theme',
Expand All @@ -293,14 +306,13 @@ sub theme_dashboard {
my ( $theme, $row ) = @_;

# Use the plugin sig to grab the plugin.
# FIXME $app->component($theme->plugin_sig) ???
my $plugin = $MT::Plugins{ $theme->plugin_sig }->{object};
my $plugin = $app->component( $theme->plugin_sig );
if ( !$plugin ) {

# This plugin couldn't be loaded! That must mean the theme has
# been uninstalled, so remove the entry in the table.
$theme->remove;
$theme->save;
$theme->save or die $theme->errstr;
next;
}
$row->{id} = $theme->ts_id;
Expand Down Expand Up @@ -467,11 +479,9 @@ sub setup_theme {
# set up. If there are, we want them to look good (including being sorted)
# into alphabeticized fieldsets and to be ordered correctly with in each
# fieldset, just like on the Theme Options page.
# FIXME Use MT->component
my $plugin = $MT::Plugins{$plugin_sig}->{object};
my $plugin = MT->component($plugin_sig);

# FIXME Use $plugin->registry('template_sets', $ts_id);
my $ts = $plugin->{registry}->{'template_sets'}->{$ts_id};
my $ts = $plugin->registry('template_sets', $ts_id);

# Convert the saved YAML back into a hash.
my $theme_meta
Expand Down Expand Up @@ -1549,6 +1559,34 @@ sub _find_supported_languages {
return @ts_langs;
} ## end sub _find_supported_languages

# Add all the necessary values to $param to populate the theme dashboard.
sub _populate_theme_dashboard {
my ($param) = shift;
my ($theme_meta) = shift;
my ($plugin) = shift;

$param->{theme_label} = theme_label( $theme_meta->{label}, $plugin );
$param->{theme_description}
= theme_description( $theme_meta->{description}, $plugin );
$param->{theme_author_name}
= theme_author_name( $theme_meta->{author_name}, $plugin );
$param->{theme_author_link}
= theme_author_link( $theme_meta->{author_link}, $plugin );
$param->{theme_link} = theme_link( $theme_meta->{link}, $plugin );
$param->{theme_doc_link}
= theme_doc_link( $theme_meta->{doc_link}, $plugin );
$param->{theme_version}
= theme_version( $theme_meta->{version}, $plugin );
$param->{theme_paypal_email}
= theme_paypal_email( $theme_meta->{paypal_email}, $plugin );
$param->{theme_about_designer}
= theme_about_designer( $theme_meta->{about_designer}, $plugin );
$param->{theme_documentation}
= theme_documentation( $theme_meta->{documentation}, $plugin );

return $param;
}

1;

__END__
7 changes: 3 additions & 4 deletions addons/ThemeManager.plugin/lib/ThemeManager/Util.pm
Expand Up @@ -8,7 +8,7 @@ use base 'Exporter';
our @EXPORT_OK = qw( theme_label theme_thumbnail_url theme_preview_url
theme_description theme_author_name theme_author_link
theme_paypal_email theme_version theme_link theme_doc_link
theme_about_designer theme_docs theme_thumb_path theme_thumb_url
theme_about_designer theme_documentation theme_thumb_path theme_thumb_url
prepare_theme_meta );

# TODO - this looks very broken to me. NO global variables.
Expand Down Expand Up @@ -154,9 +154,8 @@ sub theme_about_designer {
return _return_data( $data, $obj );
}

sub theme_docs {

# Theme Docs are inline-presented documentation.
# Theme Docs are inline-presented documentation.
sub theme_documentation {
my ( $data, $obj ) = @_;
return _return_data( $data, $obj );
}
Expand Down

0 comments on commit 5867b84

Please sign in to comment.