2022-01-21 02:09:31 +00:00
|
|
|
require "rss"
|
|
|
|
class EventNewsFeedsController < ApplicationController
|
|
|
|
include Admin::EventNewsHelper
|
2024-09-16 11:15:10 +00:00
|
|
|
def feed_add_remote
|
|
|
|
if params[:url].present?
|
|
|
|
uid = params[:uid].to_s
|
|
|
|
event_news_feed = EventNewsFeed.where(uid: uid).first
|
|
|
|
if !(event_news_feed.remote_urls.include?(params[:url]))
|
|
|
|
event_news_feed.remote_urls << params[:url]
|
|
|
|
event_news_feed.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render :json => {success: true}
|
|
|
|
end
|
|
|
|
def feed_remove_remote
|
|
|
|
if params[:url].present?
|
|
|
|
uid = params[:uid].to_s
|
|
|
|
event_news_feed = EventNewsFeed.where(uid: uid).first
|
|
|
|
if event_news_feed.remote_urls.delete(params[:url])
|
|
|
|
event_news_feed.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render :json => {success: true}
|
|
|
|
end
|
2022-01-21 02:09:31 +00:00
|
|
|
def feed
|
2022-10-24 08:26:33 +00:00
|
|
|
uid = params[:uid].to_s
|
2024-09-16 03:30:37 +00:00
|
|
|
startdt = params[:start].blank? ? nil : params[:start]
|
|
|
|
enddt = params[:end].blank? ? nil : params[:end]
|
|
|
|
dt = params[:date].blank? ? nil : params[:date]
|
|
|
|
feed_cache = EventNewsFeedCache.where(uid: uid, start: startdt, end: enddt, date: dt)
|
|
|
|
feed_cache_old = feed_cache.all_of([{:invalid_date.ne=>nil},{:invalid_date.lte => Time.now}]).last
|
|
|
|
feed_cache.all_of([{:invalid_date.ne=>nil},{:invalid_date.lte => Time.now}]).destroy
|
|
|
|
count = feed_cache.count
|
|
|
|
if count > 1
|
|
|
|
feed_cache.limit(count-1).destroy
|
|
|
|
end
|
|
|
|
feed_cache = feed_cache.first
|
|
|
|
anns = ''
|
|
|
|
if feed_cache.nil?
|
|
|
|
anns = EventNewsFeed.where(uid: uid).first.generate_one_cache_timeout(startdt: startdt,enddt: enddt,dt: dt,base_url: request.base_url,timeout: 20)
|
|
|
|
anns = (feed_cache_old.content rescue "") if anns.nil?
|
|
|
|
else
|
|
|
|
anns = feed_cache.content
|
|
|
|
end
|
|
|
|
render :json => anns
|
2022-01-21 02:09:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def rssfeed
|
2022-10-24 08:26:33 +00:00
|
|
|
uid = params[:uid].to_s
|
2022-01-21 02:09:31 +00:00
|
|
|
@bf = EventNewsFeed.find_by(:uid => uid) rescue nil
|
|
|
|
if !@bf.nil?
|
|
|
|
tags = @bf.tag_ids
|
|
|
|
if !tags.empty?
|
|
|
|
@event_news = EventNews.can_display_and_sorted.is_approved.filter_by_tags(tags)
|
2024-09-16 03:30:37 +00:00
|
|
|
else
|
|
|
|
@event_news = EventNews.can_display_and_sorted.is_approved
|
2022-01-21 02:09:31 +00:00
|
|
|
end
|
|
|
|
categories = @bf.category_ids
|
|
|
|
if !categories.empty?
|
|
|
|
@event_news = @event_news.filter_by_categories(categories)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@event_news = []
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {redirect_to "/xhr/event_news/rssfeed/#{@bf.uid}.rss"}
|
|
|
|
format.rss
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def feeds
|
|
|
|
feeds = []
|
|
|
|
EventNewsFeed.all.each do |bf|
|
|
|
|
feed = {}
|
|
|
|
feed["title_translations"] = bf.title_translations
|
|
|
|
feed["uid"] = bf.uid
|
|
|
|
feed["url"] = "#{request.base_url}/xhr/event_news/feed/#{bf.uid}"
|
|
|
|
feed["xml_url"] = "#{request.base_url}/xhr/event_news/rssfeed/#{bf.uid}.rss"
|
|
|
|
feed["tags"] = []
|
|
|
|
bf.tag_ids.each do |t|
|
|
|
|
tag = Tag.find(t)
|
|
|
|
d = {}
|
|
|
|
d["name_translations"] = tag.name_translations
|
|
|
|
feed["tags"] << d
|
|
|
|
end
|
|
|
|
feeds << feed
|
|
|
|
end
|
|
|
|
render :json => {"feeds" => feeds}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|