orbit-basic/app/controllers/front_controller.rb

107 lines
3.0 KiB
Ruby
Raw Permalink Normal View History

class FrontController < ApplicationController
layout false
2013-01-31 11:20:55 +00:00
def show_breadcrumb
@ancestors = Page.find(params[:id]).ancestors_and_self
2013-02-07 09:26:40 +00:00
@ancestors = nil if @ancestors.size == 1
2013-01-31 11:20:55 +00:00
end
def show_banner
@ad_banner = AdBanner.find(params[:id]) rescue nil
end
def show_footer
@page = Page.find(:all, :conditions => {:name => /terms/i})
@name = @page.first.name if @page.first.present?
2013-11-25 04:41:32 +00:00
@url = "/#{@name}" if @name.present?
if (!@site.enable_terms_of_use && @page.first.present?)
render :text => (@site.footer + "<a href='#{@url}'>#{t(:terms_of_use)}</a>")
else
render :text => @site.footer
end
end
def show_menu
page = Page.find(params[:id]) rescue nil
render :text => menu_level(Page.root, page, 1, page.design.layout.menu) if page
end
def show_site_sub_menu
@page = Page.find(:all, :conditions => {:name => /sitemap/i})
2013-11-25 04:53:57 +00:00
@name = @page.first.name if @page.first.present?
@url = "/#{@name}"
2013-11-25 04:53:57 +00:00
if (!@site.sitemap_menu_in_header && @page.first.present?)
render :text => (@site.sub_menu + "<a href='#{@url}'>#{t(:sitemap)}</a>")
else
render :text => @site.sub_menu
end
end
def show_sitemap
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
end
def show_page_sub_menu
@menu_page = Page.find(params[:menu_page_id]) rescue nil
@page_id = params[:page_id]
end
2013-01-09 08:54:33 +00:00
def show_inner_ad_image
@ad_image = AdImage.find(params[:id]) rescue nil
@ad_images = AdImage.all
end
2013-05-24 10:42:01 +00:00
def show_tag_cloud
module_app = ModuleApp.find(params[:id]) rescue nil
@tags = module_app.sorted_tags_for_cloud
end
def show_terms_of_use
@site = Site.first rescue nil
@terms = @site.terms_of_use
end
private
def menu_level(page, current_page, current, menu)
res = ''
if page.visible_children.size > 0
res << "<ul class='"
res << menu.values["class_#{current}"] rescue nil
res << "'>"
i = nil
i = 1 if menu.values["li_incremental_#{current}"]
2012-12-28 03:37:37 +00:00
children = current == 1 ? page.visible_children : page.visible_children
children.each do |child|
res << menu_li(child, current_page, current, menu, i)
i += 1 if i
end
if menu.values['home'] && current == 1
res << menu_li(page, current_page, current, menu, i)
end
res << "</ul>"
end
res
end
def menu_li(page, current_page, current, menu, i)
res = "<li class='"
res << menu.values["li_class_#{current}"] rescue nil
res << "_#{i}" if i
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
res << "'>"
root = "/"
res << "<a href='#{(page.class.to_s.eql?('Page') ? root + page.path : page.url)}' target=#{(page.class.to_s.eql?('Page') ? '_self' : '_blank')} ><span>#{page.title}</span></a>"
if page.visible_children.size > 0 && current < menu.levels
res << "<span class='dot'></span>"
res << menu_level(page, current_page, current + 1, menu)
end unless (page.root? rescue nil)
res << "</li>"
end
end