wp_wrapper 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
 - data/lib/wp_wrapper/client.rb +1 -2
 - data/lib/wp_wrapper/modules/authorization.rb +34 -18
 - data/lib/wp_wrapper/modules/plugins/w3_total_cache.rb +16 -0
 - data/lib/wp_wrapper/modules/plugins/wordpress_seo.rb +150 -87
 - data/lib/wp_wrapper/modules/plugins.rb +26 -29
 - data/lib/wp_wrapper/modules/setup.rb +3 -3
 - data/lib/wp_wrapper/modules/themes.rb +32 -18
 - data/lib/wp_wrapper/modules/upgrade.rb +1 -1
 - data/lib/wp_wrapper.rb +2 -2
 - data/wp_wrapper.gemspec +3 -3
 - metadata +7 -8
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3e362d33e278825bbab4a85b2161ba17b53591b42b8b2a2424e99e0a9a0ff78c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1ca4a325336463bdc0246072ab56b7a8d0ff2a7b573b26a7ed195a3f8b86c9d1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 980890aeb6515d2835261e7ae34757abfcb1f48ec614b157752f3871f00e7ff9cec4ac421513724c11578e321459c5977da0974b180ad5082cb77cbfe2eca795
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 15cac8b3a3464d788664c09518b815793888df55c8a50d71a182e5e162a1107c19c58284fa54fa3bcb4c1755e86fd22abf00a64df68015e9709e59a411e3d4c5
         
     | 
    
        data/lib/wp_wrapper/client.rb
    CHANGED
    
    | 
         @@ -57,8 +57,7 @@ module WpWrapper 
     | 
|
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
                def set_options_and_submit(url, form_identifier = {}, fields = {}, submit_identifier = :first, options = {})
         
     | 
| 
       59 
59 
     | 
    
         
             
                  login unless logged_in?
         
     | 
| 
       60 
     | 
    
         
            -
                  
         
     | 
| 
       61 
     | 
    
         
            -
                  form_page_url   =   "#{get_url(:admin)}/#{url}"
         
     | 
| 
      
 60 
     | 
    
         
            +
                  form_page_url   =   "#{get_url(:admin)}#{url}"
         
     | 
| 
       62 
61 
     | 
    
         
             
                  response        =   self.mechanize_client.set_form_and_submit(form_page_url, form_identifier, submit_identifier, fields, options)
         
     | 
| 
       63 
62 
     | 
    
         
             
                end
         
     | 
| 
       64 
63 
     | 
    
         | 
| 
         @@ -1,47 +1,63 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module WpWrapper
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Modules
         
     | 
| 
       3 
     | 
    
         
            -
                
         
     | 
| 
       4 
3 
     | 
    
         
             
                module Authorization
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                  def login(retries  
     | 
| 
       7 
     | 
    
         
            -
                    success                 =   logged_in?
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                    if  
     | 
| 
      
 5 
     | 
    
         
            +
                  def login(force: false, retries: 3)
         
     | 
| 
      
 6 
     | 
    
         
            +
                    success                 =   force ? false : logged_in?
         
     | 
| 
      
 7 
     | 
    
         
            +
                  
         
     | 
| 
      
 8 
     | 
    
         
            +
                    if !success
         
     | 
| 
       10 
9 
     | 
    
         
             
                      login_page            =   self.mechanize_client.open_url(get_url(:admin))
         
     | 
| 
       11 
10 
     | 
    
         
             
                      agent                 =   self.mechanize_client.agent
         
     | 
| 
       12 
11 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                      if  
     | 
| 
       14 
     | 
    
         
            -
                         
     | 
| 
      
 12 
     | 
    
         
            +
                      if login_page
         
     | 
| 
      
 13 
     | 
    
         
            +
                        upgraded            =   upgrade_if_necessary(login_page)
         
     | 
| 
      
 14 
     | 
    
         
            +
                        login(retries) if upgraded
         
     | 
| 
      
 15 
     | 
    
         
            +
                        
         
     | 
| 
      
 16 
     | 
    
         
            +
                        login_form          =   login_page.form_with(name: 'loginform')
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                        if  
     | 
| 
       17 
     | 
    
         
            -
                          login_form.field_with(: 
     | 
| 
       18 
     | 
    
         
            -
                          login_form.field_with(: 
     | 
| 
      
 18 
     | 
    
         
            +
                        if login_form
         
     | 
| 
      
 19 
     | 
    
         
            +
                          login_form.field_with(name: 'log').value = self.username
         
     | 
| 
      
 20 
     | 
    
         
            +
                          login_form.field_with(name: 'pwd').value = self.password
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
22 
     | 
    
         
             
                          begin
         
     | 
| 
       21 
23 
     | 
    
         
             
                            logged_in_page  =   login_form.submit
         
     | 
| 
       22 
     | 
    
         
            -
                            log_out_link    =   logged_in_page.link_with(: 
     | 
| 
      
 24 
     | 
    
         
            +
                            log_out_link    =   logged_in_page.link_with(href: /wp-login\.php\?action=logout/i)
         
     | 
| 
       23 
25 
     | 
    
         
             
                            self.logged_in  =   !log_out_link.nil?
         
     | 
| 
       24 
26 
     | 
    
         
             
                            success         =   self.logged_in
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                            puts "#{Time.now}: Url: #{self.url}. Successfully logged in? #{self.logged_in}"
         
     | 
| 
      
 28 
     | 
    
         
            +
                            puts "[WpWrapper::Modules::Authorization] - #{Time.now}: Url: #{self.url}. Successfully logged in? #{self.logged_in}"
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
30 
     | 
    
         
             
                          rescue Exception => e
         
     | 
| 
       29 
     | 
    
         
            -
                            puts "#{Time.now}: Url: #{self.url}. Failed to login. Error Class: #{e.class.name}. Error Message: #{e.message}"
         
     | 
| 
       30 
     | 
    
         
            -
                            login(retries - 1) if retries > 0
         
     | 
| 
      
 31 
     | 
    
         
            +
                            puts "[WpWrapper::Modules::Authorization] - #{Time.now}: Url: #{self.url}. Failed to login. Error Class: #{e.class.name}. Error Message: #{e.message}"
         
     | 
| 
      
 32 
     | 
    
         
            +
                            login(force: force, retries: retries - 1) if retries > 0
         
     | 
| 
       31 
33 
     | 
    
         
             
                            raise WpWrapper::FailedLoginException, "Failed to login" if retries <= 0 && self.reraise_exceptions
         
     | 
| 
       32 
34 
     | 
    
         
             
                          end
         
     | 
| 
       33 
35 
     | 
    
         | 
| 
       34 
36 
     | 
    
         
             
                        else
         
     | 
| 
       35 
     | 
    
         
            -
                          puts " 
     | 
| 
       36 
     | 
    
         
            -
                          login(retries - 1) if retries > 0
         
     | 
| 
      
 37 
     | 
    
         
            +
                          puts "[WpWrapper::Modules::Authorization] - #{Time.now}: Url: #{self.url}. Something's broken! Can't find wp-admin login form! Retrying...\n\n"
         
     | 
| 
      
 38 
     | 
    
         
            +
                          login(force: force, retries: retries - 1) if retries > 0
         
     | 
| 
      
 39 
     | 
    
         
            +
                          raise WpWrapper::FailedLoginException, "Failed to login" if retries <= 0 && self.reraise_exceptions
         
     | 
| 
       37 
40 
     | 
    
         
             
                        end
         
     | 
| 
       38 
41 
     | 
    
         
             
                      end
         
     | 
| 
       39 
42 
     | 
    
         
             
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    
         
     | 
| 
      
 44 
     | 
    
         
            +
                    success         =   !(retries <= 0)
         
     | 
| 
       40 
45 
     | 
    
         | 
| 
       41 
46 
     | 
    
         
             
                    return success
         
     | 
| 
       42 
47 
     | 
    
         
             
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
                  
         
     | 
| 
      
 49 
     | 
    
         
            +
                  def upgrade_if_necessary(page)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    upgraded        =   false
         
     | 
| 
      
 51 
     | 
    
         
            +
                    upgrade_link    =   page.link_with(href: /upgrade\.php/i)
         
     | 
| 
      
 52 
     | 
    
         
            +
                    
         
     | 
| 
      
 53 
     | 
    
         
            +
                    if upgrade_link
         
     | 
| 
      
 54 
     | 
    
         
            +
                      upgrade_link.click
         
     | 
| 
      
 55 
     | 
    
         
            +
                      upgraded      =   true
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
                    
         
     | 
| 
      
 58 
     | 
    
         
            +
                    return upgraded
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
       43 
60 
     | 
    
         | 
| 
       44 
61 
     | 
    
         
             
                end
         
     | 
| 
       45 
     | 
    
         
            -
                
         
     | 
| 
       46 
62 
     | 
    
         
             
              end
         
     | 
| 
       47 
     | 
    
         
            -
            end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -12,6 +12,8 @@ module WpWrapper 
     | 
|
| 
       12 
12 
     | 
    
         
             
                    end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                    def configure_general_settings(caching_mechanism, options = {})
         
     | 
| 
      
 15 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
      
 16 
     | 
    
         
            +
                      
         
     | 
| 
       15 
17 
     | 
    
         
             
                      caching_options           =   {}
         
     | 
| 
       16 
18 
     | 
    
         
             
                      cache_sections            =   [:pg, :db, :object]
         
     | 
| 
       17 
19 
     | 
    
         | 
| 
         @@ -49,11 +51,19 @@ module WpWrapper 
     | 
|
| 
       49 
51 
     | 
    
         
             
                      }
         
     | 
| 
       50 
52 
     | 
    
         | 
| 
       51 
53 
     | 
    
         
             
                      caching_options.merge!(varnish_options)
         
     | 
| 
      
 54 
     | 
    
         
            +
                      
         
     | 
| 
      
 55 
     | 
    
         
            +
                      fragment_options            =   {
         
     | 
| 
      
 56 
     | 
    
         
            +
                        "fragmentcache___engine"         =>    {:value     =>  caching_mechanism,  :type   =>  :select},
         
     | 
| 
      
 57 
     | 
    
         
            +
                      }
         
     | 
| 
      
 58 
     | 
    
         
            +
                    
         
     | 
| 
      
 59 
     | 
    
         
            +
                      caching_options.merge!(fragment_options)
         
     | 
| 
       52 
60 
     | 
    
         | 
| 
       53 
61 
     | 
    
         
             
                      return set_options_and_submit(url, form_identifier, caching_options, button_identifier)
         
     | 
| 
       54 
62 
     | 
    
         
             
                    end
         
     | 
| 
       55 
63 
     | 
    
         | 
| 
       56 
64 
     | 
    
         
             
                    def configure_page_cache
         
     | 
| 
      
 65 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
      
 66 
     | 
    
         
            +
                      
         
     | 
| 
       57 
67 
     | 
    
         
             
                      url                       =   "admin.php?page=w3tc_pgcache"
         
     | 
| 
       58 
68 
     | 
    
         
             
                      form_identifier           =   {:action => /admin\.php\?page=w3tc_pgcache/i, :index => 1}
         
     | 
| 
       59 
69 
     | 
    
         
             
                      button_identifier         =   {:name => 'w3tc_default_save_and_flush'}
         
     | 
| 
         @@ -66,6 +76,8 @@ module WpWrapper 
     | 
|
| 
       66 
76 
     | 
    
         
             
                    end
         
     | 
| 
       67 
77 
     | 
    
         | 
| 
       68 
78 
     | 
    
         
             
                    def configure_minification(options = {})
         
     | 
| 
      
 79 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
      
 80 
     | 
    
         
            +
                      
         
     | 
| 
       69 
81 
     | 
    
         
             
                      url                       =   "admin.php?page=w3tc_minify"
         
     | 
| 
       70 
82 
     | 
    
         
             
                      form_identifier           =   {:action => /admin\.php\?page=w3tc_minify/i, :index => 1}
         
     | 
| 
       71 
83 
     | 
    
         
             
                      button_identifier         =   {:name => 'w3tc_default_save_and_flush'}
         
     | 
| 
         @@ -90,6 +102,8 @@ module WpWrapper 
     | 
|
| 
       90 
102 
     | 
    
         
             
                    end
         
     | 
| 
       91 
103 
     | 
    
         | 
| 
       92 
104 
     | 
    
         
             
                    def configure_browser_cache
         
     | 
| 
      
 105 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
      
 106 
     | 
    
         
            +
                      
         
     | 
| 
       93 
107 
     | 
    
         
             
                      options                   =   {}
         
     | 
| 
       94 
108 
     | 
    
         | 
| 
       95 
109 
     | 
    
         
             
                      url                       =   "admin.php?page=w3tc_browsercache"
         
     | 
| 
         @@ -114,6 +128,8 @@ module WpWrapper 
     | 
|
| 
       114 
128 
     | 
    
         
             
                    end
         
     | 
| 
       115 
129 
     | 
    
         | 
| 
       116 
130 
     | 
    
         
             
                    def activate_configuration
         
     | 
| 
      
 131 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
      
 132 
     | 
    
         
            +
                      
         
     | 
| 
       117 
133 
     | 
    
         
             
                      url         =   "#{get_url(:admin)}admin.php?page=w3tc_general"
         
     | 
| 
       118 
134 
     | 
    
         
             
                      page        =   self.mechanize_client.get_page(url)
         
     | 
| 
       119 
135 
     | 
    
         | 
| 
         @@ -8,87 +8,69 @@ module WpWrapper 
     | 
|
| 
       8 
8 
     | 
    
         
             
                    def configure_wordpress_seo(language = :sv)
         
     | 
| 
       9 
9 
     | 
    
         
             
                      login unless logged_in?
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                       
     | 
| 
      
 11 
     | 
    
         
            +
                      puts "[WpWrapper::Modules::Plugins::WordpressSeo] - #{Time.now}: Starting configuration of Wordpress SEO / Yoast SEO."
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                       
     | 
| 
       14 
     | 
    
         
            -
                       
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                      enable_wordpress_seo_settings_page
         
     | 
| 
      
 14 
     | 
    
         
            +
                      configure_wordpress_seo_titles(language)
         
     | 
| 
      
 15 
     | 
    
         
            +
                      #configure_wordpress_seo_advanced_options
         
     | 
| 
      
 16 
     | 
    
         
            +
                    end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                       
     | 
| 
      
 18 
     | 
    
         
            +
                    def enable_wordpress_seo_settings_page
         
     | 
| 
      
 19 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                       
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                          case values[:type]
         
     | 
| 
       24 
     | 
    
         
            -
                            when :input
         
     | 
| 
       25 
     | 
    
         
            -
                              form[key] = values[:value]
         
     | 
| 
       26 
     | 
    
         
            -
                            when :checkbox
         
     | 
| 
       27 
     | 
    
         
            -
                              form[key] = "on" if values[:checked]
         
     | 
| 
       28 
     | 
    
         
            -
                          end
         
     | 
| 
       29 
     | 
    
         
            -
                        end
         
     | 
| 
      
 21 
     | 
    
         
            +
                      page      =   self.mechanize_client.get_page("#{get_url(:admin)}admin.php?page=wpseo_dashboard")
         
     | 
| 
      
 22 
     | 
    
         
            +
                      form      =   self.mechanize_client.get_form(page, {action: /wp-admin\/options\.php/i})
         
     | 
| 
       30 
23 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
                      options   =   {
         
     | 
| 
      
 25 
     | 
    
         
            +
                        "wpseo[enable_setting_pages]"      =>  {:type   =>  :checkbox,   :checked    =>  true},
         
     | 
| 
      
 26 
     | 
    
         
            +
                        "wpseo[show_onboarding_notice]"    =>  {:type   =>  :checkbox,   :checked    =>  false}
         
     | 
| 
      
 27 
     | 
    
         
            +
                      }
         
     | 
| 
       33 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
                      response  =   submit_wordpress_seo_form(form, options)
         
     | 
| 
       34 
30 
     | 
    
         
             
                    end
         
     | 
| 
       35 
31 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                    def  
     | 
| 
       37 
     | 
    
         
            -
                       
     | 
| 
       38 
     | 
    
         
            -
                        "wpseo_titles[noindex-author-wpseo]"  =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
       39 
     | 
    
         
            -
                        "wpseo_titles[disable-author]"        =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
       40 
     | 
    
         
            -
                      }
         
     | 
| 
       41 
     | 
    
         
            -
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
                    def configure_wordpress_seo_titles(language = :sv)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
       42 
34 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                      options 
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                      options   =   get_title_options(language)
         
     | 
| 
      
 36 
     | 
    
         
            +
                      options.merge!(get_media_options)
         
     | 
| 
      
 37 
     | 
    
         
            +
                      options.merge!(get_taxonomy_options)
         
     | 
| 
      
 38 
     | 
    
         
            +
                      options.merge!(get_archive_options)
         
     | 
| 
      
 39 
     | 
    
         
            +
                      options.merge!(get_other_options)
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                      url       =   "#{get_url(:admin)}admin.php?page=wpseo_titles"
         
     | 
| 
      
 42 
     | 
    
         
            +
                      page      =   self.mechanize_client.get_page(url)
         
     | 
| 
      
 43 
     | 
    
         
            +
                      form      =   self.mechanize_client.get_form(page, {action: /wp-admin\/options\.php/i})
         
     | 
| 
       49 
44 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                       
     | 
| 
      
 45 
     | 
    
         
            +
                      response  =   submit_wordpress_seo_form(form, options)
         
     | 
| 
       51 
46 
     | 
    
         
             
                    end
         
     | 
| 
       52 
47 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                     
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                        "wpseo_titles[title-home]"            =>  {:type   =>  :input,      :value     =>  '%%sitename%% %%page%%'},
         
     | 
| 
       57 
     | 
    
         
            -
                        "wpseo_titles[title-search]"          =>  {:type   =>  :input,      :value     =>  translate_pattern(:search, language)},
         
     | 
| 
       58 
     | 
    
         
            -
                        "wpseo_titles[title-404]"             =>  {:type   =>  :input,      :value     =>  translate_pattern(:not_found, language)}
         
     | 
| 
       59 
     | 
    
         
            -
                      }
         
     | 
| 
       60 
     | 
    
         
            -
                      
         
     | 
| 
       61 
     | 
    
         
            -
                      standard_pattern        =   '%%title%% %%page%% %%sep%% %%sitename%%'
         
     | 
| 
       62 
     | 
    
         
            -
                      standard_term_pattern   =   translate_pattern(:term, language)
         
     | 
| 
       63 
     | 
    
         
            -
                    
         
     | 
| 
       64 
     | 
    
         
            -
                      types                   =   {
         
     | 
| 
       65 
     | 
    
         
            -
                        :post           =>  {:pattern => standard_pattern,                              :noindex => false},
         
     | 
| 
       66 
     | 
    
         
            -
                        :page           =>  {:pattern => standard_pattern,                              :noindex => false},
         
     | 
| 
       67 
     | 
    
         
            -
                        :attachment     =>  {:pattern => standard_pattern,                              :noindex => true},
         
     | 
| 
       68 
     | 
    
         
            -
                        :wooframework   =>  {:pattern => standard_pattern,                              :noindex => false},
         
     | 
| 
       69 
     | 
    
         
            -
                        :category       =>  {:pattern => standard_term_pattern,                         :noindex => false},
         
     | 
| 
       70 
     | 
    
         
            -
                        :post_tag       =>  {:pattern => standard_term_pattern,                         :noindex => true},
         
     | 
| 
       71 
     | 
    
         
            -
                        :post_format    =>  {:pattern => standard_term_pattern,                         :noindex => true},
         
     | 
| 
       72 
     | 
    
         
            -
                        :author         =>  {:pattern => translate_pattern(:author, language),          :noindex => true},
         
     | 
| 
       73 
     | 
    
         
            -
                        :archive        =>  {:pattern => '%%date%% %%page%% %%sep%% %%sitename%%',      :noindex => true},
         
     | 
| 
       74 
     | 
    
         
            -
                      }
         
     | 
| 
      
 48 
     | 
    
         
            +
                    # Deprecated?
         
     | 
| 
      
 49 
     | 
    
         
            +
                    def configure_wordpress_seo_advanced_options
         
     | 
| 
      
 50 
     | 
    
         
            +
                      login unless logged_in?
         
     | 
| 
       75 
51 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
                       
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                      
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                       
     | 
| 
      
 52 
     | 
    
         
            +
                      configure_wordpress_seo_permalinks
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
                    
         
     | 
| 
      
 55 
     | 
    
         
            +
                    # Deprecated?
         
     | 
| 
      
 56 
     | 
    
         
            +
                    def configure_wordpress_seo_permalinks
         
     | 
| 
      
 57 
     | 
    
         
            +
                      url       =   "#{get_url(:admin)}admin.php?page=wpseo_advanced&tab=permalinks"
         
     | 
| 
      
 58 
     | 
    
         
            +
                      page      =   self.mechanize_client.get_page(url)
         
     | 
| 
      
 59 
     | 
    
         
            +
                      form      =   self.mechanize_client.get_form(page, {:action => /wp-admin\/options\.php/i})
         
     | 
| 
      
 60 
     | 
    
         
            +
                    
         
     | 
| 
      
 61 
     | 
    
         
            +
                      options   =   {
         
     | 
| 
      
 62 
     | 
    
         
            +
                        "wpseo_permalinks[redirectattachment]"                    =>  {:type   =>  :checkbox,   :checked    =>  true},
         
     | 
| 
      
 63 
     | 
    
         
            +
                        "wpseo_permalinks[cleanreplytocom]"                       =>  {:type   =>  :checkbox,   :checked    =>  true}
         
     | 
| 
      
 64 
     | 
    
         
            +
                      }
         
     | 
| 
       84 
65 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
                       
     | 
| 
      
 66 
     | 
    
         
            +
                      response    =   submit_wordpress_seo_form(form, options)
         
     | 
| 
       86 
67 
     | 
    
         
             
                    end
         
     | 
| 
       87 
68 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                     
     | 
| 
      
 69 
     | 
    
         
            +
                    # Deprecated?
         
     | 
| 
      
 70 
     | 
    
         
            +
                    def configure_wordpress_seo_sitemaps(not_included_post_types: [:attachment], not_included_taxonomies: [:category, :post_tag, :post_format], disable_author_sitemap: true)
         
     | 
| 
       89 
71 
     | 
    
         
             
                      login unless logged_in?
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
                      url       =   "#{get_url(:admin)} 
     | 
| 
      
 72 
     | 
    
         
            +
                      
         
     | 
| 
      
 73 
     | 
    
         
            +
                      url       =   "#{get_url(:admin)}admin.php?page=wpseo_xml"
         
     | 
| 
       92 
74 
     | 
    
         
             
                      page      =   self.mechanize_client.get_page(url)
         
     | 
| 
       93 
75 
     | 
    
         
             
                      form      =   self.mechanize_client.get_form(page, {:action => /wp-admin\/options\.php/i})
         
     | 
| 
       94 
76 
     | 
    
         | 
| 
         @@ -96,7 +78,7 @@ module WpWrapper 
     | 
|
| 
       96 
78 
     | 
    
         
             
                        "wpseo_xml[enablexmlsitemap]"                             =>  {:type   =>  :checkbox,   :checked    =>  true}
         
     | 
| 
       97 
79 
     | 
    
         
             
                      }
         
     | 
| 
       98 
80 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
                      if  
     | 
| 
      
 81 
     | 
    
         
            +
                      if disable_author_sitemap
         
     | 
| 
       100 
82 
     | 
    
         
             
                        options["wpseo_xml[disable_author_sitemap]"]              =   {:type   =>  :checkbox,   :checked    =>  true}
         
     | 
| 
       101 
83 
     | 
    
         
             
                      end
         
     | 
| 
       102 
84 
     | 
    
         | 
| 
         @@ -116,33 +98,114 @@ module WpWrapper 
     | 
|
| 
       116 
98 
     | 
    
         
             
                        options.merge!(taxonomy_options)
         
     | 
| 
       117 
99 
     | 
    
         
             
                      end
         
     | 
| 
       118 
100 
     | 
    
         | 
| 
       119 
     | 
    
         
            -
                       
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
                      response    =   submit_wordpress_seo_form(form, options)
         
     | 
| 
      
 102 
     | 
    
         
            +
                    end
         
     | 
| 
      
 103 
     | 
    
         
            +
                    
         
     | 
| 
      
 104 
     | 
    
         
            +
                    private
         
     | 
| 
      
 105 
     | 
    
         
            +
                      def submit_wordpress_seo_form(form, options)
         
     | 
| 
      
 106 
     | 
    
         
            +
                        page      =   nil
         
     | 
| 
      
 107 
     | 
    
         
            +
                    
         
     | 
| 
      
 108 
     | 
    
         
            +
                        if form
         
     | 
| 
      
 109 
     | 
    
         
            +
                          options.each do |key, values|
         
     | 
| 
      
 110 
     | 
    
         
            +
                            case values[:type]
         
     | 
| 
      
 111 
     | 
    
         
            +
                              when :input
         
     | 
| 
      
 112 
     | 
    
         
            +
                                form[key] = values[:value]
         
     | 
| 
      
 113 
     | 
    
         
            +
                              when :checkbox, :radiobutton
         
     | 
| 
      
 114 
     | 
    
         
            +
                                value     = values[:checked] ? "on" : "off"
         
     | 
| 
      
 115 
     | 
    
         
            +
                                form[key] = value
         
     | 
| 
      
 116 
     | 
    
         
            +
                            end
         
     | 
| 
       126 
117 
     | 
    
         
             
                          end
         
     | 
| 
      
 118 
     | 
    
         
            +
                  
         
     | 
| 
      
 119 
     | 
    
         
            +
                          page    =   form.submit
         
     | 
| 
       127 
120 
     | 
    
         
             
                        end
         
     | 
| 
       128 
121 
     | 
    
         | 
| 
       129 
     | 
    
         
            -
                         
     | 
| 
      
 122 
     | 
    
         
            +
                        return page
         
     | 
| 
      
 123 
     | 
    
         
            +
                      end
         
     | 
| 
      
 124 
     | 
    
         
            +
                    
         
     | 
| 
      
 125 
     | 
    
         
            +
                      def get_title_options(language = :sv)
         
     | 
| 
      
 126 
     | 
    
         
            +
                        options                 =   {
         
     | 
| 
      
 127 
     | 
    
         
            +
                          "wpseo_titles[title-home-wpseo]"          =>  {:type   =>  :input,      :value     =>  '%%sitename%% %%page%%'},
         
     | 
| 
      
 128 
     | 
    
         
            +
                          "wpseo_titles[title-search-wpseo]"        =>  {:type   =>  :input,      :value     =>  translate_pattern(:search, language)},
         
     | 
| 
      
 129 
     | 
    
         
            +
                          "wpseo_titles[title-404-wpseo]"           =>  {:type   =>  :input,      :value     =>  translate_pattern(:not_found, language)}
         
     | 
| 
      
 130 
     | 
    
         
            +
                        }
         
     | 
| 
      
 131 
     | 
    
         
            +
                      
         
     | 
| 
      
 132 
     | 
    
         
            +
                        standard_pattern        =   '%%title%% %%page%% %%sep%% %%sitename%%'
         
     | 
| 
      
 133 
     | 
    
         
            +
                        standard_term_pattern   =   translate_pattern(:term, language)
         
     | 
| 
      
 134 
     | 
    
         
            +
                    
         
     | 
| 
      
 135 
     | 
    
         
            +
                        types                   =   {
         
     | 
| 
      
 136 
     | 
    
         
            +
                          :post           =>  {:pattern => standard_pattern,                              :noindex => false},
         
     | 
| 
      
 137 
     | 
    
         
            +
                          :page           =>  {:pattern => standard_pattern,                              :noindex => false},
         
     | 
| 
      
 138 
     | 
    
         
            +
                          :attachment     =>  {:pattern => standard_pattern,                              :noindex => true},
         
     | 
| 
      
 139 
     | 
    
         
            +
                          :category       =>  {:pattern => standard_term_pattern,                         :noindex => true},
         
     | 
| 
      
 140 
     | 
    
         
            +
                          :post_tag       =>  {:pattern => standard_term_pattern,                         :noindex => true},
         
     | 
| 
      
 141 
     | 
    
         
            +
                          :post_format    =>  {:pattern => standard_term_pattern,                         :noindex => true},
         
     | 
| 
      
 142 
     | 
    
         
            +
                          :author         =>  {:pattern => translate_pattern(:author, language),          :noindex => true},
         
     | 
| 
      
 143 
     | 
    
         
            +
                          :archive        =>  {:pattern => '%%date%% %%page%% %%sep%% %%sitename%%',      :noindex => true},
         
     | 
| 
      
 144 
     | 
    
         
            +
                        }
         
     | 
| 
      
 145 
     | 
    
         
            +
                        
         
     | 
| 
      
 146 
     | 
    
         
            +
                        extra_types             =   {
         
     | 
| 
      
 147 
     | 
    
         
            +
                          :wooframework   =>  {:pattern => standard_pattern,                              :noindex => true},
         
     | 
| 
      
 148 
     | 
    
         
            +
                        }
         
     | 
| 
      
 149 
     | 
    
         
            +
                        
         
     | 
| 
      
 150 
     | 
    
         
            +
                        types.merge!(extra_types)
         
     | 
| 
      
 151 
     | 
    
         
            +
                    
         
     | 
| 
      
 152 
     | 
    
         
            +
                        types.each do |key, values|
         
     | 
| 
      
 153 
     | 
    
         
            +
                          form_key              =   [:category, :post_tag, :post_format].include?(key)  ?   "tax-#{key}"        : key
         
     | 
| 
      
 154 
     | 
    
         
            +
                          form_key              =   [:author, :archive].include?(key)                   ?   "#{form_key}-wpseo" : form_key
         
     | 
| 
      
 155 
     | 
    
         
            +
                        
         
     | 
| 
      
 156 
     | 
    
         
            +
                          type_options          =   {
         
     | 
| 
      
 157 
     | 
    
         
            +
                            "wpseo_titles[title-#{form_key}]"   =>  {:type   =>  :input,      :value      =>  values[:pattern]},
         
     | 
| 
      
 158 
     | 
    
         
            +
                            "wpseo_titles[noindex-#{form_key}]" =>  {:type   =>  :checkbox,   :checked    =>  values[:noindex]}
         
     | 
| 
      
 159 
     | 
    
         
            +
                          }
         
     | 
| 
      
 160 
     | 
    
         
            +
                      
         
     | 
| 
      
 161 
     | 
    
         
            +
                          options.merge!(type_options)
         
     | 
| 
      
 162 
     | 
    
         
            +
                        end
         
     | 
| 
      
 163 
     | 
    
         
            +
                      
         
     | 
| 
      
 164 
     | 
    
         
            +
                        return options
         
     | 
| 
      
 165 
     | 
    
         
            +
                      end
         
     | 
| 
      
 166 
     | 
    
         
            +
                      
         
     | 
| 
      
 167 
     | 
    
         
            +
                      def get_media_options
         
     | 
| 
      
 168 
     | 
    
         
            +
                        options                 =   {
         
     | 
| 
      
 169 
     | 
    
         
            +
                          "wpseo_titles[disable-attachment]"      =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
      
 170 
     | 
    
         
            +
                        }
         
     | 
| 
      
 171 
     | 
    
         
            +
                      
         
     | 
| 
      
 172 
     | 
    
         
            +
                        return options
         
     | 
| 
      
 173 
     | 
    
         
            +
                      end
         
     | 
| 
      
 174 
     | 
    
         
            +
                    
         
     | 
| 
      
 175 
     | 
    
         
            +
                      def get_taxonomy_options
         
     | 
| 
      
 176 
     | 
    
         
            +
                        options                 =   {
         
     | 
| 
      
 177 
     | 
    
         
            +
                          "wpseo_titles[disable-post_format]"     =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
      
 178 
     | 
    
         
            +
                        }
         
     | 
| 
      
 179 
     | 
    
         
            +
                      
         
     | 
| 
      
 180 
     | 
    
         
            +
                        return options
         
     | 
| 
      
 181 
     | 
    
         
            +
                      end
         
     | 
| 
      
 182 
     | 
    
         
            +
                    
         
     | 
| 
      
 183 
     | 
    
         
            +
                      def get_archive_options
         
     | 
| 
      
 184 
     | 
    
         
            +
                        options                 =   {
         
     | 
| 
      
 185 
     | 
    
         
            +
                          "wpseo_titles[disable-author]"          =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
      
 186 
     | 
    
         
            +
                          "wpseo_titles[disable-date]"            =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
      
 187 
     | 
    
         
            +
                        }
         
     | 
| 
      
 188 
     | 
    
         
            +
                      end
         
     | 
| 
      
 189 
     | 
    
         
            +
                      
         
     | 
| 
      
 190 
     | 
    
         
            +
                      def get_other_options
         
     | 
| 
      
 191 
     | 
    
         
            +
                        options                 =   {
         
     | 
| 
      
 192 
     | 
    
         
            +
                          "wpseo_titles[noindex-subpages-wpseo]"  =>  {:type   =>  :checkbox,   :checked   =>  true},
         
     | 
| 
      
 193 
     | 
    
         
            +
                        }
         
     | 
| 
       130 
194 
     | 
    
         
             
                      end
         
     | 
| 
       131 
     | 
    
         
            -
                    end
         
     | 
| 
       132 
195 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
      
 196 
     | 
    
         
            +
                      #Retarded method for now, look into I18n later
         
     | 
| 
      
 197 
     | 
    
         
            +
                      def translate_pattern(key, language = :en)
         
     | 
| 
      
 198 
     | 
    
         
            +
                        case key
         
     | 
| 
      
 199 
     | 
    
         
            +
                          when :search
         
     | 
| 
      
 200 
     | 
    
         
            +
                            language.eql?(:sv) ? 'Du sökte efter %%searchphrase%% %%page%% %%sep%% %%sitename%%' : 'You searched for %%searchphrase%% %%page%% %%sep%% %%sitename%%'
         
     | 
| 
      
 201 
     | 
    
         
            +
                          when :not_found
         
     | 
| 
      
 202 
     | 
    
         
            +
                            language.eql?(:sv) ? 'Sidan kunde inte hittas %%sep%% %%sitename%%' : 'Page Not Found %%sep%% %%sitename%%'
         
     | 
| 
      
 203 
     | 
    
         
            +
                          when :author
         
     | 
| 
      
 204 
     | 
    
         
            +
                            language.eql?(:sv) ? '%%name%%, Författare %%sitename%% %%page%%' : '%%name%%, Author at %%sitename%% %%page%%'
         
     | 
| 
      
 205 
     | 
    
         
            +
                          when :term
         
     | 
| 
      
 206 
     | 
    
         
            +
                            language.eql?(:sv) ? '%%term_title%% Arkiv %%page%% %%sep%% %%sitename%%' : '%%term_title%% Archives %%page%% %%sep%% %%sitename%%'
         
     | 
| 
      
 207 
     | 
    
         
            +
                        end
         
     | 
| 
       144 
208 
     | 
    
         
             
                      end
         
     | 
| 
       145 
     | 
    
         
            -
                    end
         
     | 
| 
       146 
209 
     | 
    
         | 
| 
       147 
210 
     | 
    
         
             
                  end
         
     | 
| 
       148 
211 
     | 
    
         
             
                end
         
     | 
| 
         @@ -8,45 +8,42 @@ module WpWrapper 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  include ::WpWrapper::Modules::Plugins::TrackingCode
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                  def manage_plugins(plugin_identifiers, action = :activate)
         
     | 
| 
       11 
     | 
    
         
            -
                     
     | 
| 
      
 11 
     | 
    
         
            +
                    login unless logged_in?
         
     | 
| 
      
 12 
     | 
    
         
            +
                    
         
     | 
| 
      
 13 
     | 
    
         
            +
                    plugin_identifiers      =   (plugin_identifiers.is_a?(Array)) ? plugin_identifiers : [plugin_identifiers.to_s]
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                    plugin_identifiers.each do |plugin_identifier|
         
     | 
| 
       14 
16 
     | 
    
         
             
                      manage_plugin(plugin_identifier, action)
         
     | 
| 
       15 
     | 
    
         
            -
                    end
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end if plugin_identifiers && plugin_identifiers.any?
         
     | 
| 
       16 
18 
     | 
    
         
             
                  end
         
     | 
| 
       17 
19 
     | 
    
         | 
| 
       18 
20 
     | 
    
         
             
                  def manage_plugin(plugin_identifier, action = :activate)
         
     | 
| 
       19 
     | 
    
         
            -
                    success 
     | 
| 
       20 
     | 
    
         
            -
                  
         
     | 
| 
       21 
     | 
    
         
            -
                    if (login)
         
     | 
| 
       22 
     | 
    
         
            -
                      activation_link         =   nil
         
     | 
| 
       23 
     | 
    
         
            -
                      plugins_page            =   self.mechanize_client.open_url(get_url(:plugins))
         
     | 
| 
      
 21 
     | 
    
         
            +
                    success                 =   false
         
     | 
| 
       24 
22 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                    
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                    activation_link         =   nil
         
     | 
| 
      
 24 
     | 
    
         
            +
                    plugins_page            =   self.mechanize_client.open_url(get_url(:plugins))
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    if plugins_page
         
     | 
| 
      
 27 
     | 
    
         
            +
                      plugin_links          =   plugins_page.parser.css("table.plugins tbody tr td span.#{action} a")
         
     | 
| 
      
 28 
     | 
    
         
            +
                      regex                 =   Regexp.new("plugin=#{plugin_identifier}", Regexp::IGNORECASE)
         
     | 
| 
       31 
29 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                        if (activation_link && activation_link.present?)
         
     | 
| 
       39 
     | 
    
         
            -
                          url                 =   "#{get_url(:admin)}/#{activation_link}"
         
     | 
| 
       40 
     | 
    
         
            -
                          self.mechanize_client.open_url(url)
         
     | 
| 
       41 
     | 
    
         
            -
                          puts "#{Time.now}: Url: #{self.url}. Plugin '#{plugin_identifier}' has been #{action}d!"
         
     | 
| 
       42 
     | 
    
         
            -
                          success             =   true
         
     | 
| 
       43 
     | 
    
         
            -
                        else
         
     | 
| 
       44 
     | 
    
         
            -
                          puts "#{Time.now}: Url: #{self.url}. Couldn't find the plugin #{plugin_identifier}'s #{action}-link."
         
     | 
| 
      
 30 
     | 
    
         
            +
                      plugin_links.each do |link|
         
     | 
| 
      
 31 
     | 
    
         
            +
                        href                =   link["href"]
         
     | 
| 
      
 32 
     | 
    
         
            +
                    
         
     | 
| 
      
 33 
     | 
    
         
            +
                        if regex.match(href)
         
     | 
| 
      
 34 
     | 
    
         
            +
                          activation_link   =   href
         
     | 
| 
      
 35 
     | 
    
         
            +
                          break
         
     | 
| 
       45 
36 
     | 
    
         
             
                        end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                      end if plugin_links && plugin_links.any?
         
     | 
| 
      
 38 
     | 
    
         
            +
                      
         
     | 
| 
      
 39 
     | 
    
         
            +
                      if activation_link && activation_link.present?
         
     | 
| 
      
 40 
     | 
    
         
            +
                        url                 =   "#{get_url(:admin)}#{activation_link}"
         
     | 
| 
      
 41 
     | 
    
         
            +
                        self.mechanize_client.open_url(url)
         
     | 
| 
      
 42 
     | 
    
         
            +
                        puts "[WpWrapper::Modules::Plugins] - #{Time.now}: Url: #{self.url}. Plugin '#{plugin_identifier}' has been #{action}d!"
         
     | 
| 
      
 43 
     | 
    
         
            +
                        success             =   true
         
     | 
| 
      
 44 
     | 
    
         
            +
                      else
         
     | 
| 
      
 45 
     | 
    
         
            +
                        puts "[WpWrapper::Modules::Plugins] - #{Time.now}: Url: #{self.url}. Couldn't find the plugin #{plugin_identifier}'s #{action}-link."
         
     | 
| 
       47 
46 
     | 
    
         
             
                      end
         
     | 
| 
       48 
     | 
    
         
            -
                    else
         
     | 
| 
       49 
     | 
    
         
            -
                      puts "#{Time.now}: Failed to login for url #{self.url}, will not proceed to #{action} plugins"
         
     | 
| 
       50 
47 
     | 
    
         
             
                    end
         
     | 
| 
       51 
48 
     | 
    
         | 
| 
       52 
49 
     | 
    
         
             
                    return success
         
     | 
| 
         @@ -35,11 +35,11 @@ module WpWrapper 
     | 
|
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                      confirmation_page                                      =   setup_form.submit
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                      puts "#{Time.now}: Url: #{self.url}. The WordPress-blog has now been installed!"
         
     | 
| 
      
 38 
     | 
    
         
            +
                      puts "[WpWrapper::Modules::Setup] - #{Time.now}: Url: #{self.url}. The WordPress-blog has now been installed!"
         
     | 
| 
       39 
39 
     | 
    
         
             
                      success                                                =   true
         
     | 
| 
       40 
40 
     | 
    
         
             
                    else
         
     | 
| 
       41 
     | 
    
         
            -
                      puts "#{Time.now}: Url: #{self.url}. The blog has already been setup or the registration form couldn't be found or some data is missing."
         
     | 
| 
       42 
     | 
    
         
            -
                      puts "#{Time.now}: Url: #{self.url}. Information supplied:\nTitle: #{title}.\nUsername: #{self.username}.\nPassword: #{self.password}.\nEmail: #{email}."
         
     | 
| 
      
 41 
     | 
    
         
            +
                      puts "[WpWrapper::Modules::Setup] - #{Time.now}: Url: #{self.url}. The blog has already been setup or the registration form couldn't be found or some data is missing."
         
     | 
| 
      
 42 
     | 
    
         
            +
                      puts "[WpWrapper::Modules::Setup] - #{Time.now}: Url: #{self.url}. Information supplied:\nTitle: #{title}.\nUsername: #{self.username}.\nPassword: #{self.password}.\nEmail: #{email}."
         
     | 
| 
       43 
43 
     | 
    
         
             
                    end
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
                    return success
         
     | 
| 
         @@ -2,25 +2,25 @@ module WpWrapper 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module Modules
         
     | 
| 
       3 
3 
     | 
    
         
             
                module Themes
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                  def activate_random_theme
         
     | 
| 
       6 
     | 
    
         
            -
                    theme_links               =   get_theme_links
         
     | 
| 
       7 
     | 
    
         
            -
                     
     | 
| 
      
 5 
     | 
    
         
            +
                  def activate_random_theme(ignore_themes: [])
         
     | 
| 
      
 6 
     | 
    
         
            +
                    theme_links               =   get_theme_links(ignore_themes: ignore_themes)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    random_url                =   (theme_links && theme_links.any?) ? theme_links.sample : nil
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                    perform_activation( 
     | 
| 
      
 9 
     | 
    
         
            +
                    perform_activation(random_url) if random_url
         
     | 
| 
       10 
10 
     | 
    
         
             
                  end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                  def activate_theme(theme_identifier = 'twentytwelve')
         
     | 
| 
       13 
13 
     | 
    
         
             
                    success                   =   false
         
     | 
| 
       14 
14 
     | 
    
         
             
                    theme_links               =   get_theme_links
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                    if  
     | 
| 
      
 16 
     | 
    
         
            +
                    if theme_links && theme_links.any?
         
     | 
| 
       17 
17 
     | 
    
         
             
                      activation_link         =   nil
         
     | 
| 
       18 
18 
     | 
    
         
             
                      regex                   =   Regexp.new("stylesheet=#{theme_identifier}", Regexp::IGNORECASE)
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                      theme_links.each do |link|
         
     | 
| 
       21 
21 
     | 
    
         
             
                        href                  =   link["href"]
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                        if  
     | 
| 
      
 23 
     | 
    
         
            +
                        if regex.match(href)
         
     | 
| 
       24 
24 
     | 
    
         
             
                          activation_link     =   href
         
     | 
| 
       25 
25 
     | 
    
         
             
                          break
         
     | 
| 
       26 
26 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -39,33 +39,47 @@ module WpWrapper 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                  def perform_activation(url)
         
     | 
| 
       42 
     | 
    
         
            -
                    success 
     | 
| 
      
 42 
     | 
    
         
            +
                    success             =   false
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                    if  
     | 
| 
      
 44 
     | 
    
         
            +
                    if url && url.present?
         
     | 
| 
       45 
45 
     | 
    
         
             
                      puts "[WpWrapper::Modules::Themes] - #{Time.now}: Will activate theme with url #{url}."
         
     | 
| 
       46 
46 
     | 
    
         
             
                      self.mechanize_client.open_url(url)
         
     | 
| 
       47 
     | 
    
         
            -
                      success 
     | 
| 
      
 47 
     | 
    
         
            +
                      success           =   true
         
     | 
| 
       48 
48 
     | 
    
         
             
                    end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                    return success
         
     | 
| 
       51 
51 
     | 
    
         
             
                  end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                  def get_theme_links
         
     | 
| 
       54 
     | 
    
         
            -
                    theme_links 
     | 
| 
      
 53 
     | 
    
         
            +
                  def get_theme_links(ignore_themes: [])
         
     | 
| 
      
 54 
     | 
    
         
            +
                    theme_links         =   []
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                    if  
     | 
| 
       57 
     | 
    
         
            -
                      themes_page 
     | 
| 
      
 56 
     | 
    
         
            +
                    if login
         
     | 
| 
      
 57 
     | 
    
         
            +
                      themes_page       =   self.mechanize_client.open_url(get_url(:themes))
         
     | 
| 
      
 58 
     | 
    
         
            +
                      links             =   themes_page ? themes_page.parser.css("div.themes div.theme div.theme-actions a.activate") : []
         
     | 
| 
       58 
59 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                       
     | 
| 
       60 
     | 
    
         
            -
                         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                      links.each do |link|
         
     | 
| 
      
 61 
     | 
    
         
            +
                        href            =   link["href"]
         
     | 
| 
      
 62 
     | 
    
         
            +
                        
         
     | 
| 
      
 63 
     | 
    
         
            +
                        if ignore_themes && ignore_themes.any?
         
     | 
| 
      
 64 
     | 
    
         
            +
                          ignore_themes.each do |ignore_theme|
         
     | 
| 
      
 65 
     | 
    
         
            +
                            regex       =   ignore_theme.is_a?(Regexp) ? ignore_theme : Regexp.new("stylesheet=#{ignore_theme}", Regexp::IGNORECASE)
         
     | 
| 
      
 66 
     | 
    
         
            +
                      
         
     | 
| 
      
 67 
     | 
    
         
            +
                            if !regex.match(href)
         
     | 
| 
      
 68 
     | 
    
         
            +
                              theme_links << href
         
     | 
| 
      
 69 
     | 
    
         
            +
                              break
         
     | 
| 
      
 70 
     | 
    
         
            +
                            end
         
     | 
| 
      
 71 
     | 
    
         
            +
                          end
         
     | 
| 
      
 72 
     | 
    
         
            +
                        else
         
     | 
| 
      
 73 
     | 
    
         
            +
                          theme_links << href
         
     | 
| 
      
 74 
     | 
    
         
            +
                        end
         
     | 
| 
      
 75 
     | 
    
         
            +
                      end if links && links.any?
         
     | 
| 
       62 
76 
     | 
    
         
             
                    end
         
     | 
| 
       63 
77 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                    puts "[WpWrapper::Modules::Themes] - #{Time.now}: Found a total of #{theme_links. 
     | 
| 
      
 78 
     | 
    
         
            +
                    puts "[WpWrapper::Modules::Themes] - #{Time.now}: Found a total of #{theme_links.size} theme activation links."
         
     | 
| 
       65 
79 
     | 
    
         | 
| 
       66 
80 
     | 
    
         
             
                    return theme_links
         
     | 
| 
       67 
81 
     | 
    
         
             
                  end
         
     | 
| 
       68 
82 
     | 
    
         | 
| 
       69 
83 
     | 
    
         
             
                end
         
     | 
| 
       70 
84 
     | 
    
         
             
              end
         
     | 
| 
       71 
     | 
    
         
            -
            end
         
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -79,7 +79,7 @@ module WpWrapper 
     | 
|
| 
       79 
79 
     | 
    
         
             
                            puts "Upgrade #{type} url: #{upgrade_url.inspect}"
         
     | 
| 
       80 
80 
     | 
    
         | 
| 
       81 
81 
     | 
    
         
             
                            if (upgrade_url)
         
     | 
| 
       82 
     | 
    
         
            -
                              self.mechanize_client.agent.get("#{get_url(:admin)} 
     | 
| 
      
 82 
     | 
    
         
            +
                              self.mechanize_client.agent.get("#{get_url(:admin)}#{upgrade_url}")
         
     | 
| 
       83 
83 
     | 
    
         
             
                              puts "#{Time.now}: Url: #{self.url}. #{type.to_s.capitalize} were upgraded!"
         
     | 
| 
       84 
84 
     | 
    
         
             
                              success       =   true
         
     | 
| 
       85 
85 
     | 
    
         
             
                            end
         
     | 
    
        data/lib/wp_wrapper.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module WpWrapper
         
     | 
| 
       2 
     | 
    
         
            -
              VERSION = "0.0. 
     | 
| 
      
 2 
     | 
    
         
            +
              VERSION = "0.0.6"
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
              require File.join(File.dirname(__FILE__), 'wp_wrapper/railtie') if defined?(Rails)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
         @@ -23,4 +23,4 @@ module WpWrapper 
     | 
|
| 
       23 
23 
     | 
    
         
             
              require File.join(File.dirname(__FILE__), 'wp_wrapper/modules/api')
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
              require File.join(File.dirname(__FILE__), 'wp_wrapper/client')
         
     | 
| 
       26 
     | 
    
         
            -
            end
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
    
        data/wp_wrapper.gemspec
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       3 
3 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              s.name = 'wp_wrapper'
         
     | 
| 
       6 
     | 
    
         
            -
              s.version = '0.0. 
     | 
| 
      
 6 
     | 
    
         
            +
              s.version = '0.0.6'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              s.homepage      =   "http://github.com/Agiley/wp_wrapper"
         
     | 
| 
       9 
9 
     | 
    
         
             
              s.email         =   "sebastian@agiley.se"
         
     | 
| 
         @@ -11,8 +11,8 @@ Gem::Specification.new do |s| 
     | 
|
| 
       11 
11 
     | 
    
         
             
              s.description   =   "Wrapper to interact with WordPress using Mechanize"
         
     | 
| 
       12 
12 
     | 
    
         
             
              s.summary       =   "Wrapper to interact with WordPress using Mechanize"
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              s.add_dependency "nokogiri", ">= 1. 
     | 
| 
       15 
     | 
    
         
            -
              s.add_dependency "http_utilities", ">= 1. 
     | 
| 
      
 14 
     | 
    
         
            +
              s.add_dependency "nokogiri", ">= 1.10.2"
         
     | 
| 
      
 15 
     | 
    
         
            +
              s.add_dependency "http_utilities", ">= 1.4.2"
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              s.add_development_dependency 'rake'
         
     | 
| 
       18 
18 
     | 
    
         
             
              s.add_development_dependency 'rspec'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: wp_wrapper
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Sebastian Johnsson
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-03-28 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: nokogiri
         
     | 
| 
         @@ -16,28 +16,28 @@ dependencies: 
     | 
|
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - ">="
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version: 1. 
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 1.10.2
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
24 
     | 
    
         
             
                - - ">="
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version: 1. 
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 1.10.2
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: http_utilities
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
31 
     | 
    
         
             
                - - ">="
         
     | 
| 
       32 
32 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
     | 
    
         
            -
                    version: 1. 
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 1.4.2
         
     | 
| 
       34 
34 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       35 
35 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
36 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       37 
37 
     | 
    
         
             
                requirements:
         
     | 
| 
       38 
38 
     | 
    
         
             
                - - ">="
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
     | 
    
         
            -
                    version: 1. 
     | 
| 
      
 40 
     | 
    
         
            +
                    version: 1.4.2
         
     | 
| 
       41 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
42 
     | 
    
         
             
              name: rake
         
     | 
| 
       43 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -129,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       129 
129 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       130 
130 
     | 
    
         
             
                  version: 1.3.5
         
     | 
| 
       131 
131 
     | 
    
         
             
            requirements: []
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
            rubygems_version: 2.4.8
         
     | 
| 
      
 132 
     | 
    
         
            +
            rubygems_version: 3.0.3
         
     | 
| 
       134 
133 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       135 
134 
     | 
    
         
             
            specification_version: 2
         
     | 
| 
       136 
135 
     | 
    
         
             
            summary: Wrapper to interact with WordPress using Mechanize
         
     |