2014-04-11 07:47:33 +00:00
|
|
|
class AdBannersController < ApplicationController
|
|
|
|
def widget
|
2014-05-23 05:51:04 +00:00
|
|
|
adbanner = Banner.find(OrbitHelper.widget_custom_value)
|
2021-04-10 09:12:40 +00:00
|
|
|
widget = OrbitHelper.get_current_widget
|
|
|
|
if widget.widget_type == "ad_banner_widget2_video"
|
|
|
|
return video_widget(adbanner)
|
|
|
|
else
|
|
|
|
return image_widget(adbanner)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def image_widget(adbanner)
|
2016-05-18 08:29:39 +00:00
|
|
|
images = []
|
|
|
|
adbanner.ad_images.can_display.asc(:sort_number,:created_at).each.with_index do |b,i|
|
|
|
|
if b.language_enabled.include?(I18n.locale.to_s)
|
|
|
|
image_link = OrbitHelper.is_mobile_view ? b.file.mobile.url : b.file.url
|
|
|
|
klass = i == 0 ? "active" : ""
|
|
|
|
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
|
|
|
|
alt_title = (b.title.nil? || b.title == "" ? "ad-banner image" : b.title)
|
2015-05-11 10:19:57 +00:00
|
|
|
|
2016-05-18 08:29:39 +00:00
|
|
|
if b.link_open == "new_window"
|
|
|
|
target = "_blank"
|
|
|
|
else
|
|
|
|
target = ""
|
|
|
|
end
|
2020-04-16 11:06:14 +00:00
|
|
|
if !b.out_link.blank?
|
2020-08-11 10:38:51 +00:00
|
|
|
image_link += "\" style=\"cursor:pointer;\" onload=\"var el=this;(function(){if(el.parentElement==undefined||el.parentElement.tagName!='A'){el.outerHTML=('<a href=#{b.out_link} target=#{target}>'+el.outerHTML+'</a>');}})()\""
|
2020-04-16 11:06:14 +00:00
|
|
|
end
|
2016-05-18 08:29:39 +00:00
|
|
|
images << {
|
|
|
|
"image_link" => image_link,
|
|
|
|
"image_alt" => "ad banner image",
|
|
|
|
"title" => b.title,
|
|
|
|
"alt_title" => alt_title,
|
|
|
|
"class" => klass,
|
|
|
|
"height" => adbanner.height,
|
|
|
|
"width" => adbanner.width,
|
|
|
|
"caption" => caption,
|
|
|
|
"context" => (b.context.tr('"',"'") rescue ""),
|
|
|
|
"link" => b.out_link || "#",
|
|
|
|
"target" => target
|
|
|
|
}
|
|
|
|
end
|
2014-05-23 05:51:04 +00:00
|
|
|
end
|
2015-11-25 13:28:27 +00:00
|
|
|
base_image = adbanner.base_image.nil? ? 1 : adbanner.base_image
|
2014-05-23 05:51:04 +00:00
|
|
|
{
|
|
|
|
"extras" => {
|
2014-04-15 07:51:02 +00:00
|
|
|
"ad_fx" => adbanner.ad_fx,
|
|
|
|
"speed" => adbanner.speed,
|
|
|
|
"title" => adbanner.title,
|
2015-10-12 07:33:45 +00:00
|
|
|
"banner-height" => adbanner.height,
|
|
|
|
"banner-width" => adbanner.width,
|
2015-11-25 13:28:27 +00:00
|
|
|
"base_image" => (base_image - 1),
|
2015-10-06 07:30:59 +00:00
|
|
|
"timeout" => (adbanner.timeout * 1000),
|
2014-04-11 07:47:33 +00:00
|
|
|
"more" => "More"
|
2014-05-23 05:51:04 +00:00
|
|
|
},
|
|
|
|
"images" => images
|
2014-04-11 07:47:33 +00:00
|
|
|
}
|
|
|
|
end
|
2021-04-10 09:12:40 +00:00
|
|
|
|
|
|
|
def video_widget(adbanner)
|
|
|
|
images = []
|
|
|
|
adbanner.ad_images.can_display.asc(:sort_number).each_with_index do |ad_b,i|
|
|
|
|
if ad_b.language_enabled.include?(I18n.locale.to_s)
|
|
|
|
image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url
|
|
|
|
alt_text = (ad_b.title.nil? || ad_b.title == "" ? "ad-banner image" : ad_b.title)
|
|
|
|
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
|
|
|
|
klass = i == 0 ? "active" : ""
|
|
|
|
if ad_b.exchange_item == "1"
|
|
|
|
image_html = "<div class='w-ad-banner__slide #{klass}' data-link='#{ad_b.out_link || "#"}''><img class='w-ad-banner__image' src='#{image_link}'><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>"
|
|
|
|
else ad_b.exchange_item == "2"
|
|
|
|
youtube_url = format_url(ad_b.youtube,i)
|
2021-04-10 09:13:57 +00:00
|
|
|
image_html = "<div class='w-ad-banner__slide youtube #{klass}' data-yt-binded='0' data-youtube-id='ytplayer#{i}'><div style=\"padding-bottom: 56.25%;position: relative;height: 0;\"><iframe height=\"100%\" width=\"100%\" src=\"#{youtube_url}\" title=\"youtube\" style=\"position: absolute;\"></iframe></div><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>"
|
2021-04-10 09:12:40 +00:00
|
|
|
end
|
|
|
|
images << {
|
|
|
|
"html" => image_html
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"extras" => {
|
|
|
|
"ad_fx" => adbanner.ad_fx,
|
|
|
|
"speed" => adbanner.speed,
|
|
|
|
"title" => adbanner.title,
|
|
|
|
"timeout" => adbanner.timeout,
|
|
|
|
"more" => "More"
|
|
|
|
},
|
|
|
|
"images" => images
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def format_url(url,index)
|
|
|
|
uri = URI.parse(url)
|
|
|
|
ps = uri.query.to_s.split("&")
|
|
|
|
url_params = {}
|
|
|
|
ps.each do |p|
|
|
|
|
x = p.split("=")
|
|
|
|
url_params[x.first] = x.last
|
|
|
|
end
|
|
|
|
# url = "http://www.youtube.com/v/#{url_params["v"]}/?version=3&playerapiid=ytplayer#{index}"
|
|
|
|
url = "https://www.youtube.com/embed/#{url_params["v"]}"
|
|
|
|
end
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|