Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ruby-wpdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
51 changes: 51 additions & 0 deletions lib/ruby-wpdb/bloginfo.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/ruby-wpdb/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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