lib/tdiary/plugin.rb in tdiary-4.1.1 vs lib/tdiary/plugin.rb in tdiary-4.1.2

- old
+ new

@@ -29,10 +29,11 @@ @form_procs = [] @conf_keys = [] @conf_procs = {} @conf_genre_label = {} @content_procs = {} + @startup_procs = [] @cookies = [] @javascripts = [] @javascript_setting = [] params.each do |key, value| @@ -335,18 +336,28 @@ raise PluginError::new( "Plugin error: #{key} is not found." ) end @content_procs[key].call( date ) end + def add_startup_proc( block = Proc::new ) + @startup_procs << block + end + + def startup_proc( app ) + @startup_procs.each do |proc| + proc.call( app ) + end + end + def remove_tag( str ) str.gsub( /<[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$)/, '' ) end def apply_plugin( str, remove_tag = false ) return '' unless str r = str.dup - if @conf.options['apply_plugin'] and str.index( '<%' ) then - r = str.untaint if $SAFE < 3 + if @conf.options['apply_plugin'] and r.index( '<%' ) then + r = r.untaint if $SAFE < 3 Safe::safe( @conf.secure ? 4 : 1 ) do begin r = ERB::new( r ).result( binding ) rescue Exception r = %Q|<p class="message">Invalid Text</p>#{r}|