Skip to Content Skip to Search
Methods
B
D
I
M
P
R
T
U
V

Instance Public methods

body_class()

# File engines/member/app/helpers/member/application_helper.rb, line 43
def body_class
  [controller_name, [controller_name, action_name].join("-")].join(" ")
end

designer_font_styles(request)

# File engines/member/app/helpers/member/application_helper.rb, line 159
def designer_font_styles(request)
  Service::BrowserInfoManager.new(request.user_agent).font_styles
end

invisible_recaptcha_field()

Insert invisible recaptcha content

Intercepts the submit event and requests recaptcha verification

If the user passes verification automatically

invoke the callback

If the user does not pass verification automatically

Until Present a challenge and challenge succeeeds
  invoke the callback

callback removes submit listener and submits the form for realsizes

# File engines/member/app/helpers/member/application_helper.rb, line 70
    def invisible_recaptcha_field
      return "" if Rails.env.test?

      id = SecureRandom.hex
      site_key = Rails.application.secrets.recaptcha["site_key"]
      recaptcha_opts = {
        sitekey: site_key,
        callback: "callback#{id}",
        size: "invisible"
      }

      script_node = javascript_tag(<<~JS)
        var callback#{id} = (function(window, document) {
          var currentScript = document.currentScript;
          var currentScriptForm = currentScript.parentElement;

          while (currentScriptForm && currentScriptForm.nodeName !== 'FORM') {
            currentScriptForm = currentScriptForm.parentElement;
          };

          var submitListener = function(ev) {
            if (ev.target === currentScriptForm) {
              ev.preventDefault();
              ev.stopPropagation();
              console.log('ReCaptcha form submission intercepted');

              window.grecaptcha.execute();
            }

            // Remove this after Rails v5 upgrade
            setTimeout(function() {
              var disabledWithEls = currentScriptForm.querySelectorAll('[disabled]')
              for (var i = 0; i < disabledWithEls.length; i++) {
                disabledWithEls[i].removeAttribute('disabled')
              }
            }, 2000)
            // END Remove this after Rails v5 upgrade
          }

          document.addEventListener('submit', submitListener);

          return function(token) {
            // Verified good, remove submit intercept
            console.log('ReCaptcha passed, submitting form');
            document.removeEventListener('submit', submitListener);

            // Remove this after Rails v5 upgrade
            var disabledEls = currentScriptForm.querySelectorAll('[data-disable-with]')
            for (var i = 0; i < disabledEls.length; i++) {
              disabledEls[i].setAttribute('disabled', true)
            }
            // END Remove this after Rails v5 upgrade

            currentScriptForm.submit();
          }
        })(window, document)
      JS

      recaptcha_script_node = javascript_tag(
        "",
        id: :recaptcha,
        src: "https://www.google.com/recaptcha/api.js",
        async: true,
        defer: true
      )

      safe_join([
        script_node,
        recaptcha_script_node,
        content_tag(:div, "", class: "g-recaptcha", data: recaptcha_opts)
      ])
    end

member_custom_fields()

# File engines/member/app/helpers/member/application_helper.rb, line 47
def member_custom_fields
  current_site.custom_fields.select { |f| f.display? && current_member.has_plan_from_field?(f) }
end

plan_upgrade_message(member, plan)

# File engines/member/app/helpers/member/application_helper.rb, line 15
def plan_upgrade_message(member, plan)
  upcoming = upcoming_invoice(plan)
  tags = []

  if upcoming.errors.empty?
    upcoming_message = upcoming.message

    if upcoming_message.present?
      tags << content_tag(:div, class: "upgrade-message") {
        upcoming_message.html_safe
      }
    end
  else
    content_tag(:div, class: "alert alert-error") do
      upcoming.errors.full_messages.join("")
    end
  end

  safe_join(tags)
end

recaptcha_field()

# File engines/member/app/helpers/member/application_helper.rb, line 51
def recaptcha_field
  if params[:recaptcha] == "visible"
    visible_recaptcha_field
  else
    invisible_recaptcha_field
  end
end

te(key, options = {})

# File engines/member/app/helpers/member/application_helper.rb, line 3
def te(key, options = {})
  cache_key = Digest::SHA256.hexdigest("#{current_site.id}/#{current_site.updated_at}/#{options}")
  Rails.cache.fetch("translations/#{key}/#{cache_key}") do
    default = current_site ? {site_id: current_site.id} : {}
    if key.include?("pop_up_messages")
      reply_to_address = current_site.email_settings.reply_to_address
      default[:contact_email] = reply_to_address
    end
    allowed_html_filter I18n.translate("member.#{key}", **default.merge(options))
  end
end

upcoming_invoice(plan)

# File engines/member/app/helpers/member/application_helper.rb, line 36
def upcoming_invoice(plan)
  @upcoming ||= Billing::UpcomingInvoice.new(
    member: current_member,
    new_plan: plan.payment_gateway_id
  )
end

visible_recaptcha_field()

# File engines/member/app/helpers/member/application_helper.rb, line 143
def visible_recaptcha_field
  site_key = Rails.application.secrets.recaptcha["site_key"]

  recaptcha_script_node = javascript_tag(
    "",
    id: :recaptcha,
    src: "https://www.google.com/recaptcha/api.js",
    async: true,
    defer: true
  )
  safe_join([
    recaptcha_script_node,
    content_tag(:div, "", :class => "g-recaptcha", "data-sitekey" => site_key)
  ])
end