require "rss" class AnnouncementFeedsController < ApplicationController include Admin::AnnouncementsHelper def feed uid = params[:uid] startdt = params[:start].blank? ? nil : params[:start] enddt = params[:end].blank? ? nil : params[:end] dt = params[:date].blank? ? nil : params[:date] feed_cache = BulletinFeedCache.where(uid: uid, start: startdt, end: enddt, date: dt) feed_cache.where(: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 = BulletinFeed.where(uid: uid).first.generate_one_cache_timeout(startdt: startdt,enddt: enddt,dt: dt,base_url: request.base_url,timeout: 20) else anns = feed_cache.content end render :json => anns end def rssfeed uid = params[:uid] @bf = BulletinFeed.find_by(:uid => uid) rescue nil if !@bf.nil? tags = @bf.tag_ids if !tags.empty? @announcements = Bulletin.can_display_and_sorted.is_approved.filter_by_tags(tags) else @announcements = Bulletin.can_display_and_sorted.is_approved end categories = @bf.category_ids if !categories.empty? @announcements = @announcements.filter_by_categories(categories) end end respond_to do |format| format.html {redirect_to "/xhr/announcements/rssfeed/#{@bf.uid}.rss"} format.rss end end def feeds feeds = [] BulletinFeed.all.each do |bf| feed = {} feed["title_translations"] = bf.title_translations feed["uid"] = bf.uid feed["url"] = "#{request.base_url}/xhr/announcements/feed/#{bf.uid}" feed["xml_url"] = "#{request.base_url}/xhr/announcements/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