diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb
index 4d9ed082f..3573bb381 100644
--- a/app/views/layouts/page_layout.html.erb
+++ b/app/views/layouts/page_layout.html.erb
@@ -1,6 +1,17 @@
+
<%= page_title(@item).html_safe %>
">
diff --git a/app/views/mobile/dialog_contact.mobile.erb b/app/views/mobile/dialog_contact.mobile.erb
index f68375cc1..e68bd299e 100644
--- a/app/views/mobile/dialog_contact.mobile.erb
+++ b/app/views/mobile/dialog_contact.mobile.erb
@@ -3,7 +3,6 @@
<% end %>
diff --git a/config/locales/mobile.en.yml b/config/locales/mobile.en.yml
index 4abfe0073..c576d0799 100644
--- a/config/locales/mobile.en.yml
+++ b/config/locales/mobile.en.yml
@@ -4,10 +4,10 @@ en:
bulletin: Bulletin
contact: Contact
copyright: Copyright
- copyright_text: Thisi University © All RIGHTS RESERVED.
+ copyright_text: Copyright© 2008 National Taiwan University ALL RIGHTS RESERVED
copyright_orbit: Powered by RulingDigital
home: Home
language: Language
location: Location
- location_description: 'OFFICE OF GENERAL AFFAIRS, NTU
No. 1, Sec. 4, Roosevelt Road, Taipei, 10617 Taiwan (R.O.C)'
+ location_description: 'National Taiwan University
No. 1, Sec. 4, Roosevelt Road, Taipei, 10617 Taiwan (R.O.C)'
page: Page
\ No newline at end of file
diff --git a/config/locales/mobile.zh_tw.yml b/config/locales/mobile.zh_tw.yml
index 5708314d5..3f6233588 100644
--- a/config/locales/mobile.zh_tw.yml
+++ b/config/locales/mobile.zh_tw.yml
@@ -4,7 +4,7 @@ zh_tw:
bulletin: 公告
contact: 聯絡資訊
copyright: 著作權宣告
- copyright_text: 本網站著作權屬於本大學。
+ copyright_text: 本網站著作權屬於國立臺灣大學 學生事務處
copyright_orbit: 銳綸數位建置
home: 首頁
language: 語言
diff --git a/lib/rss_ntu_job.rb b/lib/rss_ntu_job.rb
new file mode 100644
index 000000000..9751e3c65
--- /dev/null
+++ b/lib/rss_ntu_job.rb
@@ -0,0 +1,99 @@
+# encoding: utf-8
+
+# encoding: utf-8
+
+require 'rss'
+require 'mongo'
+
+AUTHORS = %w[ 學生事務處-學生住宿服務組
+ 學生事務處-學生職業生涯發展中心
+ 學生事務處-衛生保健及醫療中心
+ 學生事務處-課外活動指導組
+ 學生事務處-學生活動中心管理組
+ 學生事務處-僑生及陸生輔導組
+ 學生事務處-生活輔導組
+ 學生事務處-軍訓組
+ 學生事務處-學生心理輔導中心
+ 學生事務處-學生事務處]
+
+DB_BASE_NAME = "site"
+
+all = []
+continue = true
+i = 1
+yesterday = Time.now - 86400
+
+while continue do
+ open("http://ann.cc.ntu.edu.tw/asp/rss.asp?page=#{i}") do |rss|
+ feed = RSS::Parser.parse(rss.read.encode('utf-8', 'big5', invalid: :replace, undef: :replace, replace: '').gsub('Wes,', 'Wed,').gsub(/(encoding=\"big5\")/, 'encoding="utf-8"'))
+ feed.items.each do |item|
+ if item.pubDate > yesterday
+ if AUTHORS.include?(item.author)
+ author = item.author.strip
+ category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
+ all << {title: item.title.strip, author: author, link: item.link.strip, date: item.pubDate, category: category, description: item.description.gsub("\r\n", '
').strip}
+ end
+ else
+ continue = false
+ break
+ end
+ end
+ end
+ i += 1
+end
+
+# Get corresponding category_id or create a new one
+def get_category_id(category, categories, coll_cat)
+ if categories.keys.include? "rss_#{category}"
+ [categories["rss_#{category}"], categories]
+ else
+ cat = {
+ _type: "BulletinCategory",
+ key: "rss_#{category}",
+ disable: false,
+ title: {:zh_tw => category},
+ created_at: Time.now,
+ updated_at: Time.now
+ }
+ categories["rss_#{category}"] = result = coll_cat.save(cat)
+ [result, categories]
+ end
+end
+
+# Get categories and id based on a given site number
+def get_mongo_and_categories(site_number="0")
+ db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}_#{site_number}")
+ coll_bulletin = db["bulletins"]
+ coll_cat = db["bulletin_categories"]
+
+ categories = coll_cat.find().to_a.inject({}) do |categories, category|
+ categories[category['key']] = category['_id']
+ categories
+ end
+ [categories, coll_bulletin, coll_cat]
+end
+
+# Get categories
+categories, coll_bulletin, coll_cat = get_mongo_and_categories
+
+all.each do |bul| # Loop through all the items
+ category_id, categories = get_category_id(bul[:category], categories, coll_cat)
+ unless coll_bulletin.find_one(rss_link: bul[:link])
+ bulletin = { _type: "Bulletin",
+ postdate: bul[:date],
+ created_at: bul[:date],
+ updated_at: bul[:date],
+ is_checked: true,
+ is_pending: false,
+ is_rejected: false,
+ bulletin_category_id: category_id,
+ title: {:zh_tw => bul[:title]},
+ text: {:zh_tw => bul[:description]},
+ available_for_zh_tw: true,
+ rss_link: bul[:link] }
+ coll_bulletin.save(bulletin)
+ end
+end
+
+
+
diff --git a/lib/rss_ntu_migrate.rb b/lib/rss_ntu_migrate.rb
new file mode 100644
index 000000000..53cb1d88a
--- /dev/null
+++ b/lib/rss_ntu_migrate.rb
@@ -0,0 +1,91 @@
+# encoding: utf-8
+
+require 'rss'
+require 'mongo'
+
+AUTHORS = %w[ 學生事務處-學生住宿服務組
+ 學生事務處-學生職業生涯發展中心
+ 學生事務處-衛生保健及醫療中心
+ 學生事務處-課外活動指導組
+ 學生事務處-學生活動中心管理組
+ 學生事務處-僑生及陸生輔導組
+ 學生事務處-生活輔導組
+ 學生事務處-軍訓組
+ 學生事務處-學生心理輔導中心
+ 學生事務處-學生事務處]
+
+DB_BASE_NAME = "site"
+
+all = []
+continue = true
+i = 1
+while continue do
+ open("http://ann.cc.ntu.edu.tw/asp/rss.asp?page=#{i}") do |rss|
+ feed = RSS::Parser.parse(rss.read.encode('utf-8', 'big5', invalid: :replace, undef: :replace, replace: '').gsub('Wes,', 'Wed,').gsub(/(encoding=\"big5\")/, 'encoding="utf-8"'))
+ feed.items.size
+ feed.items.each do |item|
+ if AUTHORS.include?(item.author)
+ author = item.author.strip
+ category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
+ all << {title: item.title.strip, author: author, link: item.link.strip, date: item.pubDate, category: category, description: item.description.gsub("\r\n", '
').strip}
+ end
+ end
+ continue = false if feed.items.size < 100
+ end
+ i += 1
+end
+
+# Get corresponding category_id or create a new one
+def get_category_id(category, categories, coll_cat)
+ if categories.keys.include? "rss_#{category}"
+ [categories["rss_#{category}"], categories]
+ else
+ cat = {
+ _type: "BulletinCategory",
+ key: "rss_#{category}",
+ disable: false,
+ title: {:zh_tw => category},
+ created_at: Time.now,
+ updated_at: Time.now
+ }
+ categories["rss_#{category}"] = result = coll_cat.save(cat)
+ [result, categories]
+ end
+end
+
+# Get categories and id based on a given site number
+def get_mongo_and_categories(site_number="0")
+ db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}_#{site_number}")
+ coll_bulletin = db["bulletins"]
+ coll_cat = db["bulletin_categories"]
+
+ categories = coll_cat.find().to_a.inject({}) do |categories, category|
+ categories[category['key']] = category['_id']
+ categories
+ end
+ [categories, coll_bulletin, coll_cat]
+end
+
+# Get categories
+categories, coll_bulletin, coll_cat = get_mongo_and_categories
+
+all.each do |bul| # Loop through all the items
+ category_id, categories = get_category_id(bul[:category], categories, coll_cat)
+ unless coll_bulletin.find_one(rss_link: bul[:link])
+ bulletin = { _type: "Bulletin",
+ postdate: bul[:date],
+ created_at: bul[:date],
+ updated_at: bul[:date],
+ is_checked: true,
+ is_pending: false,
+ is_rejected: false,
+ bulletin_category_id: category_id,
+ title: {:zh_tw => bul[:title]},
+ text: {:zh_tw => bul[:description]},
+ available_for_zh_tw: true,
+ rss_link: bul[:link] }
+ coll_bulletin.save(bulletin)
+ end
+end
+
+
diff --git a/lib/tasks/ntu_mongo_files.rake b/lib/tasks/ntu_mongo_files.rake
index 2438a21b8..245cc6d40 100644
--- a/lib/tasks/ntu_mongo_files.rake
+++ b/lib/tasks/ntu_mongo_files.rake
@@ -26,18 +26,12 @@ namespace :mongo_files do
IMAGE_UPLOADER_MODELS = %w[ad_image bulletin image site]
- # ad_banner
- # bulletin
- # design
- # site
-
task :clean => :environment do
@files = Mongoid.database['fs.files']
@chunks = Mongoid.database['fs.chunks']
clean_duplicates
clean_unused
remove_objects
- # remove_unlinked
end
# Remove unused files from db
@@ -81,7 +75,7 @@ namespace :mongo_files do
# Remove duplicate files from db
def clean_duplicates
p "# of files in db: #{@files.count}"
- file_hash = @files.find().inject({}) do |db_files, file|
+ file_hash = @files.find().sort({uploadDate: -1}).inject({}) do |db_files, file|
name = file['filename']
if db_files[name]
db_files[name] += [file['_id']]
@@ -119,17 +113,8 @@ namespace :mongo_files do
Mongoid.database['writing_journals'].remove()
Mongoid.database['writing_journal_files'].remove()
- # Destroy bulletins, bulletin_files and bulletin_links
- Bulletin.excludes(create_user_id: nil).destroy
- BulletinFile.destroy_all
- BulletinLink.destroy_all
-
- # Destroy gallery_albums and gallery_images
- Mongoid.database['gallery_albums'].remove()
- Mongoid.database['gallery_images'].remove()
-
db_array = @files.find().inject([]) do |db_files, file|
- db_files << file['filename'] if file['filename'] =~ /writing_journal_file|news_bulletin_file|bulletin_file|gallery_image|image\/image/
+ db_files << file['filename'] if file['filename'] =~ /writing_journal_file|news_bulletin_file|image\/image/
db_files
end
p db_array.size