Commit a40bfcc83028f67e62ebf02006d0afe3bff4eb53

Authored by Evandro Junior
1 parent da6fec43
Exists in master

Added full path to send email

controllers/email_article_plugin_myprofile_controller.rb
1 class EmailArticlePluginMyprofileController < MyProfileController 1 class EmailArticlePluginMyprofileController < MyProfileController
  2 +
2 3
3 needs_profile 4 needs_profile
4 # before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] 5 # before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add]
@@ -14,6 +15,7 @@ class EmailArticlePluginMyprofileController &lt; MyProfileController @@ -14,6 +15,7 @@ class EmailArticlePluginMyprofileController &lt; MyProfileController
14 end 15 end
15 16
16 class Sender < ActionMailer::Base 17 class Sender < ActionMailer::Base
  18 + add_template_helper(PersonNotifierHelper)
17 def mail(article) 19 def mail(article)
18 members = article.profile.members 20 members = article.profile.members
19 emails = [] 21 emails = []
@@ -25,7 +27,26 @@ class EmailArticlePluginMyprofileController &lt; MyProfileController @@ -25,7 +27,26 @@ class EmailArticlePluginMyprofileController &lt; MyProfileController
25 from "#{article.author.user.name} <#{article.author.user.email}>" 27 from "#{article.author.user.name} <#{article.author.user.email}>"
26 reply_to article.author.user.email 28 reply_to article.author.user.email
27 subject "[Artigo] " + article.title 29 subject "[Artigo] " + article.title
28 - body article.body 30 + body set_absolute_path(article.body, article.environment)
29 end 31 end
  32 +
  33 + def set_absolute_path(body, environment)
  34 + parsed = Hpricot(body.to_s)
  35 + parsed.search('img[@src]').map { |i| change_element_path(i, 'src', environment) }
  36 + parsed.search('a[@href]').map { |i| change_element_path(i, 'href', environment) }
  37 + parsed.to_s
30 end 38 end
  39 +
  40 + def change_element_path(el, attribute, environment)
  41 + fullpath = /^http/.match(el[attribute])
  42 + if not fullpath
  43 + relative_path = /\/?(.*)/.match(el[attribute])
  44 + el[attribute] = "http://#{environment.default_hostname}/#{relative_path[1]}"
  45 + end
  46 + end
  47 +
  48 +
  49 + end
  50 +
  51 +
31 end 52 end
32 \ No newline at end of file 53 \ No newline at end of file
lib/email_article_plugin.rb
@@ -5,7 +5,7 @@ class EmailArticlePlugin &lt; Noosfero::Plugin @@ -5,7 +5,7 @@ class EmailArticlePlugin &lt; Noosfero::Plugin
5 end 5 end
6 6
7 def self.plugin_description 7 def self.plugin_description
8 - _("A plugin that emails an article to the members of the community.") 8 + _("A plugin that emails an article to the members of the community")
9 end 9 end
10 10
11 def article_toolbar_extra_buttons 11 def article_toolbar_extra_buttons
test/unit/email_article_plugin_test.rb
@@ -11,11 +11,11 @@ class EmailArticlePluginTest &lt; ActiveSupport::TestCase @@ -11,11 +11,11 @@ class EmailArticlePluginTest &lt; ActiveSupport::TestCase
11 end 11 end
12 12
13 should 'have name' do 13 should 'have name' do
14 - assert_equal 'Relevant Content Plugin', EmailArticlePlugin.plugin_name 14 + assert_equal 'Email Article to Community Members Plugin', EmailArticlePlugin.plugin_name
15 end 15 end
16 16
17 should 'have description' do 17 should 'have description' do
18 - assert_equal _("A plugin that lists the most accessed, most commented, most liked and most disliked contents."), EmailArticlePlugin.plugin_description 18 + assert_equal _("A plugin that emails an article to the members of the community"), EmailArticlePlugin.plugin_description
19 end 19 end
20 20
21 end 21 end