Module: Plugins::CamaleonSitemapCustomizer::MainHelper

Included in:
AdminController
Defined in:
app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

methods accessible from views



5
6
7
8
9
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 5

def self.included(klass)
  klass.helper_method [:camaleon_sitemap_customizer_google_submit_url]
rescue
  ""
end

Instance Method Details

#camaleon_sitemap_customizer_form(args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 55

def camaleon_sitemap_customizer_form(args)
  args[:extra_settings] << "
    <div class='form-group'>
      <label for='options_hide_in_sitemap' class='control-label'>
      <input type='checkbox' name='options[hide_in_sitemap]' id='options_hide_in_sitemap' value='true' #{"checked" if args[:post].get_option("hide_in_sitemap").present?}>
      &nbsp;&nbsp;#{cama_t("hide_in_sitemap")}?
      </label>
    </div>
  "
end

#camaleon_sitemap_customizer_google_submit_urlObject



66
67
68
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 66

def camaleon_sitemap_customizer_google_submit_url
  "https://www.google.com/ping?sitemap=#{cama_sitemap_url}"
end

#camaleon_sitemap_customizer_on_active(plugin) ⇒ Object



11
12
13
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 11

def camaleon_sitemap_customizer_on_active(plugin)
  skip_posts plugin
end

#camaleon_sitemap_customizer_on_inactive(plugin) ⇒ Object



15
16
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 15

def camaleon_sitemap_customizer_on_inactive(plugin)
end

#camaleon_sitemap_customizer_on_plugin_options(args) ⇒ Object



22
23
24
25
26
27
28
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 22

def camaleon_sitemap_customizer_on_plugin_options(args)
  args[:links] << [
    link_to("Settings", admin_plugins_camaleon_sitemap_customizer_settings_path),
    link_to("View Sitemap", cama_sitemap_url, target: :blank),
    link_to("Submit Sitemap to Google", camaleon_sitemap_customizer_google_submit_url, target: :blank)
  ]
end

#camaleon_sitemap_customizer_on_upgrade(plugin) ⇒ Object



18
19
20
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 18

def camaleon_sitemap_customizer_on_upgrade(plugin)
  skip_posts plugin
end

#camaleon_sitemap_customizer_save(args) ⇒ Object



70
71
72
73
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 70

def camaleon_sitemap_customizer_save(args)
  args[:post].set_option "hide_in_sitemap", false unless params.dig(:options, "hide_in_sitemap").present?
  skip_posts current_plugin
end

#camaleon_sitemap_customizer_submit_sitemap(_args) ⇒ Object



75
76
77
78
79
80
81
82
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 75

def camaleon_sitemap_customizer_submit_sitemap(_args)
  plugin = current_site.get_plugin("camaleon_sitemap_customizer").decorate
  return unless plugin.get_option "submit_changes_to_google"
  CamaleonSitemapCustomizer::SubmitSitemapJob.perform_later camaleon_sitemap_customizer_google_submit_url
  flash[:alert] = "Sitemap submitted."
rescue => e
  flash[:alert] = e.message
end

#customize_sitemap(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/plugins/camaleon_sitemap_customizer/main_helper.rb', line 30

def customize_sitemap(args)
  # completely excluded content types
  args[:skip_posttype_ids] += current_plugin.get_option("skip_post_types")&.map(&:to_i).presence || []
  args[:skip_posttype_ids].each do |ptype|
    # leave out post pages within content type
    args[:skip_post_ids] += current_site.the_posts(ptype).map(&:id)
    # leave out category pages within content type
    args[:skip_cat_ids] += current_site.the_categories(ptype).map(&:id)
  end

  # excluded list pages
  args[:skip_posttype_ids] += current_plugin.get_option("skip_post_list_types")&.map(&:to_i).presence || []
  args[:skip_cat_ids] += select_categories
  args[:skip_tag_ids] += current_site.the_tags.map(&:id) if current_plugin.get_option("skip_tags")

  # exclude individual posts via post editor option
  args[:skip_post_ids] += current_plugin.get_option("skip_posts").presence || []

  # exclude redundant home page url
  args[:skip_post_ids] << current_site.options.dig(:home_page).to_i if current_plugin.get_option("skip_home") && current_site.options.dig(:home_page).present?

  # use caching in sitemap
  args[:render] = cached_sitemap_template if current_plugin.get_option("cache").present?
end