diff --git a/lib/ruby-wpdb.rb b/lib/ruby-wpdb.rb index ceb0990..7a1341d 100644 --- a/lib/ruby-wpdb.rb +++ b/lib/ruby-wpdb.rb @@ -38,6 +38,7 @@ def init(uri, prefix = nil, user_prefix = nil) WPDB.user_prefix = user_prefix || WPDB.prefix require_relative 'ruby-wpdb/options' + require_relative 'ruby-wpdb/bloginfo' require_relative 'ruby-wpdb/users' require_relative 'ruby-wpdb/terms' require_relative 'ruby-wpdb/posts' diff --git a/lib/ruby-wpdb/bloginfo.rb b/lib/ruby-wpdb/bloginfo.rb new file mode 100644 index 0000000..a6e20d5 --- /dev/null +++ b/lib/ruby-wpdb/bloginfo.rb @@ -0,0 +1,51 @@ +require "uri" + +module WPDB + class Bloginfo + class << self + def get_bloginfo(key) + case key + when "home", "siteurl", "url" + WPDB.home_url + when "wpurl" + WPDB.site_url + when "description" + Option.get_option("blogdescription") + when "rdf_url" + get_feed_link("rdf") + when "rss_url" + get_feed_link("rss") + when "rss2_url" + get_feed_link("rss2") + when "atom_url" + get_feed_link("atom") + when "comments_atom_url" + get_feed_link("comments_atom") + when "comments_rss2_url" + get_feed_link("comments_rss2") + when "pingback_url" + site_url("xmlrpc.php") + end + end + end + end + + class << self + def home_url(path = nil, scheme = nil) + make_url(Option.get_option("home"), path, scheme) + end + + def site_url(path = nil, scheme = nil) + make_url(Option.get_option("siteurl"), path, scheme) + end + + def make_url(url, path = nil, scheme = nil) + url = URI.parse(url + "/") + + url.scheme = scheme if ["http", "https", "relative"].include?(scheme) + url = URI.join(url, path) if path + + url + end + end +end diff --git a/lib/ruby-wpdb/options.rb b/lib/ruby-wpdb/options.rb index ead123a..5a32a5c 100644 --- a/lib/ruby-wpdb/options.rb +++ b/lib/ruby-wpdb/options.rb @@ -18,7 +18,7 @@ def before_validation # @param [String] name The option_name to fetch # @return String def self.get_option(name) - Option.where(:option_name => name).get(:option_value) + self.where(:option_name => name).get(:option_value) end end end