Module: WpTheme::Findable

Included in:
WpTheme
Defined in:
lib/common/models/wp_theme/findable.rb

Instance Method Summary (collapse)

Instance Method Details

- (WpTheme) find(target_uri)

Find the main theme of the blog

Parameters:

  • target_uri (URI)

Returns:



11
12
13
14
15
16
17
18
19
20
# File 'lib/common/models/wp_theme/findable.rb', line 11

def find(target_uri)
  methods.grep(/^find_from_/).each do |method|
    if wp_theme = self.send(method, target_uri)
      wp_theme.found_from = method

      return wp_theme
    end
  end
  nil
end

Discover the wordpress theme by parsing the css link rel

Parameters:

  • target_uri (URI)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/common/models/wp_theme/findable.rb', line 29

def find_from_css_link(target_uri)
  response = Browser.get_and_follow_location(target_uri.to_s)

  # https + domain is optional because of relative links
  matches = %r{(?:https?://[^"']+)?/([^/]+)/themes/([^"']+)/style.css}i.match(response.body)
  if matches
    return new(
      target_uri,
      {
        name:           matches[2],
        style_url:      matches[0],
        wp_content_dir: matches[1]
      }
    )
  end
end

- (WpTheme) find_from_wooframework(target_uri) (protected)

Parameters:

  • target_uri (URI)

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/common/models/wp_theme/findable.rb', line 51

def find_from_wooframework(target_uri)
  body = Browser.get(target_uri.to_s).body
  regexp = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?" />\s+<meta name="generator" content="WooFramework\s?([^"]+)?" />}


  if matches = regexp.match(body)
    woo_theme_name = matches[1]
    woo_theme_version = matches[2]
    #woo_framework_version = matches[3] # Not used at this time

    return new(
      target_uri,
      {
        name:    woo_theme_name,
        version: woo_theme_version
      }
    )
  end
end