Module: WpWrapper::Modules::Plugins::W3TotalCache

Included in:
WpWrapper::Modules::Plugins
Defined in:
lib/wp_wrapper/modules/plugins/w3_total_cache.rb

Instance Method Summary collapse

Instance Method Details

#activate_configurationObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/wp_wrapper/modules/plugins/w3_total_cache.rb', line 130

def activate_configuration
   unless logged_in?
  
  url         =   "#{get_url(:admin)}admin.php?page=w3tc_general"
  page        =   self.mechanize_client.get_page(url)
  
  parser      =   page      ?   self.mechanize_client.get_parser(page)      :   nil
  input       =   parser    ?   parser.at_css('input[value = "deploy"]')    :   nil

  if (input)
    on_click  =   input["onclick"]
    url       =   on_click.gsub("admin.php?page=w3tc_general", url)
    url       =   url.gsub(/^document\.location\.href='/i, "").gsub(/';$/, "")
  
    puts "Will activate new W3 Total Cache-configuration. Activation url: #{url}"
  
    self.http_client.retrieve_raw_content(url)
  end
end

#configure_browser_cacheObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/wp_wrapper/modules/plugins/w3_total_cache.rb', line 104

def configure_browser_cache
   unless logged_in?
  
  options                   =   {}

  url                       =   "admin.php?page=w3tc_browsercache"
  form_identifier           =   {:action => /admin\.php\?page=w3tc_browsercache/i, :index => 1}
  button_identifier         =   {:name => 'w3tc_default_save_and_flush'}

  sections                  =   [
    :cssjs, :html, :other
  ]

  sections.each do |section|
    section_options         =   {
      "browsercache__#{section}__expires"           =>    {:checked   =>  true,               :type   =>  :checkbox}, 
      "browsercache__#{section}__cache__control"    =>    {:checked   =>  true,               :type   =>  :checkbox},
      "browsercache__#{section}__etag"              =>    {:checked   =>  true,               :type   =>  :checkbox},
    }
  
    options.merge!(section_options)
  end

  return set_options_and_submit(url, form_identifier, options)
end

#configure_general_settings(caching_mechanism, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
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
# File 'lib/wp_wrapper/modules/plugins/w3_total_cache.rb', line 14

def configure_general_settings(caching_mechanism, options = {})
   unless logged_in?
  
  caching_options           =   {}
  cache_sections            =   [:pg, :db, :object]

  url                       =   "admin.php?page=w3tc_general"
  form_identifier           =   {:id => 'w3tc_form'}
  button_identifier         =   {:name => 'w3tc_default_save_and_flush'}

  varnish_server            =   options.fetch(:varnish_server, "localhost")

  cache_sections.each do |cache_section|
    section_options         =   {
      "#{cache_section}cache__enabled"    =>    {:checked   =>  true,               :type   =>  :checkbox}, 
      "#{cache_section}cache__engine"     =>    {:value     =>  caching_mechanism,  :type   =>  :select}
    }
  
    caching_options.merge!(section_options)
  end

  minify_options            =   {
    "minify__enabled"    =>    {:checked   =>  true,               :type   =>  :checkbox}, 
    "minify__engine"     =>    {:value     =>  caching_mechanism,  :type   =>  :select},
  }

  caching_options.merge!(minify_options)

  browser_cache_options     =   {
    "browsercache__enabled"          =>    {:checked   =>  true,               :type   =>  :checkbox},
  }

  caching_options.merge!(browser_cache_options)

  varnish_options           =   {
    "varnish__enabled"               =>    {:checked   =>  true,               :type   =>  :checkbox},
    "varnish__servers"               =>    {:value     =>  varnish_server,     :type   =>  :input}
  }

  caching_options.merge!(varnish_options)
  
  fragment_options            =   {
    "fragmentcache___engine"         =>    {:value     =>  caching_mechanism,  :type   =>  :select},
  }

  caching_options.merge!(fragment_options)

  return set_options_and_submit(url, form_identifier, caching_options, button_identifier)
end

#configure_minification(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/wp_wrapper/modules/plugins/w3_total_cache.rb', line 78

def configure_minification(options = {})
   unless logged_in?
  
  url                       =   "admin.php?page=w3tc_minify"
  form_identifier           =   {:action => /admin\.php\?page=w3tc_minify/i, :index => 1}
  button_identifier         =   {:name => 'w3tc_default_save_and_flush'}
  
  minify_html               =   options.fetch(:html, :enable).to_sym.eql?(:enable)
  minify_inline_css         =   options.fetch(:inline_css, :enable).to_sym.eql?(:enable)
  minify_inline_js          =   options.fetch(:inline_js, :enable).to_sym.eql?(:enable)

  minify_js                 =   options.fetch(:js, :disable).to_sym.eql?(:enable)
  minify_css                =   options.fetch(:css, :disable).to_sym.eql?(:enable)

  options                   =   {
    "minify__html__enable"                           =>    {:checked   =>  minify_html,          :type   =>  :checkbox},
    "minify__html__inline__css"                      =>    {:checked   =>  minify_inline_css,    :type   =>  :checkbox},
    "minify__html__inline__js"                       =>    {:checked   =>  minify_inline_js,     :type   =>  :checkbox},
    
    "minify__js__enable"                             =>    {:checked   =>  minify_js,            :type   =>  :checkbox},
    "minify__css__enable"                            =>    {:checked   =>  minify_css,           :type   =>  :checkbox},
  }

  return set_options_and_submit(url, form_identifier, options, button_identifier)
end

#configure_page_cacheObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wp_wrapper/modules/plugins/w3_total_cache.rb', line 64

def configure_page_cache
   unless logged_in?
  
  url                       =   "admin.php?page=w3tc_pgcache"
  form_identifier           =   {:action => /admin\.php\?page=w3tc_pgcache/i, :index => 1}
  button_identifier         =   {:name => 'w3tc_default_save_and_flush'}

  options                   =   {
    "pgcache__cache__feed"            =>    {:checked   =>  true,                 :type   =>  :checkbox},
  }

  return set_options_and_submit(url, form_identifier, options, button_identifier)
end

#configure_w3_total_cache(caching_mechanism = :memcached, options = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/wp_wrapper/modules/plugins/w3_total_cache.rb', line 6

def configure_w3_total_cache(caching_mechanism = :memcached, options = {})
  configure_general_settings(caching_mechanism, options)
  configure_page_cache
  configure_minification(options.fetch(:minify, {}))
  configure_browser_cache
  activate_configuration
end