Commit a40bfcc83028f67e62ebf02006d0afe3bff4eb53
1 parent
da6fec43
Exists in
master
Added full path to send email
Showing
3 changed files
with
25 additions
and
4 deletions
Show diff stats
controllers/email_article_plugin_myprofile_controller.rb
1 | 1 | class EmailArticlePluginMyprofileController < MyProfileController |
2 | + | |
2 | 3 | |
3 | 4 | needs_profile |
4 | 5 | # before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] |
... | ... | @@ -14,6 +15,7 @@ class EmailArticlePluginMyprofileController < MyProfileController |
14 | 15 | end |
15 | 16 | |
16 | 17 | class Sender < ActionMailer::Base |
18 | + add_template_helper(PersonNotifierHelper) | |
17 | 19 | def mail(article) |
18 | 20 | members = article.profile.members |
19 | 21 | emails = [] |
... | ... | @@ -25,7 +27,26 @@ class EmailArticlePluginMyprofileController < MyProfileController |
25 | 27 | from "#{article.author.user.name} <#{article.author.user.email}>" |
26 | 28 | reply_to article.author.user.email |
27 | 29 | subject "[Artigo] " + article.title |
28 | - body article.body | |
30 | + body set_absolute_path(article.body, article.environment) | |
29 | 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 | 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 | 52 | end |
32 | 53 | \ No newline at end of file | ... | ... |
lib/email_article_plugin.rb
... | ... | @@ -5,7 +5,7 @@ class EmailArticlePlugin < Noosfero::Plugin |
5 | 5 | end |
6 | 6 | |
7 | 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 | 9 | end |
10 | 10 | |
11 | 11 | def article_toolbar_extra_buttons | ... | ... |
test/unit/email_article_plugin_test.rb
... | ... | @@ -11,11 +11,11 @@ class EmailArticlePluginTest < ActiveSupport::TestCase |
11 | 11 | end |
12 | 12 | |
13 | 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 | 15 | end |
16 | 16 | |
17 | 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 | 19 | end |
20 | 20 | |
21 | 21 | end | ... | ... |