Skip to content

Commit

Permalink
Clean Wordpress sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ezkl committed Dec 29, 2013
1 parent 36f7762 commit edb3eff
Show file tree
Hide file tree
Showing 3 changed files with 822 additions and 24 deletions.
24 changes: 12 additions & 12 deletions lib/sniffles/sniffers/cms/wordpress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ class Wordpress
include HTML
attr_accessor :doc
attr_reader :name, :group, :output, :response

def initialize(response_body)
@output = {}
@output = {}
parse(response_body) && process_document
end

def process_document
if @output[:found] = found?
parse_version
Expand All @@ -18,37 +18,37 @@ def process_document
parse_pingback
end
end

private
def found?
@doc.xpath('//link[contains(@href,"wp-content")]').any?
end
end

def parse_feed
@output[:feed] = text_at("//link[@rel='alternate' and @type='application/rss+xml']/@href")
end

def parse_theme
theme_uri = text_at("//link[@rel='stylesheet' and contains(@href,'wp-content/themes/')][1]/@href")
@output[:theme] = (theme_uri ? clean_theme_uri(theme_uri)[1] : false)
end

def parse_version
version_meta_tag = text_at("//meta[@name='generator']/@content")
@output[:version] = (version_meta_tag ? extract_version(version_meta_tag)[1] : version_meta_tag)
end

def parse_pingback
@output[:pingback] = text_at("//link[@rel='pingback']/@href")
end

def clean_theme_uri(uri)
/wp-content\/themes\/([^\/]*)\//i.match uri
end

def extract_version(string)
/([\d]+\.[\d]+[\.]?[\d]?)/.match string
end
end
end
end
end
Loading

0 comments on commit edb3eff

Please sign in to comment.