Skip to content

Commit

Permalink
Multi blog view support
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Jul 18, 2010
1 parent 1c79ef8 commit fc66d65
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
4 changes: 4 additions & 0 deletions app/models/domain_model.rb
Expand Up @@ -337,6 +337,10 @@ def self.generate_hash
Digest::SHA1.hexdigest(Time.now.to_i.to_s + rand(1e100).to_s)
end

def self.hexdigest(val)
Digest::SHA1.hexdigest(val)[0..63]
end

# Generates a hexdigest hash on a hash
# by turning the hash into an array, sorting the keys
# and hashing the resultant array - allows Hash's with the same
Expand Down
1 change: 0 additions & 1 deletion config/environment.rb
Expand Up @@ -101,7 +101,6 @@ def webiva_remove_load_paths(file)

if RAILS_ENV == 'test'
config.gem 'factory_girl',:source => 'http://gemcutter.org'
config.gem 'fakeweb'
end

if CMS_CACHE_ACTIVE
Expand Down
8 changes: 4 additions & 4 deletions vendor/modules/blog/app/controllers/blog/page_controller.rb
Expand Up @@ -35,7 +35,7 @@ class Blog::PageController < ParagraphController
:inputs => [[:category, 'Selected Category', :blog_category_id]]

class EntryListOptions < HashModel
attributes :blog_id => nil, :items_per_page => 10, :detail_page => nil, :include_in_path => nil,:blog_target_id => nil, :category => nil
attributes :blog_id => 0, :items_per_page => 10, :detail_page => nil, :include_in_path => nil,:blog_target_id => nil, :category => nil


def detail_page_id
Expand All @@ -46,7 +46,7 @@ def detail_page_id
page_options :detail_page_id

options_form(fld(:blog_id, :select, :options => :blog_options),
fld(:detail_page, :page_selector),
fld(:detail_page, :page_selector,:description => 'Leave blank to use canonical content url'),
fld(:include_in_path, :select, :options => :include_in_path_options),
fld(:items_per_page, :select, :options => (1..50).to_a),
fld(:blog_target_id, :select, :options => :blog_target_options),
Expand All @@ -56,7 +56,7 @@ def detail_page_id
def blog_target_options; Blog::BlogTarget.select_options_with_nil; end

def blog_options
[['---Use Page Connection---'.t,'']] + Blog::BlogBlog.find_select_options(:all,:order=>'name')
[['---Use Page Connection---'.t,'']] + [['All Blogs'.t,-1]] + Blog::BlogBlog.find_select_options(:all,:order=>'name')
end

def include_in_path_options
Expand All @@ -67,7 +67,7 @@ def include_in_path_options
end

class EntryDetailOptions < HashModel
attributes :blog_id => nil, :list_page_id => nil, :include_in_path => nil
attributes :blog_id => 0, :list_page_id => nil, :include_in_path => nil

integer_options :blog_id
page_options :list_page_id
Expand Down
8 changes: 7 additions & 1 deletion vendor/modules/blog/app/controllers/blog/page_feature.rb
Expand Up @@ -108,7 +108,13 @@ def blog_entry_tags(c,data)
end

c.expansion_tag('entry:more') { |tag| !tag.locals.entry.preview.blank? }
c.link_tag('entry:detail') { |tag| "#{data[:detail_page]}/#{tag.locals.entry.permalink}" }
c.link_tag('entry:detail') do |tag|
if !data[:detail_page].blank?
"#{data[:detail_page]}/#{tag.locals.entry.permalink}"
else
tag.locals.entry.content_node.link if tag.locals.entry.content_node
end
end
c.link_tag('entry:full_detail') { |tag| "#{Configuration.domain_link(data[:detail_page].to_s + '/' + tag.locals.entry.permalink.to_s)}" }

c.value_tag('entry:categories') do |tag|
Expand Down
31 changes: 19 additions & 12 deletions vendor/modules/blog/app/controllers/blog/page_renderer.rb
Expand Up @@ -53,27 +53,32 @@ def entry_list
set_page_connection(:category, list_type_identifier)
end

display_string = "#{page}_#{list_type}_#{list_type_identifier}"
type_hash = DomainModel.hexdigest("#{list_type}_#{list_type_identifier}")
display_string = "#{page}_#{type_hash}"

result = renderer_cache(Blog::BlogPost, display_string) do |cache|
blog = get_blog
return render_paragraph :text => (@options.blog_id.to_i > 0 ? '[Configure paragraph]' : '') unless blog
return render_paragraph :text => (@options.blog_id.to_i > 0 ? '[Configure paragraph]' : '') unless blog || @options.blog_id == -1

detail_page = get_detail_page
items_per_page = (@options.items_per_page || 1).to_i

entries = []
pages = {}

case list_type.to_s
when 'category':
pages,entries = blog.paginate_posts_by_category(page,list_type_identifier,items_per_page)
when 'tag':
pages,entries = blog.paginate_posts_by_tag(page,list_type_identifier,items_per_page)
when 'archive':
pages,entries = blog.paginate_posts_by_month(page,list_type_identifier,items_per_page)
if blog
case list_type.to_s
when 'category':
pages,entries = blog.paginate_posts_by_category(page,list_type_identifier,items_per_page)
when 'tag':
pages,entries = blog.paginate_posts_by_tag(page,list_type_identifier,items_per_page)
when 'archive':
pages,entries = blog.paginate_posts_by_month(page,list_type_identifier,items_per_page)
else
pages,entries = blog.paginate_posts(page,items_per_page)
end
else
pages,entries = blog.paginate_posts(page,items_per_page)
pages,entries = Blog::BlogPost.paginate_published(page,items_per_page)
end

cache[:output] = blog_entry_list_feature(:blog => blog,
Expand Down Expand Up @@ -120,7 +125,7 @@ def entry_detail
set_title(result.title)
set_content_node(['Blog::BlogPost', result.entry_id])
else
return render_paragraph :text => '' if (['', 'category','tag','archive'].include?(conn_id.to_s)) && site_node.id == @options.list_page_id
return render_paragraph :text => '' if (['', 'category','tag','archive'].include?(conn_id.to_s.downcase)) && site_node.id == @options.list_page_id
raise SiteNodeEngine::MissingPageException.new( site_node, language ) unless editor?
end

Expand Down Expand Up @@ -200,7 +205,9 @@ def categories
protected

def get_blog
if @options.blog_id.to_i > 0
if @options.blog_id.to_i < 0
nil
elsif @options.blog_id.to_i > 0
Blog::BlogBlog.find_by_id(@options.blog_id.to_i)
elsif editor?
blog = Blog::BlogBlog.find(:first)
Expand Down
10 changes: 9 additions & 1 deletion vendor/modules/blog/app/models/blog/blog_post.rb
Expand Up @@ -16,7 +16,7 @@ class Blog::BlogPost < DomainModel
validates_presence_of :title

validates_length_of :permalink, :allow_nil => true, :maximum => 64

validates_datetime :published_at, :allow_nil => true

has_options :status, [ [ 'Draft','draft'], ['Published','published']]
Expand Down Expand Up @@ -88,6 +88,14 @@ def comments_count
return @comments_count
end

def self.paginate_published(page,items_per_page)
Blog::BlogPost.paginate(page,
:include => [ :active_revision, :blog_categories ],
:order => 'published_at DESC',
:conditions => ["blog_posts.status = \"published\" AND blog_posts.published_at < ?",Time.now],
:per_page => items_per_page)
end

def generate_permalink!
if permalink.blank? && self.active_revision
date = self.published_at || Time.now
Expand Down

0 comments on commit fc66d65

Please sign in to comment.