2014-11-25 10:34:14 +00:00
|
|
|
class AdBannersController < ApplicationController
|
|
|
|
def widget
|
|
|
|
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)
|
|
|
|
images = adbanner.ad_images.can_display.collect.with_index do |b,i|
|
|
|
|
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>' : ""
|
2014-11-25 10:34:14 +00:00
|
|
|
{
|
2014-12-18 12:00:46 +00:00
|
|
|
"image_link" => image_link,
|
|
|
|
"title" => b.title,
|
|
|
|
"class" => klass,
|
|
|
|
"height" => adbanner.height,
|
|
|
|
"width" => adbanner.width,
|
|
|
|
"caption" => caption,
|
|
|
|
"context" => b.context,
|
|
|
|
"link" => b.out_link || "#"
|
2014-11-25 10:34:14 +00:00
|
|
|
}
|
2014-12-18 12:00:46 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"extras" => {
|
|
|
|
"ad_fx" => adbanner.ad_fx,
|
|
|
|
"speed" => adbanner.speed,
|
|
|
|
"title" => adbanner.title,
|
|
|
|
"timeout" => adbanner.timeout,
|
|
|
|
"more" => "More"
|
|
|
|
},
|
|
|
|
"images" => images
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def video_widget(adbanner)
|
|
|
|
images = adbanner.ad_images.can_display.collect.with_index do |ad_b,i|
|
|
|
|
image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url
|
|
|
|
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>"
|
|
|
|
else ad_b.exchange_item == "2"
|
|
|
|
image_html = "<div class='w-ad-banner__slide youtube #{klass}' data-youtube-id='ytplayer#{i}'><a class='w-ad-banner__slide' href='#{format_url(ad_b.youtube,i)}'>#{ad_b.title}</a></div>"
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"html" => image_html
|
|
|
|
}
|
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
|
|
|
|
url = "http://www.youtube.com/v/#{url_params["v"]}/?version=3&playerapiid=ytplayer#{index}"
|
|
|
|
end
|
2014-11-25 10:34:14 +00:00
|
|
|
end
|