From c4296b59a7f9d667d295f9c37b71f7849b818fb3 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Tue, 28 Jan 2025 22:47:15 +0100 Subject: Big overhaul patch and style changes --- app/controllers/admin_controller.rb | 11 +++-- app/controllers/application_controller.rb | 10 ++--- app/controllers/content_controller.rb | 26 +++++++----- app/controllers/tags_controller.rb | 47 +++++++++++++--------- app/helpers/admin_helper.rb | 6 +-- app/helpers/content_helper.rb | 12 +++--- app/helpers/nodes_helper.rb | 4 ++ app/models/occurrence.rb | 3 +- app/models/page.rb | 12 +++++- app/views/content/_featured_articles.html.erb | 33 +++++++++++++-- app/views/content/_main_navigation.html.erb | 8 +++- .../public/no_date_and_author.html.erb | 4 +- .../no_title_abstract_date_and_author.html.erb | 4 +- .../public/standard_template.html.erb | 4 +- .../page_templates/public/title_only.html.erb | 4 +- .../custom/page_templates/public/update.html.erb | 4 +- app/views/custom/partials/_article.html.erb | 4 +- .../custom/partials/_no_date_and_author.html.erb | 4 +- app/views/layouts/application.html.erb | 17 ++++---- app/views/layouts/pages.html.erb | 2 + app/views/nodes/edit.html.erb | 2 +- app/views/rss/recent_changes.xml.builder | 8 ++-- app/views/rss/updates.rdf.builder | 18 ++++----- app/views/rss/updates.xml.builder | 7 ++-- app/views/search/_search_result.html.erb | 6 +-- 25 files changed, 162 insertions(+), 98 deletions(-) (limited to 'app') diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 1d1a1ca..cdfe564 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -20,13 +20,17 @@ class AdminController < ApplicationController end def search - @results = Node.search params[:search_term] + @results = Node.search params[:search_term], :per_page => 1000 respond_to do |format| - format.html + format.html do + render :template => 'admin/search_results.html' + end format.js do render( :json => @results.map do |node| - {:id => node.id, :title => node.title, :edit_path => node_path(node)} + if node + {:id => node.id, :title => node.title, :edit_path => node_path(node)} + end end ) @@ -46,7 +50,6 @@ class AdminController < ApplicationController render :partial => 'admin/menu_search_results' end - format.js do render( :json => @results.map do |node| {:node_id => node.id, :title => node.title, :unique_name => node.unique_name} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bce0c71..89cd330 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,20 +2,20 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base - + include ExceptionNotifiable include AuthenticatedSystem - + helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log filter_parameter_logging :password, :password_confirmation - + before_filter :set_locale - + protected - + def set_locale if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) I18n.locale = params[:locale].to_sym diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 1b13456..c62b726 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,30 +1,30 @@ class ContentController < ApplicationController - + # Public - + before_filter :find_page - + # This is the method that renders most of the the public content. It recieves - # a :locale and a :page_path parameter through the params hash. It looks up + # a :locale and a :page_path parameter through the params hash. It looks up # the node with the corresponding unique_name attribute. The method doesn't - # return a node though, the node is really a proxy object for pages. It + # return a node though, the node is really a proxy object for pages. It # returns the most recent page associated to this node instead. def render_page - + expires_in 20.minutes, :public => true - + if @page and @page.public? render( :file => @page.valid_template, :layout => true ) else - render( + render( :file => File.join(RAILS_ROOT, 'public', '404.html'), :status => 404 ) end - + end def render_gallery @@ -35,10 +35,14 @@ class ContentController < ApplicationController render :nothing => true, :status => 404 end end - + private def find_page path = params[:page_path].join('/') - @page = Node.find_page(path) + if path =~ /^[a-zA-Z\:\/\/\.\-\d_]+$/ + @page = Node.find_page(path) + else + @page = nil + end end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 565cdd4..bf64b73 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,33 +1,40 @@ class TagsController < ApplicationController - + # Public - + def index @page = Page.new :title => "Tags" - + @tags = Tag.all(:limit => 500) end def show - @tag = Tag.find_by_name(params[:id]) - - @tag = @tag ? @tag.name : params[:id] - - @page = Page.new - - params[:page] = ( params[:page].is_a?(Fixnum) ? params[:page] : 1 ) - - @pages = Page.heads.paginate( - Page.find_options_for_find_tagged_with(@tag).merge( - :order => 'published_at DESC', - :page=>params[:page], - :per_page => 23 + tag_name = params[:id] + + if tag_name.match(/^[a-zA-Z0-9_\w\s\-\.\']+$/) + @tag = Tag.find_by_name(tag_name) + @tag = @tag ? @tag.name : tag_name + @page = Page.new + + params[:page] = ( params[:page].is_a?(Fixnum) ? params[:page] : 1 ) + + @pages = Page.heads.paginate( + Page.find_options_for_find_tagged_with(@tag).merge( + :order => 'published_at DESC', + :page=>params[:page], + :per_page => 23 + ) ) - ) - - respond_to do |format| - format.html {} + + respond_to do |format| + format.html {} + end + else + respond_to do |format| + format.html { render :nothing => true, :status => 400 } + end end + end end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index da8945e..232862b 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -3,9 +3,9 @@ module AdminHelper def language_selector case I18n.locale when :de - link_to 'English', url_for(:overwrite_params => {:locale => :en}) + link_to 'English (Aktiv: Deutsch)', url_for(:overwrite_params => {:locale => :en}) when :en - link_to 'Deutsch', url_for(:overwrite_params => {:locale => :de}) + link_to 'Deutsch (Active: English)', url_for(:overwrite_params => {:locale => :de}) end end -end \ No newline at end of file +end diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index d6c96f1..7286976 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -9,13 +9,13 @@ module ContentHelper end def calendar - occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) + occurrences = Occurrence.find_in_range(Time.now, (Time.now+6.weeks)) if occurrences.empty? occurrences = Occurrence.find_next end - occurrences = occurrences.reject { |o| o.node.head.nil? } + occurrences = occurrences.reject { |o| o.node.nil? || o.node.head.nil? } render( :partial => 'content/front_page_calendar', @@ -75,6 +75,8 @@ module ContentHelper def aggregate? content options = {} + cccms_attributes = ActionView::Base.sanitized_allowed_attributes + [ 'lang' ] + begin if content =~ /]*)>/ tag = $~.to_s @@ -87,13 +89,13 @@ module ContentHelper options[:partial] = select_partial( options[:partial] ) - sanitize( content.sub(tag, render_collection(options)) ) + sanitize( content.sub(tag, render_collection(options)), :attributes => cccms_attributes ) else - sanitize( content ) + sanitize( content, :attributes => cccms_attributes ) end rescue - sanitize( content ) + sanitize( content, :atttributes => cccms_attributes ) end end diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb index d889719..204ad8a 100644 --- a/app/helpers/nodes_helper.rb +++ b/app/helpers/nodes_helper.rb @@ -4,6 +4,10 @@ module NodesHelper if node.head node.head.title else + if not node.draft or not node.draft.title + logger.error "Missing title in node #{node.id}" + return "NO TITLE" + end node.draft.title end end diff --git a/app/models/occurrence.rb b/app/models/occurrence.rb index 591e1e0..62432d5 100644 --- a/app/models/occurrence.rb +++ b/app/models/occurrence.rb @@ -16,7 +16,8 @@ class Occurrence < ActiveRecord::Base :include => :node, :conditions => [ "start_time > ? AND end_time < ?", start_time, end_time - ] + ], + :order => "start_time" ) end diff --git a/app/models/page.rb b/app/models/page.rb index c5da386..0cfad53 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -149,6 +149,16 @@ class Page < ActiveRecord::Base published_at.nil? ? true : published_at < Time.now end + def effective_lang + if translated_locales.empty? + return 'de' + elsif translated_locales.include?(I18n.locale) + return I18n.locale + else + return translated_locales.first + end + end + # Returns true if a page has translations where one of them is significantly # older than the other. # Takes the I18n.default locale and a second :locale to test if the @@ -238,4 +248,4 @@ class Page < ActiveRecord::Base end end -end \ No newline at end of file +end diff --git a/app/views/content/_featured_articles.html.erb b/app/views/content/_featured_articles.html.erb index 75e2e1d..0220abb 100644 --- a/app/views/content/_featured_articles.html.erb +++ b/app/views/content/_featured_articles.html.erb @@ -1,5 +1,14 @@ diff --git a/app/views/content/_main_navigation.html.erb b/app/views/content/_main_navigation.html.erb index 67d4ecc..a984512 100644 --- a/app/views/content/_main_navigation.html.erb +++ b/app/views/content/_main_navigation.html.erb @@ -3,5 +3,11 @@ <% menu_items.each do |item| %>
  • <%= link_to_path item.title, item.path %>
  • <% end %> +
  • + <%= language_selector %> +
  • +
  • + +
  • - \ No newline at end of file + diff --git a/app/views/custom/page_templates/public/no_date_and_author.html.erb b/app/views/custom/page_templates/public/no_date_and_author.html.erb index b019805..fa39e54 100644 --- a/app/views/custom/page_templates/public/no_date_and_author.html.erb +++ b/app/views/custom/page_templates/public/no_date_and_author.html.erb @@ -1,8 +1,8 @@ -
    +

    <%= @page.title %>

    <%= sanitize( @page.abstract ) %>

    <%= headline_image %>
    <%= aggregate?(@page.body) %>
    -<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file +<%= will_paginate(@content_collection) if @content_collection %> diff --git a/app/views/custom/page_templates/public/no_title_abstract_date_and_author.html.erb b/app/views/custom/page_templates/public/no_title_abstract_date_and_author.html.erb index 83cbff6..64e2a7c 100644 --- a/app/views/custom/page_templates/public/no_title_abstract_date_and_author.html.erb +++ b/app/views/custom/page_templates/public/no_title_abstract_date_and_author.html.erb @@ -1,6 +1,6 @@ -
    +
    <%= headline_image %>
    <%= aggregate?(@page.body) %>
    -<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file +<%= will_paginate(@content_collection) if @content_collection %> diff --git a/app/views/custom/page_templates/public/standard_template.html.erb b/app/views/custom/page_templates/public/standard_template.html.erb index 8000af5..bbc8cd0 100644 --- a/app/views/custom/page_templates/public/standard_template.html.erb +++ b/app/views/custom/page_templates/public/standard_template.html.erb @@ -1,8 +1,8 @@ -
    +

    <%= @page.title %>

    <%= sanitize( @page.abstract )%>

    <%= headline_image %>
    <%= aggregate?(@page.body) %>
    -<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file +<%= will_paginate(@content_collection) if @content_collection %> diff --git a/app/views/custom/page_templates/public/title_only.html.erb b/app/views/custom/page_templates/public/title_only.html.erb index 09c7455..42fe9a6 100644 --- a/app/views/custom/page_templates/public/title_only.html.erb +++ b/app/views/custom/page_templates/public/title_only.html.erb @@ -1,7 +1,7 @@ -
    +

    <%= @page.title %>

    <%= headline_image %>
    <%= aggregate?(@page.body) %>
    -<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file +<%= will_paginate(@content_collection) if @content_collection %> diff --git a/app/views/custom/page_templates/public/update.html.erb b/app/views/custom/page_templates/public/update.html.erb index 5ea277a..d5995ac 100644 --- a/app/views/custom/page_templates/public/update.html.erb +++ b/app/views/custom/page_templates/public/update.html.erb @@ -1,4 +1,4 @@ -
    +

    <%= @page.title %>

    <%= date_for_page @page %>, <%= @page.user.try(:login) %>

    <%= sanitize( @page.abstract )%>

    @@ -6,4 +6,4 @@
    <%= aggregate?(@page.body) %>
    -<%= will_paginate(@content_collection) if @content_collection %> \ No newline at end of file +<%= will_paginate(@content_collection) if @content_collection %> diff --git a/app/views/custom/partials/_article.html.erb b/app/views/custom/partials/_article.html.erb index 433c31c..b738ac7 100644 --- a/app/views/custom/partials/_article.html.erb +++ b/app/views/custom/partials/_article.html.erb @@ -1,7 +1,7 @@ -
    +

    <%= link_to_path page.title, page.node.unique_name %>

    <%= date_for_page page %>, <%= author_for_page page %>

    <%= page.abstract %> <%= link_to_path t(:more), page.node.unique_name %>

    -
    \ No newline at end of file +
    diff --git a/app/views/custom/partials/_no_date_and_author.html.erb b/app/views/custom/partials/_no_date_and_author.html.erb index 61d6aac..fed02ac 100644 --- a/app/views/custom/partials/_no_date_and_author.html.erb +++ b/app/views/custom/partials/_no_date_and_author.html.erb @@ -1,4 +1,4 @@ -
    +

    <%= link_to page.title, content_path(page.node.unique_path) %>

    <%= page.abstract %>

    -
    \ No newline at end of file +
    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3c95d75..e6efccf 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,6 +4,11 @@ + + + + + <%= page_title %> <%= stylesheet_link_tag "ccc" %> @@ -16,7 +21,7 @@ <%= auto_discovery_link_tag(:rss, {:locale => :de, :controller => "rss", :action => "updates", :format => :rdf}) %> - +
    - \ No newline at end of file + diff --git a/app/views/layouts/pages.html.erb b/app/views/layouts/pages.html.erb index 327e0eb..70ceece 100644 --- a/app/views/layouts/pages.html.erb +++ b/app/views/layouts/pages.html.erb @@ -4,6 +4,8 @@ + + Pages: <%= controller.action_name %> <%= stylesheet_link_tag 'scaffold' %> diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index 8e27d0f..b9260d2 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb @@ -107,4 +107,4 @@ <% end %> <% end %> -
    \ No newline at end of file +
    diff --git a/app/views/rss/recent_changes.xml.builder b/app/views/rss/recent_changes.xml.builder index c3b3ec9..cce3b5d 100644 --- a/app/views/rss/recent_changes.xml.builder +++ b/app/views/rss/recent_changes.xml.builder @@ -2,19 +2,19 @@ xml.instruct! xml.feed(:xmlns => "http://www.w3.org/2005/Atom", "xml:base" => @host) do xml.title("CCC.de Recent Change") - xml.link(:href => "http://www.ccc.de/") + xml.link(:href => "https://www.ccc.de/") xml.link(:rel => "self", :href => "/rss/updates.xml") xml.updated(@items.first.updated_at.xmlschema) xml.author do xml.name("Chaos Computer Club e.V.") end - xml.id("http://www.ccc.de/") + xml.id("https://www.ccc.de/") @items.each do |item| xml.entry do xml.title(item.title) xml.link( - :href => "http://www.ccc.de/#{item.node.unique_path}", + :href => "https://www.ccc.de/#{item.node.unique_path}", :rel => "alternate" ) xml.id(content_url_helper(item.node.unique_path)) @@ -26,4 +26,4 @@ xml.feed(:xmlns => "http://www.w3.org/2005/Atom", "xml:base" => @host) do end -end \ No newline at end of file +end diff --git a/app/views/rss/updates.rdf.builder b/app/views/rss/updates.rdf.builder index 00b6242..cc63201 100644 --- a/app/views/rss/updates.rdf.builder +++ b/app/views/rss/updates.rdf.builder @@ -2,26 +2,26 @@ xml.instruct! xml.tag!("rdf:RDF", "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "xmlns:dc" => "http://purl.org/dc/elements/1.1/", "xmlns" => "http://purl.org/rss/1.0/") do xml.tag!( "rdf:Description", "rdf:about" => "http://www.w3.org/TR/rdf-syntax-grammar", "dc:title"=>"RDF/XML Syntax Specification (Revised)") - xml.channel do + xml.channel( "rdf:about" => "https://www.ccc.de/de/rss/updates.xml" ) do xml.title("Chaos Computer Club: Updates") - xml.link("http://www.ccc.de") + xml.link("https://www.ccc.de") xml.description("Kabelsalat ist gesund.") xml.tag!("dc:date", @items.first.published_at.xmlschema) end - - xml.image( "rdf:about" => "http://www.ccc.de/images/chaosknoten.gif") do + + xml.image( "rdf:about" => "https://www.ccc.de/images/chaosknoten.gif") do xml.title("Chaos Computer Club (Chaosknoten)") - xml.link("http://www.ccc.de") - xml.url("http://www.ccc.de/images/chaosknoten.gif") + xml.link("https://www.ccc.de") + xml.url("https://www.ccc.de/images/chaosknoten.gif") end - + @items.each do |item| xml.item("rdf:about" => content_url(:page_path => item.node.unique_path)) do xml.title(item.title) xml.link(content_url(:page_path => item.node.unique_path)) xml.description(item.abstract) - xml.tag!("dc:creator", item.user.login) + xml.tag!("dc:creator", (item.user ? item.user.login : "CCC")) xml.tag!("dc:date", item.published_at.xmlschema) end end -end \ No newline at end of file +end diff --git a/app/views/rss/updates.xml.builder b/app/views/rss/updates.xml.builder index c09c9c9..6afcd56 100644 --- a/app/views/rss/updates.xml.builder +++ b/app/views/rss/updates.xml.builder @@ -2,13 +2,13 @@ xml.instruct! xml.feed(:xmlns => "http://www.w3.org/2005/Atom", "xml:base" => @host) do xml.title("Chaos Computer Club Updates") - xml.link(:href => "http://www.ccc.de/") + xml.link(:href => "https://www.ccc.de/") xml.link(:rel => "self", :href => "#{@host}/rss/updates") xml.updated(@items.first.published_at.xmlschema) xml.author do xml.name("Chaos Computer Club e.V.") end - xml.id("#{@host}/rss/updates") + xml.id("https://www.ccc.de/rss/updates") @items.each do |item| xml.entry do @@ -21,6 +21,7 @@ xml.feed(:xmlns => "http://www.w3.org/2005/Atom", "xml:base" => @host) do xml.id(content_url(:page_path => item.node.feed_id)) xml.updated(item.updated_at.xmlschema) xml.published(item.published_at.xmlschema) + xml.summary(item.abstract) xml.content(:type => "xhtml") do xml.div(item.body, :xmlns => "http://www.w3.org/1999/xhtml") end @@ -28,4 +29,4 @@ xml.feed(:xmlns => "http://www.w3.org/2005/Atom", "xml:base" => @host) do end -end \ No newline at end of file +end diff --git a/app/views/search/_search_result.html.erb b/app/views/search/_search_result.html.erb index 14898a2..6cd01f8 100644 --- a/app/views/search/_search_result.html.erb +++ b/app/views/search/_search_result.html.erb @@ -1,6 +1,6 @@ -<% if node.head %> -
    +<% if node and node.head %> +

    <%= link_to node.head.title, content_path(node.unique_path) %>

    <%= node.head.abstract %>

    -<% end %> \ No newline at end of file +<% end %> -- cgit v1.3