From 59a198005d44d3fad26f30ed0846cc881a40e523 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 7 Jul 2015 19:55:46 +0800 Subject: [PATCH] added some stuff for feeds and utility --- .gitignore | 1 + app/helpers/orbit_helper.rb | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/.gitignore b/.gitignore index 27ddcd8..0c35e3e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ app/views/frontend /public/uploads/* public/assets/* +public/site_feeds/* public/import_status.yml public/announcement_link_widget_en.json public/announcement_link_widget_zh_tw.json diff --git a/app/helpers/orbit_helper.rb b/app/helpers/orbit_helper.rb index 0b89bbf..e65ab81 100644 --- a/app/helpers/orbit_helper.rb +++ b/app/helpers/orbit_helper.rb @@ -381,6 +381,72 @@ module OrbitHelper ActionView::Base.full_sanitizer.sanitize(string) end + # get feeds for the module + + def self.get_feed_for_module(type) + categories = [] + ma = nil + if type == "index" + categories = @categories if !@categories.nil? + ma = @module_app + elsif type == "widget" + categories = @widget_categories if !@widget_categories.nil? + ma = @widget_module_app + end + if categories.first == "all" + feeds = SiteFeed.where(:channel_key => ma.key).enabled + else + feeds = SiteFeed.where(:channel_key => ma.key, :merge_with_category.in => categories).enabled + end + data = [] + if feeds.count > 0 + temp_ids = [] + feeds.each do |feed| + file = File.join(Rails.root,"public","site_feeds",feed.id.to_s,feed.feed_uid.to_s + ".json") + if File.exists?(file) + d = File.read(file) + d = JSON.parse(d) + cat = Category.find(feed.merge_with_category).title + final_d = [] + d[ma.key.pluralize].each{|a| + a["category"] = cat + if !temp_ids.include?(a["id"]) + temp_ids << a["id"] + a["params"] = a["params"] + "_" + feed.id.to_s + "h" + final_d << a + end + } + data.concat(final_d) + end + end + end + data + end + + def self.is_object_from_feed?(uid) + return uid.ends_with?("h") + end + + def self.get_from_feed(uidwithid) + temp = uidwithid.split("_") + feed_id = temp[1][0...-1] + uid = temp[0] + object = nil + feed = SiteFeed.find(feed_id) rescue nil + if !feed.nil? + file = File.join(Rails.root,"public","site_feeds",feed.id.to_s,feed.feed_uid.to_s + ".json") + if File.exists?(file) + d = File.read(file) + d = JSON.parse(d) + objects = d[@module_app.key.pluralize] + object = objects.select{|obj| obj["id"] == uid}.first + cat = Category.find(feed.merge_with_category) + object = {} if cat.disable + end + end + object + end + # =============================================================== # Breadcrumbs # ===============================================================