/app/helpers/simple_helper.rb
Ruby | 147 lines | 134 code | 10 blank | 3 comment | 10 complexity | 82379997b093055444313f61de774d96 MD5 | raw file
Possible License(s): LGPL-2.1
- module SimpleHelper
- def use_tinymce
- @uses_tinymce = true
- end
- def uses_tinymce?
- return @uses_tinymce
- end
- def escape_quotes(text)
- text = text.gsub(/\r\n/, '<br />')
- text = text.gsub(/\n/, '<br />')
- text = text.gsub('"', '"')
- text = text.gsub("'", "\\\\'")
- return sanitize(text)
- end
- # helper methods to render stuff on page
- def main_content
- if @page
- render :partial => 'admin/' + @page.content_type.pluralize.underscore + '/render'
- else
- #'Main content'
- 'No content!'
- end
- end
- def check_role(role)
- if @current_simple_user
- for r in @current_simple_user.roles
- if role == SimpleRole::ROLE_SITEADMIN && (r.role == SimpleRole::ROLE_SUPERADMIN or r.role == SimpleRole::ROLE_SITEADMIN)
- return true
- elsif role == r.role
- return true
- end
- end
- end
- return false
- end
- def is_superadmin?
- return check_role(SimpleRole::ROLE_SUPERADMIN)
- end
- def is_siteadmin?
- if check_role(SimpleRole::ROLE_SUPERADMIN) or check_role(SimpleRole::ROLE_SITEADMIN)
- return true
- else
- return false
- end
- end
- def page_title
- if !@page.blank?
- if !@page.nil? && !@page.page_title.blank?
- @page.page_title
- elsif !@page.active_layout.nil? && !@page.active_layout.default_page_title.blank?
- @page.active_layout.default_page_title
- else
- ''
- end
- end
- end
- def meta_description
- if @page && !@page.meta_description.nil? && !@page.meta_description.empty?
- "<meta name='description' content='#{@page.meta_description}' />"
- end
- end
- def meta_keywords
- if @page && !@page.meta_keywords.nil? && !@page.meta_keywords.empty?
- "<meta name='keywords' content='#{@page.meta_keywords}' />"
- end
- end
- def include_content(name)
- if @page
- @page.include_content(name)
- else
- ''
- end
- end
- def include_css
- # todo: find css for page
- # todo: pack css into one
- css_paths = ''
- if @page
- layout = @page.active_layout
- elsif @layout
- layout = @layout
- end
- if layout
- for css in layout.stylesheets
- css_path = "/download/stylesheets/#{css.id}/#{get_urlname(css.name)}.css"
- css_paths += "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{css_path}\" />\n"
- end
- return css_paths
- end
- end
- def page_menu
- if !@page.blank? && !@page.active_layout.nil? && !@page.active_layout.menu_content.nil?
- render :partial => 'admin/simple_menu_contents/render', :locals => {:menu_content => @page.active_layout.menu_content.menu_content_array}
- else
- #'menu'
- ''
- end
- end
-
- def get_urlname(name)
- foo = name.downcase.strip
- foo.gsub!(/[ÀÁÂÃÄÅâäàãáäå????????????]/,'a')
- foo.gsub!(/[ëêéè????????????????????]/,'e')
- foo.gsub!(/[ÌÍÎ?Ïiìíî???ï?????????]/,'i')
- foo.gsub!(/[ÒÓÔÕÖòóôõ???ö?????????ø???????????????????]/,'o')
- foo.gsub!(/[ÙÚÛ?Üùúû???ü????????????????????????]/,'u')
- foo.gsub!(/[?ý????ÿ????]/,'y')
- foo.gsub!(/[œ]/,'oe')
- foo.gsub!(/[Æ??æ]/,'ae')
- foo.gsub!(/[ñ??]/,'n')
- foo.gsub!(/[Çç]/,'c')
- foo.gsub!(/[ß]/,'b')
- foo.gsub!(/[œ]/,'oe')
- foo.gsub!(/[?]/,'ij')
- foo.gsub!(/[\s\\\/\?\.\=\+\&\%\:]/,'_')
- foo.gsub!(/[\'\"]/,'')
- foo.gsub!(/_+/,'_')
- return foo
- end
- def get_relative_path(full_url)
- full_url.gsub!(request.protocol + request.host_with_port, '')
- end
- def show_text_in_form(text)
- if !text.blank?
- text = text.gsub('&', '&')
- end
- text
- end
-
- end