/app/controllers/simple_controller.rb
Ruby | 128 lines | 108 code | 15 blank | 5 comment | 11 complexity | 3a1b804959700960a1d5f1ec98d4398c MD5 | raw file
Possible License(s): LGPL-2.1
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- require "will_paginate"
- class SimpleController < ApplicationController
- unloadable
- # See ActionController::RequestForgeryProtection for details
- # Uncomment the :secret if you're not using the cookie session store
- #protect_from_forgery # :secret => '1159dd7a699f6b0ecac00f33cf591e64'
- self.allow_forgery_protection = false
- before_filter :detect_site
- before_filter :load_objects
-
- rescue_from(Simple::NoAccessException) {render :template => 'security/no_access'}
- HTML_CONTENT = 'SimpleHtmlContent'
- REVIEW_CONTENT = 'ReviewContent'
- SITEMAP_CONTENT = 'SimpleSitemapContent'
- CONTENT_TYPES = [HTML_CONTENT, REVIEW_CONTENT, SITEMAP_CONTENT]
- NEWS_MODULE = 'NewsModule'
- NEWSLETTER_SIGNUP_MODULE = 'NewsletterSignupModule'
- FAQ_MODULE = 'FaqModule'
- BLOG_MODULE = 'BlogModule'
- FORM_MODULE = 'FormModule'
- SIMPLE_MODULES = [NEWS_MODULE, NEWSLETTER_SIGNUP_MODULE, FAQ_MODULE, BLOG_MODULE, FORM_MODULE]
-
- def detect_site
- logger.info(request.host)
- name = request.host.split(':')[0]
- domain = SimpleDomain.find(:first, :conditions => ["name = ?", name])
- if domain
- @current_site = domain.site
- elsif params[:controller] == 'admin/sessions'
- @current_site = nil
- else
- render :status => 404, :file => "#{RAILS_ROOT}/public/404.html"
- return
- end
- path = request.path.split('/')
-
- if (@current_site.nil? or !@current_site.active) && path[1] != 'admin' && path[1] != 'simplelogin' && path[1] != 'simplelogout'
- render :status => 404, :file => "#{RAILS_ROOT}/public/404.html"
- end
- end
- def load_objects
- if session[:simple_user_id]
- @current_simple_user = SimpleUser.find(session[:simple_user_id])
- end
- end
- def login_required
- if !session[:simple_user_id]
- redirect_to login_path
- end
- end
- def index
- 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 check_role(role)
- if !@current_simple_user
- raise Simple::NoAccessException
- else
- 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
- raise Simple::NoAccessException
- end
- end
- def must_be_superadmin
- check_role(SimpleRole::ROLE_SUPERADMIN)
- end
- def must_be_siteadmin
- check_role(SimpleRole::ROLE_SITEADMIN)
- end
- def render_layout(layout)
- rendered_page = render_to_string :inline => layout.template
- rendered_page.gsub!(/\[\[(.*)\]\]/) do |m|
- logger.debug "MATCH: #{m} #{$1}"
- cc = $1
- if SimpleComponent.instance_methods.include?(cc.split('(').first)
- eval(cc)
- elsif RAILS_ENV == 'development'
- "Unknown component: #{cc}"
- else
- ''
- end
- end
- return rendered_page
- end
-
- end