Commit 22cae98ba54fcadba6fde00d8cfe586a6eea2c89

Authored by Evandro Junior
1 parent 59c52951
Exists in master

adapt to new way for sending mail

controllers/email_article_plugin_myprofile_controller_old.rb 0 → 100644
... ... @@ -0,0 +1,80 @@
  1 +require 'nokogiri'
  2 +
  3 +class EmailArticlePluginMyprofileController < MyProfileController
  4 +
  5 + needs_profile
  6 +
  7 + def send_email
  8 + if user.is_admin?(profile)
  9 + article = profile.articles.find(params[:id])
  10 + #EmailArticlePluginMyprofileController::Sender.content(article).deliver
  11 + Sender.content(article)
  12 + render :text => "Email sent to queue"
  13 + else
  14 + render :status => :forbidden, :text => "Forbidden user"
  15 + end
  16 + end
  17 +
  18 + class Sender
  19 + def self.content(article)
  20 + source = article.author.user.person
  21 + mail = Mailing.new
  22 + mail.
  23 + # mailing = create(Mailing, :source => article.author.user.person, :subject => 'Hello', :body => 'We have some news', :person => article.author.user.person)
  24 + end
  25 +
  26 + def absolute_url? url
  27 + url.start_with?('http') || url.start_with?('ftp')
  28 + end
  29 + end
  30 +
  31 +
  32 + class Sender < ActionMailer::Base
  33 + def content(article)
  34 + doc = Nokogiri::HTML(article.body)
  35 + doc.css("a").each do |link|
  36 + if !link.attribute("href").nil? and !absolute_url?(link.attribute("href").value)
  37 + relative_path = link.attribute("href").value
  38 + if relative_path.starts_with?('/')
  39 + relative_path[0]=''
  40 + end
  41 + link.attribute("href").value = "http://#{article.environment.default_hostname}/#{relative_path}"
  42 + end
  43 + end
  44 +
  45 + doc.css("img").each do |link|
  46 + unless link.attribute("src").nil? and absolute_url?(link.attribute("src").value)
  47 + relative_path = link.attribute("src").value
  48 + link.attribute("src").value = "http://#{article.environment.default_hostname}/#{relative_path}"
  49 + end
  50 + end
  51 +
  52 +# link.attributes["href"].value = "http://myproxy.com/?url=#{CGI.escape link.attributes["href"].value}"
  53 +# http://#{environment.default_hostname}/#{relative_path[1]}
  54 +
  55 +
  56 + body = doc.to_html
  57 + sender = Person.find(article.author_id)
  58 + members = article.profile.members
  59 + emails = []
  60 + members.each{ |m|
  61 + emails.push(m.user.email)
  62 + }
  63 +
  64 + # mailing = create(Mailing, :source => article.author.user.person, :subject => 'Hello', :body => 'We have some news', :person => article.author.user.person)
  65 +
  66 + mail(
  67 + content_type: 'text/html',
  68 + to: emails,
  69 + from: "#{article.author_name} <#{sender.contact_email}>",
  70 + reply_to: article.author.user.email,
  71 + subject: "[Artigo] " + article.title,
  72 + body: body
  73 +# body: set_absolute_path(article.body, article.environment)
  74 + )
  75 + end
  76 +end
  77 +
  78 +
  79 +
  80 +end
... ...