1 class SiteController < ApplicationController
3 layout :map_layout, :only => [:index, :export]
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]
13 unless STATUS == :database_readonly or STATUS == :database_offline
14 session[:location] ||= OSM::IPLocation(request.env['REMOTE_ADDR'])
19 lon, lat, zoom = ShortLink::decode(params[:code])
20 new_params = params.except(:code, :lon, :lat, :zoom, :node, :way, :relation, :changeset)
22 if new_params.has_key? :m
24 new_params[:mlat] = lat
25 new_params[:mlon] = lon
28 if params.has_key? :node
29 new_params[:controller] = 'browse'
30 new_params[:action] = 'node'
31 new_params[:id] = params[:node]
32 elsif params.has_key? :way
33 new_params[:controller] = 'browse'
34 new_params[:action] = 'way'
35 new_params[:id] = params[:way]
36 elsif params.has_key? :relation
37 new_params[:controller] = 'browse'
38 new_params[:action] = 'relation'
39 new_params[:id] = params[:relation]
40 elsif params.has_key? :changeset
41 new_params[:controller] = 'browse'
42 new_params[:action] = 'changeset'
43 new_params[:id] = params[:changeset]
45 new_params[:controller] = 'site'
46 new_params[:action] = 'index'
49 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
51 redirect_to new_params
55 expires_in 7.days, :public => true
56 render :layout => false
60 editor = preferred_editor
64 render :action => :index, :layout => map_layout
69 bbox = Node.find(params[:node]).bbox.to_unscaled
70 @lat = bbox.centre_lat
71 @lon = bbox.centre_lon
74 bbox = Way.find(params[:way]).bbox.to_unscaled
75 @lat = bbox.centre_lat
76 @lon = bbox.centre_lon
79 note = Note.find(params[:note])
84 trace = Trace.visible_to(@user).find(params[:gpx])
86 @lon = trace.longitude
92 @locale = params[:copyright_locale] || I18n.locale
111 render :text => RichText.new(params[:format], params[:text]).to_html
115 render "id", :layout => false
120 def redirect_browse_params
122 redirect_to node_path(params[:node])
124 redirect_to way_path(params[:way])
125 elsif params[:relation]
126 redirect_to relation_path(params[:relation])
128 redirect_to browse_note_path(params[:note])
130 redirect_to search_path(:query => params[:query])
134 def redirect_map_params
137 if params[:lat] && params[:lon]
138 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
142 anchor << "layers=#{params.delete(:layers)}"
143 elsif params.delete(:notes) == 'yes'
148 redirect_to params.merge(:anchor => anchor.join('&'))