added rss feeds
This commit is contained in:
parent
1ff7b59123
commit
308370c4df
|
@ -30,7 +30,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
def feed
|
||||
@table_feed_fields = ["announcement.feed_name", :tags]
|
||||
@table_feed_fields = ["announcement.feed_name", :tags, "announcement.rssfeed"]
|
||||
@feeds = BulletinFeed.all.asc(:created_at)
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,50 @@
|
|||
require "rss"
|
||||
class AnnouncementFeedsController < ApplicationController
|
||||
|
||||
include Admin::AnnouncementsHelper
|
||||
def feed
|
||||
uid = params[:uid]
|
||||
anns = get_announcements(uid)
|
||||
render :json => anns.to_json
|
||||
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.is_approved.filter_by_tags(tags)
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def get_announcements(uid)
|
||||
bf = BulletinFeed.find_by(:uid => uid) rescue nil
|
||||
if !bf.nil?
|
||||
tags = bf.tag_ids
|
||||
|
@ -57,28 +100,11 @@ class AnnouncementFeedsController < ApplicationController
|
|||
end
|
||||
all_anns << a
|
||||
end
|
||||
render :json => {"announcements" => all_anns, "tags" => tag_names}.to_json
|
||||
{
|
||||
"announcements" => all_anns,
|
||||
"tags" => tag_names
|
||||
}
|
||||
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["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
|
||||
|
||||
|
||||
|
|
|
@ -31,4 +31,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/xhr/announcements/rssfeed/<%= feed.uid %>.rss" target="_blank">Rss Feed</a>
|
||||
</td>
|
||||
</tr>
|
|
@ -0,0 +1,16 @@
|
|||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.rss :version => "2.0" do
|
||||
xml.channel do
|
||||
xml.title @bf.title
|
||||
xml.link "/xhr/announcements/rssfeed/73999228.rss"
|
||||
|
||||
for announcement in @announcements
|
||||
xml.item do
|
||||
xml.title announcement.title
|
||||
xml.description announcement.subtitle
|
||||
xml.pubDate announcement.created_at.to_s(:rfc822)
|
||||
xml.link page_for_bulletin(announcement)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,6 +13,7 @@ en:
|
|||
view_count: View Count
|
||||
add_new: Add New
|
||||
feed_name: Feed Name
|
||||
rssfeed: Rss Feed Link
|
||||
feed_list: Feed List
|
||||
approve: Approve
|
||||
all_articles: All Articles
|
||||
|
|
|
@ -14,6 +14,7 @@ zh_tw:
|
|||
add_new: 新建
|
||||
approve: 通過
|
||||
feed_name: Feed 標題
|
||||
rssfeed: Rss Feed Link
|
||||
feed_list: 訂閱清單
|
||||
all_articles: 文章列表
|
||||
announcement: 公告
|
||||
|
|
|
@ -23,6 +23,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
get "/xhr/announcements/feed/:uid" => "announcement_feeds#feed"
|
||||
get "/xhr/announcements/rssfeed/:uid" => "announcement_feeds#rssfeed"
|
||||
get "/xhr/announcements/feeds" => "announcement_feeds#feeds"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue