闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.3 KiB

  1. # frozen_string_literal: true
  2. class AboutController < ApplicationController
  3. include RegistrationSpamConcern
  4. layout 'public'
  5. # before_action :require_open_federation!, only: [:show, :more]
  6. before_action :set_body_classes, only: :show
  7. before_action :set_instance_presenter
  8. before_action :set_expires_in, only: [:more, :terms]
  9. before_action :set_registration_form_time, only: :show
  10. before_action :authenticate_user!, only: [:jump, :my_data]
  11. skip_before_action :require_functional!, only: [:more, :terms]
  12. def show; end
  13. def more
  14. flash.now[:notice] = I18n.t('about.instance_actor_flash') if params[:instance_actor]
  15. toc_generator = TOCGenerator.new(@instance_presenter.site_extended_description)
  16. @contents = toc_generator.html
  17. @table_of_contents = toc_generator.toc
  18. @blocks = DomainBlock.with_user_facing_limitations.by_severity if display_blocks?
  19. end
  20. def terms; end
  21. def jump
  22. @jump_url = "https://#{request.fullpath[6..-1]}"
  23. end
  24. def my_data
  25. @uid = params[:user_id]
  26. if @uid and current_account.user.admin
  27. @account = Account.find(@uid)
  28. else
  29. @account = current_account
  30. end
  31. year = params[:year].to_i
  32. year = nil unless year > 2000
  33. @year_text = year or ''
  34. y = year ? "statuses.created_at >= '#{year}-1-1' and statuses.created_at < '#{year+1}-1-1'" : nil
  35. y2 = year ? "s2.created_at >= '#{year}-1-1' and s2.created_at < '#{year+1}-1-1'" : nil
  36. yf = year ? "favourites.created_at >='#{year}-1-1' and favourites.created_at < '#{year+1}-1-1'" : nil
  37. def raw_to_list(r)
  38. r.map{|k,v| {:account => Account.find(k), :num => v.to_s}}
  39. end
  40. @total = @account.statuses.where(y).count
  41. @most_times = @account.statuses.where(y).group('cast (created_at as date)').reorder('count_id desc').limit(1).count(:id).map{ |k,v| {:date => k.to_s, :num => v.to_s}}
  42. @most_fav = @account.statuses.where(y).joins(:status_stat).reorder('status_stats.favourites_count desc').first
  43. @like_me_most = raw_to_list(@account.statuses.where(yf).joins(:favourites).group('favourites.account_id').reorder('count_id desc').limit(5).count(:id))
  44. @i_like_most = raw_to_list(@account.favourites.where(yf).joins(:status).group('statuses.account_id').reorder('count_id desc').limit(5).count(:id))
  45. @communi_most = raw_to_list(@account.statuses.where(y).where(y2).joins('join statuses as s2 on statuses.account_id != s2.account_id and (statuses.in_reply_to_id = s2.id or s2.in_reply_to_id = statuses.id)').group('s2.account_id').reorder('count_id desc').limit(5).count(:id))
  46. end
  47. helper_method :display_blocks?
  48. helper_method :display_blocks_rationale?
  49. helper_method :public_fetch_mode?
  50. helper_method :new_user
  51. private
  52. def require_open_federation!
  53. not_found if whitelist_mode?
  54. end
  55. def display_blocks?
  56. Setting.show_domain_blocks == 'all' || (Setting.show_domain_blocks == 'users' && user_signed_in?)
  57. end
  58. def display_blocks_rationale?
  59. Setting.show_domain_blocks_rationale == 'all' || (Setting.show_domain_blocks_rationale == 'users' && user_signed_in?)
  60. end
  61. def new_user
  62. User.new.tap do |user|
  63. user.build_account
  64. user.build_invite_request
  65. end
  66. end
  67. def set_instance_presenter
  68. @instance_presenter = InstancePresenter.new
  69. end
  70. def set_body_classes
  71. @hide_navbar = true
  72. end
  73. def set_expires_in
  74. expires_in 0, public: true
  75. end
  76. end