Class: CamaleonCms::Site
- Inherits:
-
TermTaxonomy
- Object
- ActiveRecord::Base
- CamaleonRecord
- TermTaxonomy
- CamaleonCms::Site
- Includes:
- SiteDefaultSettings
- Defined in:
- app/models/camaleon_cms/site.rb
Constant Summary
Constants inherited from CamaleonRecord
CamaleonRecord::TRANSLATION_TAG_HIDE_MAP, CamaleonRecord::TRANSLATION_TAG_HIDE_REGEX, CamaleonRecord::TRANSLATION_TAG_RESTORE_MAP, CamaleonRecord::TRANSLATION_TAG_RESTORE_REGEX
Instance Attribute Summary collapse
-
#site_domain ⇒ Object
attrs: [name, description, slug].
Class Method Summary collapse
-
.main_site ⇒ Object
return main site.
Instance Method Summary collapse
-
#admin_per_page ⇒ Object
items per page to be listed on admin panel.
-
#assign_user(user) ⇒ Object
assign user to this site.
-
#categories ⇒ Object
all main categories for this site.
-
#front_comment_status ⇒ Object
frontend comments status for new comments on frontend.
-
#front_per_page ⇒ Object
items per page to be listed on frontend.
-
#full_categories ⇒ Object
select full_categories for the site, include all children categories.
-
#get_admin_language ⇒ Object
return current admin language configured for this site.
-
#get_anonymous_user ⇒ Object
return the anonymous user if the anonymous user not exist, will create one.
-
#get_domain ⇒ Object
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.
-
#get_languages ⇒ Object
return all languages configured by the admin if it is empty, then return default locale.
-
#get_plugin(plugin_slug) ⇒ Object
return plugin model with slug plugin_slug.
-
#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.
-
#get_theme_slug ⇒ Object
return current theme slug configured for this site if theme was not configured, then return system.json defined.
-
#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.
-
#is_active? ⇒ Boolean
check if current site is active or not.
-
#is_enable_captcha_for_comments? ⇒ Boolean
check if current site permit capctha for anonymous comments.
-
#is_inactive? ⇒ Boolean
check if current site is active or not.
-
#is_maintenance? ⇒ Boolean
check if current site is in maintenance or not.
-
#main_site? ⇒ Boolean
(also: #is_default?)
check if this site is the main site main site is a site that doesn’t have slug.
- #need_validate_email? ⇒ Boolean
-
#post_tags ⇒ Object
all post_tags for this site.
-
#security_user_register_captcha_enabled? ⇒ Boolean
security: user register form show captcha?.
-
#set_admin_language(language) ⇒ Object
set current admin language for this site.
-
#upload_directory(inner_directory = nil) ⇒ Object
return upload directory for this site (deprecated for cloud support).
-
#upload_directory_name ⇒ Object
return the directory name where to upload file for this site.
-
#user_roles ⇒ Object
all user roles for this site.
-
#users ⇒ Object
(also: #users_include_admins)
list all users of current site.
Methods included from SiteDefaultSettings
#default_settings, #set_default_user_roles
Methods inherited from TermTaxonomy
#children, #in_nav_menu_items, inherited, #skip_slug_validation?
Methods included from NormalizeAttrs
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
Methods inherited from CamaleonRecord
#ability, #cama_build_cache_key, #cama_fetch_cache, #cama_get_cache, #cama_remove_cache, #cama_set_cache, #can?, #current_site, #current_user, #reset_ability
Instance Attribute Details
#site_domain ⇒ Object
attrs: [name, description, slug]
8 9 10 |
# File 'app/models/camaleon_cms/site.rb', line 8 def site_domain @site_domain end |
Class Method Details
.main_site ⇒ Object
return main site
139 140 141 |
# File 'app/models/camaleon_cms/site.rb', line 139 def self.main_site @main_site ||= CamaleonCms::Site.reorder(id: :asc).first end |
Instance Method Details
#admin_per_page ⇒ Object
items per page to be listed on admin panel
115 116 117 |
# File 'app/models/camaleon_cms/site.rb', line 115 def admin_per_page get_option('admin_per_page', 10) end |
#assign_user(user) ⇒ Object
assign user to this site
105 106 107 |
# File 'app/models/camaleon_cms/site.rb', line 105 def assign_user(user) user.assign_site(self) end |
#categories ⇒ Object
all main categories for this site
60 61 62 |
# File 'app/models/camaleon_cms/site.rb', line 60 def categories CamaleonCms::Category.includes(:post_type_parent).where(post_type_parent: post_types.pluck(:id)) end |
#front_comment_status ⇒ Object
frontend comments status for new comments on frontend
120 121 122 |
# File 'app/models/camaleon_cms/site.rb', line 120 def front_comment_status get_option('comment_status', 'pending') end |
#front_per_page ⇒ Object
items per page to be listed on frontend
110 111 112 |
# File 'app/models/camaleon_cms/site.rb', line 110 def front_per_page get_option('front_per_page', 10) end |
#full_categories ⇒ Object
select full_categories for the site, include all children categories
50 51 52 |
# File 'app/models/camaleon_cms/site.rb', line 50 def full_categories CamaleonCms::Category.where(site_id: id) end |
#get_admin_language ⇒ Object
return current admin language configured for this site
78 79 80 |
# File 'app/models/camaleon_cms/site.rb', line 78 def get_admin_language [:_admin_theme] || 'en' end |
#get_anonymous_user ⇒ Object
return the anonymous user if the anonymous user not exist, will create one
212 213 214 215 216 217 218 219 220 |
# File 'app/models/camaleon_cms/site.rb', line 212 def get_anonymous_user user = users.where(username: 'anonymous').first unless user.present? pass = "anonymous#{rand(9999)}" user = users.create({ email: 'anonymous_user@local.com', username: 'anonymous', password: pass, password_confirmation: pass, first_name: 'Anonymous' }) end user end |
#get_domain ⇒ Object
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
225 226 227 228 229 230 231 |
# File 'app/models/camaleon_cms/site.rb', line 225 def get_domain @site_domain || (if main_site? slug else (slug.include?('.') ? slug : "#{slug}.#{Cama::Site.main_site.slug}") end) end |
#get_languages ⇒ Object
return all languages configured by the admin if it is empty, then return default locale
66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/camaleon_cms/site.rb', line 66 def get_languages return @_languages if defined?(@_languages) l = ('languages_site', [I18n.default_locale]) @_languages = begin l.map(&:to_sym) rescue StandardError [I18n.default_locale.to_sym] end end |
#get_plugin(plugin_slug) ⇒ Object
return plugin model with slug plugin_slug
100 101 102 |
# File 'app/models/camaleon_cms/site.rb', line 100 def get_plugin(plugin_slug) 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
95 96 97 |
# File 'app/models/camaleon_cms/site.rb', line 95 def get_theme(theme_slug = nil) themes.where(slug: theme_slug || get_theme_slug, status: nil).first_or_create! end |
#get_theme_slug ⇒ Object
return current theme slug configured for this site if theme was not configured, then return system.json defined
89 90 91 |
# File 'app/models/camaleon_cms/site.rb', line 89 def get_theme_slug [:_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
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'app/models/camaleon_cms/site.rb', line 176 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 = 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
196 197 198 |
# File 'app/models/camaleon_cms/site.rb', line 196 def is_active? status.blank? || status == 'active' end |
#is_enable_captcha_for_comments? ⇒ Boolean
check if current site permit capctha for anonymous comments
130 131 132 |
# File 'app/models/camaleon_cms/site.rb', line 130 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
201 202 203 |
# File 'app/models/camaleon_cms/site.rb', line 201 def is_inactive? status == 'inactive' end |
#is_maintenance? ⇒ Boolean
check if current site is in maintenance or not
206 207 208 |
# File 'app/models/camaleon_cms/site.rb', line 206 def is_maintenance? 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
145 146 147 |
# File 'app/models/camaleon_cms/site.rb', line 145 def main_site? self.class.main_site == self end |
#need_validate_email? ⇒ Boolean
134 135 136 |
# File 'app/models/camaleon_cms/site.rb', line 134 def need_validate_email? get_option('need_validate_email', false) == true end |
#post_tags ⇒ Object
all post_tags for this site
55 56 57 |
# File 'app/models/camaleon_cms/site.rb', line 55 def CamaleonCms::PostTag.includes(:post_type).where(post_type: post_types.pluck(:id)) end |
#security_user_register_captcha_enabled? ⇒ Boolean
security: user register form show captcha?
125 126 127 |
# File 'app/models/camaleon_cms/site.rb', line 125 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
83 84 85 |
# File 'app/models/camaleon_cms/site.rb', line 83 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)
161 162 163 164 |
# File 'app/models/camaleon_cms/site.rb', line 161 def upload_directory(inner_directory = nil) File.join(Rails.public_path, "/media/#{PluginRoutes.static_system_info['media_slug_folder'] ? slug : id}", inner_directory.to_s) end |
#upload_directory_name ⇒ Object
return the directory name where to upload file for this site
167 168 169 |
# File 'app/models/camaleon_cms/site.rb', line 167 def upload_directory_name (PluginRoutes.static_system_info['media_slug_folder'] ? slug : id).to_s end |
#user_roles ⇒ Object
all user roles for this site
41 42 43 44 45 46 47 |
# File 'app/models/camaleon_cms/site.rb', line 41 def user_roles if PluginRoutes.system_info['users_share_sites'] CamaleonCms::Site.main_site.user_roles_rel else user_roles_rel end end |
#users ⇒ Object Also known as: users_include_admins
list all users of current site
151 152 153 154 155 156 157 |
# File 'app/models/camaleon_cms/site.rb', line 151 def users if PluginRoutes.system_info['users_share_sites'] CamaleonCms::User.all else CamaleonCms::User.where(site_id: id) end end |