2013-02-05 14:16:51 -05:00
|
|
|
class ClicksController < ApplicationController
|
|
|
|
|
|
|
|
skip_before_filter :check_xhr
|
2013-02-07 10:45:24 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def track
|
2013-06-06 03:14:32 -04:00
|
|
|
params = track_params.merge(ip: request.remote_ip)
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-06-06 03:14:32 -04:00
|
|
|
if params[:topic_id].present? || params[:post_id].present?
|
|
|
|
params.merge!({ user_id: current_user.id }) if current_user.present?
|
2013-07-26 12:14:11 -04:00
|
|
|
@redirect_url = TopicLinkClick.create_from(params)
|
2013-12-13 12:56:20 -05:00
|
|
|
|
|
|
|
if @redirect_url.blank? && params[:url].index('?')
|
|
|
|
# Check the url without query parameters
|
|
|
|
params[:url].sub!(/\?.*$/, '')
|
|
|
|
@redirect_url = TopicLinkClick.create_from(params)
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Sometimes we want to record a link without a 302. Since XHR has to load the redirected
|
|
|
|
# URL we want it to not return a 302 in those cases.
|
2013-07-26 12:14:11 -04:00
|
|
|
if params[:redirect] == 'false' || @redirect_url.blank?
|
2013-02-05 14:16:51 -05:00
|
|
|
render nothing: true
|
|
|
|
else
|
2013-07-26 12:14:11 -04:00
|
|
|
redirect_to(@redirect_url)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-06 03:14:32 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def track_params
|
|
|
|
params.require(:url)
|
|
|
|
params.permit(:url, :post_id, :topic_id, :redirect)
|
|
|
|
end
|
|
|
|
|
2013-02-07 10:45:24 -05:00
|
|
|
end
|