vlog/app/controllers/vlogs_controller.rb

73 lines
2.2 KiB
Ruby

class VlogsController < ApplicationController
def index
vlogs = VLog.all.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags.collect do |vlog|
{
"thumbnail" => (vlog.type == "youtube" ? vlog.youtube_thumbnail : vlog.thumbnail),
"title" => vlog.title,
"username" => (!vlog.create_user_id.nil? ? User.find(vlog.create_user_id).name : ""),
"url_to_show" => OrbitHelper.url_to_show(vlog.to_param)
}
end
heads = ["vlog.thumbnail", :title, "vlog.uploaded_by"].collect do |title|
{
"column-title" => t(title)
}
end
{
"heads" => heads,
"vlogs" => vlogs
}
end
def widget
vlog = VLog.all.filter_by_widget_categories.sample(1).first
if vlog.type == "upload" && !vlog.v_log_video.nil?
video = "<video src='#{vlog.v_log_video.video.url}' controls> Your browser does not support the <code>video</code> element.</video>"
elsif vlog.type == "youtube" && !vlog.youtube_link.nil?
video = "<iframe src='#{vlog.youtube_link}' allowfullscreen frameborder='0'></iframe>"
end
{
"extras" => {"widget-title"=>t(:web_resource),"more_url" => OrbitHelper.widget_more_url, "video" => video, "title" => vlog.title, "subtitle" => vlog.subtitle}
}
end
def show
params = OrbitHelper.params
vlog = VLog.where(:uid => params[:uid]).first
if vlog.type == "upload" && !vlog.v_log_video.nil?
video = "<video src='#{vlog.v_log_video.video.url}' controls> Your browser does not support the <code>video</code> element.</video>"
elsif vlog.type == "youtube" && !vlog.youtube_link.nil?
video = "<iframe src='#{vlog.youtube_link}' allowfullscreen frameborder='0'></iframe>"
end
files = vlog.v_log_files.collect do |file|
title = (file.title.blank? ? File.basename(file.file.path) : file.title) rescue ""
{
"title" => title,
"link" => "/xhr/vlogfiles/download?file=#{file.id}"
}
end
{
"files" => files,
"data" => {
"title" => vlog.title,
"subtitle" => vlog.subtitle,
"type" => vlog.type,
"video" => video
}
}
end
def download_file
file_id = params[:file]
file = VLogFile.find(file_id) rescue nil
if !file.nil?
redirect_to file.file.url and return
end
render :nothing => true
end
end