1 class SiteController < ApplicationController
3 layout :map_layout, :only => [:index, :export]
5 before_action :authorize_web
6 before_action :set_locale
7 before_action :redirect_browse_params, :only => :index
8 before_action :redirect_map_params, :only => [:index, :edit, :export]
9 before_action :require_user, :only => [:welcome]
10 before_action :require_oauth, :only => [:index]
11 before_action :update_totp, :only => [:index]
14 unless STATUS == :database_readonly || STATUS == :database_offline
15 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"])
20 lon, lat, zoom = ShortLink.decode(params[:code])
21 new_params = params.except(:code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
25 new_params[:mlat] = lat
26 new_params[:mlon] = lon
30 new_params[:controller] = "browse"
31 new_params[:action] = "node"
32 new_params[:id] = params[:node]
33 elsif params.key? :way
34 new_params[:controller] = "browse"
35 new_params[:action] = "way"
36 new_params[:id] = params[:way]
37 elsif params.key? :relation
38 new_params[:controller] = "browse"
39 new_params[:action] = "relation"
40 new_params[:id] = params[:relation]
41 elsif params.key? :changeset
42 new_params[:controller] = "browse"
43 new_params[:action] = "changeset"
44 new_params[:id] = params[:changeset]
46 new_params[:controller] = "site"
47 new_params[:action] = "index"
50 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
51 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
53 redirect_to Hash[new_params]
57 expires_in 7.days, :public => true
58 render :layout => false
62 editor = preferred_editor
66 render :action => :index, :layout => map_layout
73 bbox = Node.find(params[:node]).bbox.to_unscaled
74 @lat = bbox.centre_lat
75 @lon = bbox.centre_lon
78 bbox = Way.find(params[:way]).bbox.to_unscaled
79 @lat = bbox.centre_lat
80 @lon = bbox.centre_lon
83 note = Note.find(params[:note])
87 elsif params[:gpx] && @user
88 trace = Trace.visible_to(@user).find(params[:gpx])
90 @lon = trace.longitude
96 @locale = params[:copyright_locale] || I18n.locale
110 render :text => RichText.new(params[:format], params[:text]).to_html
114 render "id", :layout => false
119 def redirect_browse_params
121 redirect_to node_path(params[:node])
123 redirect_to way_path(params[:way])
124 elsif params[:relation]
125 redirect_to relation_path(params[:relation])
127 redirect_to browse_note_path(params[:note])
129 redirect_to search_path(:query => params[:query])
133 def redirect_map_params
136 if params[:lat] && params[:lon]
137 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
141 anchor << "layers=#{params.delete(:layers)}"
142 elsif params.delete(:notes) == "yes"
147 redirect_to Hash[params].merge(:anchor => anchor.join("&"))