module ParserCommon
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FrontHelper
# include ActionView::Helpers::UrlHelper
def menu_level(page, current_page, current, menu, edit = false)
res = ''
if page.visible_children.size > 0
res << "
"
end
res
end
def menu_li(page, current_page, current, menu, i, edit)
res = ""
end
# ad_banners
def parse_ad_banners_edit(body = nil, page = nil, edit=nil)
body.css('ad_banner').each do |banner|
res = ''
ad_banner = AdBanner.find(banner["id"]) rescue nil
if ad_banner
res << ""
res << "
"
res << "
"
ad_banner.ad_images.can_display.each do |ad_image|
link = ad_image_link(ad_image)
res << "
"
end
res << "
"
res << "
"
res << ""
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
banner.swap(fragment)
end
end
# page_images
def parse_images_edit(body, page, edit=nil)
body.css('.page_image').each do |page_image|
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
# image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
image = page.design.images.detect{|image| image.name.eql?(File.basename(page_image['src'])) } unless image
if image
res = "'
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
page_image.swap(fragment)
end
end
# page_menu
def parse_menu_edit(body, page, edit=nil)
page_menu = body.css('.page_menu').first
home = get_homepage
menu = page.design.layout.menu
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit))
page_menu.swap(fragment)
end
# sub_menus
def parse_sub_menus_edit(body = nil, page = nil, edit=nil)
body.css('sub_menu').each do |sub_menu|
menu_page = Page.find(sub_menu['id']) rescue nil
res = ''
if menu_page && menu_page.visible_children.size > 0
res << ""
res << "
#{menu_page.title}
"
res << "
"
menu_page.visible_children.each do |child|
res << "- "
root = ""
res << "#{child.title}"
res << "
"
end
res << "
"
res << ""
res << "
"
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
sub_menu.swap(fragment)
end
end
# breadcrumb
def parse_breadcrumbs_edit(body = nil, page = nil, edit=nil)
body.css('breadcrumb').each do |breadcrumb|
ancestors = Page.find(page.id).ancestors_and_self rescue nil
ancestors = nil if ancestors.size == 1
res = ''
if ancestors
res << ""
ancestors.each_with_index do |node, i|
last = i == ancestors.size-1
res << "- "
if last
res << node.title
else
res << "#{node.title}"
res << "/"
end
res << "
"
end
res << "
"
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
breadcrumb.swap(fragment)
end
end
# tag_cloud
def parse_tag_clouds_edit(body = nil, page = nil, edit=nil)
body.css('tag_cloud').each do |tag_cloud|
module_app = ModuleApp.find(tag_cloud["id"]) rescue nil
res = ''
if module_app
res << ""
res << "
#{t(:tag_cloud)}
"
res << "
"
module_app.sorted_tags_for_cloud.each do |tag|
# res << link_to(tag[0].name, ('/' + {:tag_id => tag[0].id, :category_id => params[:category_id]}.to_param), :class => "#{tag[1]} #{tag[0].id.to_s.eql?(params[:tag_id]) ? 'active' : nil} ")
res << ""
res << tag[0].name
res << ""
end
res << "
"
res << "
"
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
tag_cloud.swap(fragment)
end
end
# page_footer
def parse_footer_edit(body, page)
page_footer = body.css('.page_footer').first
if page_footer
res = ""
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
page_footer.swap(fragment) rescue nil
else
''
end
end
# page_sub_menu
def parse_sub_menu_edit(body, page)
page_sub_menu = body.css('.page_sub_menu').first
if page_sub_menu
res = ""
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
page_sub_menu.swap(fragment) rescue nil
else
''
end
end
def parse_breadcrumb_edit(body, page)
page_breadcrumb = body.css('.page_breadcrumb').first
if page_breadcrumb
res = ""
res << @site.breadcrumb rescue nil
res << "
"
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
page_breadcrumb.swap(fragment) rescue nil
else
''
end
end
# sitemap
def parse_sitemaps_edit(body = nil, page = nil, edit=nil)
sitemap = body.css('sitemap').first
url = front_show_sitemap_path
options = "?inner=true"
fragment = Nokogiri::HTML::DocumentFragment.new(body, "")
sitemap.swap(fragment)
end
# terms_of_use
def parse_terms_of_uses_edit(body = nil, page = nil, edit=nil)
terms_of_use = body.css('terms_of_use').first
url = front_show_terms_of_use_path
options = "?inner=true"
fragment = Nokogiri::HTML::DocumentFragment.new(body, "")
terms_of_use.swap(fragment)
end
# page_contents
def parse_contents_edit(body, page, edit=nil)
public_r_tags = []
url = ''
body.css('.page_content').each do |content|
ret = ''
category = params[:category_id].blank? ? page[:category] : params[:category_id]
tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id]
if (content["main"] == "true" && !page.module_app.nil?)
if page.app_frontend_url == 'default_widget'
url = "/panel/orbit_app/widget/#{page.frontend_style}?inner=true"
else
url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}"
end
ret << ""
else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
part_title = part.title rescue nil
if edit
ret << "" if part
ret << "
'
end
case part.kind
when 'text'
ret << part.content rescue ''
when 'module_widget'
url = case part.widget_path
when 'default_widget'
"/panel/orbit_app/widget/#{part.widget_style}?inner=true"
else
# raise ModuleAppError,"PagePart can't find ModuleApp" if part.module_app.nil?
"/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" rescue ''
end
categories_str=(!part[:category].blank? ? part[:category] : category).collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=(!part[:tag].blank? ? part[:tag] : tag).collect{|t| "tag_id[]=#{t}"}.join('&')
categories_str = "{categories_str}" unless categories_str.blank?
tags_str = "{tags_str}" unless tags_str.blank?
options = "&part_id=#{part.id}#{categories_str}#{tags_str}&page=#{params[:page]}&search_query=#{params[:search_query]}&clicked_field_name=#{params[:clicked_field_name]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part"
ret << "
"
when 'public_r_tag'
ret << "
"
public_r_tags << part.public_r_tag
else
''
end if part
end
scope = "<#{content.name}"
content.attributes.each_pair do |key, value|
scope << " #{key}='#{value}'"
end
scope << ">#{ret}#{content.name}>"
fragment = Nokogiri::HTML::DocumentFragment.new(body, scope)
content.swap(fragment)
end
public_r_tags.uniq
end
# page_counter
def parse_counter_edit(body = nil)
body.css('.page_counter').each do |counter|
res = ''
case counter['option']
when 'all'
res << display_visitors.to_s
when 'today'
res << display_visitors_today.to_s
when 'this_week'
res << display_visitors_this_week.to_s
when 'this_month'
res << display_visitors_this_month.to_s
when 'this_year'
res << display_visitors_this_year.to_s
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, "
#{res}
")
counter.swap(fragment)
end
end
end