Class: TDiary::Plugin

Inherits:
Object show all
Includes:
ERB::Util, ViewHelper
Defined in:
lib/tdiary/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ViewHelper

#base_url, #bot?

Constructor Details

#initialize(params) ⇒ Plugin

Returns a new instance of Plugin.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tdiary/plugin.rb', line 16

def initialize( params )
	@header_procs = []
	@footer_procs = []
	@update_procs = []
	@title_procs = []
	@body_enter_procs = []
	@body_leave_procs = []
	@section_index = {}
	@section_enter_procs = []
	@comment_leave_procs = []
	@subtitle_procs = []
	@section_leave_procs = []
	@edit_procs = []
	@form_procs = []
	@conf_keys = []
	@conf_procs = {}
	@conf_genre_label = {}
	@content_procs = {}
	@startup_procs = []
	@cookies = []
	@javascripts = []
	@javascript_setting = []

	params.each do |key, value|
		instance_variable_set( "@#{key}", value )
	end

	# for 1.4 compatibility
	@index = @conf.index
	@update = @conf.update
	@author_name = @conf.author_name || ''
	@author_mail = @conf.author_mail || ''
	@index_page = @conf.index_page || ''
	@html_title = @conf.html_title || ''
	@theme = @conf.theme
	@css = @conf.css
	@date_format = @conf.date_format
	@referer_table = @conf.referer_table
	@options = @conf.options

	# setup plugin storage
	unless @conf.io_class.method_defined?(:plugin_open)
		require 'tdiary/io/plugin_pstore'
		@conf.io_class.extend(TDiary::IO::PluginPStore)
	end
	@storage = @conf.io_class.plugin_open(@conf)

	# loading plugins
	@plugin_files = []
	plugin_path = @conf.plugin_path || "#{File.dirname(__FILE__)}/plugin"
	plugin_file = ''
	begin
		Dir::glob( "#{plugin_path}/*.rb" ).sort.each do |file|
			plugin_file = file
			load_plugin( file )
			@plugin_files << plugin_file
		end
	rescue ::TDiary::ForceRedirect
		raise
	rescue Exception
		raise PluginError::new( "Plugin error in '#{File::basename( plugin_file )}'.\n#{$!}\n#{$!.backtrace[0]}" )
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*m) ⇒ Object (private)



388
389
390
391
# File 'lib/tdiary/plugin.rb', line 388

def method_missing( *m )
	super if @debug
	# ignore when no plugin
end

Instance Attribute Details

#comment=(value) ⇒ Object (writeonly)

Sets the attribute comment

Parameters:

  • value

    the value to set the attribute comment to.



14
15
16
# File 'lib/tdiary/plugin.rb', line 14

def comment=(value)
  @comment = value
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



13
14
15
# File 'lib/tdiary/plugin.rb', line 13

def cookies
  @cookies
end

#date=(value) ⇒ Object (writeonly)

Sets the attribute date

Parameters:

  • value

    the value to set the attribute date to.



14
15
16
# File 'lib/tdiary/plugin.rb', line 14

def date=(value)
  @date = value
end

#diaries=(value) ⇒ Object (writeonly)

Sets the attribute diaries

Parameters:

  • value

    the value to set the attribute diaries to.



14
15
16
# File 'lib/tdiary/plugin.rb', line 14

def diaries=(value)
  @diaries = value
end

#last_modified=(value) ⇒ Object (writeonly)

Sets the attribute last_modified

Parameters:

  • value

    the value to set the attribute last_modified to.



14
15
16
# File 'lib/tdiary/plugin.rb', line 14

def last_modified=(value)
  @last_modified = value
end

Instance Method Details

#eval_src(src, secure) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/tdiary/plugin.rb', line 95

def eval_src( src, secure )
	self.taint
	@conf.taint
	@title_procs.taint
	@body_enter_procs.taint
	@body_leave_procs.taint
	@section_index.taint
	@section_enter_procs.taint
	@comment_leave_procs.taint
	@subtitle_procs.taint
	@section_leave_procs.taint
	ret = Safe::safe( secure ? 4 : 1 ) do
		eval( src, binding, "(TDiary::Plugin#eval_src)", 1 )
	end
	@conf.io_class.plugin_close(@storage)
	return ret
end

#load_plugin(file) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/tdiary/plugin.rb', line 80

def load_plugin( file )
	@resource_loaded = false
	begin
		res_file = File::dirname( file ) + "/#{@conf.lang}/" + File::basename( file )
		open( res_file.untaint ) do |src|
			instance_eval( src.read.untaint, "(plugin/#{@conf.lang}/#{File::basename( res_file )})", 1 )
		end
		@resource_loaded = true
	rescue IOError, Errno::ENOENT
	end
	File::open( file.untaint ) do |src|
		instance_eval( src.read.untaint, "(plugin/#{File::basename( file )})", 1 )
	end
end