From fcbba6660bd90bf008c41b2ceff345c5aa46c391 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 19 Dec 2012 17:15:31 +0800 Subject: [PATCH] Only one parser for front end Separate site map for i18n --- app/assets/stylesheets/new_admin.css.erb | 1 + app/controllers/admin/sites_controller.rb | 13 +- app/controllers/application_controller.rb | 2 +- app/controllers/front_controller.rb | 70 ++++++++ app/controllers/pages_controller.rb | 103 ++++++------ app/models/item.rb | 21 ++- app/models/page.rb | 57 ++++--- app/models/page_part.rb | 5 + app/views/admin/ad_images/_form.html.erb | 2 +- app/views/admin/sites/_sitemap_block.html.erb | 14 +- app/views/admin/sites/sitemap.html.erb | 28 +++- app/views/front/show_banner.html.erb | 26 +++ app/views/front/show_page_sub_menu.html.erb | 12 ++ app/views/front/show_sitemap.html.erb | 27 +++ config/routes.rb | 11 +- lib/parsers/parser_back_end.rb | 12 +- lib/parsers/parser_common.rb | 43 ++--- lib/parsers/parser_front_end.rb | 157 ++++++++++++++---- lib/tasks/migrate.rake | 7 + .../back_end/bulletins/_form.html.erb | 2 +- 20 files changed, 445 insertions(+), 168 deletions(-) create mode 100644 app/controllers/front_controller.rb create mode 100644 app/views/front/show_banner.html.erb create mode 100644 app/views/front/show_page_sub_menu.html.erb create mode 100644 app/views/front/show_sitemap.html.erb diff --git a/app/assets/stylesheets/new_admin.css.erb b/app/assets/stylesheets/new_admin.css.erb index a634fb42..2fb7e28e 100644 --- a/app/assets/stylesheets/new_admin.css.erb +++ b/app/assets/stylesheets/new_admin.css.erb @@ -15,4 +15,5 @@ *= require scroll_style *= require isotope *= require icons + *= require site-map */ diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index b44ef25e..943134d4 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,8 +1,8 @@ class Admin::SitesController < ApplicationController layout "new_admin" - before_filter :authenticate_user!, :except => [:sitemap_frontend] - before_filter :is_admin?, :except => [:sitemap_frontend] + before_filter :authenticate_user! + before_filter :is_admin? before_filter :get_site # def index @@ -31,18 +31,13 @@ class Admin::SitesController < ApplicationController @items = get_homepage.children rescue [] end - def sitemap_frontend - @items = get_homepage.children.excludes(sitemap_enabled: false) rescue [] - render :layout => false - end - def sitemap_toggle @item = Item.find(params[:id]) - @item.sitemap_enabled = !@item.sitemap_enabled + @item.sitemap_enabled[params[:temp_locale]] = (!@item.show_in_sitemap_for(params[:temp_locale])).to_s @item.save if params[:parent] @item.children.each do |child| - child.sitemap_enabled = @item.sitemap_enabled + child.sitemap_enabled[params[:temp_locale]] = @item.sitemap_enabled[params[:temp_locale]].to_s child.save end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 23474c5c..59ff3de2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base def render_page if @item respond_to do |format| - format.html { render :text => parse_page_noko(@item), :layout => 'page_layout' } + format.html { render :text => parse_page_content(@item), :layout => 'page_layout' } format.rss { render_main_rss } end else diff --git a/app/controllers/front_controller.rb b/app/controllers/front_controller.rb new file mode 100644 index 00000000..2f58d9ed --- /dev/null +++ b/app/controllers/front_controller.rb @@ -0,0 +1,70 @@ +class FrontController < ApplicationController + + layout false + + def show_banner + @ad_banner = AdBanner.find(params[:id]) rescue nil + end + + def show_footer + render :text => @site.footer + 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 + render :text => @site.sub_menu + 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 + + + private + + def menu_level(page, current_page, current, menu) + res = '' + if page.visible_children.size > 0 + res << "" + end + res + end + + def menu_li(page, current_page, current, menu, i) + res = "" + end + +end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 6e00b859..f39a9078 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -29,63 +29,62 @@ class PagesController < ApplicationController 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 + #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 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 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 + def load_orbit_bar + render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer} + end - protected - - def get_item - 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 - @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 - #TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性 - end - protected + + def get_item + 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 + @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 + #TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性 + end + 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 + 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 diff --git a/app/models/item.rb b/app/models/item.rb index ae086c7d..81366a21 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -11,7 +11,7 @@ class Item field :enabled_for, :type => Array, :default => nil field :menu_enabled_for, :type => Array, :default => nil field :title, localize: true - field :sitemap_enabled, :type => Boolean, :default => true + field :sitemap_enabled, :type => Hash validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ @@ -53,12 +53,29 @@ class Item save! end end - end + end + + def show_in_sitemap_for(locale) + if !sitemap_enabled[locale].blank? + sitemap_enabled[locale].eql?('true') ? true : false + else + true + end + end protected def rebuild_path self.path = (self.ancestors_and_self - [Item.root]).collect{|x| x.name unless x.root?}.join('/') + self.rebuild_children_path + end + + def rebuild_children_path + self.children.each do |child| + child.path = (child.ancestors_and_self - [Item.root]).collect{|x| x.name}.join('/') + child.save + child.rebuild_children_path + end end def find_by_parent_and_position(parent, position) diff --git a/app/models/page.rb b/app/models/page.rb index f6e95a03..d13b403a 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,9 +1,11 @@ class Page < Item + include Rails.application.routes.url_helpers include Impressionist::Impressionable + include ParserFrontEnd is_impressionable :counter_cache => { :column_name => :view_count } - field :content + field :content, localize: true field :app_frontend_url field :theme_id, :type => BSON::ObjectId, :default => nil field :category, :default => '' @@ -17,40 +19,34 @@ class Page < Item belongs_to :design belongs_to :module_app - has_many :page_parts, :autosave => true, :dependent => :destroy + has_many :page_parts, :dependent => :destroy has_many :page_contexts, :autosave => true, :dependent => :destroy has_many :page_metas, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :page_parts, :allow_destroy => true - before_save :create_parts, :delete_empty_frontend_field - - # embeds_many :custom_images, :class_name => 'Image', as: :design_image - - def generate_parts - page_design = self.design - page_design.layout.layout_parts.each do |layout_part| - current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)} - current_part = self.page_parts.build(:name => layout_part.name) unless current_part - current_part.save if current_part.new_record? - end - end + before_save :delete_empty_frontend_field + before_save :create_parts, if: Proc.new { |page| page.new_record? || page.design_id_changed? } + after_save :generate_html protected def create_parts - if self.new_record? || self.design_id_changed? - page_design = self.design - parent = self.parent - menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent - page_design.layout.layout_parts.each do |layout_part| - current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)} - current_part = self.page_parts.build(:name => layout_part.name) unless current_part - if menu_part && current_part.name.eql?(menu_part.name) - if current_part.new_record? - current_part.kind = menu_part.kind - current_part.public_r_tag = menu_part.public_r_tag - current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id - else + page_design = self.design + parent = self.parent + menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent + page_design.layout.layout_parts.each do |layout_part| + current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)} + current_part = self.page_parts.build(:name => layout_part.name) unless current_part + if menu_part && current_part.name.eql?(menu_part.name) + if current_part.new_record? + current_part.kind = menu_part.kind + current_part.public_r_tag = menu_part.public_r_tag + current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id + PagePart.without_callback(:save, :after, :update_parent) do + current_part.save + end + else + PagePart.without_callback(:save, :after, :update_parent) do current_part.update_attributes(:kind => menu_part.kind, :public_r_tag => menu_part.public_r_tag, :public_r_tag_object_id => menu_part.public_r_tag_object_id) end end @@ -69,5 +65,12 @@ class Page < Item # end end end + + def generate_html + Page.without_callback(:save, :after, :generate_html) do + self.content_translations = parse_page_noko(self, Site.first) + self.save + end + end end diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 595d5fb3..994424c8 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -20,6 +20,7 @@ class PagePart belongs_to :module_app before_save :delete_empty_widget_field + after_save :update_parent protected @@ -30,4 +31,8 @@ class PagePart # self.widget_field.delete("") if self.widget_field end + def update_parent + self.page.save + end + end \ No newline at end of file diff --git a/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index 3dded6ed..fd139347 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -138,7 +138,7 @@ <% end %>
- <%= select_tag 'ad_banner[id]',options_from_collection_for_select(AdBanner.all, "id", "title",params[:ad_banner_id]) , :class=>"input-medium", %> + <%= select_tag 'ad_banner[id]',options_from_collection_for_select(AdBanner.all, "id", "title",params[:ad_banner_id]) , :class=>"input-medium" %> <% @site_valid_locales.each do |locale|%> <%= content_tag :div,:class => "tab-pane #{active_when_current_locale_eq locale}",:id=>"#{locale}" do%>
diff --git a/app/views/admin/sites/_sitemap_block.html.erb b/app/views/admin/sites/_sitemap_block.html.erb index 1d91f5ac..5d1d5c3c 100644 --- a/app/views/admin/sites/_sitemap_block.html.erb +++ b/app/views/admin/sites/_sitemap_block.html.erb @@ -1,15 +1,15 @@ -
+

- - <%= sitemap_block_counter + 1 %> <%= sitemap_block.title %> + + <%= sitemap_block_counter + 1 %> <%= sitemap_block.title_translations[temp_locale] %>

    <% sitemap_block.children.each_with_index do |child, i| %> -
  • - <%= content_tag :button, :id => child.id, :class => "onoff pull-right", :disabled => !sitemap_block.sitemap_enabled do %> - <%= child.sitemap_enabled ? t('on_upcase') : t('off_upcase') %> +
  • + <%= content_tag :button, :id => child.id, :class => "onoff pull-right", :temp_locale => temp_locale, :disabled => !child.show_in_sitemap_for(temp_locale) do %> + <%= child.show_in_sitemap_for(temp_locale) ? t('on_upcase') : t('off_upcase') %> <% end %> - <%= "#{sitemap_block_counter + 1}-#{i + 1}" %> <%= child.title %> + <%= "#{sitemap_block_counter + 1}-#{i + 1}" %> <%= child.title_translations[temp_locale] %>
  • <% end if sitemap_block.children %>
diff --git a/app/views/admin/sites/sitemap.html.erb b/app/views/admin/sites/sitemap.html.erb index 7c606497..cdcbc59b 100644 --- a/app/views/admin/sites/sitemap.html.erb +++ b/app/views/admin/sites/sitemap.html.erb @@ -2,9 +2,18 @@ <%= render :partial => 'layouts/side_bar', :locals => {:link_name => t('site.settings'), :link_url => admin_site_site_info_path(@site), :icon => 'icons-cog', :side_bar_content => 'admin/sites/side_bar'} %> <% end %> - -
- <%= render :partial => 'sitemap_block', :collection => @items %> + + +
+ <% @site_valid_locales.each_with_index do |temp_locale, i| %> +
"> + <%= render :partial => 'sitemap_block', :collection => @items, :locals => {:temp_locale => temp_locale} %> +
+ <% end %>
<% content_for :page_specific_javascript do %> @@ -13,9 +22,14 @@ $(document).ready(function(){ $('.site-map').masonry({ itemSelector: '.map-block', - columnWidth: 260, - isAnimated: true + columnWidth: 260 }); + $('a[data-toggle="tab"]').on('shown', function (e) { + $('.site-map').masonry({ + itemSelector: '.map-block', + columnWidth: 260 + }); + }) }); $(document).on('click', 'li .onoff', function () { $(this).parents("li").toggleClass("disabled"); @@ -24,7 +38,7 @@ } else { $(this).text("<%= t('on_upcase') %>") } - $.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle'); + $.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle?temp_locale=' + $(this).attr('temp_locale')); }); $(document).on('click', 'h4 .onoff', function () { $(this).parents(".map-block").toggleClass("disabled"); @@ -39,7 +53,7 @@ $(this).parents(".map-block").find('button').text("<%= t('on_upcase') %>") $(this).parents(".map-block").find('li button').removeAttr("disabled") } - $.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle?parent=true'); + $.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle?parent=true&temp_locale=' + $(this).attr('temp_locale')); }); <% end %> \ No newline at end of file diff --git a/app/views/front/show_banner.html.erb b/app/views/front/show_banner.html.erb new file mode 100644 index 00000000..2d790279 --- /dev/null +++ b/app/views/front/show_banner.html.erb @@ -0,0 +1,26 @@ + + + +
+ +
+ <% (images = @ad_banner.ad_images).shuffle.each do |ad_image| %> + <% if ad_image.display? %> + <%= ad_image.title || ' time_to_next='<%= @ad_banner.transition_msec %>' link_open='<%= ad_image.link_open %>' link_url='<%= (ad_image.direct_to_after_click? ? ad_image.out_link : ad_image.context) || ' ' %>' link_url='<%= (ad_image.out_link) %>' style=' <%= 'cursor:pointer;' if !ad_image.out_link.blank? %>'/> + <% end %> + <% end %> +
+
\ No newline at end of file diff --git a/app/views/front/show_page_sub_menu.html.erb b/app/views/front/show_page_sub_menu.html.erb new file mode 100644 index 00000000..0154bfc0 --- /dev/null +++ b/app/views/front/show_page_sub_menu.html.erb @@ -0,0 +1,12 @@ +<% if @menu_page && @menu_page.visible_children.size > 0 %> +
+

<%= @menu_page.title} %>

+
    " + <% menu_page.visible_children.each do |child| %> +
  • + <%= child.title %> +
  • + <% end %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/front/show_sitemap.html.erb b/app/views/front/show_sitemap.html.erb new file mode 100644 index 00000000..74da0ac0 --- /dev/null +++ b/app/views/front/show_sitemap.html.erb @@ -0,0 +1,27 @@ +
+ <% @items.each_with_index do |item, i| %> + <% if item.show_in_sitemap_for(I18n.locale.to_s) %> +
+

<%= i+1 %> <%= item.title %>

+
    + <% item.children.each_with_index do |child, ii| %> + <% if child.show_in_sitemap_for(I18n.locale.to_s) %> +
  • <%= "#{i+1}-#{ii+1}" %> <%= child.title %>
  • + <% end %> + <% end if item.children %> +
+
+ <% end %> + <% end %> +
+ +<%= javascript_include_tag "lib/jquery.masonry.min.js" %> + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cae07963..2c52f6ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -162,7 +162,8 @@ Orbit::Application.routes.draw do post 'upload' end end - match "desktop" => "desktop#index" + + match "desktop" => "desktop#index" namespace :desktop do match "desktop" => "desktop#desktop" match '/journal_pages/get_journals_json' => 'journal_pages#get_journals_json' @@ -231,6 +232,14 @@ Orbit::Application.routes.draw do # match '/desktop_orbit/eventajaxload' => 'desktop_publications#update_journal' + scope '/front' do + match 'show_banner/:id' => 'front#show_banner', :as => :front_show_banner + match 'show_footer' => 'front#show_footer', :as => :front_show_footer + match 'show_menu/:id' => 'front#show_menu', :as => :front_show_menu + match 'show_page_sub_menu' => 'front#show_page_sub_menu', :as => :front_show_page_sub_menu + match 'show_site_sub_menu' => 'front#show_site_sub_menu', :as => :front_show_site_sub_menu + match 'show_sitemap' => 'front#show_sitemap', :as => :front_show_sitemap + end match '/panel/:app_name/front_end/:app_action/:id(/:controller_action)' => 'pages#show_from_link', :constraints => lambda { |request| diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 2a590417..c3c43fe8 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -25,13 +25,13 @@ module ParserBackEnd def parse_page_edit_noko(page) body = Nokogiri::HTML(page.design.layout.body) - parse_menu(body, page, true) - public_r_tags = parse_contents(body, page, true) - parse_images(body, page) - parse_footer(body, page) - parse_sub_menu(body, page) + parse_menu_edit(body, page, true) + public_r_tags = parse_contents_edit(body, page, true) + parse_images_edit(body, page) + parse_footer_edit(body, page) + parse_sub_menu_edit(body, page) public_r_tags.each do |tag| - send("parse_#{tag}s", body, page, true) + send("parse_#{tag}s_edit", body, page, true) end body.to_html end diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 047f72e6..6dbec1e2 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -38,7 +38,7 @@ module ParserCommon end # ad_banners - def parse_ad_banners(body = nil, page = nil, edit=nil) + 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 @@ -94,7 +94,7 @@ module ParserCommon end # page_images - def parse_images(body, page, edit=nil) + 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 @@ -112,20 +112,16 @@ module ParserCommon end # page_menu - def parse_menu(body, page, edit=nil) + def parse_menu_edit(body, page, edit=nil) page_menu = body.css('.page_menu').first - if page_menu - 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) - else - '' - end + 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(body = nil, page = nil, edit=nil) + 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 = '' @@ -149,7 +145,7 @@ module ParserCommon end # page_footer - def parse_footer(body, page) + def parse_footer_edit(body, page) page_footer = body.css('.page_footer').first if page_footer res = "
" @@ -163,7 +159,7 @@ module ParserCommon end # page_sub_menu - def parse_sub_menu(body, page) + def parse_sub_menu_edit(body, page) page_sub_menu = body.css('.page_sub_menu').first if page_sub_menu res = "
" @@ -177,20 +173,16 @@ module ParserCommon end # sitemap - def parse_sitemaps(body = nil, page = nil, edit=nil) + def parse_sitemaps_edit(body = nil, page = nil, edit=nil) sitemap = body.css('sitemap').first - if sitemap - url = admin_site_sitemap_frontend_path(@site) - options = "?inner=true" - fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") - sitemap.swap(fragment) - else - '' - end + url = admin_site_sitemap_frontend_path(@site) + options = "?inner=true" + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") + sitemap.swap(fragment) end # page_contents - def parse_contents(body, page, edit=nil) + def parse_contents_edit(body, page, edit=nil) public_r_tags = [] body.css('.page_content').each do |content| ret = '' @@ -199,7 +191,6 @@ module ParserCommon if (content["main"] == "true" && !page.module_app.nil?) ret << "
" else @@ -216,7 +207,7 @@ module ParserCommon ret << part.content rescue '' when 'module_widget' url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" - options = "&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}&part_id=#{part.id}" + options = "&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 << "
" when 'public_r_tag' ret << "" diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 3d39bd5f..8e3a3190 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -1,38 +1,139 @@ module ParserFrontEnd - include ParserCommon - # c.define_tag 'language_bar' do - # @site.in_use_locales.map{ |locale| - # lang = I18nVariable.first(:conditions => {:key => locale})[locale] - # if I18n.locale.to_s.eql?(locale) - # lang - # else - # "#{lang}" - # end - # }.join(' | ') - # end - # c.define_tag 'link' do |tag| - # item = Item.first(:conditions => { :path => tag.attr['name'] }) - # ret = '' - # ret << "" - # ret << item.i18n_variable[I18n.locale] - # ret << '' - # end - # end require 'nokogiri' - def parse_page_noko(page) - body = Nokogiri::HTML(page.design.layout.body) - parse_menu(body, page) - public_r_tags = parse_contents(body, page) - parse_images(body, page) - parse_footer(body, page) - parse_sub_menu(body, page) - public_r_tags.each do |tag| - send("parse_#{tag}s", body, page) + 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) + i18n.merge!({locale => body.to_html}) end + i18n + end + def parse_page_content(page) + category = params[:category_id].blank? ? page[:category] : params[:category_id] + tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id] + body = Nokogiri::HTML(page.content) + body.css('orbit_front').each do |front| + ret = '' + part = PagePart.find(front['part_id']) if front['part_id'] + ret << eval("\"#{front['path']}\"") rescue '' + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") + 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 = "
" + res << "
" + 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 = "
" + res << "
" + res << "
" + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + page_sub_menu.swap(fragment) + else + '' + end + end + + # page_contents + def parse_contents(body, page, edit=nil, locale) + public_r_tags = [] + body.css('.page_content').each do |content| + ret = '' + if (content["main"] == "true" && !page.module_app.nil?) + url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}\#{(\"/\" + params[:id]) if params[:id] && !params[:id].eql?(page.id.to_s)}?inner=true" + options = "&page_id=#{page.id}&category_id=\#{category}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}" + ret << "
" + else + part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil + 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 = "&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 << "
" + when 'public_r_tag' + ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page) + else + '' + end if part + end + scope = "<#{content.name}" + content.attributes.each_pair do |key, value| + scope << " #{key}='#{value}'" + end + scope << ">#{ret}" + fragment = Nokogiri::HTML::DocumentFragment.new(body, scope) + content.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 end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index c41e6d9b..da07e20a 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -304,5 +304,12 @@ namespace :migrate do i += 1 end if news_bulletins end + + task :sitemap_i18n => :environment do + Item.all.each do |item| + item.sitemap_enabled = item.sitemap_enabled ? {'en' => 'true', 'zh_tw' => 'true'} : nil + item.save + end + end end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index ddee9f96..02182008 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -43,7 +43,7 @@
-

<%= t(:date) %>

+

<%= t(:date_) %>