Commit 8791c34e3b80da1556128b89e31dba53cca99e70

Authored by Joenio Costa
1 parent 2ee4ac05

Removed unused file

Showing 1 changed file with 0 additions and 639 deletions   Show diff stats
lib/noosfero/plugin.rb.orig
... ... @@ -1,639 +0,0 @@
1   -require 'noosfero'
2   -
3   -class Noosfero::Plugin
4   -
5   - attr_accessor :context
6   -
7   - def initialize(context=nil)
8   - self.context = context
9   - end
10   -
11   - class << self
12   -
13   - attr_writer :should_load
14   -
15   - def should_load
16   - @should_load.nil? && true || @boot
17   - end
18   -
19   -<<<<<<< HEAD
20   - def initialize!
21   - return if !should_load
22   - enabled.each do |plugin_dir|
23   - plugin_name = File.basename(plugin_dir)
24   - plugin = load_plugin(plugin_name)
25   - load_plugin_extensions(plugin_dir)
26   - load_plugin_filters(plugin)
27   - end
28   - end
29   -
30   - def setup(config)
31   - return if !should_load
32   - enabled.each do |dir|
33   - setup_plugin(dir, config)
34   -=======
35   - def init_system
36   - available_plugins.each do |dir|
37   - load_plugin dir
38   ->>>>>>> rails235
39   - end
40   - end
41   -
42   - def setup_plugin(dir, config)
43   - plugin_name = File.basename(dir)
44   -
45   - plugin_dependencies_ok = true
46   - plugin_dependencies_file = File.join(dir, 'dependencies.rb')
47   - if File.exists?(plugin_dependencies_file)
48   - begin
49   - require plugin_dependencies_file
50   - rescue LoadError => ex
51   - plugin_dependencies_ok = false
52   - $stderr.puts "W: Noosfero plugin #{plugin_name} failed to load (#{ex})"
53   - end
54   - end
55   -
56   - if plugin_dependencies_ok
57   - %w[
58   - controllers
59   - controllers/public
60   - controllers/profile
61   - controllers/myprofile
62   - controllers/admin
63   - ].each do |folder|
64   - config.autoload_paths << File.join(dir, folder)
65   - end
66   - [ config.autoload_paths, $:].each do |path|
67   - path << File.join(dir, 'models')
68   - path << File.join(dir, 'lib')
69   - # load vendor/plugins
70   - Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin|
71   - path << "#{vendor_plugin}/lib"
72   - init = "#{vendor_plugin}/init.rb"
73   - require init.gsub(/.rb$/, '') if File.file? init
74   - end
75   - end
76   -
77   - # add view path
78   - ActionController::Base.view_paths.unshift(File.join(dir, 'views'))
79   - end
80   - end
81   -
82   - def load_plugin(plugin_name)
83   - (plugin_name.to_s.camelize + 'Plugin').constantize
84   - end
85   -
86   - # This is a generic method that initialize any possible filter defined by a
87   - # plugin to a specific controller
88   - def load_plugin_filters(plugin)
89   - plugin_methods = plugin.instance_methods.select {|m| m.to_s.end_with?('_filters')}
90   - plugin_methods.each do |plugin_method|
91   - controller_class = plugin_method.to_s.gsub('_filters', '').camelize.constantize
92   - filters = plugin.new.send(plugin_method)
93   - filters = [filters] if !filters.kind_of?(Array)
94   -
95   - filters.each do |plugin_filter|
96   - filter_method = (plugin.name.underscore.gsub('/','_') + '_' + plugin_filter[:method_name]).to_sym
97   - controller_class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {}))
98   - controller_class.send(:define_method, filter_method) do
99   - instance_eval(&plugin_filter[:block]) if environment.plugin_enabled?(plugin)
100   - end
101   - end
102   - end
103   - end
104   -
105   - def load_plugin_extensions(dir)
106   - Rails.configuration.to_prepare do
107   - Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file }
108   - end
109   - end
110   -
111   - def enabled
112   - @enabled ||=
113   - begin
114   - plugins = Dir.glob(Rails.root.join('config', 'plugins', '*'))
115   - if Rails.env.test? && !plugins.include?(Rails.root.join('config', 'plugins', 'foo'))
116   - plugins << Rails.root.join('plugins', 'foo')
117   - end
118   - plugins.select do |entry|
119   - File.directory?(entry)
120   - end
121   - end
122   - end
123   -
124   -<<<<<<< HEAD
125   -
126   - def all
127   - @all ||= []
128   -=======
129   - def available_plugins
130   - unless @available_plugins
131   - path = File.join(Rails.root, 'config', 'plugins', '*')
132   - @available_plugins = Dir.glob(path).select{ |i| File.directory?(i) }
133   - if Rails.env.test? && !@available_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo'))
134   - @available_plugins << File.join(Rails.root, 'plugins', 'foo')
135   - end
136   - end
137   - @available_plugins
138   ->>>>>>> rails235
139   - end
140   -
141   - def all
142   - @all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize }
143   - end
144   -
145   - def public_name
146   - self.name.underscore.gsub('_plugin','')
147   - end
148   -
149   - def public_path(file = '')
150   - File.join('/plugins', public_name, file)
151   - end
152   -
153   - def root_path
154   - Rails.root.join('plugins', public_name)
155   - end
156   -
157   - def view_path
158   - File.join(root_path,'views')
159   - end
160   -
161   - # Here the developer should specify the meta-informations that the plugin can
162   - # inform.
163   - def plugin_name
164   - self.name.underscore.humanize
165   - end
166   - def plugin_description
167   - _("No description informed.")
168   - end
169   -
170   - def admin_url
171   - {:controller => "#{name.underscore}_admin", :action => 'index'}
172   - end
173   -
174   - def has_admin_url?
175   - File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb"))
176   - end
177   - end
178   -
179   - def expanded_template(file_path, locals = {})
180   - views_path = Rails.root.join('plugins', "#{self.class.public_name}", 'views')
181   - ERB.new(File.read("#{views_path}/#{file_path}")).result(binding)
182   - end
183   -
184   - def extra_blocks(params = {})
185   - return [] if self.class.extra_blocks.nil?
186   - blocks = self.class.extra_blocks.map do |block, options|
187   - type = options[:type]
188   - type = type.is_a?(Array) ? type : [type].compact
189   - type = type.map do |x|
190   - x.is_a?(String) ? x.capitalize.constantize : x
191   - end
192   - raise "This is not a valid type" if !type.empty? && ![Person, Community, Enterprise, Environment].detect{|m| type.include?(m)}
193   -
194   - position = options[:position]
195   - position = position.is_a?(Array) ? position : [position].compact
196   - position = position.map{|p| p.to_i}
197   - raise "This is not a valid position" if !position.empty? && ![1,2,3].detect{|m| position.include?(m)}
198   -
199   - if !type.empty? && (params[:type] != :all)
200   - block = type.include?(params[:type]) ? block : nil
201   - end
202   -
203   - if !position.empty? && !params[:position].nil?
204   - block = position.detect{ |p| [params[:position]].flatten.include?(p)} ? block : nil
205   - end
206   -
207   - block
208   - end
209   - blocks.compact!
210   - blocks || []
211   - end
212   -
213   - def macros
214   - self.class.constants.map do |constant_name|
215   - self.class.const_get(constant_name)
216   - end.select {|const| const.is_a?(Class) && const < Noosfero::Plugin::Macro}
217   - end
218   -
219   - # Here the developer may specify the events to which the plugins can
220   - # register and must return true or false. The default value must be false.
221   - # Must also explicitly define its returning variables.
222   -
223   - # -> If true, noosfero will include plugin_dir/public/style.css into
224   - # application
225   - def stylesheet?
226   - false
227   - end
228   -
229   - # -> Adds buttons to the control panel
230   - # returns = { :title => title, :icon => icon, :url => url }
231   - # title = name that will be displayed.
232   - # icon = css class name (for customized icons include them in a css file).
233   - # url = url or route to which the button will redirect.
234   - def control_panel_buttons
235   - nil
236   - end
237   -
238   - # -> Customize profile block design and behavior
239   - # (overwrites profile_image_link function)
240   - # returns = lambda block that creates html code.
241   - def profile_image_link(profile, size, tag, extra_info)
242   - nil
243   - end
244   -
245   - # -> Adds tabs to the profile
246   - # returns = { :title => title, :id => id, :content => content, :start => start }
247   - # title = name that will be displayed.
248   - # id = div id.
249   - # content = lambda block that creates html code.
250   - # start = boolean that specifies if the tab must come before noosfero tabs (optional).
251   - def profile_tabs
252   - nil
253   - end
254   -
255   - # -> Adds plugin-specific content types to CMS
256   - # returns = [ContentClass1, ContentClass2, ...]
257   - def content_types
258   - nil
259   - end
260   -
261   - # -> Adds content to calalog item
262   - # returns = lambda block that creates html code
263   - def catalog_item_extras(item)
264   - nil
265   - end
266   -
267   - # -> Adds content to profile editor info and settings
268   - # returns = lambda block that creates html code or raw rhtml/html.erb
269   - def profile_editor_extras
270   - nil
271   - end
272   -
273   - # -> Adds content to calalog list item
274   - # returns = lambda block that creates html code
275   - def catalog_list_item_extras(item)
276   - nil
277   - end
278   -
279   - # -> Adds content to products info
280   - # returns = lambda block that creates html code
281   - def product_info_extras(product)
282   - nil
283   - end
284   -
285   - # -> Adds content to products on asset list
286   - # returns = lambda block that creates html code
287   - def asset_product_extras(product)
288   - nil
289   - end
290   -
291   - # -> Adds a property to the product on asset products
292   - # returns = {:name => name, :content => content}
293   - # name = Name of the property
294   - # content = lambda block that creates an html
295   - def asset_product_properties(product)
296   - nil
297   - end
298   -
299   - # -> Adds content to the beginning of the page
300   - # returns = lambda block that creates html code or raw rhtml/html.erb
301   - def body_beginning
302   - nil
303   - end
304   -
305   - # -> Adds content to the ending of the page head
306   - # returns = lambda block that creates html code or raw rhtml/html.erb
307   - def head_ending
308   - nil
309   - end
310   -
311   - # -> Adds plugins' javascript files to application
312   - # returns = ['example1.js', 'javascripts/example2.js', 'example3.js']
313   - def js_files
314   - []
315   - end
316   -
317   - # -> Adds stuff in user data hash
318   - # returns = { :some_data => some_value, :another_data => another_value }
319   - def user_data_extras
320   - {}
321   - end
322   -
323   - # -> Parse and possibly make changes of content (article, block, etc) during HTML rendering
324   - # returns = content as string after parser and changes
325   - def parse_content(html, source)
326   - [html, source]
327   - end
328   -
329   - # -> Adds links to the admin panel
330   - # returns = {:title => title, :url => url}
331   - # title = name that will be displayed in the link
332   - # url = url or route to which the link will redirect to.
333   - def admin_panel_links
334   - nil
335   - end
336   -
337   - # -> Adds buttons to manage members page
338   - # returns = { :title => title, :icon => icon, :url => url }
339   - # title = name that will be displayed.
340   - # icon = css class name (for customized icons include them in a css file).
341   - # url = url or route to which the button will redirect.
342   - def manage_members_extra_buttons
343   - nil
344   - end
345   -
346   - # This method will be called just before a comment is saved to the database.
347   - #
348   - # It can modify the comment in several ways. In special, a plugin can call
349   - # reject! on the comment and that will cause the comment to not be saved.
350   - #
351   - # example:
352   - #
353   - # def filter_comment(comment)
354   - # if user_not_logged_in
355   - # comment.reject!
356   - # end
357   - # end
358   - #
359   - def filter_comment(comment)
360   - end
361   -
362   - # Define custom logic to filter loaded comments.
363   - #
364   - # Example:
365   - #
366   - # def unavailable_comments(scope)
367   - # scope.without_spams
368   - # end
369   - #
370   - def unavailable_comments(scope)
371   - scope
372   - end
373   -
374   - # -> Allows plugins to check weather object is a spam
375   - def check_for_spam(object)
376   - end
377   -
378   - # -> Allows plugins to know when an object is marked as a spam
379   - def marked_as_spam(object)
380   - end
381   -
382   - # -> Allows plugins to know when an object is marked as a ham
383   - def marked_as_ham(object)
384   - end
385   -
386   - # Adds extra actions for comments
387   - # returns = list of hashes or lambda block that creates a list of hashes
388   - # example:
389   - #
390   - # def comment_actions(comment)
391   - # [{:link => link_to_function(...)}]
392   - # end
393   - #
394   - def comment_actions(comment)
395   - nil
396   - end
397   -
398   - # This method is called when the user click on comment actions menu.
399   - # returns = list or lambda block that return ids of enabled menu items for comments
400   - # example:
401   - #
402   - # def check_comment_actions(comment)
403   - # ['#action1', '#action2']
404   - # end
405   - #
406   - def check_comment_actions(comment)
407   - []
408   - end
409   -
410   - # -> Adds adicional content to article
411   - # returns = lambda block that creates html code
412   - def article_extra_contents(article)
413   - nil
414   - end
415   -
416   - # -> Adds fields to the signup form
417   - # returns = lambda block that creates html code
418   - def signup_extra_contents
419   - nil
420   - end
421   -
422   - # -> Adds adicional content to profile info
423   - # returns = lambda block that creates html code
424   - def profile_info_extra_contents
425   - nil
426   - end
427   -
428   - # -> Removes the invite friend button from the friends controller
429   - # returns = boolean
430   - def remove_invite_friends_button
431   - nil
432   - end
433   -
434   - # -> Extends organization list of members
435   - # returns = An instance of ActiveRecord::NamedScope::Scope retrieved through
436   - # Person.members_of method.
437   - def organization_members(organization)
438   - nil
439   - end
440   -
441   - # -> Extends person memberships list
442   - # returns = An instance of ActiveRecord::NamedScope::Scope retrived through
443   - # Person.memberships_of method.
444   - def person_memberships(person)
445   - nil
446   - end
447   -
448   - # -> Extends person permission access
449   - # returns = boolean
450   - def has_permission?(person, permission, target)
451   - nil
452   - end
453   -
454   - # -> Adds hidden_fields to the new community view
455   - # returns = {key => value}
456   - def new_community_hidden_fields
457   - nil
458   - end
459   -
460   - # -> Adds hidden_fields to the enterprise registration view
461   - # returns = {key => value}
462   - def enterprise_registration_hidden_fields
463   - nil
464   - end
465   -
466   - # -> Add an alternative authentication method.
467   - # Your plugin have to make the access control and return the logged user.
468   - # returns = User
469   - def alternative_authentication
470   - nil
471   - end
472   -
473   - # -> Adds adicional link to make the user authentication
474   - # returns = lambda block that creates html code
475   - def alternative_authentication_link
476   - nil
477   - end
478   -
479   - # -> Allow or not user registration
480   - # returns = boolean
481   - def allow_user_registration
482   - true
483   - end
484   -
485   - # -> Allow or not password recovery by users
486   - # returns = boolean
487   - def allow_password_recovery
488   - true
489   - end
490   -
491   - # -> Adds fields to the login form
492   - # returns = lambda block that creates html code
493   - def login_extra_contents
494   - nil
495   - end
496   -
497   - # -> Adds adicional content to comment form
498   - # returns = lambda block that creates html code
499   - def comment_form_extra_contents(args)
500   - nil
501   - end
502   -
503   - # -> Adds adicional content to article header
504   - # returns = lambda block that creates html code
505   - def article_header_extra_contents(article)
506   - nil
507   - end
508   -
509   - # -> Adds adittional content to comment visualization
510   - # returns = lambda block that creates html code
511   - def comment_extra_contents(args)
512   - nil
513   - end
514   -
515   - # This method is called when the user clicks to send a comment.
516   - # A plugin can add new content to comment form and this method can process the params sent to avoid creating field on core tables.
517   - # returns = params after processed by plugins
518   - # example:
519   - #
520   - # def process_extra_comment_params(params)
521   - # params.delete(:extra_field)
522   - # end
523   - #
524   - def process_extra_comment_params(params)
525   - params
526   - end
527   -
528   - # -> Finds objects by their contents
529   - # returns = {:results => [a, b, c, ...], ...}
530   - # P.S.: The plugin might add other informations on the return hash for its
531   - # own use in specific views
532   - def find_by_contents(asset, scope, query, paginate_options={}, options={})
533   - end
534   -
535   - # -> Adds aditional fields for change_password
536   - # returns = [{:field => 'field1', :name => 'field 1 name', :model => 'person'}, {...}]
537   - def change_password_fields
538   - nil
539   - end
540   -
541   - # -> Adds additional blocks to profiles and environments.
542   - # Your plugin must implements a class method called 'extra_blocks'
543   - # that returns a hash with the following syntax.
544   - # {
545   - # 'block_name' =>
546   - # {
547   - # :type => 'for which holder the block will be available',
548   - # :position => 'where the block could be displayed'
549   - # }
550   - # }
551   - #
552   - # Where:
553   - #
554   - # - block_name: Name of the new block added to the blocks list
555   - # - type: Might have some of the values
556   - # - 'environment' or Environment: If the block is available only for Environment models
557   - # - 'community' or Community: If the block is available only for Community models
558   - # - 'enterprise' or Enterprise: If the block is available only for Enterprise models
559   - # - 'person' or Person: If the block is available only for Person models
560   - # - nil: If no type parameter is passed the block will be available for all types
561   - # - position: Is the layout position of the block. It should be:
562   - # - '1' or 1: Area 1 of layout
563   - # - '2' or 2: Area 2 of layout
564   - # - '3' or 3: Area 3 of layout
565   - # - nil: If no position parameter is passed the block will be available for all positions
566   - #
567   - # OBS: Area 1 is where stay the main content of layout. Areas 2 and 3 are the sides of layout.
568   - #
569   - # examples:
570   - #
571   - # def self.extra_blocks(params)
572   - # {
573   - # #Display 'CustomBlock1' only for 'Person' on position '1'
574   - # CustomBlock1 => {:type => 'person', :position => '1' },
575   - #
576   - # #Display 'CustomBlock2' only for 'Community' on position '2'
577   - # CustomBlock2 => {:type => Community, :position => '2' },
578   - #
579   - # #Display 'CustomBlock3' only for 'Enterprise' on position '3'
580   - # CustomBlock3 => {:type => 'enterprise', :position => 3 },
581   - #
582   - # #Display 'CustomBlock2' for 'Environment' and 'Person' on positions '1' and '3'
583   - # CustomBlock4 => {:type => ['environment', Person], :position => ['1','3'] },
584   - #
585   - # #Display 'CustomBlock5' for all types and all positions
586   - # CustomBlock5 => {},
587   - # }
588   - # end
589   - #
590   - # OBS: The default value is a empty hash.
591   - def self.extra_blocks
592   - {}
593   - end
594   -
595   - def method_missing(method, *args, &block)
596   - # This is a generic hotspot for all controllers on Noosfero.
597   - # If any plugin wants to define filters to run on any controller, the name of
598   - # the hotspot must be in the following form: <underscored_controller_name>_filters.
599   - # Example: for ProfileController the hotspot is profile_controller_filters
600   - #
601   - # -> Adds a filter to a controller
602   - # returns = { :type => type,
603   - # :method_name => method_name,
604   - # :options => {:opt1 => opt1, :opt2 => opt2},
605   - # :block => Proc or lambda block}
606   - # type = 'before_filter' or 'after_filter'
607   - # method_name = The name of the filter
608   - # option = Filter options, like :only or :except
609   - # block = Block that the filter will call
610   - if method.to_s =~ /^(.+)_controller_filters$/
611   - []
612   - # -> Removes the action button from the content
613   - # returns = boolean
614   - elsif method.to_s =~ /^content_remove_(#{content_actions.join('|')})$/
615   - nil
616   - # -> Expire the action button from the content
617   - # returns = string with reason of expiration
618   - elsif method.to_s =~ /^content_expire_(#{content_actions.join('|')})$/
619   - nil
620   - else
621   - super
622   - end
623   - end
624   -
625   - private
626   -
627   - def content_actions
628   - #FIXME 'new' and 'upload' only works for content_remove. It should work for
629   - #content_expire too.
630   - %w[edit delete spread locale suggest home new upload]
631   - end
632   -
633   -end
634   -
635   -require 'noosfero/plugin/hot_spot'
636   -require 'noosfero/plugin/manager'
637   -require 'noosfero/plugin/active_record'
638   -require 'noosfero/plugin/mailer_base'
639   -require 'noosfero/plugin/settings'