class AdBannersController < ApplicationController def widget adbanner = Banner.find(OrbitHelper.widget_custom_value) 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.asc(:sort_number).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 ? '
' : "" alt_text = (b.title.nil? || b.title == "" ? "ad-banner image" : b.title) if b.link_open == "new_window" target = "_blank" else target = "" end images << { "image_link" => image_link, "title" => b.title, "class" => klass, "alt_title" => alt_text, "height" => adbanner.height, "width" => adbanner.width, "target" => target, "caption" => caption, "context" => (b.context.tr('"',"'") rescue ""), "link" => b.out_link || "#" } end end base_image = adbanner.base_image.nil? ? 1 : adbanner.base_image { "extras" => { "ad_fx" => adbanner.ad_fx, "speed" => adbanner.speed, "title" => adbanner.title, "timeout" => adbanner.timeout, "base_image" => (base_image - 1), "more" => "More" }, "images" => images } end 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 ? '
' : "" klass = i == 0 ? "active" : "" if ad_b.exchange_item == "1" image_html = "
#{ad_b.title}
" else ad_b.exchange_item == "2" image_html = "
#{ad_b.title}
#{ad_b.title}
" 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.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 = "http://www.youtube.com/embed/#{url_params["v"]}" end end