From 472744fc875cf4ca5787d36facf97b6c232ad3fe Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Wed, 21 Mar 2012 15:51:55 +0800 Subject: [PATCH 01/93] Changes for IE9 with html5 --- app/assets/javascripts/html5.js | 3 +++ app/views/layouts/admin.html.erb | 2 +- app/views/layouts/devise.html.erb | 2 +- app/views/layouts/module_widget.html.erb | 2 +- app/views/layouts/new_admin.html.erb | 2 +- app/views/layouts/site_editor.html.erb | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/html5.js diff --git a/app/assets/javascripts/html5.js b/app/assets/javascripts/html5.js new file mode 100644 index 000000000..5c92911e2 --- /dev/null +++ b/app/assets/javascripts/html5.js @@ -0,0 +1,3 @@ +/*! HTML5 Shiv pre3.5 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed + Uncompressed source: https://github.com/aFarkas/html5shiv */ +(function(a,b){function h(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function i(){var a=l.elements;return typeof a=="string"?a.split(" "):a}function j(a){var b={},c=a.createElement,f=a.createDocumentFragment,g=f();a.createElement=function(a){l.shivMethods||c(a);var f;return b[a]?f=b[a].cloneNode():e.test(a)?f=(b[a]=c(a)).cloneNode():f=c(a),f.canHaveChildren&&!d.test(a)?g.appendChild(f):f},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+i().join().replace(/\w+/g,function(a){return b[a]=c(a),g.createElement(a),'c("'+a+'")'})+");return n}")(l,g)}function k(a){var b;return a.documentShived?a:(l.shivCSS&&!f&&(b=!!h(a,"article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio{display:none}canvas,video{display:inline-block;*display:inline;*zoom:1}[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}mark{background:#FF0;color:#000}")),g||(b=!j(a)),b&&(a.documentShived=b),a)}function p(a){var b,c=a.getElementsByTagName("*"),d=c.length,e=RegExp("^(?:"+i().join("|")+")$","i"),f=[];while(d--)b=c[d],e.test(b.nodeName)&&f.push(b.applyElement(q(b)));return f}function q(a){var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(n+":"+a.nodeName);while(d--)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function r(a){var b,c=a.split("{"),d=c.length,e=RegExp("(^|[\\s,>+~])("+i().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),f="$1"+n+"\\:$2";while(d--)b=c[d]=c[d].split("}"),b[b.length-1]=b[b.length-1].replace(e,f),c[d]=b.join("}");return c.join("{")}function s(a){var b=a.length;while(b--)a[b].removeNode()}function t(a){var b,c,d=a.namespaces,e=a.parentWindow;return!o||a.printShived?a:(typeof d[n]=="undefined"&&d.add(n),e.attachEvent("onbeforeprint",function(){var d,e,f,g=a.styleSheets,i=[],j=g.length,k=Array(j);while(j--)k[j]=g[j];while(f=k.pop())if(!f.disabled&&m.test(f.media)){for(d=f.imports,j=0,e=d.length;j",f="hidden"in c,f&&typeof injectElementWithStyles=="function"&&injectElementWithStyles("#modernizr{}",function(b){b.hidden=!0,f=(a.getComputedStyle?getComputedStyle(b,null):b.currentStyle).display=="none"}),g=c.childNodes.length==1||function(){try{b.createElement("a")}catch(a){return!0}var c=b.createDocumentFragment();return typeof c.cloneNode=="undefined"||typeof c.createDocumentFragment=="undefined"||typeof c.createElement=="undefined"}()})();var l={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:k};a.html5=l,k(b);var m=/^$|\b(?:all|print)\b/,n="html5shiv",o=!g&&function(){var c=b.documentElement;return typeof b.namespaces!="undefined"&&typeof b.parentWindow!="undefined"&&typeof c.applyElement!="undefined"&&typeof c.removeNode!="undefined"&&typeof a.attachEvent!="undefined"}();l.type+=" print",l.shivPrint=t,t(b)})(this,document) \ No newline at end of file diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index d800ab5d0..4adce7a54 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -5,7 +5,7 @@ <%= @title || APP_CONFIG['orbit'] %> <%= stylesheet_link_tag "admin" %> <%= javascript_include_tag "admin" %> diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index 976b5422f..d1a3512c9 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -4,7 +4,7 @@ <%= @title || APP_CONFIG['orbit'] %> <%= stylesheet_link_tag "devise" %> <%= javascript_include_tag "devise" %> diff --git a/app/views/layouts/module_widget.html.erb b/app/views/layouts/module_widget.html.erb index 254ac4e92..44a2be85c 100644 --- a/app/views/layouts/module_widget.html.erb +++ b/app/views/layouts/module_widget.html.erb @@ -2,7 +2,7 @@ <%#= stylesheet_link_tag "module_widget" %> <%= javascript_include_tag "module_widget" %> diff --git a/app/views/layouts/new_admin.html.erb b/app/views/layouts/new_admin.html.erb index 3ae7a2a23..b6156c5d3 100644 --- a/app/views/layouts/new_admin.html.erb +++ b/app/views/layouts/new_admin.html.erb @@ -4,7 +4,7 @@ <%= @title || APP_CONFIG['orbit'] %> <%= stylesheet_link_tag "new_admin" %> <%= javascript_include_tag "new_admin" %> diff --git a/app/views/layouts/site_editor.html.erb b/app/views/layouts/site_editor.html.erb index f4df75c4b..efcc54ca2 100644 --- a/app/views/layouts/site_editor.html.erb +++ b/app/views/layouts/site_editor.html.erb @@ -5,7 +5,7 @@ <%= @title || APP_CONFIG['orbit'] %> <%= stylesheet_link_tag "site_editor" %> <%= javascript_include_tag "site_editor" %> From a126935d2c66d8cd57f63f754b04ee549d852b4c Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Wed, 21 Mar 2012 18:30:12 +0800 Subject: [PATCH 02/93] Clean the parsers and introduce the metas --- app/models/meta.rb | 11 +++ app/models/meta/meta.rb | 11 +++ app/models/meta/page_meta.rb | 5 ++ app/models/meta/site_meta.rb | 5 ++ app/models/page.rb | 14 ++- app/models/site.rb | 2 + lib/parsers/parser_back_end.rb | 111 ++++++++++------------- lib/parsers/parser_front_end.rb | 154 ++++++++++++-------------------- lib/parsers/parser_layout.rb | 25 +++--- 9 files changed, 165 insertions(+), 173 deletions(-) create mode 100644 app/models/meta.rb create mode 100644 app/models/meta/meta.rb create mode 100644 app/models/meta/page_meta.rb create mode 100644 app/models/meta/site_meta.rb diff --git a/app/models/meta.rb b/app/models/meta.rb new file mode 100644 index 000000000..411a4f0c5 --- /dev/null +++ b/app/models/meta.rb @@ -0,0 +1,11 @@ +class Meta + + include Mongoid::Document + include Mongoid::Timestamps + + field :key + field :value, :default => nil + + has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + +end diff --git a/app/models/meta/meta.rb b/app/models/meta/meta.rb new file mode 100644 index 000000000..411a4f0c5 --- /dev/null +++ b/app/models/meta/meta.rb @@ -0,0 +1,11 @@ +class Meta + + include Mongoid::Document + include Mongoid::Timestamps + + field :key + field :value, :default => nil + + has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + +end diff --git a/app/models/meta/page_meta.rb b/app/models/meta/page_meta.rb new file mode 100644 index 000000000..9b3ded990 --- /dev/null +++ b/app/models/meta/page_meta.rb @@ -0,0 +1,5 @@ +class PageMeta < Meta + + belongs_to :page + +end diff --git a/app/models/meta/site_meta.rb b/app/models/meta/site_meta.rb new file mode 100644 index 000000000..9a17c4fa2 --- /dev/null +++ b/app/models/meta/site_meta.rb @@ -0,0 +1,5 @@ +class SiteMeta < Meta + + belongs_to :site + +end diff --git a/app/models/page.rb b/app/models/page.rb index ceead525a..b9e061431 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -6,17 +6,23 @@ class Page < Item belongs_to :design belongs_to :module_app + has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_many :page_parts, :autosave => true, :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 + before_save :create_parts, :set_key # embeds_many :custom_images, :class_name => 'Image', as: :design_image def is_home? self.parent ? false : true end + + def title + @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil + end protected @@ -27,4 +33,10 @@ class Page < Item end end + def set_key + if title.new_record? + title.key = 'title' + end + end + end diff --git a/app/models/site.rb b/app/models/site.rb index 065a6f795..8f367c0a2 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -12,6 +12,8 @@ class Site field :school field :department + + has_many :site_metas, :autosave => true, :dependent => :destroy def generate_keys private_key = OpenSSL::PKey::RSA.generate(2048) diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 37c22ed18..787f579b3 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -13,63 +13,6 @@ module ParserBackEnd def parser_context_edit(page, attributes = {}) Radius::Context.new do |c| - c.define_tag 'snippet' do |tag| - snippet = Snippet.first(:conditions => {:name => tag.attr['name']}) - if snippet - snippet.content - else - t('nothing') - end - end - 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 'css' do |tag| - assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip)) - res = '' - assets.each do |asset| - res << " " if asset.data.file.content_type.eql?('text/css') - end - res - end - c.define_tag 'image' do |tag| - # 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?(tag.attr['name']) } unless image - if image - res = "' - end - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" if page.design.reset_css - res << "" if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - res << "" - end - res - end c.define_tag 'ad_banner' do |tag| res = '' ad_banner = AdBanner.find(tag.attr["id"]) rescue nil @@ -89,13 +32,6 @@ module ParserBackEnd res << "" end end - c.define_tag 'layout_part' do |tag| - part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } - ret = '' - ret << "
" - ret << tag.expand - ret << '
' - end c.define_tag 'content' do |tag| ret = '' if (tag.attributes["main"] == "true" && !page.module_app.nil?) @@ -124,6 +60,39 @@ module ParserBackEnd end ret << '' end + end + c.define_tag 'image' do |tag| + # 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?(tag.attr['name']) } unless image + if image + res = "' + end + end + c.define_tag 'javascripts' do |tag| + res = '' + res << "" + res << "" + res << "" + res << "" + page.design.javascripts.each do |js| + res << "" + end + res + end + 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 => { :full_name => tag.attr['name'] }) @@ -139,6 +108,20 @@ module ParserBackEnd menu = page.design.layout.menu menu_level(home, 0, menu, true) end + c.define_tag 'meta' do |tag| + "" + end + c.define_tag 'stylesheets' do |tag| + res = '' + res << "" if page.design.reset_css + res << "" if page.design.default_css + theme = page.design.themes.detect{ |d| d.id == page.theme_id } + res << "" if theme + res + end + c.define_tag 'title' do |tag| + "#{page.title ? page.title : page.i18n_variable[I18n.locale]}" + end end end diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 99353cc16..4b5a523f9 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -4,88 +4,6 @@ module ParserFrontEnd def parser_context(page, attributes = {}, id = nil) Radius::Context.new do |c| - c.define_tag 'snippet' do |tag| - snippet = Snippet.first(:conditions => {:name => tag.attr['name']}) - if snippet - snippet.content - else - t('nothing') - end - end - 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 'locale' do |tag| - case attributes[:locale] - when 'create' - var = I18nVariable.new(:key => (tag.attr['name'] rescue nil), :document_class => 'Text') - @site.valid_locales.each do |locale| - var[locale] = tag.attr[locale] rescue nil - end - var.save! - res = '' - res << "' - when 'show' - var = I18nVariable.find(tag.attr['id']) - res = '' - res << "' - when 'destroy' - var = I18nVariable.find(tag.attr['id']) - var.destroy - end - end - c.define_tag 'css' do |tag| - assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip)) - res = '' - assets.each do |asset| - res << " " if asset.data.file.content_type.eql?('text/css') - end - res - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" if page.design.reset_css - res << " " if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - # res << "" - end - res - end c.define_tag 'ad_banner' do |tag| res = '' ad_banner = AdBanner.find(tag.attr["id"]) rescue nil @@ -106,22 +24,6 @@ module ParserFrontEnd end res end - c.define_tag 'image' do |tag| - # 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?(tag.attr['name']) } unless image - if image - res = "' - end - end - c.define_tag 'layout_part' do |tag| - part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil - part.content - end c.define_tag 'content' do |tag| ret = '' if (tag.attributes["main"] == "true" && !page.module_app.nil?) @@ -149,6 +51,44 @@ module ParserFrontEnd end ret end + c.define_tag 'image' do |tag| + # 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?(tag.attr['name']) } unless image + if image + res = "' + end + end + c.define_tag 'javascripts' do |tag| + res = '' + res << "" + res << "" + res << "" + res << "" + res << "" + res << "" + res << "" + res << "" + res << "" + page.design.javascripts.each do |js| + # res << "" + end + res + end + 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 => { :full_name => tag.attr['name'] }) ret = '' @@ -161,6 +101,24 @@ module ParserFrontEnd menu = page.design.layout.menu menu_level(home, 0, menu) end + c.define_tag 'meta' do |tag| + res = '' + #res << "" + end + c.define_tag 'stylesheets' do |tag| + res = '' + res << "" + res << "" + res << "" + res << "" if page.design.reset_css + res << " " if page.design.default_css + theme = page.design.themes.detect{ |d| d.id == page.theme_id } + res << "" if theme + res + end + c.define_tag 'title' do |tag| + "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}" + end end end diff --git a/lib/parsers/parser_layout.rb b/lib/parsers/parser_layout.rb index 4a0232c63..063078dfa 100644 --- a/lib/parsers/parser_layout.rb +++ b/lib/parsers/parser_layout.rb @@ -10,12 +10,17 @@ module ParserLayout end def parser_layout_contents(layout) - Radius::Context.new do |c| - c.define_tag 'javascripts' do |tag| - end - c.define_tag 'stylesheets' do |tag| - end + Radius::Context.new do |c| c.define_tag 'ad_banner' do |tag| + end + c.define_tag 'content' do |tag| + layout.layout_parts.new(:name => tag.attr['name']) + end + c.define_tag 'image' do |tag| + image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) } + image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image + end + c.define_tag 'javascripts' do |tag| end c.define_tag 'menu' do |tag| layout.build_menu(:levels => 0, :values => {}) unless layout.menu @@ -24,13 +29,13 @@ module ParserLayout layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']}) tag.expand end - c.define_tag 'content' do |tag| - layout.layout_parts.new(:name => tag.attr['name']) + c.define_tag 'meta' do |tag| end - c.define_tag 'image' do |tag| - image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) } - image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image + c.define_tag 'stylesheets' do |tag| end + c.define_tag 'title' do |tag| + end + end end From 4f741418a09516082210ea1138ee62495e9bda81 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 01:51:16 +0800 Subject: [PATCH 03/93] Trying nokogiri --- Gemfile | 1 + Gemfile.lock | 4 + app/controllers/application_controller.rb | 2 +- app/controllers/pages_controller.rb | 2 + app/helpers/application_helper.rb | 47 ++++++++++ app/models/design/layout.rb | 8 +- app/models/meta.rb | 4 + app/views/layouts/page_layout.html.erb | 17 ++++ lib/parsers/parser_front_end.rb | 105 ++++++++++++++-------- lib/parsers/parser_layout.rb | 57 +++++------- 10 files changed, 172 insertions(+), 75 deletions(-) create mode 100644 app/views/layouts/page_layout.html.erb diff --git a/Gemfile b/Gemfile index 024f3449f..d1afdb8cc 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'kaminari', :git => 'git://github.com/amatsuda/kaminari.git' gem 'mini_magick' gem 'mongoid' gem "mongo_session_store-rails3" +gem 'nokogiri' gem 'radius' gem 'rake' gem 'ruby-debug19' diff --git a/Gemfile.lock b/Gemfile.lock index 1df648c48..71742974a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM archive-tar-minitar (0.5.2) arel (2.2.3) bcrypt-ruby (3.0.1) + bcrypt-ruby (3.0.1-x86-mingw32) brakeman (1.5.1) activesupport erubis (~> 2.6) @@ -115,6 +116,8 @@ GEM mongo (~> 1.3) tzinfo (~> 0.3.22) multi_json (1.1.0) + nokogiri (1.5.2) + nokogiri (1.5.2-x86-mingw32) orm_adapter (0.0.6) pdf-writer (1.1.8) color (>= 1.4.0) @@ -252,6 +255,7 @@ DEPENDENCIES mini_magick mongo_session_store-rails3 mongoid + nokogiri radius rails (>= 3.1.0, < 3.2.0) rake diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b433777d..fb82774ef 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,7 +47,7 @@ class ApplicationController < ActionController::Base # Render the page def render_page(id = nil) if @item - render :text => parse_page(@item, id) + render :text => process_page(@item, id), :layout => 'page_layout' else render :text => '404 Not Found' end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 8ea353919..4860ea2e8 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,5 +1,7 @@ class PagesController < ApplicationController + include ApplicationHelper + before_filter :get_item, :only => [:index_from_link, :show_from_link] def index diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 50510e3c6..9c03de3d3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -107,4 +107,51 @@ module ApplicationHelper end end + + def process_page(page, id) + parse_page_noko(page, id) + end + + def page_metas(page) + metas = '' + @site.page_metas.each do |meta| + name, content = meta.get_name_content + metas << "\n" + end rescue nil + return metas + end + + def page_title(page) + "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}\n" + end + + def page_stylesheets(page) + stylesheets = '' + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" if page.design.reset_css + stylesheets << "\n" if page.design.default_css + theme = page.design.themes.detect{ |d| d.id == page.theme_id } + stylesheets << "\n" if theme + stylesheets + end + + def page_javascripts(page) + javascripts = '' + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + page.design.javascripts.each do |js| + # javascripts << "" + end + javascripts + end + end diff --git a/app/models/design/layout.rb b/app/models/design/layout.rb index e13498f3a..bf48415cb 100644 --- a/app/models/design/layout.rb +++ b/app/models/design/layout.rb @@ -2,6 +2,8 @@ class Layout < DesignFile include ParserLayout attr_reader :content + + field :body embeds_one :menu embedded_in :design @@ -17,8 +19,10 @@ class Layout < DesignFile Layout.count > 0 end - def parse_layout - parse_layout_contents(self) + def parse_layout + html = Nokogiri::HTML(self.file.read) + self.body = html.at_css("body").inner_html + parse_body(self) end end diff --git a/app/models/meta.rb b/app/models/meta.rb index 411a4f0c5..dbeac167f 100644 --- a/app/models/meta.rb +++ b/app/models/meta.rb @@ -7,5 +7,9 @@ class Meta field :value, :default => nil has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + + def get_name_content + [self.key, self.value ? self.value : self.i18n_variable[I18n.locale]] + end end diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb new file mode 100644 index 000000000..8fb884b07 --- /dev/null +++ b/app/views/layouts/page_layout.html.erb @@ -0,0 +1,17 @@ + + + + + <%= page_title(@item).html_safe %> + <%= page_metas(@item).html_safe %> + <%= @metas %> + + <%= page_stylesheets(@item).html_safe %> + <%= page_javascripts(@item).html_safe %> + + + <%= yield %> + + diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 4b5a523f9..8ea3840a6 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -63,22 +63,6 @@ module ParserFrontEnd res << '>' end end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - # res << "" - end - res - end c.define_tag 'language_bar' do @site.in_use_locales.map{ |locale| lang = I18nVariable.first(:conditions => {:key => locale})[locale] @@ -101,38 +85,87 @@ module ParserFrontEnd menu = page.design.layout.menu menu_level(home, 0, menu) end - c.define_tag 'meta' do |tag| - res = '' - #res << "" - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" if page.design.reset_css - res << " " if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'title' do |tag| - "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}" - end end end def parse_page(page, id = nil) if page._type == 'Page' - layout_content = page.design.layout.content.force_encoding('UTF-8') rescue '' context = parser_context(page, {}, id) parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(layout_content)) + parser.parse(parser.parse(page.design.layout.body)) end end def self.included(base) base.send :helper_method, :parse_page if base.respond_to? :helper_method end + + + + require 'nokogiri' + + def parse_page_noko(page, id = nil) + body = Nokogiri::HTML(page.design.layout.body, nil, 'UTF-8') + + # page_contents + body.css('.page_content').each do |content| + ret = '' + if (content["main"] == "true" && !page.module_app.nil?) + 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.i18n_variable[I18n.locale] rescue '' + when 'module_widget' + if part[:category] + ret << "
" + else + ret << "
" + end + when 'public_r_tag' + ret << "" + else + '' + end + 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 + + # page_menu + page_menu = body.css('.page_menu').first + home = get_homepage + menu = page.design.layout.menu + fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 0, menu)) + page_menu.swap(fragment) + + # page_image + 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?(page_image['name']) } unless image + if image + res = "' + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + page_image.swap(fragment) + end + + body.to_html + end end diff --git a/lib/parsers/parser_layout.rb b/lib/parsers/parser_layout.rb index 063078dfa..01d681ef2 100644 --- a/lib/parsers/parser_layout.rb +++ b/lib/parsers/parser_layout.rb @@ -1,44 +1,27 @@ module ParserLayout - require 'radius' - include ParserCommon + require 'nokogiri' - def parse_layout_contents(layout) - content = layout.content.force_encoding('UTF-8') - context = parser_layout_contents(layout) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(content) - end - - def parser_layout_contents(layout) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - end - c.define_tag 'content' do |tag| - layout.layout_parts.new(:name => tag.attr['name']) - end - c.define_tag 'image' do |tag| - image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) } - image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image - end - c.define_tag 'javascripts' do |tag| - end - c.define_tag 'menu' do |tag| - layout.build_menu(:levels => 0, :values => {}) unless layout.menu - layout.menu.levels = i = tag.attr['level'].to_i - layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1 - layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']}) - tag.expand - end - c.define_tag 'meta' do |tag| - end - c.define_tag 'stylesheets' do |tag| - end - c.define_tag 'title' do |tag| - end + def parse_body(layout) + body = Nokogiri::HTML(layout.body) + body.css('.page_content').each do |content| + layout.layout_parts.build(:name => content['name']) end + + body.css('.page_image').each do |image| + image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(image.to_html)) } + image.update_attributes(:name => image['name'], :html_id => image['id'], :html_class => image['class']) if image + end + + body.css('.page_menu').each do |menu| + layout.build_menu(:levels => 0, :values => {}) unless layout.menu + layout.menu.levels = i = menu['level'].to_i + layout.menu.values.merge!({'home' => menu['home']}) if i == 1 + layout.menu.values.merge!({"id_#{i}" => menu['id'], "class_#{i}" => menu['class'], "li_class_#{i}" => menu['li_class'], "li_incremental_#{i}" => menu['li_incremental']}) + end + end - + def parse_html_image(html) html.scan(/(?<=\)/){ $1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){ @@ -46,4 +29,6 @@ module ParserLayout } } end + + end From b109410a7aeb456f01bbd529e5eb1c6a2f2ef63f Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 10:11:02 +0800 Subject: [PATCH 04/93] Add ad_banner to nokogiri --- lib/parsers/parser_front_end.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 8ea3840a6..529802ffb 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -105,7 +105,7 @@ module ParserFrontEnd require 'nokogiri' def parse_page_noko(page, id = nil) - body = Nokogiri::HTML(page.design.layout.body, nil, 'UTF-8') + body = Nokogiri::HTML(page.design.layout.body) # page_contents body.css('.page_content').each do |content| @@ -165,6 +165,29 @@ module ParserFrontEnd page_image.swap(fragment) end + # ad_banner + body.css('ad_banner').each do |banner| + res = '' + ad_banner = AdBanner.find(banner["id"]) rescue nil + if ad_banner && ad_banner.display? + res << "" + res << "
" + ad_banner.ad_images.each do |ad_image| + res << "" + end + res << "
" + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + banner.swap(fragment) + end + body.to_html end From 34a4e47057730bb59f62b0d3570af5e84e04330e Mon Sep 17 00:00:00 2001 From: Matt Fu Date: Thu, 22 Mar 2012 14:33:59 +0800 Subject: [PATCH 05/93] Fact check program completed,Lin checked --- Gemfile.lock | 1 + app/models/object_auth.rb | 2 +- app/views/layouts/_side_bar.html.erb | 3 +- lib/orbit_core_lib.rb | 16 ++++-- .../back_end/bulletin_categorys_controller.rb | 2 +- .../back_end/bulletins_controller.rb | 51 +++++++++---------- .../back_end/fact_checks_controller.rb | 2 +- .../front_end/bulletins_controller.rb | 6 +-- .../widget/bulletins_controller.rb | 8 +-- .../announcement/app/models/bulletin.rb | 48 +++++++++-------- .../back_end/bulletins/_bulletin.html.erb | 10 +++- .../bulletins/_bulletin_link_qe.html.erb | 3 +- .../back_end/bulletins/_form.html.erb | 4 ++ .../widget/bulletins/index.html.erb | 1 - 14 files changed, 91 insertions(+), 66 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1df648c48..ef54f585d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM archive-tar-minitar (0.5.2) arel (2.2.3) bcrypt-ruby (3.0.1) + bcrypt-ruby (3.0.1-x86-mingw32) brakeman (1.5.1) activesupport erubis (~> 2.6) diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index 8932bb762..ae3fd7015 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -1,6 +1,6 @@ class ObjectAuth < PrototypeAuth include OrbitCoreLib::ObjectTokenUnility - validates_uniqueness_of :obj_authable_type,:scope => :title #{ |c| } + validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id] #{ |c| } belongs_to :obj_authable, polymorphic: true # > - Something.find_with_auth(query) # > - or Something.find(query).auth diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 71e8106d1..baeef6c43 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -9,8 +9,9 @@ <%= content_tag :li, link_to(t('admin.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %> <%= content_tag :li, link_to(t('admin.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %> <%= content_tag :li, link_to(t('admin.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('tags', 'index') %> - <%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('tags', 'index') %> + <%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('tags', 'index') if is_manager? %> <% end -%> + <% end -%> <%= content_tag :li, :class => active_for_controllers('users') do -%> diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index 561fceba0..bcde17e0c 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -21,11 +21,19 @@ module OrbitCoreLib def authed_users(title=nil) users = [] - unless title.nil? - users = self.object_auths.where(title: title )[0].auth_users_after_block_list rescue [] + users = case title + when :all + ary = self.object_auths.collect{|t| t.auth_users} + ary.flatten! + when nil + if self.object_auths.count ==1 + self.object_auths.first.auth_users_after_block_list rescue [] + else + logger.info "Warning calling a auth commend without specificed value( has multi-auths ), return empty" + [] + end else - users = self.object_auths.collect{|t| t.auth_users_after_block_list} rescue [] - users.flatten!.uniq! + self.object_auths.where(title: title).first.auth_users rescue [] end users end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb index 92bf922f8..cb70aaf7d 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb @@ -1,4 +1,4 @@ -class Panel::Announcement::BackEnd::BulletinCategorysController < ApplicationController +class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController layout 'new_admin' diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 0eda0723c..2e6f90b06 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -110,40 +110,39 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController def link_quick_edit # debugger - - @bulletin = Bulletin.find(params[:bulletin_id]) - - @link_url = panel_announcement_back_end_bulletin_path(@bulletin) - - respond_to do |format| - format.js - end - + @bulletin = Bulletin.find(params[:bulletin_id]) + unless @bulletin.is_expired? + @link_url = panel_announcement_back_end_bulletin_path(@bulletin) + respond_to do |format| + format.js + end + end end # PUT /bulletins/1 # PUT /bulletins/1.xml def update @bulletin = Bulletin.find(params[:id]) + unless @bulletin.is_expired? + @bulletin.update_user_id = current_user.id - @bulletin.update_user_id = current_user.id - - # @bulletin.image.clear if params[:bulletin][:image_del] == '1' - # if params[:bulletin][:image_del] == '1' - # @bulletin.remove_image! - # @bulletin.image_del = nil - # params[:bulletin][:image_del] = nil - # end + # @bulletin.image.clear if params[:bulletin][:image_del] == '1' + # if params[:bulletin][:image_del] == '1' + # @bulletin.remove_image! + # @bulletin.image_del = nil + # params[:bulletin][:image_del] = nil + # end - respond_to do |format| - if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save - # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) } - format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } - format.js { render 'toggle_enable' } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } + respond_to do |format| + if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save + # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) } + format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } + format.js { render 'toggle_enable' } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } + end end end end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb index c47e91fb4..9095a4d37 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb @@ -18,7 +18,7 @@ class Panel::Announcement::BackEnd::FactChecksController < OrbitBackendControll else first_category = @bulletin_categorys.first end - preload_object_auth = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check') + preload_object_auth = first_category.object_auths.where(title: 'fact_check').empty?? (first_category.object_auths.create! :title=> 'fact_check') : first_category.object_auths.where(title: 'fact_check') @users_array = preload_object_auth.first.privilege_users rescue [] respond_to do |format| format.html diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index ff3cbdc98..fe0b2aa58 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -12,9 +12,9 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController date_now = Time.now if params[:category_id] - @bulletins = Bulletin.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) else - @bulletins = Bulletin.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) end get_categorys @@ -23,7 +23,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController end def show - @bulletin = Bulletin.find(params[:id]) + @bulletin = Bulletin.can_display.where.where(_id: params[:id]) get_categorys end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb index 60aad3d9e..783ee9ef8 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb @@ -14,9 +14,9 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController # @bulletin_categorys = BulletinCategory.first; # @bulletins = Bulletin.widget_datas(@bulletin_categorys.id).limit(9) if params[:category_id] - @bulletins = Bulletin.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9) + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9) else - @bulletins = Bulletin.widget_datas.limit(9) + @bulletins = Bulletin.can_display.widget_datas.limit(9) end get_categorys @@ -26,14 +26,14 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController def bulletins_and_web_links @tags = AnnouncementTag.all @selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0] - @bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil render :layout => 'module_widget' end def reload_bulletins @selected_tag = AnnouncementTag.find(params[:tag_id]) - @bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil end def reload_web_links diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index d1b7f3c52..e24f7f215 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -19,12 +19,14 @@ class Bulletin field :is_top, :type => Boolean, :default => false field :is_hot, :type => Boolean, :default => false field :is_hidden, :type => Boolean, :default => false - field :is_checked, :type => Boolean, :default => false + field :is_checked, :type => Boolean, :default => nil field :not_checked_reason field :public, :type => Boolean, :default => true + scope :can_display,where(is_checked: true) + mount_uploader :image, ImageUploader belongs_to :bulletin_category @@ -47,28 +49,17 @@ class Bulletin def self.search( search = nil, category_id = nil ) - - if category_id.to_s.size > 0 and search.to_s.size > 0 - + if category_id.to_s.size > 0 and search.to_s.size > 0 key = /#{search}/ - - find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate ) - - elsif category_id.to_s.size > 0 and search.to_s.size < 1 - - find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate ) - - elsif search.to_s.size > 0 and category_id.to_s.size < 1 - + find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate ) + elsif category_id.to_s.size > 0 and search.to_s.size < 1 + find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate ) + elsif search.to_s.size > 0 and category_id.to_s.size < 1 key = /#{search}/ - - find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) - else - - find(:all).desc( :is_top, :postdate) - - end - + find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) + else + find(:all).desc( :is_top, :postdate) + end end @@ -87,7 +78,11 @@ class Bulletin end end - + + def is_expired? + Date.today > self.deadline ? true : false rescue false + #some dates might sat as nil so rescue false + end def is_top? self.is_top @@ -101,6 +96,15 @@ class Bulletin self.is_hidden end + def is_checked? + self.is_checked + end + + def is_check_rejected? + self.is_checked == false + end + + def save_bulletin_links self.bulletin_links.each do |t| if t.should_destroy diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb index e12af233c..c0a9cee62 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb @@ -10,8 +10,10 @@ <% if bulletin.is_hidden? %> <%= t(:hidden) %> <% end %> +
- + <%#= debugger %> + <%#= a=1 %> + <% if (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager?) and !bulletin.is_expired? %>
  • <%= link_to t('bulletin.fact_check'), edit_panel_announcement_back_end_bulletin_path(bulletin) %>
  • <%#= #TODO add ancher so user can quick access into that part %> + <% end %> + <% end %> +
    + <%= bulletin.bulletin_category.i18n_variable[I18n.locale] %> <%= link_to bulletin.title[I18n.locale], panel_announcement_back_end_bulletin_path(bulletin) rescue ''%> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb index 7208f73cb..55ea8e8ce 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb @@ -1,6 +1,7 @@ <% # encoding: utf-8 %> - <%= form_for(@bulletin.bulletin_links, :remote => true, :url => @link_url) do |f| %> + + <%= form_for(@bulletin.bulletin_links, :remote => true, :url => @link_url) do |f| %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb index 5a33b86a2..30cbbb561 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb @@ -1,7 +1,3 @@ -<% content_for :secondary do %> -<%= render :partial => '/panel/announcement/back_end/announcement_secondary' %> -<% end -%> - <%= flash_messages %>
    From 422a49f56c50533807d7208068a416f589a37b77 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 27 Mar 2012 15:03:00 +0800 Subject: [PATCH 17/93] Ray's changes in announcenment back-end --- app/assets/fonts/widget.css | 8 ++-- app/assets/javascripts/bootstrap.js | 3 +- app/assets/javascripts/orbit-1.0.js | 21 +++++++++- app/assets/stylesheets/bootstrap-orbit.css | 2 +- app/assets/stylesheets/list.css | 31 ++++++++++---- app/assets/stylesheets/reset.css.erb | 1 - app/assets/stylesheets/style.css.erb | 2 - app/assets/stylesheets/widget.css | 4 +- .../back_end/bulletins/_bulletin.html.erb | 20 ++++++---- .../back_end/bulletins/_bulletins.html.erb | 14 ++++++- .../back_end/bulletins/_filter.html.erb | 40 +++++++++++++++++++ .../back_end/bulletins/_form.html.erb | 27 ++++++++++--- .../back_end/bulletins/edit.html.erb | 17 ++++---- .../back_end/bulletins/new.html.erb | 4 +- 14 files changed, 150 insertions(+), 44 deletions(-) diff --git a/app/assets/fonts/widget.css b/app/assets/fonts/widget.css index 0c596876d..fe83b22d4 100644 --- a/app/assets/fonts/widget.css +++ b/app/assets/fonts/widget.css @@ -45,10 +45,10 @@ opacity: 1; filter: alpha(opacity=100); cursor: pointer; -} -.select-role { - display:none; - overflow:hidden; +} +.select-role { + display:none; + padding: 10px 0 0; } .file-upload { position:relative; diff --git a/app/assets/javascripts/bootstrap.js b/app/assets/javascripts/bootstrap.js index b822d62bf..f1b88f8d1 100644 --- a/app/assets/javascripts/bootstrap.js +++ b/app/assets/javascripts/bootstrap.js @@ -1251,7 +1251,8 @@ var that = this , complete = function () { if (startEvent == 'show') that.reset() - that.$element.trigger(completeEvent) + that.$element.trigger(completeEvent) + mainTablePosition(); } this.$element diff --git a/app/assets/javascripts/orbit-1.0.js b/app/assets/javascripts/orbit-1.0.js index f8daaecdf..520473f69 100644 --- a/app/assets/javascripts/orbit-1.0.js +++ b/app/assets/javascripts/orbit-1.0.js @@ -49,6 +49,25 @@ $(document).ready(function(){ $(document).on('click', '.sort-header > .sort', function() { $.getScript($(this).attr('rel')); }); + + + var $role = $('.select-role'); + var method =$('.privacy:eq(1)').attr('checked'); + if(method == 'checked'){ + $role.slideDown(0); + } + $('.privacy').each(function($i) { + $(this).click(function() { + switch ($i) { + case 0: + $role.slideUp(300); + break; + case 1: + $role.slideDown(300); + break; + } + }); + }); /*tinyscrollbar&windows-Size*/ resize(); @@ -86,7 +105,7 @@ function mainTablePosition() { var $height = $('#main-wrap > .subnav').height() var $table = $('#main-wrap > .table') //alert ($table.height()) - $table.stop().animate({marginTop:$height},500) + $table.stop().animate({marginTop:$height-17},500) //$table.css({marginTop : $height}) } $(window).scroll(function () { diff --git a/app/assets/stylesheets/bootstrap-orbit.css b/app/assets/stylesheets/bootstrap-orbit.css index 88bca1b30..eede71d43 100644 --- a/app/assets/stylesheets/bootstrap-orbit.css +++ b/app/assets/stylesheets/bootstrap-orbit.css @@ -98,7 +98,7 @@ h1, h2, h3, h4, h5, h6 { border-radius: 0 0 4px 4px; } table .span1-2 { - width: 94px; + min-width: 85px; float: none; margin-left: 0; } diff --git a/app/assets/stylesheets/list.css b/app/assets/stylesheets/list.css index ccf35f242..b4becb423 100644 --- a/app/assets/stylesheets/list.css +++ b/app/assets/stylesheets/list.css @@ -9,9 +9,9 @@ .main-list { margin-bottom: 0; } -.main-list thead th { - background-color: rgba(0,0,0,0.05); - border-right: 1px solid #ddd; +.main-wrap>.main-list thead th { + background-color: transparent; + border-right: medium none; } .main-list thead th:last-child { border-right: none; @@ -29,19 +29,22 @@ } .main-list tbody .quick-edit { position:relative; - height:40px; + height:20px; } .main-list tbody .quick-edit .nav { /*left: -55px;*/ position: absolute; /*top: -3px;*/ width: 350px; + left: -8px; } .main-list td { - /*height:80px;*/ + background-color: #FFFFFF; + border-bottom: 1px solid #DDDDDD; + border-top: medium none; } .main-list .nav { - margin-top: 15px; + margin-top: 0; margin-bottom: 3px; } .main-list tr.with_action:hover .hide { @@ -53,7 +56,7 @@ } .main-list .label-td { background-color: rgba(255, 255, 255, 1); - height: 60px; + height: 40px; overflow: hidden; position: absolute; width: 100%; @@ -74,6 +77,15 @@ -webkit-border-radius: 3px; -moz-border-radius: 3px; z-index: 5; +} +.table-label { + background-color: #F2F2F2; + position: relative; +} +.table-label .main-list thead th { + background-color: #F2F2F2; + border-right: 1px solid #DDDDDD; + border-top: 1px solid #DDDDDD !important; } .route-group .route { padding: 0; @@ -108,7 +120,10 @@ legend { -webkit-border-radius: 0; border-radius: 0; border-left: none; - border-right: none; + border-right: none; + position: fixed; + top: 30px; + z-index: 50; } .subnav .nav > li:first-child > a, .subnav .nav > li:first-child > a:hover { -moz-border-radius: 0; diff --git a/app/assets/stylesheets/reset.css.erb b/app/assets/stylesheets/reset.css.erb index 0d91f32ad..5c0a9cd57 100644 --- a/app/assets/stylesheets/reset.css.erb +++ b/app/assets/stylesheets/reset.css.erb @@ -2,7 +2,6 @@ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockq -webkit-text-size-adjust:none; } html, body{ - background: url(<%= asset_path 'background.jpg' %>) repeat left top; height: 100%; } /*自定*/ diff --git a/app/assets/stylesheets/style.css.erb b/app/assets/stylesheets/style.css.erb index beae5a8ea..2e203a022 100644 --- a/app/assets/stylesheets/style.css.erb +++ b/app/assets/stylesheets/style.css.erb @@ -350,8 +350,6 @@ border-top: none; } #post-body .editor { - background-color: #333333; - height: 20px; margin: 8px 0; width: 100%; } diff --git a/app/assets/stylesheets/widget.css b/app/assets/stylesheets/widget.css index b66a60742..b0e3568de 100644 --- a/app/assets/stylesheets/widget.css +++ b/app/assets/stylesheets/widget.css @@ -58,8 +58,8 @@ cursor: pointer; } .select-role { - display:none; - overflow:hidden; + display:none; + padding: 10px 0; } .file-upload { position:relative; diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb index 643553205..0ae522cb7 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb @@ -10,7 +10,10 @@ <% if bulletin.is_hidden? %> <%= t(:hidden) %> <% end %> - + + <%= bulletin.bulletin_category.i18n_variable[I18n.locale] %> + + <%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%>
    - - <%= bulletin.bulletin_category.i18n_variable[I18n.locale] %> - <%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%> <%= bulletin.postdate %> <%= (bulletin.deadline) ? bulletin.deadline : t('bulletin.no_deadline') %> - <% bulletin.sorted_tags.each do |tag| %> - <%= tag[I18n.locale] %> - <% end %> +
    +
    + <% bulletin.sorted_tags.each do |tag| %> + <%= tag[I18n.locale] %> + <% end %> +
    +
    <%= User.from_id(bulletin.update_user_id).name rescue ''%> @@ -54,4 +58,4 @@ -<% end %> \ No newline at end of file +<% end %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb index bbe383bc7..979f3f4ad 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb @@ -1,4 +1,4 @@ - + + + + + + + + + + + + <%= render :partial => 'bulletin', :collection => @bulletins %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb index 5b078391d..09222a36c 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb @@ -53,5 +53,45 @@ Clear/重置 +
    + + + + + + + + + + + + + +
    + + + + <%= t('bulletin.status') %> + <%= content_tag(:b, nil, :class => is_sort?('status')) %> + + <%= t('bulletin.category') %> + <%= content_tag(:b, nil, :class => is_sort?('category')) %> + + <%= t('bulletin.title') %> + <%= content_tag(:b, nil, :class => is_sort?('title')) %> + + <%= t('bulletin.start_date') %> + <%= content_tag(:b, nil, :class => is_sort?('postdate')) %> + + <%= t('bulletin.end_date') %> + <%= content_tag(:b, nil, :class => is_sort?('deadline')) %> + + <%= t('bulletin.tags') %> + <%= content_tag(:b, nil, :class => is_sort?('tags')) %> + + <%= t('bulletin.last_modified') %> + <%= content_tag(:b, nil, :class => is_sort?('update_user_id')) %> +
    +
    \ No newline at end of file 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 27ad1df1a..9b2d3557d 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 @@ -3,13 +3,16 @@ <%= f.error_messages %>
    + <% if params[:action] != 'new' %>
    +

    Audit

    - <% if is_manager? || @bulletin.bulletin_category.authed_users('fact_check').include?(current_user) || current_user.admin?%> + + <% if is_manager? || @bulletin.bulletin_category.authed_users('fact_check').include?(current_user) || current_user.admin? %>
    <%= f.label :fact_check_stat, t('announcement.bulletin.fact_check_stat') %> <%= content_tag :label,:class => "radio inline" do -%> @@ -29,6 +32,7 @@ <% end %>
    + <% end %>
    @@ -84,9 +88,18 @@

    Status

    - <%= f.check_box :is_top %><%= t('top') %> - <%= f.check_box :is_hot %><%= t('hot') %> - <%= f.check_box :is_hidden %><%= t('hide') %> + <%= content_tag :label,:class => "checkbox inline" do -%> + <%= f.check_box :is_top %> + <%= t('top') %> + <% end -%> + <%= content_tag :label,:class => "checkbox inline" do -%> + <%= f.check_box :is_hot %> + <%= t('hot') %> + <% end -%> + <%= content_tag :label,:class => "checkbox inline" do -%> + <%= f.check_box :is_hidden %> + <%= t('hide') %> + <% end -%>
    @@ -98,8 +111,10 @@

    Tags

    <% @tags.each do |tag| %> - <%= check_box_tag 'bulletin[tag_ids][]', tag.id, @bulletin.tag_ids.include?(tag.id)%> - <%= tag[I18n.locale] %> + <%= content_tag :label,:class => "checkbox inline" do -%> + <%= check_box_tag 'bulletin[tag_ids][]', tag.id, @bulletin.tag_ids.include?(tag.id)%> + <%= tag[I18n.locale] %> + <% end %> <% end %>
    diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/edit.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/edit.html.erb index 56cfd258a..c448c6a1f 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/edit.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/edit.html.erb @@ -1,7 +1,10 @@ -

    <%= t('announcement.editing_announcement') %>

    - -<%= form_for @bulletin, :url => panel_announcement_back_end_bulletin_path(@bulletin), :html => {:class => 'clear'} do |f| %> - <%= render :partial => 'form', :locals => {:f => f} %> -<% end %> - -<%= link_back %> + +
    + <%= form_for @bulletin, :url => panel_announcement_back_end_bulletin_path(@bulletin), :html => {:class => 'clear'} do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> + <% end %> +
    \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/new.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/new.html.erb index 74e1291ab..33a1e6098 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/new.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/new.html.erb @@ -1,5 +1,5 @@ +
    <%= form_for @bulletin, :url => panel_announcement_back_end_bulletins_path do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <% end %> - -<%= link_back %> +
    \ No newline at end of file From 436c866a6fb95e219222384d8cfa60deee29cf70 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 27 Mar 2012 15:10:29 +0800 Subject: [PATCH 18/93] admin now can post without fact check --- .../views/panel/announcement/back_end/bulletins/_form.html.erb | 2 ++ 1 file changed, 2 insertions(+) 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 9b2d3557d..6815205c8 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 @@ -32,6 +32,8 @@ <% end %>
    + <% elsif current_user.admin? %> + <%= f.hidden_field :is_checked,:value => true%> <% end %>
    From 1451c3ac1d70e873a91fc45e07c2b837d2adde6d Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 27 Mar 2012 15:34:21 +0800 Subject: [PATCH 19/93] changing to new admin_layout --- app/views/admin/ad_banners/_ad_banner.html.erb | 11 +++++++++++ .../back_end/bulletin_links_controller-ƻs.rb | 14 -------------- 2 files changed, 11 insertions(+), 14 deletions(-) create mode 100644 app/views/admin/ad_banners/_ad_banner.html.erb delete mode 100644 vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_links_controller-ƻs.rb diff --git a/app/views/admin/ad_banners/_ad_banner.html.erb b/app/views/admin/ad_banners/_ad_banner.html.erb new file mode 100644 index 000000000..787a03ed0 --- /dev/null +++ b/app/views/admin/ad_banners/_ad_banner.html.erb @@ -0,0 +1,11 @@ + + + <%= location %> + + > + + <%= link_to (ad_image.picture_intro || t("untitled")),'' %> + <%= start_date %> + <%= end_date.nil?? t('form.date_unlimited'): end_date %> + <%= style %> + \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_links_controller-ƻs.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_links_controller-ƻs.rb deleted file mode 100644 index 04a75fa63..000000000 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_links_controller-ƻs.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Panel::Announcement::BackEnd::BulletinLinksController < ApplicationController - - layout 'new_admin' - - def index - @bulletin_links = BulletinLink.all - - respond_to do |format| - format.html # index.html.erb - # format.xml { render :xml => @bulletins } - format.js - end - -end From 48d1d45ced0f8481f25876fb847c9a713544ef11 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 27 Mar 2012 17:57:50 +0800 Subject: [PATCH 20/93] Nokogiri in parsers --- app/views/admin/pages/_show.html.erb | 6 +- lib/parsers/parser_back_end.rb | 190 ++++++++++----------------- lib/parsers/parser_common.rb | 52 ++++++++ lib/parsers/parser_front_end.rb | 183 +++++--------------------- 4 files changed, 162 insertions(+), 269 deletions(-) diff --git a/app/views/admin/pages/_show.html.erb b/app/views/admin/pages/_show.html.erb index 1937fe92d..ba9bcf48a 100644 --- a/app/views/admin/pages/_show.html.erb +++ b/app/views/admin/pages/_show.html.erb @@ -1,3 +1,7 @@ <%= flash_messages %> -<%= parse_page_edit(@item).html_safe %> \ No newline at end of file + +<%= page_stylesheets(@item).html_safe %> +<%= page_javascripts(@item).html_safe %> + +<%= parse_page_edit_noko(@item).html_safe %> \ No newline at end of file diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 787f579b3..3e6411182 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -1,132 +1,86 @@ module ParserBackEnd - require 'radius' include ParserCommon - - def parse_page_edit(page) - if page._type == 'Page' - layout_content = page.design.layout.content.force_encoding('UTF-8') rescue '' - context = parser_context_edit(page) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(layout_content)) + + require 'nokogiri' + + # 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 => { :full_name => tag.attr['name'] }) + # ret = '' + # ret << "" + # ret << item.i18n_variable[I18n.locale] + # ret << "" + # end + + def parse_page_edit_noko(page, id = nil) + body = Nokogiri::HTML(page.design.layout.body) + parse_menu(body, page, true) + public_r_tags = parse_contents(body, page, id) + parse_images(body, page) + + public_r_tags.each do |tag| + send("parse_#{tag}s", body, page,id) end + + body.to_html end - - def parser_context_edit(page, attributes = {}) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - res = '' - ad_banner = AdBanner.find(tag.attr["id"]) rescue nil - if ad_banner - res << "" - res << "
    " - ad_banner.ad_images.each do |ad_image| - res << "" - end - res << "
    " - end - end - c.define_tag 'content' do |tag| - ret = '' - if (tag.attributes["main"] == "true" && !page.module_app.nil?) - ret << "
    " - else - part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } - ret << "
    " - ret << "' - case part.kind - when 'text' - ret << part.i18n_variable[I18n.locale] rescue '' - when 'module_widget' - if part[:category] - ret << "
    " - else - ret << "
    " - end - when 'public_r_tag' - ret << "" - else - '' - end - ret << '
    ' - end - end - c.define_tag 'image' do |tag| - # 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?(tag.attr['name']) } unless image - if image - res = "' - end - end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - res << "" - end - res - end - 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 + + # page_contents + def parse_contents(body, page, id) + public_r_tags = [] + body.css('.page_content').each do |content| + ret = '' + if (content["main"] == "true" && !page.module_app.nil?) + ret << "
    " + else + part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil + ret << "
    " + ret << "' + case part.kind + when 'text' + ret << part.i18n_variable[I18n.locale] rescue '' + when 'module_widget' + if part[:category] + ret << "
    " else - "#{lang}" + ret << "
    " end - }.join(' | ') + when 'public_r_tag' + ret << "" + public_r_tags << part.public_r_tag + else + '' + end end - c.define_tag 'link' do |tag| - item = Item.first(:conditions => { :full_name => tag.attr['name'] }) - ret = '' - ret << "" - ret << item.i18n_variable[I18n.locale] - ret << "" - end - c.define_tag 'menu' do |tag| - home = get_homepage - menu = page.design.layout.menu - menu_level(home, 0, menu, true) - end - c.define_tag 'meta' do |tag| - "" - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" if page.design.reset_css - res << "" if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'title' do |tag| - "#{page.title ? page.title : page.i18n_variable[I18n.locale]}" + 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 + public_r_tags.uniq end - + + def self.included(base) - base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method + base.send :helper_method, :parse_page_edit_noko if base.respond_to? :helper_method end end diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 8d43c0709..96cbb4b98 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -44,4 +44,56 @@ module ParserCommon res << "" end + # ad_banners + def parse_ad_banners(body = nil, page = nil, id = nil) + body.css('ad_banner').each do |banner| + res = '' + ad_banner = AdBanner.find(banner["id"]) rescue nil + if ad_banner && ad_banner.display? + res << "" + res << "
    " + ad_banner.ad_images.each do |ad_image| + res << "" + end + res << "
    " + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + banner.swap(fragment) + end + end + + # page_images + def parse_images(body, page) + 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?(page_image['name']) } 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, 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, 0, menu, true)) + page_menu.swap(fragment) + end + end diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 529802ffb..c3ca17870 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -1,113 +1,42 @@ module ParserFrontEnd - require 'radius' include ParserCommon - - def parser_context(page, attributes = {}, id = nil) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - res = '' - ad_banner = AdBanner.find(tag.attr["id"]) rescue nil - if ad_banner && ad_banner.display? - res << "" - res << "
    " - ad_banner.ad_images.each do |ad_image| - res << "" - end - res << "
    " - end - res - end - c.define_tag 'content' do |tag| - ret = '' - if (tag.attributes["main"] == "true" && !page.module_app.nil?) - ret << "
    " - else - part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil - case part.kind - when 'text' - ret << part.i18n_variable[I18n.locale] rescue '' - when 'module_widget' - if part[:category] - ret << "
    " - else - ret << "
    " - end - when 'public_r_tag' - ret << "" - else - '' - end - end - ret - end - c.define_tag 'image' do |tag| - # 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?(tag.attr['name']) } unless image - if image - res = "' - end - end - 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 => { :full_name => tag.attr['name'] }) - ret = '' - ret << "" - ret << item.i18n_variable[I18n.locale] - ret << '' - end - c.define_tag 'menu' do |tag| - home = get_homepage - menu = page.design.layout.menu - menu_level(home, 0, menu) - end - end - end - - def parse_page(page, id = nil) - if page._type == 'Page' - context = parser_context(page, {}, id) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(page.design.layout.body)) - end - end - - def self.included(base) - base.send :helper_method, :parse_page if base.respond_to? :helper_method - end - - + # 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 => { :full_name => tag.attr['name'] }) + # ret = '' + # ret << "" + # ret << item.i18n_variable[I18n.locale] + # ret << '' + # end + # end require 'nokogiri' def parse_page_noko(page, id = nil) body = Nokogiri::HTML(page.design.layout.body) + parse_menu(body, page) + public_r_tags = parse_contents(body, page, id) + parse_images(body, page) - # page_contents + public_r_tags.each do |tag| + send("parse_#{tag}s", body, page,id) + end + + body.to_html + end + + # page_contents + def parse_contents(body, page, id) + public_r_tags = [] body.css('.page_content').each do |content| ret = '' if (content["main"] == "true" && !page.module_app.nil?) @@ -129,6 +58,7 @@ module ParserFrontEnd end when 'public_r_tag' ret << "" + public_r_tags << part.public_r_tag else '' end @@ -141,54 +71,7 @@ module ParserFrontEnd fragment = Nokogiri::HTML::DocumentFragment.new(body, scope) content.swap(fragment) end - - # page_menu - page_menu = body.css('.page_menu').first - home = get_homepage - menu = page.design.layout.menu - fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 0, menu)) - page_menu.swap(fragment) - - # page_image - 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?(page_image['name']) } unless image - if image - res = "' - end - fragment = Nokogiri::HTML::DocumentFragment.new(body, res) - page_image.swap(fragment) - end - - # ad_banner - body.css('ad_banner').each do |banner| - res = '' - ad_banner = AdBanner.find(banner["id"]) rescue nil - if ad_banner && ad_banner.display? - res << "" - res << "
    " - ad_banner.ad_images.each do |ad_image| - res << "" - end - res << "
    " - end - fragment = Nokogiri::HTML::DocumentFragment.new(body, res) - banner.swap(fragment) - end - - body.to_html + public_r_tags.uniq end end From f5fd3dec7a015f3974f388927bf8637a5ce7f0fd Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 01:51:16 +0800 Subject: [PATCH 21/93] Trying nokogiri --- Gemfile | 1 + Gemfile.lock | 4 + app/controllers/application_controller.rb | 2 +- app/controllers/pages_controller.rb | 2 + app/helpers/application_helper.rb | 47 ++++++++++ app/models/design/layout.rb | 8 +- app/models/meta.rb | 4 + app/views/layouts/page_layout.html.erb | 17 ++++ lib/parsers/parser_front_end.rb | 105 ++++++++++++++-------- lib/parsers/parser_layout.rb | 57 +++++------- 10 files changed, 172 insertions(+), 75 deletions(-) create mode 100644 app/views/layouts/page_layout.html.erb diff --git a/Gemfile b/Gemfile index 024f3449f..d1afdb8cc 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'kaminari', :git => 'git://github.com/amatsuda/kaminari.git' gem 'mini_magick' gem 'mongoid' gem "mongo_session_store-rails3" +gem 'nokogiri' gem 'radius' gem 'rake' gem 'ruby-debug19' diff --git a/Gemfile.lock b/Gemfile.lock index 1df648c48..71742974a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM archive-tar-minitar (0.5.2) arel (2.2.3) bcrypt-ruby (3.0.1) + bcrypt-ruby (3.0.1-x86-mingw32) brakeman (1.5.1) activesupport erubis (~> 2.6) @@ -115,6 +116,8 @@ GEM mongo (~> 1.3) tzinfo (~> 0.3.22) multi_json (1.1.0) + nokogiri (1.5.2) + nokogiri (1.5.2-x86-mingw32) orm_adapter (0.0.6) pdf-writer (1.1.8) color (>= 1.4.0) @@ -252,6 +255,7 @@ DEPENDENCIES mini_magick mongo_session_store-rails3 mongoid + nokogiri radius rails (>= 3.1.0, < 3.2.0) rake diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b433777d..fb82774ef 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,7 +47,7 @@ class ApplicationController < ActionController::Base # Render the page def render_page(id = nil) if @item - render :text => parse_page(@item, id) + render :text => process_page(@item, id), :layout => 'page_layout' else render :text => '404 Not Found' end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 8ea353919..4860ea2e8 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,5 +1,7 @@ class PagesController < ApplicationController + include ApplicationHelper + before_filter :get_item, :only => [:index_from_link, :show_from_link] def index diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 50510e3c6..9c03de3d3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -107,4 +107,51 @@ module ApplicationHelper end end + + def process_page(page, id) + parse_page_noko(page, id) + end + + def page_metas(page) + metas = '' + @site.page_metas.each do |meta| + name, content = meta.get_name_content + metas << "\n" + end rescue nil + return metas + end + + def page_title(page) + "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}\n" + end + + def page_stylesheets(page) + stylesheets = '' + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" if page.design.reset_css + stylesheets << "\n" if page.design.default_css + theme = page.design.themes.detect{ |d| d.id == page.theme_id } + stylesheets << "\n" if theme + stylesheets + end + + def page_javascripts(page) + javascripts = '' + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + page.design.javascripts.each do |js| + # javascripts << "" + end + javascripts + end + end diff --git a/app/models/design/layout.rb b/app/models/design/layout.rb index e13498f3a..bf48415cb 100644 --- a/app/models/design/layout.rb +++ b/app/models/design/layout.rb @@ -2,6 +2,8 @@ class Layout < DesignFile include ParserLayout attr_reader :content + + field :body embeds_one :menu embedded_in :design @@ -17,8 +19,10 @@ class Layout < DesignFile Layout.count > 0 end - def parse_layout - parse_layout_contents(self) + def parse_layout + html = Nokogiri::HTML(self.file.read) + self.body = html.at_css("body").inner_html + parse_body(self) end end diff --git a/app/models/meta.rb b/app/models/meta.rb index 411a4f0c5..dbeac167f 100644 --- a/app/models/meta.rb +++ b/app/models/meta.rb @@ -7,5 +7,9 @@ class Meta field :value, :default => nil has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + + def get_name_content + [self.key, self.value ? self.value : self.i18n_variable[I18n.locale]] + end end diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb new file mode 100644 index 000000000..8fb884b07 --- /dev/null +++ b/app/views/layouts/page_layout.html.erb @@ -0,0 +1,17 @@ + + + + + <%= page_title(@item).html_safe %> + <%= page_metas(@item).html_safe %> + <%= @metas %> + + <%= page_stylesheets(@item).html_safe %> + <%= page_javascripts(@item).html_safe %> + + + <%= yield %> + + diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 4b5a523f9..8ea3840a6 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -63,22 +63,6 @@ module ParserFrontEnd res << '>' end end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - # res << "" - end - res - end c.define_tag 'language_bar' do @site.in_use_locales.map{ |locale| lang = I18nVariable.first(:conditions => {:key => locale})[locale] @@ -101,38 +85,87 @@ module ParserFrontEnd menu = page.design.layout.menu menu_level(home, 0, menu) end - c.define_tag 'meta' do |tag| - res = '' - #res << "" - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" if page.design.reset_css - res << " " if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'title' do |tag| - "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}" - end end end def parse_page(page, id = nil) if page._type == 'Page' - layout_content = page.design.layout.content.force_encoding('UTF-8') rescue '' context = parser_context(page, {}, id) parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(layout_content)) + parser.parse(parser.parse(page.design.layout.body)) end end def self.included(base) base.send :helper_method, :parse_page if base.respond_to? :helper_method end + + + + require 'nokogiri' + + def parse_page_noko(page, id = nil) + body = Nokogiri::HTML(page.design.layout.body, nil, 'UTF-8') + + # page_contents + body.css('.page_content').each do |content| + ret = '' + if (content["main"] == "true" && !page.module_app.nil?) + 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.i18n_variable[I18n.locale] rescue '' + when 'module_widget' + if part[:category] + ret << "
    " + else + ret << "
    " + end + when 'public_r_tag' + ret << "" + else + '' + end + 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 + + # page_menu + page_menu = body.css('.page_menu').first + home = get_homepage + menu = page.design.layout.menu + fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 0, menu)) + page_menu.swap(fragment) + + # page_image + 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?(page_image['name']) } unless image + if image + res = "' + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + page_image.swap(fragment) + end + + body.to_html + end end diff --git a/lib/parsers/parser_layout.rb b/lib/parsers/parser_layout.rb index 063078dfa..01d681ef2 100644 --- a/lib/parsers/parser_layout.rb +++ b/lib/parsers/parser_layout.rb @@ -1,44 +1,27 @@ module ParserLayout - require 'radius' - include ParserCommon + require 'nokogiri' - def parse_layout_contents(layout) - content = layout.content.force_encoding('UTF-8') - context = parser_layout_contents(layout) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(content) - end - - def parser_layout_contents(layout) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - end - c.define_tag 'content' do |tag| - layout.layout_parts.new(:name => tag.attr['name']) - end - c.define_tag 'image' do |tag| - image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) } - image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image - end - c.define_tag 'javascripts' do |tag| - end - c.define_tag 'menu' do |tag| - layout.build_menu(:levels => 0, :values => {}) unless layout.menu - layout.menu.levels = i = tag.attr['level'].to_i - layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1 - layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']}) - tag.expand - end - c.define_tag 'meta' do |tag| - end - c.define_tag 'stylesheets' do |tag| - end - c.define_tag 'title' do |tag| - end + def parse_body(layout) + body = Nokogiri::HTML(layout.body) + body.css('.page_content').each do |content| + layout.layout_parts.build(:name => content['name']) end + + body.css('.page_image').each do |image| + image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(image.to_html)) } + image.update_attributes(:name => image['name'], :html_id => image['id'], :html_class => image['class']) if image + end + + body.css('.page_menu').each do |menu| + layout.build_menu(:levels => 0, :values => {}) unless layout.menu + layout.menu.levels = i = menu['level'].to_i + layout.menu.values.merge!({'home' => menu['home']}) if i == 1 + layout.menu.values.merge!({"id_#{i}" => menu['id'], "class_#{i}" => menu['class'], "li_class_#{i}" => menu['li_class'], "li_incremental_#{i}" => menu['li_incremental']}) + end + end - + def parse_html_image(html) html.scan(/(?<=\)/){ $1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){ @@ -46,4 +29,6 @@ module ParserLayout } } end + + end From 7efaddf57cb78c3f9203de59e456c548f9147fa3 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 10:11:02 +0800 Subject: [PATCH 22/93] Add ad_banner to nokogiri --- lib/parsers/parser_front_end.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 8ea3840a6..529802ffb 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -105,7 +105,7 @@ module ParserFrontEnd require 'nokogiri' def parse_page_noko(page, id = nil) - body = Nokogiri::HTML(page.design.layout.body, nil, 'UTF-8') + body = Nokogiri::HTML(page.design.layout.body) # page_contents body.css('.page_content').each do |content| @@ -165,6 +165,29 @@ module ParserFrontEnd page_image.swap(fragment) end + # ad_banner + body.css('ad_banner').each do |banner| + res = '' + ad_banner = AdBanner.find(banner["id"]) rescue nil + if ad_banner && ad_banner.display? + res << "" + res << "
    " + ad_banner.ad_images.each do |ad_image| + res << "" + end + res << "
    " + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + banner.swap(fragment) + end + body.to_html end From 3ba89ecbcff0a7f513f5d6d469591e95e4e2c92c Mon Sep 17 00:00:00 2001 From: Matt Fu Date: Thu, 22 Mar 2012 14:33:59 +0800 Subject: [PATCH 23/93] Fact check program completed,Lin checked --- app/models/object_auth.rb | 2 +- app/views/layouts/_side_bar.html.erb | 3 +- lib/orbit_core_lib.rb | 16 ++- .../back_end/bulletin_categorys_controller.rb | 2 +- .../back_end/bulletins_controller.rb | 106 +++++++++--------- .../back_end/fact_checks_controller.rb | 2 +- .../front_end/bulletins_controller.rb | 6 +- .../widget/bulletins_controller.rb | 8 +- .../announcement/app/models/bulletin.rb | 48 ++++---- .../back_end/bulletins/_bulletin.html.erb | 12 +- .../bulletins/_bulletin_link_qe.html.erb | 66 +++++------ .../back_end/bulletins/_form.html.erb | 2 + .../widget/bulletins/index.html.erb | 1 - 13 files changed, 144 insertions(+), 130 deletions(-) diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index 8932bb762..ae3fd7015 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -1,6 +1,6 @@ class ObjectAuth < PrototypeAuth include OrbitCoreLib::ObjectTokenUnility - validates_uniqueness_of :obj_authable_type,:scope => :title #{ |c| } + validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id] #{ |c| } belongs_to :obj_authable, polymorphic: true # > - Something.find_with_auth(query) # > - or Something.find(query).auth diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 71e8106d1..baeef6c43 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -9,8 +9,9 @@ <%= content_tag :li, link_to(t('admin.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %> <%= content_tag :li, link_to(t('admin.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %> <%= content_tag :li, link_to(t('admin.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('tags', 'index') %> - <%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('tags', 'index') %> + <%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('tags', 'index') if is_manager? %> <% end -%> + <% end -%> <%= content_tag :li, :class => active_for_controllers('users') do -%> diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index 561fceba0..bcde17e0c 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -21,11 +21,19 @@ module OrbitCoreLib def authed_users(title=nil) users = [] - unless title.nil? - users = self.object_auths.where(title: title )[0].auth_users_after_block_list rescue [] + users = case title + when :all + ary = self.object_auths.collect{|t| t.auth_users} + ary.flatten! + when nil + if self.object_auths.count ==1 + self.object_auths.first.auth_users_after_block_list rescue [] + else + logger.info "Warning calling a auth commend without specificed value( has multi-auths ), return empty" + [] + end else - users = self.object_auths.collect{|t| t.auth_users_after_block_list} rescue [] - users.flatten!.uniq! + self.object_auths.where(title: title).first.auth_users rescue [] end users end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb index f55ad6e3e..97378c5a6 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb @@ -1,4 +1,4 @@ -class Panel::Announcement::BackEnd::BulletinCategorysController < ApplicationController +class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController layout 'new_admin' diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 31f446a0e..31b3b4a21 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -159,12 +159,12 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end def file_quick_add - # debugger + # debugger @bulletin_file = BulletinFile.new - @file_url = panel_announcement_back_end_bulletins_path + @file_url = panel_announcement_back_end_bulletins_path - @bulletin_file.bulletin_id = params[:bulletin_id] + @bulletin_file.bulletin_id = params[:bulletin_id] respond_to do |format| format.js @@ -173,75 +173,73 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end def file_quick_edit - # debugger + # debugger @bulletin_file = BulletinFile.find(params[:bulletin_id]) - @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) + @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) respond_to do |format| format.js end - end # PUT /bulletins/1 # PUT /bulletins/1.xml def update - if params[:bulletin_link] - - @bulletin_link = BulletinLink.find(params[:id]) - - @link_url = panel_announcement_back_end_bulletin_path(@bulletin_link) + if params[:bulletin_link] + + @bulletin_link = BulletinLink.find(params[:id]) + + @link_url = panel_announcement_back_end_bulletin_path(@bulletin_link) - respond_to do |format| - if @bulletin_link.update_attributes(params[:bulletin_link]) - # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } - format.js { render 'update_bulletin_link' } - end - end - - elsif params[:bulletin_file] - - @bulletin_file = BulletinFile.find(params[:id]) - - @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) + respond_to do |format| + if @bulletin_link.update_attributes(params[:bulletin_link]) + # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } + format.js { render 'update_bulletin_link' } + end + end + + elsif params[:bulletin_file] + + @bulletin_file = BulletinFile.find(params[:id]) + + @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) - respond_to do |format| - if @bulletin_file.update_attributes(params[:bulletin_file]) - # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } - format.js { render 'update_bulletin_file' } - end - end - - else - - @bulletin = Bulletin.find(params[:id]) - - @bulletin.update_user_id = current_user.id - - # @bulletin.image.clear if params[:bulletin][:image_del] == '1' - # if params[:bulletin][:image_del] == '1' - # @bulletin.remove_image! - # @bulletin.image_del = nil - # params[:bulletin][:image_del] = nil - # end + respond_to do |format| + if @bulletin_file.update_attributes(params[:bulletin_file]) + # format.html { redirect_to(panel_announcement_back_end_bulletins_url) } + format.js { render 'update_bulletin_file' } + end + end + + else + + @bulletin = Bulletin.find(params[:id]) + + @bulletin.update_user_id = current_user.id + + # @bulletin.image.clear if params[:bulletin][:image_del] == '1' + # if params[:bulletin][:image_del] == '1' + # @bulletin.remove_image! + # @bulletin.image_del = nil + # params[:bulletin][:image_del] = nil + # end - respond_to do |format| - if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save - # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) } - format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } - format.js { render 'toggle_enable' } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } - end - end + respond_to do |format| + if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save + # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) } + format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } + format.js { render 'toggle_enable' } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } + end + end end - end # DELETE /bulletins/1 diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb index c47e91fb4..9095a4d37 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/fact_checks_controller.rb @@ -18,7 +18,7 @@ class Panel::Announcement::BackEnd::FactChecksController < OrbitBackendControll else first_category = @bulletin_categorys.first end - preload_object_auth = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check') + preload_object_auth = first_category.object_auths.where(title: 'fact_check').empty?? (first_category.object_auths.create! :title=> 'fact_check') : first_category.object_auths.where(title: 'fact_check') @users_array = preload_object_auth.first.privilege_users rescue [] respond_to do |format| format.html diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index ff3cbdc98..fe0b2aa58 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -12,9 +12,9 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController date_now = Time.now if params[:category_id] - @bulletins = Bulletin.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) else - @bulletins = Bulletin.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10) end get_categorys @@ -23,7 +23,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController end def show - @bulletin = Bulletin.find(params[:id]) + @bulletin = Bulletin.can_display.where.where(_id: params[:id]) get_categorys end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb index 60aad3d9e..783ee9ef8 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb @@ -14,9 +14,9 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController # @bulletin_categorys = BulletinCategory.first; # @bulletins = Bulletin.widget_datas(@bulletin_categorys.id).limit(9) if params[:category_id] - @bulletins = Bulletin.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9) + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9) else - @bulletins = Bulletin.widget_datas.limit(9) + @bulletins = Bulletin.can_display.widget_datas.limit(9) end get_categorys @@ -26,14 +26,14 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController def bulletins_and_web_links @tags = AnnouncementTag.all @selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0] - @bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil render :layout => 'module_widget' end def reload_bulletins @selected_tag = AnnouncementTag.find(params[:tag_id]) - @bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(5) rescue nil + @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil end def reload_web_links diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index d1b7f3c52..e24f7f215 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -19,12 +19,14 @@ class Bulletin field :is_top, :type => Boolean, :default => false field :is_hot, :type => Boolean, :default => false field :is_hidden, :type => Boolean, :default => false - field :is_checked, :type => Boolean, :default => false + field :is_checked, :type => Boolean, :default => nil field :not_checked_reason field :public, :type => Boolean, :default => true + scope :can_display,where(is_checked: true) + mount_uploader :image, ImageUploader belongs_to :bulletin_category @@ -47,28 +49,17 @@ class Bulletin def self.search( search = nil, category_id = nil ) - - if category_id.to_s.size > 0 and search.to_s.size > 0 - + if category_id.to_s.size > 0 and search.to_s.size > 0 key = /#{search}/ - - find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate ) - - elsif category_id.to_s.size > 0 and search.to_s.size < 1 - - find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate ) - - elsif search.to_s.size > 0 and category_id.to_s.size < 1 - + find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate ) + elsif category_id.to_s.size > 0 and search.to_s.size < 1 + find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate ) + elsif search.to_s.size > 0 and category_id.to_s.size < 1 key = /#{search}/ - - find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) - else - - find(:all).desc( :is_top, :postdate) - - end - + find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) + else + find(:all).desc( :is_top, :postdate) + end end @@ -87,7 +78,11 @@ class Bulletin end end - + + def is_expired? + Date.today > self.deadline ? true : false rescue false + #some dates might sat as nil so rescue false + end def is_top? self.is_top @@ -101,6 +96,15 @@ class Bulletin self.is_hidden end + def is_checked? + self.is_checked + end + + def is_check_rejected? + self.is_checked == false + end + + def save_bulletin_links self.bulletin_links.each do |t| if t.should_destroy diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb index 5338fb415..a67464c1e 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb @@ -10,8 +10,10 @@ <% if bulletin.is_hidden? %> <%= t(:hidden) %> <% end %> +
    - + <%#= debugger %> + <%#= a=1 %> + <% if (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager?) and !bulletin.is_expired? %>
  • <%= link_to t('bulletin.fact_check'), edit_panel_announcement_back_end_bulletin_path(bulletin) %>
  • <%#= #TODO add ancher so user can quick access into that part %> + <% end %> + <% end %> +
    + <%= bulletin.bulletin_category.i18n_variable[I18n.locale] %> <%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%> @@ -39,4 +47,4 @@ <%= User.from_id(bulletin.update_user_id).name rescue ''%> - \ No newline at end of file + diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb index b90063523..c146da486 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link_qe.html.erb @@ -1,43 +1,37 @@ <% # encoding: utf-8 %> - <%= form_for(@bulletin_link, :remote => true, :url => @link_url) do |f| %> - - - - - - +<%= form_for(@bulletin_link, :remote => true, :url => @link_url) do |f| %> + + +