=== app/controllers/admin/blog_controller.rb
==================================================================
--- app/controllers/admin/blog_controller.rb (revision 1808)
+++ app/controllers/admin/blog_controller.rb (local)
@@ -0,0 +1,46 @@
+class Admin::BlogController < Admin::BaseController
+
+ def index
+ list
+ render_action 'list'
+ end
+
+ def list
+ @blogs = Blog.find :all
+ end
+
+ def show
+ @blog = Blog.find(params[:id])#, :include => [ :articles ])
+ # @articles = @blog.articles
+ end
+
+ def new
+ if request.post?
+ @blog = Blog.new
+ Blog.transaction do
+ params[:blog].each { |k,v| @blog.send("#{k.to_s}=", v) }
+ @blog.save
+ flash[:notice] = 'Blog was successfully created.'
+ end
+ redirect_to :controller => 'admin/general'
+ end
+ end
+
+ def edit
+ @blog = Blog.find(params[:id])
+ @blog.attributes = params[:blog]
+ if request.post? and @blog.save
+ flash[:notice] = 'Blog was successfully updated.'
+ redirect_to :action => 'show', :id => @blog.id
+ end
+ end
+
+ def destroy
+ @blog = Blog.find(params[:id])
+ if request.post?
+ @blog.destroy if Blog.count > 1
+ redirect_to :action => 'list'
+ end
+ end
+
+end
=== app/controllers/grouping_controller.rb
==================================================================
--- app/controllers/grouping_controller.rb (revision 1808)
+++ app/controllers/grouping_controller.rb (local)
@@ -22,7 +22,7 @@
end
def index
- self.groupings = grouping_class.find_all_with_article_counters(1000)
+ self.groupings = grouping_class.find_all_with_article_counters(this_blog, 1000)
render_index(groupings)
end
=== app/controllers/xml_controller.rb
==================================================================
--- app/controllers/xml_controller.rb (revision 1808)
+++ app/controllers/xml_controller.rb (local)
@@ -117,7 +117,7 @@
def prep_sitemap
fetch_items(:articles, 'created_at DESC', 1000)
fetch_items(:pages, 'created_at DESC', 1000)
- @items += Category.find_all_with_article_counters(1000)
- @items += Tag.find_all_with_article_counters(1000)
+ @items += Category.find_all_with_article_counters(this_blog, 1000)
+ @items += Tag.find_all_with_article_counters(this_blog, 1000)
end
end
=== app/models/category.rb
==================================================================
--- app/models/category.rb (revision 1808)
+++ app/models/category.rb (local)
@@ -13,7 +13,7 @@
:order => "published_at DESC"
module Finders
- def find_all_with_article_counters(maxcount=nil)
+ def find_all_with_article_counters(current_blog, maxcount=nil)
self.find_by_sql([%{
SELECT categories.id, categories.name, categories.permalink, categories.position, COUNT(articles.id) AS article_counter
FROM #{Category.table_name} categories
@@ -21,9 +21,10 @@
ON articles_categories.category_id = categories.id
LEFT OUTER JOIN #{Article.table_name} articles
ON (articles_categories.article_id = articles.id AND articles.published = ?)
+ WHERE articles.blog_id = ?
GROUP BY categories.id, categories.name, categories.position, categories.permalink
ORDER BY position
- }, true]).each {|item| item.article_counter = item.article_counter.to_i }
+ }, true, current_blog.id]).each {|item| item.article_counter = item.article_counter.to_i }
end
def find(*args)
=== app/models/content.rb
==================================================================
--- app/models/content.rb (revision 1808)
+++ app/models/content.rb (local)
@@ -36,11 +36,6 @@
@@content_fields = Hash.new
@@html_map = Hash.new
- def initialize(*args, &block)
- super(*args, &block)
- set_default_blog
- end
-
def invalidates_cache?(on_destruction = false)
if on_destruction
just_changed_published_status? || published?
@@ -49,12 +44,6 @@
end
end
- def set_default_blog
- if self.blog_id.nil? || self.blog_id == 0
- self.blog = Blog.default
- end
- end
-
class << self
# Quite a bit of this isn't needed anymore.
def content_fields(*attribs)
=== app/models/tag.rb
==================================================================
--- app/models/tag.rb (revision 1808)
+++ app/models/tag.rb (local)
@@ -30,7 +30,7 @@
before_save :ensure_naming_conventions
- def self.find_all_with_article_counters(limit = 20)
+ def self.find_all_with_article_counters(current_blog, limit = 20)
# Only count published articles
self.find_by_sql([%{
SELECT tags.id, tags.name, tags.display_name, COUNT(articles_tags.article_id) AS article_counter
@@ -38,11 +38,11 @@
ON articles_tags.tag_id = tags.id
LEFT OUTER JOIN #{Tag.table_name_prefix + Article.table_name + Tag.table_name_prefix} articles
ON articles_tags.article_id = articles.id
- WHERE articles.published = ?
+ WHERE articles.published = ? AND articles.blog_id = ?
GROUP BY tags.id, tags.name, tags.display_name
ORDER BY article_counter DESC
LIMIT ?
- },true, limit]).each{|item| item.article_counter = item.article_counter.to_i }
+ },true, current_blog.id, limit]).each{|item| item.article_counter = item.article_counter.to_i }
end
def self.find_by_permalink(*args)
=== app/models/user.rb
==================================================================
--- app/models/user.rb (revision 1808)
+++ app/models/user.rb (local)
@@ -47,7 +47,7 @@
end
# Let's be lazy, no need to fetch the counters, rails will handle it.
- def self.find_all_with_article_counters(ignored_arg)
+ def self.find_all_with_article_counters(current_blog, ignored_arg)
find(:all)
end
=== app/views/admin/general/index.rhtml
==================================================================
--- app/views/admin/general/index.rhtml (revision 1808)
+++ app/views/admin/general/index.rhtml (local)
@@ -5,6 +5,7 @@
<%= subtab _("Advanced settings"), "", {:controller => "advanced"} %>
<%= subtab _("Empty Fragment Cache"), "", {:controller => '/admin/cache', :action => 'sweep'} %>
<%= subtab _("Rebuild cached HTML"), "", {:controller => '/admin/cache', :action => 'sweep_html'} %>
+ <%= subtab _("Add Another Blog"), "", {:controller => 'blog', :action => 'new'} %>
<% end -%>
<% form_tag :action => 'update' do %>
=== app/views/admin/blog (new directory)
==================================================================
=== app/views/admin/blog/new.rhtml
==================================================================
--- app/views/admin/blog/new.rhtml (revision 1808)
+++ app/views/admin/blog/new.rhtml (local)
@@ -0,0 +1,15 @@
+<% form_tag :action=> "new" do %>
+
+<%= error_messages_for 'blog' %>
+
+