inaka-wp_on_rails 0.1.0

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.
Files changed (4) hide show
  1. data/README.rdoc +61 -0
  2. data/Rakefile +14 -0
  3. data/lib/wp_on_rails.rb +90 -0
  4. metadata +56 -0
@@ -0,0 +1,61 @@
1
+ == WordPress On Rails
2
+
3
+ The goal of this simple Gem is to provide a set of ActiveRecord objects
4
+ that can manipulate a WordPress database.
5
+
6
+ == What's new in this release?
7
+
8
+ This is really just a set of objects right now. It needs to be expanded on before it can be used to manipulate a WP installation without a lot of inside information as to what each field means.
9
+
10
+ == Installation/Usage
11
+
12
+ WordPress Administrators must use PRE-2.5 credential hashing algorithm, which is less secure, if you want to be able to authenticate users
13
+ in Rails. See http://wordpress.org/extend/plugins/md5-password-hashes/
14
+ gem install wp_on_rails
15
+
16
+ require 'wp_on_rails'
17
+
18
+ # if you want to use one database for your rails application and another for wordpress
19
+ # create a 'blog' connection in your database file with the proper credentials
20
+ # also, a third parameter can be passed in which is the prefix to assign to the
21
+ # wordpress table names - this is optional.
22
+ WordPress::Base.init_connection(#{RAILS_ROOT}/config/database.yml','blog','blog1_')
23
+
24
+ # if you set a prefix in your installation and your wordpress tables are in the current database
25
+ WordPress::Base.set_table_prefix('prefix_')
26
+
27
+ == TODO
28
+
29
+ - Not all tables are in place
30
+ - Relationships between tables are missing
31
+ - Tests
32
+ - Documentation
33
+ - Implement PHPass and remove MD5 password hashing requirement
34
+
35
+ == See Also
36
+
37
+ The WordPress schema is at http://codex.wordpress.org/Database_Description
38
+
39
+ == License
40
+
41
+ (Licensed under the terms of the MIT License)
42
+
43
+ Copyright (c) 2008 Chad DePue, Electronic Inaka, LLC
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy
46
+ of this software and associated documentation files (the "Software"), to deal
47
+ in the Software without restriction, including without limitation the rights
48
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+ copies of the Software, and to permit persons to whom the Software is
50
+ furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in
53
+ all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
61
+ THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('wp_on_rails','0.1.0') do |p|
6
+ p.description = "Use ActiveRecord to manipulate a WordPress database directly."
7
+ p.url = "http://github.com/inaka/wp_on_rails"
8
+ p.author = "Chad DePue"
9
+ p.email = "chad@inakanetworks.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,90 @@
1
+ require 'active_record'
2
+
3
+ module WordPress
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ attr_accessor :config
11
+ attr_accessor :yaml_db_name
12
+
13
+ # a wordpress installation may prefix all tables with a string to allow a DB to colocate multiple installations in the same physical db
14
+ # we must track the 'root name' of the table and call set_table_name when the prefix is set.
15
+ attr_accessor :table_root
16
+
17
+ # establishes a separate connection to a WP database. Expects a YAML file with the name of the database
18
+ def init_connection(file, db_name, prefix=nil)
19
+ config = YAML.load_file(file)
20
+ @yaml_db_name = db_name
21
+ self.subclasses.each() do |c|
22
+ c.establish_connection(config[db_name])
23
+ c.send('set_table_name',prefix.blank? ? c.table_root : "#{prefix}#{c.table_root}")
24
+ end
25
+ end
26
+
27
+ def set_table_prefix(prefix)
28
+ self.subclasses.each() { |c| c.send('set_table_name',prefix.blank? ? c.table_root : "#{prefix}#{c.table_root}") }
29
+ end
30
+
31
+ def set_table_root(table)
32
+ @table_root = table
33
+ end
34
+
35
+ # currently only supports md5 passwords - requires wp administrator
36
+ # to install this plugin - http://wordpress.org/extend/plugins/md5-password-hashes/
37
+ # should upgrade to match encryption w/PHPass
38
+ def hash_password(pass)
39
+ require 'digest/md5'
40
+ Digest::MD5.digest(pass).unpack("H*")[0]
41
+ end
42
+ end
43
+
44
+ class Base < ActiveRecord::Base
45
+ extend WordPress::ClassMethods
46
+ end
47
+
48
+ class Comment < WordPress::Base
49
+ set_table_root 'comments'
50
+ end
51
+
52
+ class Link < WordPress::Base
53
+ set_table_root 'links'
54
+ end
55
+
56
+ class Option < WordPress::Base
57
+ set_table_root 'options'
58
+ end
59
+
60
+ class PostMeta < WordPress::Base
61
+ set_table_root 'postmeta'
62
+ set_primary_key 'meta_id'
63
+ belongs_to :post, :class_name => "WordPress::Post"
64
+ end
65
+
66
+ class Term < WordPress::Base
67
+ set_table_root 'terms'
68
+ end
69
+
70
+ class Post < WordPress::Base
71
+ set_table_root 'posts'
72
+ set_primary_key 'ID' # required because the field in the wp db is capitalized
73
+ has_many :post_metas, :class_name => "WordPress::PostMeta", :foreign_key => "post_id"
74
+ end
75
+
76
+ class User < WordPress::Base
77
+ set_table_root 'users'
78
+ end
79
+
80
+ class Usermeta < WordPress::Base
81
+ set_table_root 'usermeta'
82
+ set_primary_key 'umeta_id'
83
+ end
84
+
85
+ # must be at end to set all subclasses
86
+ class Base < ActiveRecord::Base
87
+ set_table_prefix 'wp_' # default prefix
88
+ end
89
+
90
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inaka-wp_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chad DePue
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-04 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: wp_on_rails is an ActiveRecord interface to a WordPress database.
17
+ email: chad@inakanetworks.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.rdoc
26
+ - lib/wp_on_rails.rb
27
+ - Manifest
28
+ - Rakefile
29
+ has_rdoc: true
30
+ homepage: http://github.com/inaka/wp_on_rails
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.2.0
52
+ signing_key:
53
+ specification_version: 2
54
+ summary: ActiveRecord interface to a WordPress database
55
+ test_files: []
56
+