]> git.openstreetmap.org Git - rails.git/blob - app/controllers/site_controller.rb
Add link to per-user RSS feed on diary view page
[rails.git] / app / controllers / site_controller.rb
1 class SiteController < ApplicationController
2   layout 'site'
3   layout :map_layout, :only => [:index, :export]
4
5   before_filter :authorize_web
6   before_filter :set_locale
7   before_filter :redirect_browse_params, :only => :index
8   before_filter :redirect_map_params, :only => [:index, :edit, :export]
9   before_filter :require_user, :only => [:edit, :welcome]
10   before_filter :require_oauth, :only => [:index]
11
12   def index
13     unless STATUS == :database_readonly or STATUS == :database_offline
14       session[:location] ||= OSM::IPLocation(request.env['REMOTE_ADDR'])
15     end
16   end
17
18   def permalink
19     lon, lat, zoom = ShortLink::decode(params[:code])
20     new_params = params.except(:code, :lon, :lat, :zoom)
21
22     if new_params.has_key? :m
23       new_params.delete :m
24       new_params[:mlat] = lat
25       new_params[:mlon] = lon
26     end
27
28     new_params[:controller] = 'site'
29     new_params[:action] = 'index'
30     new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
31
32     redirect_to new_params
33   end
34
35   def key
36     expires_in 7.days, :public => true
37     render :layout => false
38   end
39
40   def edit
41     editor = preferred_editor
42
43     if editor == "remote"
44       require_oauth
45       render :action => :index, :layout => map_layout
46       return
47     end
48
49     if params[:node]
50       bbox = Node.find(params[:node]).bbox.to_unscaled
51       @lat = bbox.centre_lat
52       @lon = bbox.centre_lon
53       @zoom = 18
54     elsif params[:way]
55       bbox = Way.find(params[:way]).bbox.to_unscaled
56       @lat = bbox.centre_lat
57       @lon = bbox.centre_lon
58       @zoom = 17
59     elsif params[:note]
60       note = Note.find(params[:note])
61       @lat = note.lat
62       @lon = note.lon
63       @zoom = 17
64     elsif params[:gpx]
65       trace = Trace.visible_to(@user).find(params[:gpx])
66       @lat = trace.latitude
67       @lon = trace.longitude
68       @zoom = 16
69     end
70   end
71
72   def copyright
73     @locale = params[:copyright_locale] || I18n.locale
74   end
75
76   def welcome
77   end
78
79   def help
80   end
81
82   def about
83   end
84
85   def preview
86     render :text => RichText.new(params[:format], params[:text]).to_html
87   end
88
89   def id
90     render "id", :layout => false
91   end
92
93   private
94
95   def redirect_browse_params
96     if params[:node]
97       redirect_to node_path(params[:node])
98     elsif params[:way]
99       redirect_to way_path(params[:way])
100     elsif params[:relation]
101       redirect_to relation_path(params[:relation])
102     elsif params[:note]
103       redirect_to browse_note_path(params[:note])
104     elsif params[:query]
105       redirect_to search_path(:query => params[:query])
106     end
107   end
108
109   def redirect_map_params
110     anchor = []
111
112     if params[:lat] && params[:lon]
113       anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
114     end
115
116     if params[:layers]
117       anchor << "layers=#{params.delete(:layers)}"
118     elsif params.delete(:notes) == 'yes'
119       anchor << "layers=N"
120     end
121
122     if anchor.present?
123       redirect_to params.merge(:anchor => anchor.join('&'))
124     end
125   end
126 end