summaryrefslogtreecommitdiff
path: root/app/controllers/rss_controller.rb
blob: 489a732047d3c8543571975f13ad7b1e3bfa36d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class RssController < ApplicationController
  
  before_action :authenticate, :only => :recent_changes
  before_action :get_host
  
  def updates
    expires_in 31.minutes, :public => true
    
    I18n.locale = :de
  
    @items = Page.heads
      .joins("JOIN taggings ON taggings.taggable_id = pages.id
            AND taggings.taggable_type = 'Page'
            AND taggings.context = 'tags'")
      .joins("JOIN tags ON tags.id = taggings.tag_id")
      .where("LOWER(tags.name) = ?", "update")
      .order("published_at DESC").limit(20)

    respond_to do |format|
      format.xml {}
      format.rdf {}
    end
  end

  def tag_updates
    expires_in 31.minutes, :public => true

    I18n.locale = I18n.default_locale
    @tag  = params[:tag]
    @items = Page.heads
      .joins("JOIN taggings ON taggings.taggable_id = pages.id
          AND taggings.taggable_type = 'Page'
          AND taggings.context = 'tags'")
      .joins("JOIN tags ON tags.id = taggings.tag_id")
      .where("LOWER(tags.name) = ?", @tag.downcase)
      .order("published_at DESC").limit(20)

    respond_to do |format|
      format.xml {}
    end
  end

  def recent_changes
    @items = Page.where(
      "updated_at < ? AND updated_at > ?", Time.now, Time.now - 14.days
    ).limit(20).order("updated_at desc")
  end
  
  protected
    def authenticate
      authenticate_or_request_with_http_basic do |username, password|
        username == "recent" && password == "d@t3N+kLAu-23"
      end
    end
    
    def get_host
      @host = request.protocol + request.host_with_port
    end
  
end