application_helper.rb 2.47 KB
Newer Older
1 2
# frozen_string_literal: true

danielgrippi's avatar
danielgrippi committed
3
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
Raphael's avatar
Raphael committed
4
#   licensed under the Affero General Public License version 3 or later.  See
Raphael's avatar
Raphael committed
5
#   the COPYRIGHT file.
6

Raphael Sofaer's avatar
Raphael Sofaer committed
7
module ApplicationHelper
8
  def pod_name
9
    AppConfig.settings.pod_name
10 11
  end

12
  def pod_version
13
    AppConfig.version.number
14 15
  end

16
  def changelog_url
17 18
    return AppConfig.settings.changelog_url.get if AppConfig.settings.changelog_url.present?

19
    url = "https://github.com/diaspora/diaspora/blob/master/Changelog.md"
20 21 22
    return url if AppConfig.git_revision.blank?

    url.sub("/master/", "/#{AppConfig.git_revision}/")
23 24
  end

25 26 27 28
  def source_url
    AppConfig.settings.source_url.presence || "#{root_path.chomp('/')}/source.tar.gz"
  end

29 30 31 32 33 34
  def donations_enabled?
    AppConfig.settings.paypal_donations.enable? ||
    AppConfig.settings.liberapay_username.present? ||
    AppConfig.bitcoin_donation_address.present?
  end

35
  def timeago(time, options={})
Steffen van Bergerem's avatar
Steffen van Bergerem committed
36
    timeago_tag(time, options.merge(:class => 'timeago', :title => time.iso8601, :force => true)) if time
37 38
  end

Florian Staudacher's avatar
Florian Staudacher committed
39 40 41 42
  def bookmarklet_code(height=400, width=620)
    "javascript:" +
      BookmarkletRenderer.body +
      "bookmarklet('#{bookmarklet_url}', #{width}, #{height});"
43 44
  end

45
  def all_services_connected?
Jonne Haß's avatar
Jonne Haß committed
46
    current_user.services.size == AppConfig.configured_services.size
47
  end
48

49 50 51 52
  def service_unconnected?(service)
    AppConfig.show_service?(service, current_user) && current_user.services.none? {|x| x.provider == service }
  end

53
  def popover_with_close_html(without_close_html)
Steffen van Bergerem's avatar
Steffen van Bergerem committed
54
    without_close_html + link_to('×'.html_safe, "#", :class => 'close')
55
  end
56

Steven Hancock's avatar
Steven Hancock committed
57 58 59 60
  # Require jQuery from CDN if possible, falling back to vendored copy, and require
  # vendored jquery_ujs
  def jquery_include_tag
    buf = []
Jonne Haß's avatar
Jonne Haß committed
61
    if AppConfig.privacy.jquery_cdn?
cmrd Senya's avatar
cmrd Senya committed
62
      version = Jquery::Rails::JQUERY_3_VERSION
Benjamin Neff's avatar
Benjamin Neff committed
63
      buf << [javascript_include_tag("//code.jquery.com/jquery-#{version}.min.js")]
cmrd Senya's avatar
cmrd Senya committed
64 65 66
      buf << [
        nonced_javascript_tag("!window.jQuery && document.write(unescape('#{j javascript_include_tag('jquery3')}'));")
      ]
Steven Hancock's avatar
Steven Hancock committed
67
    else
cmrd Senya's avatar
cmrd Senya committed
68
      buf << [javascript_include_tag("jquery3")]
Steven Hancock's avatar
Steven Hancock committed
69
    end
Benjamin Neff's avatar
Benjamin Neff committed
70 71 72
    buf << [javascript_include_tag("jquery_ujs")]
    buf << [nonced_javascript_tag("jQuery.ajaxSetup({'cache': false});")]
    buf << [nonced_javascript_tag("$.fx.off = true;")] if Rails.env.test?
Steven Hancock's avatar
Steven Hancock committed
73 74
    buf.join("\n").html_safe
  end
lislis's avatar
lislis committed
75 76 77 78 79

  def qrcode_uri
    label = current_user.username
    current_user.otp_provisioning_uri(label, issuer: AppConfig.environment.url)
  end
Raphael Sofaer's avatar
Raphael Sofaer committed
80
end