Class: EmbedController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- EmbedController
- Includes:
- TopicQueryParams
- Defined in:
- app/controllers/embed_controller.rb
Constant Summary
Constants inherited from ApplicationController
ApplicationController::CHALLENGE_KEY, ApplicationController::HONEYPOT_KEY, ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
Constants included from CanonicalURL::ControllerExtensions
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary collapse
Methods included from TopicQueryParams
Methods inherited from ApplicationController
#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #login_method, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale
Methods included from VaryHeader
Methods included from ThemeResolver
Methods included from ReadOnlyMixin
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, #get_or_check_readonly_mode, #get_or_check_staff_writes_only_mode, included, #staff_writes_only_mode?
Methods included from Hijack
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
Methods included from JsonError
Methods included from CanonicalURL::ControllerExtensions
#canonical_url, #default_canonical, included
Methods included from CurrentUser
#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session
Instance Method Details
#comments ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/embed_controller.rb', line 79 def comments = params[:embed_url] = params[:discourse_username] = params[:topic_id]&.to_i unless || EmbeddableHost.url_allowed?() raise Discourse::InvalidAccess.new("invalid embed host") end if .present? topic_id = TopicEmbed.() else topic_id = params[:topic_id].to_i end response.headers["X-Robots-Tag"] = "noindex, indexifembedded" if topic_id @topic_view = TopicView.new( topic_id, current_user, limit: SiteSetting., only_regular: true, exclude_first: true, exclude_deleted_users: true, exclude_hidden: true, ) raise Discourse::NotFound if @topic_view.blank? @posts_left = 0 @second_post_url = "#{@topic_view.topic.url}/2" @reply_count = @topic_view.filtered_posts.count - 1 @reply_count = 0 if @reply_count < 0 @posts_left = @reply_count - SiteSetting. if @reply_count > SiteSetting. elsif .present? Jobs.enqueue( :retrieve_topic, user_id: current_user.try(:id), embed_url: , author_username: , referer: request.env["HTTP_REFERER"], ) render "loading" end discourse_expires_in 1.minute end |
#count ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/controllers/embed_controller.rb', line 137 def count = params[:embed_url] by_url = {} if .present? urls = .map { |u| u.sub(/#discourse-comments\z/, "").sub(%r{/\z}, "") } = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic) .each do |te| url = te. url = "#{url}#discourse-comments" if params[:embed_url].exclude?(url) if te.topic.present? by_url[url] = I18n.t("embed.replies", count: te.topic.posts_count - 1) else by_url[url] = I18n.t("embed.replies", count: 0) end end end render json: { counts: by_url }, callback: params[:callback] end |
#info ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'app/controllers/embed_controller.rb', line 128 def info = params.require(:embed_url) @topic_embed = TopicEmbed.where(embed_url: ).first raise Discourse::NotFound if @topic_embed.nil? render_serialized(@topic_embed, TopicEmbedSerializer, root: false) end |
#topics ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/embed_controller.rb', line 22 def topics discourse_expires_in 1.minute unless SiteSetting. render "embed_topics_error", status: 400 return end if @embed_id = params[:discourse_embed_id] raise Discourse::InvalidParameters.new(:embed_id) unless @embed_id =~ /\Ade\-[a-zA-Z0-9]+\z/ end if @embed_class = params[:embed_class] unless @embed_class =~ /\A[a-zA-Z0-9\-_]+\z/ raise Discourse::InvalidParameters.new(:embed_class) end end response.headers["X-Robots-Tag"] = "noindex, indexifembedded" if params.has_key?(:template) && params[:template] == "complete" @template = "complete" else @template = "basic" end = if params.has_key?(:per_page) [:per_page] = [params[:per_page].to_i, SiteSetting.].min end if params[:allow_create] @allow_create = true create_url_params = {} create_url_params[:category_id] = params[:category] if params[:category].present? create_url_params[:tags] = params[:tags] if params[:tags].present? @create_url = "#{Discourse.base_url}/new-topic?#{create_url_params.to_query}" end topic_query = TopicQuery.new(current_user, ) top_period = params[:top_period] begin TopTopic.validate_period(top_period) valid_top_period = true rescue Discourse::InvalidParameters valid_top_period = false end @list = if valid_top_period topic_query.list_top_for(top_period) else topic_query.list_latest end end |