2014-01-01 03:37:43 +08:00
|
|
|
class EmbedController < ApplicationController
|
|
|
|
skip_before_filter :check_xhr
|
|
|
|
skip_before_filter :preload_json
|
|
|
|
before_filter :ensure_embeddable
|
|
|
|
|
|
|
|
layout 'embed'
|
|
|
|
|
2014-01-04 01:52:24 +08:00
|
|
|
def comments
|
2014-01-01 03:37:43 +08:00
|
|
|
embed_url = params.require(:embed_url)
|
|
|
|
topic_id = TopicEmbed.topic_id_for_embed(embed_url)
|
|
|
|
|
|
|
|
if topic_id
|
2014-01-04 01:52:24 +08:00
|
|
|
@topic_view = TopicView.new(topic_id, current_user, limit: SiteSetting.embed_post_limit, exclude_first: true)
|
2014-01-03 01:15:48 +08:00
|
|
|
@second_post_url = "#{@topic_view.topic.url}/2" if @topic_view
|
2014-01-04 03:55:37 +08:00
|
|
|
@posts_left = 0
|
|
|
|
if @topic_view && @topic_view.posts.size == SiteSetting.embed_post_limit
|
|
|
|
@posts_left = @topic_view.topic.posts_count - SiteSetting.embed_post_limit
|
|
|
|
end
|
2014-01-01 03:37:43 +08:00
|
|
|
else
|
|
|
|
Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url)
|
|
|
|
render 'loading'
|
|
|
|
end
|
|
|
|
|
|
|
|
discourse_expires_in 1.minute
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ensure_embeddable
|
2014-01-03 00:32:50 +08:00
|
|
|
|
|
|
|
if !(Rails.env.development? && current_user.try(:admin?))
|
|
|
|
raise Discourse::InvalidAccess.new('embeddable host not set') if SiteSetting.embeddable_host.blank?
|
2014-01-03 00:55:45 +08:00
|
|
|
raise Discourse::InvalidAccess.new('invalid referer host') if URI(request.referer || '').host != SiteSetting.embeddable_host
|
2014-01-03 00:32:50 +08:00
|
|
|
end
|
2014-01-01 03:37:43 +08:00
|
|
|
|
|
|
|
response.headers['X-Frame-Options'] = "ALLOWALL"
|
|
|
|
rescue URI::InvalidURIError
|
|
|
|
raise Discourse::InvalidAccess.new('invalid referer host')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|