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 => [: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
71 bbox = Node.find(params[:node]).bbox.to_unscaled
72 @lat = bbox.centre_lat
73 @lon = bbox.centre_lon
76 bbox = Way.find(params[:way]).bbox.to_unscaled
77 @lat = bbox.centre_lat
78 @lon = bbox.centre_lon
81 note = Note.find(params[:note])
86 trace = Trace.visible_to(@user).find(params[:gpx])
88 @lon = trace.longitude
94 @locale = params[:copyright_locale] || I18n.locale
113 render :text => RichText.new(params[:format], params[:text]).to_html
117 render "id", :layout => false
122 def redirect_browse_params
124 redirect_to node_path(params[:node])
126 redirect_to way_path(params[:way])
127 elsif params[:relation]
128 redirect_to relation_path(params[:relation])
130 redirect_to browse_note_path(params[:note])
132 redirect_to search_path(:query => params[:query])
136 def redirect_map_params
139 if params[:lat] && params[:lon]
140 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
144 anchor << "layers=#{params.delete(:layers)}"
145 elsif params.delete(:notes) == 'yes'
150 redirect_to params.merge(:anchor => anchor.join('&'))