+ def data
+ trace = Trace.find(params[:id])
+
+ if trace.visible? and (trace.public? or (@user and @user == trace.user))
+ send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment')
+ else
+ render :nothing, :status => :not_found
+ end
+ rescue ActiveRecord::RecordNotFound
+ render :nothing => true, :status => :not_found
+ end
+
+ def delete
+ trace = Trace.find(params[:id])
+
+ if @user and trace.user == @user
+ if request.post? and trace.visible?
+ trace.visible = false
+ trace.save
+ flash[:notice] = 'Track scheduled for deletion'
+ redirect_to :controller => 'traces', :action => 'mine'
+ else
+ render :nothing, :status => :bad_request
+ end
+ else
+ render :nothing, :status => :forbidden
+ end
+ rescue ActiveRecord::RecordNotFound
+ render :nothing => true, :status => :not_found
+ end
+
+ def make_public
+ trace = Trace.find(params[:id])
+
+ if @user and trace.user == @user
+ if request.post? and !trace.public?
+ trace.public = true
+ trace.save
+ flash[:notice] = 'Track made public'
+ redirect_to :controller => 'trace', :action => 'view', :id => params[:id]
+ else
+ render :nothing, :status => :bad_request
+ end
+ else
+ render :nothing, :status => :forbidden
+ end
+ rescue ActiveRecord::RecordNotFound
+ render :nothing => true, :status => :not_found
+ end
+
+ def georss
+ conditions = ["gpx_files.public = 1"]
+
+ if params[:display_name]
+ conditions[0] += " AND users.display_name = ?"
+ conditions << params[:display_name]
+ end
+
+ if params[:tag]
+ conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)"
+ conditions << params[:tag]
+ end
+
+ traces = Trace.find(:all, :include => :user, :conditions => conditions,
+ :order => "timestamp DESC", :limit => 20)
+
+ rss = OSM::GeoRSS.new
+
+ traces.each do |trace|
+ rss.add(trace.latitude, trace.longitude, trace.name, trace.user.display_name, url_for({:controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name}), "<img src='#{url_for({:controller => 'trace', :action => 'icon', :id => trace.id, :user_login => trace.user.display_name})}'> GPX file with #{trace.size} points from #{trace.user.display_name}", trace.timestamp)
+ end
+
+ render :text => rss.to_s, :content_type => "application/rss+xml"