This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/pages_controller.rb

97 lines
4.3 KiB
Ruby
Raw Normal View History

class PagesController < ApplicationController
2012-03-21 17:51:16 +00:00
include ApplicationHelper
before_filter :get_item, :only => [:index_from_link, :show_from_link]
# caches_page :index
2012-07-26 07:44:53 +00:00
def index
@item = Page.find_by_name('home')
2012-07-12 03:47:24 +00:00
2012-07-13 07:36:10 +00:00
if @item
impressionist(@item)
render_page
else
2012-11-27 03:15:15 +00:00
render :text => t(:need_home)
end
end
2011-12-23 10:34:21 +00:00
def show
2012-05-15 13:26:09 +00:00
#begin
@item = Item.first(:conditions => {:path => params[:page_name]})
2012-09-11 02:52:27 +00:00
if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
impressionist(@item)
2012-07-30 10:34:54 +00:00
case @item.class.to_s
when 'Page'
render_page unless save_from_no_lang_for_page
2012-05-15 13:26:09 +00:00
when 'Link'
redirect_to(@item[:url]) unless save_from_no_lang_for_page
2012-05-15 13:26:09 +00:00
end
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found
end
#rescue
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
#end
end
def index_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page
end
def show_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank?
redirect_to(url + options) unless save_from_no_lang_for_page
end
def load_orbit_bar
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
end
protected
def get_item
if params[:same_page_id]
@item = Item.find(params[:same_page_id])
else
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
if !params[:category_id].blank? && !params[:tag_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
elsif !params[:category_id].blank?
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], category: params[:category_id]).any_in(tag: [nil,'']).first
elsif !params[:tag_id].blank?
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], tag: params[:tag_id]).any_in(category: [nil,'']).first
end
2013-02-07 13:15:38 +00:00
@item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
@item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item
2013-02-07 13:15:38 +00:00
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
end
2013-01-03 07:35:14 +00:00
raise PageError,'Missing Frontend Page' if @item.nil?
end
2011-12-23 10:34:21 +00:00
def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:error] = t('sys.module_page_lang_not_support')
redirect_to '/'
return true
else
return false
end
end
end