tickets/app/helpers/tickets_helper.rb

47 lines
1.8 KiB
Ruby

module TicketsHelper
def smart_links_parser(html,site)
if !site.nil?
html = html.gsub("href=\"/uploads/","href=\"http://#{site.site_domain}/uploads/")
html = html.gsub("src=\"/uploads/","src=\"http://#{site.site_domain}/uploads/")
temp_html = ActionView::Base.full_sanitizer.sanitize(html)
urls = URI.extract(temp_html,["http","https"])
#urls.each do |url|
# html = html.sub(url, "<a href='#{url}' target='_blank'>#{url}</a>")
#end
end
return html
end
def smart_store_link_parser(html)
html = html.gsub("href=\"/uploads/","href=\"http://#{request.host_with_port}/uploads/")
html = html.gsub("src=\"/uploads/","src=\"http://#{request.host_with_port}/uploads/")
temp_html = ActionView::Base.full_sanitizer.sanitize(html)
urls = URI.extract(temp_html,["http","https"])
urls.each do |url|
html = html.sub(url, "<a href='#{url}' target='_blank'>#{url}</a>")
end
return html
end
def notify_response_to_client(ticket)
network = ONetwork.new("http://" + ticket.registered_site.site_domain, "post") rescue nil
network.request("/store/ticket_response_update",{"ticket_id" => ticket.uid}) if !network.nil?
end
def send_notification_emails(response, ticket)
response.user_tags.each do |u|
user = User.find(u) rescue nil
if !user.nil?
mp = user.member_profile
send_email(mp.email,ticket,response,user.name) if !mp.email.nil?
sleep(2.seconds)
end
end
end
def send_email(useremail,ticket,response, username)
url = "#{request.protocol}#{request.host_with_port}/#{I18n.locale}/admin/tickets_manage/#{ticket.id.to_s}#response_#{response.id.to_s}"
email = Email.new(:mail_to => useremail, :mail_subject => "Tagged : #{ticket.subject}.", :template => "email/ticket_tag_email.html.erb", :template_data => {"url" => url, "mention" => current_user.name, "name" => username})
email.deliver
end
end