]> git.openstreetmap.org Git - rails.git/blob - app/controllers/site_controller.rb
Improve handling of sidebar close link
[rails.git] / app / controllers / site_controller.rb
1 class SiteController < ApplicationController
2   layout 'site', :except => [:key, :permalink]
3   layout false, :only => [:key, :permalink]
4
5   before_filter :authorize_web
6   before_filter :set_locale
7   before_filter :require_user, :only => [:edit]
8
9   def export
10     render :action => 'index'
11   end
12
13   def permalink
14     lon, lat, zoom = ShortLink::decode(params[:code])
15     new_params = params.clone
16     new_params.delete :code
17     if new_params.has_key? :m
18       new_params.delete :m
19       new_params[:mlat] = lat
20       new_params[:mlon] = lon
21     else
22       new_params[:lat] = lat
23       new_params[:lon] = lon
24     end
25     new_params[:zoom] = zoom
26     new_params[:controller] = 'site'
27     new_params[:action] = 'index'
28     redirect_to new_params
29   end
30
31   def key
32     expires_in 7.days, :public => true
33   end
34
35   def edit
36     editor = params[:editor] || @user.preferred_editor || DEFAULT_EDITOR
37
38     if editor == "remote"
39       render :action => :index
40     else
41       # Decide on a lat lon to initialise potlatch with. Various ways of doing this
42       if params['lon'] and params['lat']
43         @lon = params['lon'].to_f
44         @lat = params['lat'].to_f
45         @zoom = params['zoom'].to_i
46
47       elsif params['mlon'] and params['mlat']
48         @lon = params['mlon'].to_f
49         @lat = params['mlat'].to_f
50         @zoom = params['zoom'].to_i
51
52       elsif params['bbox']
53         bbox = BoundingBox.from_bbox_params(params)
54
55         @lon = bbox.centre_lon
56         @lat = bbox.centre_lat
57         @zoom = 16
58       elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
59         bbox = BoundingBox.from_lon_lat_params(params)
60
61         @lon = bbox.centre_lon
62         @lat = bbox.centre_lat
63         @zoom = 16
64
65       elsif params['gpx']
66         @lon = Trace.find(params['gpx']).longitude
67         @lat = Trace.find(params['gpx']).latitude
68
69       elsif cookies.key?("_osm_location")
70         @lon, @lat, @zoom, layers = cookies["_osm_location"].split("|")
71
72       elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
73         @lon = @user.home_lon
74         @lat = @user.home_lat
75
76       else
77         #catch all.  Do nothing.  lat=nil, lon=nil
78         #Currently this results in potlatch starting up at 0,0 (Atlantic ocean).
79       end
80
81       @zoom = '17' if @zoom.nil?
82     end
83   end
84
85   def copyright
86     @locale = params[:copyright_locale] || I18n.locale
87   end
88
89   def preview
90     render :text => RichText.new(params[:format], params[:text]).to_html
91   end
92 end