2020-02-17 13:23:26 +00:00
|
|
|
class Site
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Slug
|
|
|
|
|
|
|
|
DEBUG = false
|
|
|
|
has_many :page_sets, :autosave => true, :dependent => :destroy
|
|
|
|
accepts_nested_attributes_for :page_sets, :allow_destroy => true
|
2021-11-21 02:52:37 +00:00
|
|
|
def popup_subparts
|
|
|
|
part = SitePagePart.first
|
|
|
|
part.sub_parts(true)
|
|
|
|
end
|
2022-07-13 16:11:42 +00:00
|
|
|
BannerHeightSettings = ['use_max_height', 'use_first_height', 'no_height_fix']
|
|
|
|
field :banner_height_setting, type: Integer, default: 0
|
|
|
|
field :prohibit_proxy_feature, type: Boolean, default: false
|
|
|
|
field :enable_cache, type: Boolean, default: false
|
|
|
|
field :enable_counter, type: Boolean, default: true
|
|
|
|
field :redirect_page, type: Integer, default: 0
|
2021-11-21 02:52:37 +00:00
|
|
|
field :password_failed_lock_num, type: Integer, default: 5
|
|
|
|
field :password_failed_lock_time, type: Integer, default: 1
|
|
|
|
field :password_change_constrained, type: Integer, default: 0
|
2021-12-01 03:21:20 +00:00
|
|
|
field :view_count_start, type: Integer, default: 0
|
2021-11-21 02:52:37 +00:00
|
|
|
field :social_share_hide_in_menu, type: Boolean, default: false
|
|
|
|
field :social_share_position, type: Integer, default: 0
|
|
|
|
field :render_popup_only_on_root, type: Boolean, default: false
|
|
|
|
field :orbit_bar_extra_render_files_inside, type: Array, default: []
|
|
|
|
field :orbit_bar_extra_render_files_outside, type: Array, default: []
|
|
|
|
field :display_default_accesskey_help_in_sitemap, type: Boolean, default: false
|
|
|
|
field :accessibility_mode, type: Boolean, default: false
|
|
|
|
field :redirect_404_to_home, type: Boolean, default: false
|
|
|
|
field :block_cross_site_request, type: Boolean, default: false
|
|
|
|
field :member_extra_db, type: String, :default => ""
|
|
|
|
field :member_extra_url, type: String, :default => ""
|
|
|
|
field :database_info, type: Hash, :default => {}
|
2021-03-08 05:55:46 +00:00
|
|
|
field :root_url, type: String
|
|
|
|
field :update_flag, type: Boolean, default: true
|
|
|
|
field :password_high_security, type: Boolean, default: false
|
|
|
|
field :change_password_regularly, type: Boolean, default: false
|
|
|
|
field :change_password_period, type: String
|
2020-02-17 13:23:26 +00:00
|
|
|
field :title, as: :slug_title, type: String, localize: true
|
|
|
|
field :school, type: String
|
|
|
|
field :department, type: String
|
|
|
|
field :address, type: String
|
|
|
|
field :footer, localize: true
|
|
|
|
field :social_share, type: String
|
2021-11-21 02:52:37 +00:00
|
|
|
field :floating_window, type: Boolean, default: false
|
2020-02-17 13:23:26 +00:00
|
|
|
field :sub_menu, localize: true
|
|
|
|
field :site_type
|
|
|
|
field :site_map_link, type: String, :default => "/sitemap"
|
|
|
|
field :terms_of_use_link, type: String
|
|
|
|
field :google_analytics, type: String
|
|
|
|
field :in_use_locales, :type => Array
|
|
|
|
field :valid_locales, :type => Array
|
|
|
|
field :site_active, :type => Boolean
|
|
|
|
field :frontend_open, :type => Boolean, :default => true
|
|
|
|
field :backend_openness_on, :type => Boolean, :default => false
|
2020-07-23 08:16:17 +00:00
|
|
|
field :mobile_api_openness_on, :type => Boolean, :default => false
|
2020-02-17 13:23:26 +00:00
|
|
|
field :desktop_closed, :type => Boolean, :default => false
|
|
|
|
field :enable_language_detection, :type => Boolean, :default => false
|
|
|
|
field :enable_redirect_index, :type => Boolean, :default => true
|
|
|
|
field :enable_zh_cn, :type => Boolean, :default => true
|
|
|
|
field :enable_language_options, :type => Boolean, :default => true
|
|
|
|
field :default_locale, :default => "zh_tw"
|
|
|
|
field :mobile_on, :type => Boolean, :default => false
|
|
|
|
field :announcement_category, :type => Array, :default=>[]
|
|
|
|
field :mobile_bar_color, :type => Array, :default=>[]
|
|
|
|
field :phone_number, :type => Array,:default=>[]
|
|
|
|
field :title_always_on, :type => Boolean, :default => false
|
|
|
|
field :display_title_in_frontend, :type => Boolean, :default => true
|
|
|
|
field :sitemap_menu_in_header, :type => Boolean, :default => false
|
|
|
|
field :enable_terms_of_use, :type => Boolean, :default => false
|
|
|
|
field :search,:type => Hash
|
|
|
|
field :site_settings
|
|
|
|
field :template, type: String
|
|
|
|
field :store_token
|
|
|
|
field :enable_last_update, type: Boolean, :default => false
|
|
|
|
field :personal_plugins_sort, type: Array, :default => []
|
2021-11-21 02:52:37 +00:00
|
|
|
field :personal_plugins_custom_names, type: Hash, :default => {}
|
2020-02-17 13:23:26 +00:00
|
|
|
field :sign_up_roles, type: Array, :default => []
|
2020-07-04 13:22:30 +00:00
|
|
|
field :required_sign_up_attributes , :type => Hash , :default => {}
|
2020-02-17 13:23:26 +00:00
|
|
|
field :mobile_orbit_bar_title, localize: true
|
|
|
|
field :google_oauth_enabled, :type => Boolean, :default => false
|
|
|
|
field :google_client_id
|
|
|
|
field :google_client_secret
|
2021-03-08 05:55:46 +00:00
|
|
|
|
|
|
|
field :gmail_oauth2_enabled, :type => Boolean, :default => false
|
|
|
|
field :gmail_login_flag, :type => Boolean, :default => false
|
|
|
|
field :gmail_client_id
|
|
|
|
field :gmail_client_secret
|
|
|
|
field :gmail_access_token
|
|
|
|
field :gmail_refresh_token
|
|
|
|
field :gmail
|
|
|
|
|
2020-02-17 13:23:26 +00:00
|
|
|
field :meta_tags
|
2020-07-23 08:16:17 +00:00
|
|
|
field :every_page_sharer, type: Array, :default => ["facebook","line","twitter","google","printer"]
|
2020-02-17 13:23:26 +00:00
|
|
|
|
|
|
|
field :sync_enabled, type: Boolean, :default => false
|
|
|
|
field :sync_rake_task
|
2020-07-23 08:16:17 +00:00
|
|
|
|
2020-02-17 13:23:26 +00:00
|
|
|
field :month_traffic_cache
|
|
|
|
field :home_link, :type => String, :default=>"/"
|
|
|
|
field :home_link_1, :type => String, :default=>"/"
|
|
|
|
field :site_title, :type => Hash, :default=>{:zh_tw=>"主頁",:en=>"home_page"}
|
|
|
|
field :site_title_1, :type => Hash, :default=>{:zh_tw=>"主頁",:en=>"home_page"}
|
2020-09-14 10:03:44 +00:00
|
|
|
field :orbitbar_language_login_btn_mobile_configuration , type: String, :default => ""
|
2020-02-17 13:23:26 +00:00
|
|
|
field :is_hidden_orbit_bar , type: Boolean, :default => false
|
2022-08-03 04:51:25 +00:00
|
|
|
field :orbit_bar_not_display , type: Boolean, :default => false
|
|
|
|
field :hide_login_button , type: Boolean, :default => false
|
|
|
|
field :privileged_ip_login_only , type: Boolean, :default => false
|
|
|
|
field :privileged_ip, type: Array, default: [] #ex: [['192.168.1.1', '192.168.1.254']]
|
|
|
|
field :privileged_ip_range, type: Array, default: [] #ex: [[3232235777, 3232236030]] # IPAddr.new("192.168.1.1").to_i
|
|
|
|
field :privileged_page_count, type: Integer, default: 0
|
2020-02-17 13:23:26 +00:00
|
|
|
field :orbit_bar_background_color , type: String, :default => ""
|
2020-05-20 05:29:54 +00:00
|
|
|
field :orbit_bar_background_hover_color
|
2020-05-13 09:57:30 +00:00
|
|
|
field :orbit_bar_text_color , type: String, :default => "#ffffff"
|
2020-05-20 05:29:54 +00:00
|
|
|
field :orbit_bar_text_hover_color
|
2020-02-17 13:23:26 +00:00
|
|
|
field :orbit_bar_submenu_background_color , type: String, :default => ""
|
2020-05-13 09:57:30 +00:00
|
|
|
field :orbit_bar_submenu_text_color , type: String, :default => "#ffffff"
|
2020-02-17 13:23:26 +00:00
|
|
|
field :orbit_bar_animation_time , type: String, :default => "0.3s"
|
2020-05-13 09:57:30 +00:00
|
|
|
field :login_text , type: String, :default => "", localize: true
|
2021-03-08 05:55:46 +00:00
|
|
|
field :sign_up_hint ,:type => Hash, :default => {}
|
|
|
|
field :sign_up_hint_enable ,:type => Hash, :default => {}
|
2021-11-21 02:52:37 +00:00
|
|
|
field :cache_menu_data , :type => String, :default => "", :localize => true
|
|
|
|
field :cache_header_data , :type => String, :default => "", :localize => true
|
|
|
|
field :mobile_cache_menu_data , :type => String, :default => "", :localize => true
|
|
|
|
field :mobile_cache_header_data , :type => String, :default => "", :localize => true
|
|
|
|
field :need_update_header_cache , :type => Boolean, :default => true, localize: true
|
|
|
|
field :need_update_mobile_header_cache , :type => Boolean, :default => true, localize: true
|
|
|
|
field :need_update_menu_cache , :type => Boolean, :default => true, localize: true
|
|
|
|
field :need_update_mobile_menu_cache , :type => Boolean, :default => true, localize: true
|
|
|
|
field :has_sub_home , :type => Boolean, :default => false
|
|
|
|
field :prohibit_general_memebers_access_backend_member_page , :type => Boolean, :default => false
|
2021-12-01 03:21:20 +00:00
|
|
|
field :avoid_member_display_in_wrong_show_page , :type => Boolean, :default => true
|
2021-12-02 02:38:48 +00:00
|
|
|
field :tmp_flags, :type => Array, :default => []
|
2020-02-17 13:23:26 +00:00
|
|
|
mount_uploader :default_image, ImageUploader
|
|
|
|
mount_uploader :site_logo, ImageUploader
|
|
|
|
mount_uploader :site_logo_1, ImageUploader
|
|
|
|
mount_uploader :favicon, ImageUploader
|
|
|
|
mount_uploader :mobile_icon, ImageUploader
|
2021-11-21 02:52:37 +00:00
|
|
|
before_save do
|
2021-12-01 03:21:20 +00:00
|
|
|
# begin
|
|
|
|
# cache_header(false)
|
|
|
|
# rescue => e
|
|
|
|
# File.open("test.html","w+"){|f| f.write(e.backtrace.join(""))}
|
|
|
|
# puts "cache header failed"
|
|
|
|
# end
|
2022-08-03 04:51:25 +00:00
|
|
|
@changed = self.changed?
|
|
|
|
if self.privileged_ip_changed?
|
|
|
|
self.privileged_ip_range = self.privileged_ip.map do |a, b|
|
|
|
|
if a.present? && b.blank?
|
|
|
|
b = a.sub(/[\d]+$/,'254')
|
|
|
|
elsif a.blank? && b.present?
|
|
|
|
a = b.sub(/[\d]+$/,'1')
|
|
|
|
end
|
|
|
|
if a.include?('x')
|
|
|
|
b = a.gsub('x','254')
|
|
|
|
a = a.gsub('x','1')
|
|
|
|
end
|
|
|
|
if a.blank?
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
a = IPAddr.new(a).to_i rescue 0
|
|
|
|
b = IPAddr.new(b).to_i rescue 0
|
|
|
|
[a, b]
|
|
|
|
end
|
|
|
|
end.compact
|
|
|
|
end
|
2021-11-21 02:52:37 +00:00
|
|
|
end
|
|
|
|
after_save do
|
|
|
|
File.open("config/member_extra_db.txt","w+"){|f| f.write(self.member_extra_db)}
|
2022-08-04 02:20:51 +00:00
|
|
|
if (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash rescue false)
|
|
|
|
OrbitHelper::SharedHash['current_site']['site'] = self if @changed && OrbitHelper::SharedHash['current_site']
|
|
|
|
OrbitHelper::SharedHash['privileged_page_count'].value = self.privileged_page_count
|
|
|
|
end
|
2021-11-21 02:52:37 +00:00
|
|
|
end
|
2020-05-13 09:57:30 +00:00
|
|
|
after_initialize do |record|
|
2021-11-21 02:52:37 +00:00
|
|
|
if !record.new_record? && !@skip_callback
|
|
|
|
save_flag = false
|
|
|
|
if record.orbit_bar_background_color == '#000000' && record.orbit_bar_text_color == '#000000'
|
|
|
|
record.orbit_bar_text_color = "#ffffff"
|
|
|
|
save_flag = true
|
2020-05-13 09:57:30 +00:00
|
|
|
end
|
2021-11-21 02:52:37 +00:00
|
|
|
if record.orbit_bar_submenu_background_color == '#000000' && record.orbit_bar_submenu_text_color == '#000000'
|
|
|
|
record.orbit_bar_submenu_text_color = "#ffffff"
|
|
|
|
save_flag = true
|
2020-05-13 09:57:30 +00:00
|
|
|
end
|
2021-11-21 02:52:37 +00:00
|
|
|
if save_flag
|
2022-08-03 04:51:25 +00:00
|
|
|
@changed = true
|
2021-11-21 02:52:37 +00:00
|
|
|
@skip_callback = true
|
2020-05-13 09:57:30 +00:00
|
|
|
record.save
|
2021-11-21 02:52:37 +00:00
|
|
|
@skip_callback = false
|
2020-05-13 09:57:30 +00:00
|
|
|
end
|
|
|
|
end
|
2020-02-17 13:23:26 +00:00
|
|
|
end
|
2022-08-03 04:51:25 +00:00
|
|
|
def need_process_ip
|
2022-08-04 02:20:51 +00:00
|
|
|
OrbitHelper::SharedHash['privileged_page_count'].value != 0 rescue false
|
2022-08-03 04:51:25 +00:00
|
|
|
end
|
|
|
|
def has_privileged_page
|
2022-08-04 02:20:51 +00:00
|
|
|
(OrbitHelper::SharedHash['privileged_page_count'].value != 0 && self.privileged_ip_range.present? rescue false)
|
2022-08-03 04:51:25 +00:00
|
|
|
end
|
|
|
|
def check_ip_is_privileged?(ip, user=(user_nil=true; nil))
|
|
|
|
flag = (self.privileged_ip_range.blank?)
|
|
|
|
user = OrbitHelper.current_user if user_nil
|
|
|
|
if user && user.user_name == 'rulingcom'
|
|
|
|
flag = true
|
|
|
|
else
|
|
|
|
ip_int = IPAddr.new(ip).to_i rescue 0
|
|
|
|
self.privileged_ip_range.each do |r|
|
|
|
|
flag = Range.new(r[0], r[1]).include?(ip_int)
|
|
|
|
break if flag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return flag
|
|
|
|
end
|
2021-12-01 03:21:20 +00:00
|
|
|
def default_locale
|
|
|
|
tmp = super()
|
|
|
|
tmp.blank? ? "zh_tw" : tmp
|
|
|
|
end
|
2020-02-17 13:23:26 +00:00
|
|
|
def register_site(url,university,department,email,country)
|
|
|
|
api_key = STORE_CONFIG[:store_settings]["api_key"]
|
|
|
|
self.generate_site_token
|
|
|
|
store = Store.new(self.id.to_s,self.site_token,api_key)
|
|
|
|
store.post_client(self.id.to_s,self.site_token,self.title,url,university,department,email,country)
|
|
|
|
end
|
2021-11-21 02:52:37 +00:00
|
|
|
def cache_header(save_flag=true)
|
|
|
|
if defined?(Page)
|
|
|
|
org_mobile = $mobile
|
|
|
|
@site = self
|
|
|
|
self.in_use_locales.each do |locale|
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
[true,false].each do |mobile|
|
|
|
|
$mobile = mobile
|
|
|
|
self.store_cache_header_data($mobile,ApplicationHelper.render_header_for_extend(true))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$mobile = org_mobile
|
|
|
|
self.save if save_flag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.make_cache
|
|
|
|
@@ac_controller ||= ApplicationController.new
|
|
|
|
s = Site.first
|
|
|
|
@@ac_controller.class_eval{include ApplicationHelper}
|
|
|
|
@@ac_controller.instance_eval{@site = s;@key = s.template}
|
|
|
|
s.in_use_locales.each do |locale|
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
@@ac_controller.send("render_menu",false)
|
|
|
|
@@ac_controller.send("render_menu",true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def get_cache_menu_data(is_mobile)
|
|
|
|
if is_mobile
|
|
|
|
if self.need_update_mobile_menu_cache
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return self.mobile_cache_menu_data
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if self.need_update_menu_cache
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return self.cache_menu_data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def store_cache_menu_data(is_mobile,data)
|
|
|
|
if is_mobile
|
|
|
|
self.mobile_cache_menu_data = data
|
|
|
|
self.need_update_mobile_menu_cache = false
|
|
|
|
else
|
|
|
|
self.cache_menu_data = data
|
|
|
|
self.need_update_menu_cache = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def get_cache_header_data(is_mobile)
|
|
|
|
if is_mobile
|
|
|
|
if self.need_update_mobile_header_cache
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return self.mobile_cache_header_data
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if self.need_update_header_cache
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return self.cache_header_data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def store_cache_header_data(is_mobile,data)
|
|
|
|
if is_mobile
|
|
|
|
self.mobile_cache_header_data = data
|
|
|
|
self.need_update_mobile_header_cache = false
|
|
|
|
else
|
|
|
|
self.cache_header_data = data
|
|
|
|
self.need_update_header_cache = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def reset_cache
|
|
|
|
localize_true = self.in_use_locales.map{|l| [l.to_s,true]}.to_h
|
2022-07-13 16:11:42 +00:00
|
|
|
#localize_str = self.in_use_locales.map{|l| [l.to_s,""]}.to_h
|
|
|
|
self.class.all.update_all(:need_update_header_cache=>localize_true,:need_update_mobile_header_cache=>localize_true,:need_update_menu_cache=>localize_true,:need_update_mobile_menu_cache=>localize_true)
|
|
|
|
Site.update_all({'$unset'=> {"cache_menu_data"=>1,"cache_header_data"=>1,"mobile_cache_menu_data"=>1,"mobile_cache_header_data"=>1}})
|
|
|
|
self.in_use_locales.each do |l|
|
|
|
|
Site.update_all({'$unset'=> {"cache_menu_data.#{l}"=>1,"cache_header_data.#{l}"=>1,"mobile_cache_menu_data.#{l}"=>1,"mobile_cache_header_data.#{l}"=>1}})
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
def min_memory
|
|
|
|
return 50000 #50k bytes
|
2021-11-21 02:52:37 +00:00
|
|
|
end
|
2022-08-04 02:20:51 +00:00
|
|
|
end
|