Class: CamaleonCms::Site

Inherits:
TermTaxonomy show all
Includes:
SiteDefaultSettings
Defined in:
app/models/camaleon_cms/site.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SiteDefaultSettings

#default_settings, #set_default_user_roles

Methods inherited from TermTaxonomy

#children, #in_nav_menu_items, #skip_slug_validation?

Methods included from CustomFieldsRead

#add_custom_field_group, #add_custom_field_to_default_group, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_grouped, #get_fields_object, #get_user_field_groups, #save_field_value, #set_field_value, #set_field_values, #update_field_value

Methods included from Metas

#delete_meta, #delete_option, #fix_save_metas_options_no_changed, #get_meta, #get_option, #options, #save_metas_options, #save_metas_options_skip, #set_meta, #set_metas, #set_option, #set_options

Instance Attribute Details

#site_domainObject

attrs: [name, description, slug]


3
4
5
# File 'app/models/camaleon_cms/site.rb', line 3

def site_domain
  @site_domain
end

Class Method Details

.main_siteObject

return main site


123
124
125
# File 'app/models/camaleon_cms/site.rb', line 123

def self.main_site
  @main_site ||= CamaleonCms::Site.reorder(id: :asc).first
end

Instance Method Details

#admin_per_pageObject

items per page to be listed on admin panel


99
100
101
# File 'app/models/camaleon_cms/site.rb', line 99

def admin_per_page
  get_option("admin_per_page", 10)
end

#assign_user(user) ⇒ Object

assign user to this site


89
90
91
# File 'app/models/camaleon_cms/site.rb', line 89

def assign_user(user)
  user.assign_site(self)
end

#categoriesObject

all main categories for this site


49
50
51
# File 'app/models/camaleon_cms/site.rb', line 49

def categories
  CamaleonCms::Category.includes(:post_type_parent).where(post_type_parent: self.post_types.pluck(:id))
end

#front_comment_statusObject

frontend comments status for new comments on frontend


104
105
106
# File 'app/models/camaleon_cms/site.rb', line 104

def front_comment_status
  get_option("comment_status", "pending")
end

#front_per_pageObject

items per page to be listed on frontend


94
95
96
# File 'app/models/camaleon_cms/site.rb', line 94

def front_per_page
  get_option("front_per_page", 10)
end

#full_categoriesObject

select full_categories for the site, include all children categories


39
40
41
# File 'app/models/camaleon_cms/site.rb', line 39

def full_categories
  CamaleonCms::Category.where({site_id: self.id})
end

#get_admin_languageObject

return current admin language configured for this site


62
63
64
# File 'app/models/camaleon_cms/site.rb', line 62

def get_admin_language
  options[:_admin_theme] || "en"
end

#get_anonymous_userObject

return the anonymous user if the anonymous user not exist, will create one


194
195
196
197
198
199
200
201
# File 'app/models/camaleon_cms/site.rb', line 194

def get_anonymous_user
  user = self.users.where(username: 'anonymous').first
  unless user.present?
    pass = "anonymous#{rand(9999)}"
    user = self.users.create({email: '[email protected]', username: 'anonymous', password: pass, password_confirmation: pass, first_name: 'Anonymous'})
  end
  user
end

#get_domainObject

return the domain for current site sample: mysite.com | sample.mysite.com also, you can define custom domain for this site by: my_site.site_domain = 'my_site.com' # used for sites with different domains to call from console or task


206
207
208
# File 'app/models/camaleon_cms/site.rb', line 206

def get_domain
  @site_domain || (main_site? ? slug : (slug.include?(".") ? slug : "#{slug}.#{Cama::Site.main_site.slug}"))
end

#get_languagesObject

return all languages configured by the admin if it is empty, then return default locale


55
56
57
58
59
# File 'app/models/camaleon_cms/site.rb', line 55

def get_languages
  return @_languages if defined?(@_languages)
  l = get_meta("languages_site", [I18n.default_locale])
  @_languages = l.map { |x| x.to_sym } rescue [I18n.default_locale.to_sym]
end

#get_plugin(plugin_slug) ⇒ Object

return plugin model with slug plugin_slug


84
85
86
# File 'app/models/camaleon_cms/site.rb', line 84

def get_plugin(plugin_slug)
  self.plugins.where(slug: plugin_slug).first_or_create!
end

#get_theme(theme_slug = nil) ⇒ Object

return theme model with slug theme_slug for this site theme_slug: (optional) if it is null, this will return current theme for this site


79
80
81
# File 'app/models/camaleon_cms/site.rb', line 79

def get_theme(theme_slug = nil)
  self.themes.where(slug: (theme_slug || get_theme_slug), status: nil).first_or_create!
end

#get_theme_slugObject

return current theme slug configured for this site if theme was not configured, then return system.json defined


73
74
75
# File 'app/models/camaleon_cms/site.rb', line 73

def get_theme_slug
  options[:_theme] || PluginRoutes.system_info["default_template"]
end

#get_valid_post_slug(slug, post_id = nil) ⇒ Object

return an available slug for a new post slug: (String) possible slug value post_id: (integer, optional) current post id sample: (“<!–:es–>features-1<!–:–><!–:en–>caract-1<!–:–>”) | (“features”) return: (String) available slugs


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'app/models/camaleon_cms/site.rb', line 159

def get_valid_post_slug(slug, post_id=nil)
  slugs = slug.translations
  if slugs.present?
    slugs.each do |k, v|
      slugs[k] = get_valid_post_slug(v)
    end
    slugs.to_translate
  else
    res = slug
    (1..9999).each do |i|
      p = self.posts.find_by_slug(res)
      break if !p.present? || (p.present? && p.id == post_id)
      res = "#{slug}-#{i}"
    end
    res
  end
end

#is_active?Boolean

check if current site is active or not

Returns:

  • (Boolean)

178
179
180
# File 'app/models/camaleon_cms/site.rb', line 178

def is_active?
  !self.status.present? || self.status == 'active'
end

#is_enable_captcha_for_comments?Boolean

check if current site permit capctha for anonymous comments

Returns:

  • (Boolean)

114
115
116
# File 'app/models/camaleon_cms/site.rb', line 114

def is_enable_captcha_for_comments?
  get_option('enable_captcha_for_comments', false)
end

#is_inactive?Boolean

check if current site is active or not

Returns:

  • (Boolean)

183
184
185
# File 'app/models/camaleon_cms/site.rb', line 183

def is_inactive?
  self.status == 'inactive'
end

#is_maintenance?Boolean

check if current site is in maintenance or not

Returns:

  • (Boolean)

188
189
190
# File 'app/models/camaleon_cms/site.rb', line 188

def is_maintenance?
  self.status == 'maintenance'
end

#main_site?Boolean Also known as: is_default?

check if this site is the main site main site is a site that doesn't have slug

Returns:

  • (Boolean)

129
130
131
# File 'app/models/camaleon_cms/site.rb', line 129

def main_site?
  self.class.main_site == self
end

#need_validate_email?Boolean

Returns:

  • (Boolean)

118
119
120
# File 'app/models/camaleon_cms/site.rb', line 118

def need_validate_email?
  get_option('need_validate_email', false) == true
end

#post_tagsObject

all post_tags for this site


44
45
46
# File 'app/models/camaleon_cms/site.rb', line 44

def 
  CamaleonCms::PostTag.includes(:post_type).where(post_type: self.post_types.pluck(:id))
end

#security_user_register_captcha_enabled?Boolean

security: user register form show captcha?

Returns:

  • (Boolean)

109
110
111
# File 'app/models/camaleon_cms/site.rb', line 109

def security_user_register_captcha_enabled?
  get_option('security_captcha_user_register', false) == true
end

#set_admin_language(language) ⇒ Object

set current admin language for this site


67
68
69
# File 'app/models/camaleon_cms/site.rb', line 67

def set_admin_language(language)
  set_option("_admin_theme", language)
end

#upload_directory(inner_directory = nil) ⇒ Object

return upload directory for this site (deprecated for cloud support)


145
146
147
# File 'app/models/camaleon_cms/site.rb', line 145

def upload_directory(inner_directory = nil)
  File.join(Rails.public_path, "/media/#{PluginRoutes.static_system_info["media_slug_folder"] ? self.slug : self.id}", inner_directory.to_s)
end

#upload_directory_nameObject

return the directory name where to upload file for this site


150
151
152
# File 'app/models/camaleon_cms/site.rb', line 150

def upload_directory_name
  "#{PluginRoutes.static_system_info["media_slug_folder"] ? self.slug : self.id}"
end

#user_rolesObject

all user roles for this site


30
31
32
33
34
35
36
# File 'app/models/camaleon_cms/site.rb', line 30

def user_roles
  if PluginRoutes.system_info["users_share_sites"]
    CamaleonCms::Site.main_site.user_roles_rel
  else
    user_roles_rel
  end
end

#usersObject Also known as: users_include_admins

list all users of current site


135
136
137
138
139
140
141
# File 'app/models/camaleon_cms/site.rb', line 135

def users
  if PluginRoutes.system_info["users_share_sites"]
    CamaleonCms::User.all
  else
    CamaleonCms::User.where(site_id: self.id)
  end
end