module ParserFrontEnd
require 'nokogiri'
def parse_page_noko(page, site)
i18n = {}
Site.first.valid_locales.each do |locale|
body = Nokogiri::HTML(page.design.layout.body)
parse_contents(body, page, locale)
parse_footer(body, page, site)
parse_images(body, page)
parse_menu(body, page)
parse_sub_menu(body, page, site)
parse_breadcrumb(body, page, site)
parse_counter(body)
i18n.merge!({locale => body.to_html})
end
i18n
end
def parse_page_content(page,args={})
args["category_id"] = args["category_id"].gsub(/\"|\[|\]/,'').split(",").each(&:strip!) if !args["category_id"].blank? and args["category_id"].is_a?(String)
args["tag_id"] = args["tag_id"].gsub(/\"|\[|\]/,'').split(",").each(&:strip!) if !args["tag_id"].blank? and args["tag_id"].is_a? String
# tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id]
# category = params[:category_id].blank? ? page[:category] : params[:category_id]
body = Nokogiri::HTML(page.content)
if @edit
body.css('.page_part').each do |page_part|
part = PagePart.find(page_part['part_id']) rescue nil
ret = ''
ret << "
"
ret << "
'
ret << page_part.inner_html rescue nil
ret << '
'
fragment = Nokogiri::HTML::DocumentFragment.new(body, ret)
page_part.swap(fragment)
end
end
body.css('orbit_front').each do |front|
if front['value']
fragment = Nokogiri::HTML::DocumentFragment.new(body, "#{eval(front['value']).to_s}
")
else
ret = ''
part = PagePart.find(front['part_id']) if front['part_id']
ret << eval("\"#{front['path']}\"") rescue ''
ret << (ret.include?("?") ? "{args.to_param}" : "?#{args.to_param}") if args
fragment = Nokogiri::HTML::DocumentFragment.new(body, "")
end
front.swap(fragment)
end
body.to_html
end
# page_footer
def parse_footer(body, page, site)
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_images
def parse_images(body, page, edit=nil)
body.css('.page_image').each do |page_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(body, page)
page_menu = body.css('.page_menu').first
if page_menu
fragment = Nokogiri::HTML::DocumentFragment.new(body, "")
page_menu.swap(fragment)
else
''
end
end
# page_sub_menu
def parse_sub_menu(body, page, site)
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)
else
''
end
end
# page_breadcrumb
def parse_breadcrumb(body, page, site)
page_breadcrumb = body.css('.page_breadcrumb').first
if page_breadcrumb
res = ""
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
page_breadcrumb.swap(fragment)
else
''
end
end
# page_contents
def parse_contents(body, page, edit=nil, locale)
public_r_tags = []
url = ''
body.css('.page_content').each do |content|
ret = ''
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"
url << "&id=\#{params[:id] if params[:id] && !params[:id].eql?(page.id.to_s)}"
else
url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}\#{(\"/\" + params[:id]) if params[:id] && !params[:id].eql?(page.id.to_s)}\#{(\"/\" + params[:controller_action]) if params[:controller_action] && params[:id]}?inner=true"
end
categories_str=category.collect{|t| "base_category_id[]=#{t}"}.join('&')
tags_str=tag.collect{|t| "base_tag_id[]=#{t}"}.join('&')
categories_str = "{categories_str}" unless categories_str.blank?
tags_str = "{tags_str}" unless tags_str.blank?
options = "&page_id=\#{page.id}#{categories_str}#{tags_str}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&name=\#{params[:name]}&item_type=page"
ret << ""
else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
if part
ret << ""
case part.kind
when 'text'
ret << part.content_translations[locale.to_s] rescue ''
when 'module_widget'
# url = "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
# options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}"
# ret << "
"
url = case part.widget_path
when 'default_widget'
"/panel/orbit_app/widget/\#{part.widget_style}?inner=true"
else
"/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
end
categories_str=part[:category].collect{|t| "base_category_id[]=#{t}"}.join('&')
tags_str=part[:tag].collect{|t| "base_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&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}"
ret << ""
when 'public_r_tag'
ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page)
else
''
end
ret << ""
end
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
end
def parse_counter(body = nil)
body.css('.page_counter').each do |counter|
ret = ''
case counter['option']
when 'all'
ret << "display_visitors"
when 'today'
ret << "display_visitors_today"
when 'this_week'
ret << "display_visitors_this_week"
when 'this_month'
ret << "display_visitors_this_month"
when 'this_year'
ret << "display_visitors_this_year"
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, "")
counter.swap(fragment)
end
end
# ad_banners
def generate_ad_banners(*args)
""
end
# sitemap
def generate_sitemaps(*args)
""
end
# sub_menus
def generate_sub_menus(*args)
""
end
# breadcrumb
def generate_breadcrumbs(*args)
""
end
# tag_cloud
def generate_tag_clouds(*args)
""
end
# tag_cloud
def generate_terms_of_uses(*args)
""
end
end