2014-11-25 10:34:14 +00:00
|
|
|
class AdBannersController < ApplicationController
|
|
|
|
def widget
|
2016-02-17 12:37:37 +00:00
|
|
|
adbanner = Banner.find(OrbitHelper.widget_custom_value)
|
2014-12-18 12:00:46 +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)
|
2015-05-08 07:47:29 +00:00
|
|
|
images = []
|
2016-02-17 12:37:37 +00:00
|
|
|
adbanner.ad_images.can_display.asc(:sort_number).each_with_index do |b,i|
|
2015-05-08 07:47:29 +00:00
|
|
|
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>' : ""
|
2015-05-11 10:20:30 +00:00
|
|
|
alt_text = (b.title.nil? || b.title == "" ? "ad-banner image" : b.title)
|
2015-06-02 05:58:58 +00:00
|
|
|
if b.link_open == "new_window"
|
|
|
|
target = "_blank"
|
|
|
|
else
|
|
|
|
target = ""
|
|
|
|
end
|
2015-05-08 07:47:29 +00:00
|
|
|
images << {
|
|
|
|
"image_link" => image_link,
|
2015-05-11 10:20:30 +00:00
|
|
|
"title" => b.title,
|
2015-05-08 07:47:29 +00:00
|
|
|
"class" => klass,
|
2015-05-25 07:41:16 +00:00
|
|
|
"alt_title" => alt_text,
|
2015-05-08 07:47:29 +00:00
|
|
|
"height" => adbanner.height,
|
|
|
|
"width" => adbanner.width,
|
2015-06-02 05:58:58 +00:00
|
|
|
"target" => target,
|
2015-05-08 07:47:29 +00:00
|
|
|
"caption" => caption,
|
2015-12-09 17:35:16 +00:00
|
|
|
"context" => (b.context.tr('"',"'") rescue ""),
|
2015-05-08 07:47:29 +00:00
|
|
|
"link" => b.out_link || "#"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-05-25 09:51:34 +00:00
|
|
|
base_image = adbanner.base_image.nil? ? 1 : adbanner.base_image
|
2014-11-25 10:34:14 +00:00
|
|
|
{
|
2015-05-08 07:47:29 +00:00
|
|
|
"extras" => {
|
|
|
|
"ad_fx" => adbanner.ad_fx,
|
|
|
|
"speed" => adbanner.speed,
|
|
|
|
"title" => adbanner.title,
|
|
|
|
"timeout" => adbanner.timeout,
|
2016-05-25 09:51:34 +00:00
|
|
|
"base_image" => (base_image - 1),
|
2015-05-08 07:47:29 +00:00
|
|
|
"more" => "More"
|
|
|
|
},
|
|
|
|
"images" => images
|
2014-11-25 10:34:14 +00:00
|
|
|
}
|
2014-12-18 12:00:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def video_widget(adbanner)
|
2015-05-08 07:47:29 +00:00
|
|
|
images = []
|
2016-02-17 12:37:37 +00:00
|
|
|
adbanner.ad_images.can_display.asc(:sort_number).each_with_index do |ad_b,i|
|
2015-05-08 07:47:29 +00:00
|
|
|
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
|
2015-05-11 10:20:30 +00:00
|
|
|
alt_text = (ad_b.title.nil? || ad_b.title == "" ? "ad-banner image" : ad_b.title)
|
2015-05-08 07:47:29 +00:00
|
|
|
caption = i == 0 ? '<div class="cycle-overlay"></div><div class="cycle-pager"></div>' : ""
|
|
|
|
klass = i == 0 ? "active" : ""
|
|
|
|
if ad_b.exchange_item == "1"
|
2015-05-11 10:20:30 +00:00
|
|
|
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>"
|
2015-05-08 07:47:29 +00:00
|
|
|
else ad_b.exchange_item == "2"
|
2015-05-11 10:20:30 +00:00
|
|
|
image_html = "<div class='w-ad-banner__slide youtube #{klass}' data-yt-binded='0' data-youtube-id='ytplayer#{i}'><a class='w-ad-banner__slide' href='#{format_url(ad_b.youtube,i)}'>#{ad_b.title}</a><div class='w-ad-banner__caption_text'>#{ad_b.title}</div></div>"
|
2015-05-08 07:47:29 +00:00
|
|
|
end
|
|
|
|
images << {
|
|
|
|
"html" => image_html
|
|
|
|
}
|
2014-12-18 12:00:46 +00:00
|
|
|
end
|
2014-11-25 10:34:14 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"extras" => {
|
|
|
|
"ad_fx" => adbanner.ad_fx,
|
|
|
|
"speed" => adbanner.speed,
|
|
|
|
"title" => adbanner.title,
|
|
|
|
"timeout" => adbanner.timeout,
|
|
|
|
"more" => "More"
|
|
|
|
},
|
|
|
|
"images" => images
|
|
|
|
}
|
|
|
|
end
|
2014-12-18 12:00:46 +00:00
|
|
|
|
|
|
|
def format_url(url,index)
|
|
|
|
uri = URI.parse(url)
|
|
|
|
ps = uri.query.split("&")
|
|
|
|
url_params = {}
|
|
|
|
ps.each do |p|
|
|
|
|
x = p.split("=")
|
|
|
|
url_params[x.first] = x.last
|
|
|
|
end
|
2015-04-08 05:49:03 +00:00
|
|
|
# url = "http://www.youtube.com/v/#{url_params["v"]}/?version=3&playerapiid=ytplayer#{index}"
|
2019-07-16 07:25:57 +00:00
|
|
|
url = "https://www.youtube.com/embed/#{url_params["v"]}"
|
2014-12-18 12:00:46 +00:00
|
|
|
end
|
2014-11-25 10:34:14 +00:00
|
|
|
end
|