Revisions
-
rayners revised this gist
May 21, 2010 . 3 changed files with 55 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,8 @@ use warnings; use base qw( MT::Plugin ); use MT::Util qw(dirify); sub load_config { my $plugin = shift; @@ -19,5 +21,45 @@ sub load_config { # for example, set dynamic_setting to the current time $param->{dynamic_setting} = time; require MT::Blog; my $blog = MT::Blog->load($blog_id); my $setting_name = dirify( $blog->name ); $param->{custom_setting_loop} = [ { setting_name => $setting_name, setting_value => $plugin->get_config_value( $setting_name, $scope ) || ${ $plugin->get_config_value( 'settings_hash', $scope ) || {} }{$setting_name} } ]; } } sub save_config { my $plugin = shift; my ( $param, $scope ) = @_; if ( $scope =~ /^blog:(\d+)$/ ) { my $blog_id = $1; require MT::Blog; my $blog = MT::Blog->load($blog_id); my $setting_name = dirify( $blog->name ); my $setting_value = $param->{$setting_name}; $param->{settings_hash} = { $setting_name => $setting_value }; } $plugin->SUPER::save_config(@_); if ( $scope =~ /^blog:(\d+)$/ ) { my $blog_id = $1; require MT::Blog; my $blog = MT::Blog->load($blog_id); my $setting_name = dirify( $blog->name ); my $setting_value = $param->{$setting_name}; $plugin->set_config_value( $setting_name, $setting_value, $scope ); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,12 @@ id="dynamic_setting" label="Dynamic Setting"> <input type="text" name="dynamic_setting" value="<mt:var name="dynamic_setting">" /> </mtapp:setting> <mt:loop name="custom_setting_loop"> <mtapp:setting id="$setting_name" label="$setting_name"> <input type="text" name="<mt:var name="setting_name">" value="<mt:var name="setting_value">" /> </mtapp:setting> </mt:loop> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,10 @@ name: Plugin Name settings: dynamic_setting: scope: blog default: 0 settings_hash: scope: blog init: sub { my $p = shift; require PluginName::Plugin; bless $p, 'PluginName::Plugin', $p; } -
rayners revised this gist
May 17, 2010 . 2 changed files with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ sub load_config { # tweak $param as needed for values # to pass to the config template # for example, set dynamic_setting to the current time $param->{dynamic_setting} = time; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ <mtapp:setting id="dynamic_setting" label="Dynamic Setting"> -
rayners revised this gist
May 17, 2010 . 3 changed files with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ package PluginName::Plugin; use strict; @@ -17,5 +16,8 @@ sub load_config { # tweak $param as needed for values # to pass to the config template # for example, set dynamic setting to the current time $param->{dynamic_setting} = time; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,9 @@ name: Plugin Name settings: dynamic_setting: default: 0 init: sub { my $p = shift; require PluginName::Plugin; bless $p, 'PluginName::Plugin', $p; } config_template: config.tmpl This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ <mtapp:setting id="dynamic_setting" label="Dynamic Setting"> <input type="text" name="dynamic_setting" value="<mt:var name="dynamic_setting">" /> </mtapp:setting> -
rayners created this gist
May 17, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ name: Plugin Name init: sub { my $p = shift; require PluginName::Plugin; bless $p, 'PluginName::Plugin', $p; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ package PluginName::Plugin; use strict; use warnings; use base qw( MT::Plugin ); sub load_config { my $plugin = shift; $plugin->SUPER::load_config(@_); my ( $param, $scope ) = @_; if ( $scope =~ /^blog:(\d+)$/ ) { my $blog_id = $1; # tweak $param as needed for values # to pass to the config template } }