class VideoProgramsController < ApplicationController include VideoProgramsHelper def initialize super @app_title = 'video_program' end def short_desc(str, len) if str && str.length > len str[0...len] + '...' else str end end def index VideoProgram.remove_expired_status sorted,total_pages = get_sorted_video_programs #If no data , hide title&table if sorted.count == 0 display_class = "hide" categories = [] else grouped_data = sorted.group_by(&:category_id) category_title_map = Category.where(:id.in=>grouped_data.keys).pluck(:id, "title.#{I18n.locale}").map{|k,v| [k, v.values[0]]}.to_h categories = grouped_data.map do |category_id, video_programs| { "category-title" => category_title_map[category_id], "video-programs" => video_programs.map do |vp| statuses = vp.statuses_with_classname.collect do |status| { "status" => status["name"], "status-class" => "status-#{status['classname']}" } end episodes = vp.episodes || 0 { "title" => vp.title, "subtitle" => short_desc(vp.subtitle, 100), "episodes" => episodes, "episodes_text" => t("video_program.episodes_text",{:num=> episodes}), "thumb-src" => (vp.image.thumb.url || "/assets/video_program/default.jpg"), "link_to_show" => OrbitHelper.url_to_show(vp.to_param), "statuses" => statuses } end } end end { "categories" => categories, "extras" => { "program_notes-head" => t('video_program.program_notes'), "video_notes-head" => t('video_program.video_notes'), "play-head" => t('video_program.play'), "view-count-head" => t('video_program.table.view_count'), "display_class" => display_class }, "total_pages" => total_pages } end def get_file @url = request.path begin if @url.match(/\/\.\./) render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html' return end file = VideoProgramFile.find(params[:id]) if File.basename(file.file.path) != URI.decode(params[:f_name]) render :file => "#{Rails.root}/app/views/errors/403.html", :layout => false, :status => :not_found, :content_type => 'text/html' return end @url = file.file.url if file.can_access?(OrbitHelper.current_user) @path = file.file.path rescue "" @filename = @path.split("/").last @ext = @path.split("/").last.to_s.split(".").last if @ext == "png" || @ext == "jpg" || @ext == "bmp" || @ext == "pdf" render "archives/download_file.html",:layout=>false else if (current_site.accessibility_mode rescue false) render "archives/redirect_to_file.html",:layout=>false return else send_file(@path) return end end else render :file => "#{Rails.root}/app/views/errors/403.html", :layout => false, :status => :not_found, :content_type => 'text/html' return end rescue render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html' return end end def show_local_video_program(uid) locale = OrbitHelper.get_site_locale.to_s video_program = VideoProgram.where(:uid => uid).first return nil if video_program.nil? url_to_edit = OrbitHelper.user_can_edit?(video_program) ? "/admin/video_program/#{video_program.id.to_s}/edit" : "" return {} if (video_program.category.disable rescue false) tags = video_program.tags.map{|tag| { "tag" => tag.name , "url" => OrbitHelper.page_for_tag(tag) } } files = video_program.video_program_files.to_fronted(locale) links = video_program.video_program_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] update_user = video_program.update_user.member_profile.name rescue "" desc = OrbitHelper.get_default_value(video_program.image_description, "VideoProgram image") request = OrbitHelper.request meta_desc = video_program.subtitle.nil? || video_program.subtitle == "" ? short_desc(video_program.video_notes, 200) : video_program.subtitle OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => video_program.title},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => "#{request.base_url}#{video_program.image.url}"},{"property" => "og:type", "content" => "Article"}]) subtitle = nil image_html = nil video_image_html = nil img_description = nil video_img_description = nil subtitle = video_program.subtitle if video_program.display_image && video_program.image.present? img_description = OrbitHelper.get_default_value(video_program.image_description, video_program.title) image_html = "\"#{img_description}\"" end if video_program.display_video_image && video_program.video_image.present? video_img_description = OrbitHelper.get_default_value(video_program.video_image_description, video_program.title) video_image_html = "\"#{video_img_description}\"" end if video_program.video_external_link.present? video_external_link = video_program.video_external_link video_external_link_class = "" else video_external_link = "javascript:;" video_external_link_class = "disabled" end video_program_carousel_images = video_program.video_program_carousel_images.map{|image| {"src"=>image.file.url,"description"=>image.description.to_s,"description_text"=>image.description_text }} resume_btn_title = t("plugin_control.resume") pause_btn_title = t("plugin_control.pause") prev_btn_title = t("plugin_control.prev") next_btn_title = t("plugin_control.next") episodes_text = t("video_program.episodes_text",{:num=> video_program.episodes}) grouped_data = video_program.albums.asc(:order).group_by{|a| a.tag_ids.first} tag_sort_number_map = {} tag_title_map = Tag.where(:id.in=>grouped_data.keys).pluck(:id, "name.#{I18n.locale}", :tmp_sort_number).map do |k,v, sort_number| tag_sort_number_map[k] = sort_number [k, v.values[0]] end.to_h episodes_albums = grouped_data.sort_by{|k, v| tag_sort_number_map[k].to_i}.map.with_index do |(tag_id, albums), i| tag_name = tag_id ? tag_title_map[tag_id] : nil images = albums.map do |album| skip_tag_ids = album.tag_ids album.album_images.asc(:order).map do |album_image| { "img-src" => album_image.file.url, "img-tags" => album_image.tags.map{|tag| next if skip_tag_ids.include?(tag.id) { "tag" => tag.name, } }.compact, "ep_title" => album_image.title, "ep_desc" => album_image.description } end end.flatten { "images_tag" => tag_name, "images" => images, "tab-class" => (i == 0 ? 'active in' : ''), "tab-index" => i } end data = { "tags" => tags, "video_program_files" => files, "video_program_links" => links, "episodes_albums" => episodes_albums, "data" => { "title-head" => t('video_program.title'), "program_notes-head" => t('video_program.program_notes'), "actor_notes-head" => t('video_program.actor_notes'), "video_notes-head" => t('video_program.video_notes'), "carousel_image-head" => t('video_program.carousel_image'), "episodes_albums-head" => t('video_program.episodes_albums'), "play-head" => t('video_program.play'), "program_notes" => video_program.program_notes, "program_notes_class" => (video_program.program_notes.present? ? "" : "hide"), "actor_notes" => video_program.actor_notes, "actor_notes_class" => (video_program.actor_notes.present? ? "" : "hide"), "video_notes" => video_program.video_notes, "episodes_albums_class" => (episodes_albums.present? ? "" : "hide"), "title" => video_program.title, "subtitle" => subtitle, "image_html" => image_html, "video_image_html" => video_image_html, "img_description" => img_description, "video_img_description" => video_img_description, "alt_title" => desc, "resume_btn_title" => resume_btn_title, "pause_btn_title" => pause_btn_title, "prev_btn_title" => prev_btn_title, "next_btn_title" => next_btn_title, "carousel_display_style" => (video_program_carousel_images.count == 0 ? 'display: none;' : video_program.carousel_image_width ? "width: #{video_program.carousel_image_width};margin: auto;" : nil), "carousel_count" => video_program_carousel_images.count, "video_external_link" => video_external_link, "video_external_link_class" => video_external_link_class, "episodes_text" => episodes_text, "carousel_image_class" => (video_program_carousel_images.present? ? "" : "hide") }, "impressionist" => video_program, "url_to_edit"=>url_to_edit } data['data']['video_program_carousel_images'] = (video_program_carousel_images.present? ? render_ad_banner(video_program_carousel_images,data['data']) : nil) data end def show params = OrbitHelper.params uid = params[:uid].to_s show_local_video_program(uid) end end