Skip to content

Commit

Permalink
Multi blog, keywords and d duplicate support for blogs
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Aug 2, 2010
1 parent 19300f6 commit 53ab3e7
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/controllers/paragraph_renderer.rb
Expand Up @@ -423,7 +423,7 @@ def html_include(part, value=[])
@includes[part.to_sym] += value
end

# Includes the specified javascript file when the page is rendered
# Includes the specified javascript file when the page is rendered
# uses the standard rails javascript_include_tag syntax
def require_js(js)
@includes[:js] ||= []
Expand Down
4 changes: 4 additions & 0 deletions app/models/model_extension/content_node_extension.rb
Expand Up @@ -78,6 +78,10 @@ def self.append_features(mod) #:nodoc:

module InstanceMethods

def content_node_link
self.content_node.link if self.content_node
end

def content_node_save #:nodoc:
# Only save if we aren't already inside of save_content
save_content(nil,{},true) if(!content_node_skip)
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/page.rhtml
Expand Up @@ -8,8 +8,8 @@
<% if @output.meta_description || @output.includes[:meta_description] -%>
<meta name='DESCRIPTION' content='<%= vh (@output.includes[:meta_description] || @output.meta_description).to_s %>'/>
<% end -%>
<% if @output.meta_keywords%>
<meta name='KEYWORDS' content='<%= vh @output.meta_keywords%>'/>
<% if @output.meta_keywords || @output.includes[:meta_keywords] %>
<meta name='KEYWORDS' content='<%= vh (@output.includes[:meta_keywords] || @output.meta_keywords).to_s %>'/>
<% end -%>
<% if @robots.length > 0 %>
<meta name='ROBOTS' content='<%= @robots.join(',') %>'/>
Expand Down
39 changes: 14 additions & 25 deletions vendor/modules/blog/app/controllers/blog/manage_controller.rb
Expand Up @@ -44,9 +44,7 @@ def self.mail_manager_generator_handler_info
]

def display_generate_post_table(display=true)

@tbl = generate_post_table_generate params, :order => 'blog_posts.published_at DESC',:joins => [ :active_revision, :blog_blog ]

render :partial =>'generate_post_table' if display
end

Expand Down Expand Up @@ -81,29 +79,21 @@ def generate_categories
end

def post_table(display=true)
if(request.post? && params[:table_action] && params[:post].is_a?(Hash))

case params[:table_action]
when 'delete':
params[:post].each do |entry_id,val|
Blog::BlogPost.destroy(entry_id.to_i)
end
when 'publish':
params[:post].each do |entry_id,val|
entry = Blog::BlogPost.find(entry_id)
unless (entry.status == 'published' && entry.published_at && entry.published_at < Time.now)
entry.status = 'published'
entry.published_at = Time.now
entry.save
end
end

active_table_action(:post) do |act,eids|
entries = Blog::BlogPost.find(eids)
case act
when 'delete': entries.map(&:destroy)
when 'publish': entries.map(&:publish!)
when 'unpublish': entries.map(&:unpublish!)
when 'duplicate': entries.map(&:duplicate!)
end
end

@active_table_output = post_table_generate params, :joins => [ :active_revision ], :include => [ :blog_categories ],
:order => 'blog_posts.updated_at DESC', :conditions => ['blog_posts.blog_blog_id = ?',@blog.id ]
:order => 'blog_posts.updated_at DESC', :conditions => ['blog_posts.blog_blog_id = ?',@blog.id ]



render :partial => 'post_table' if display
end

Expand Down Expand Up @@ -154,10 +144,9 @@ def post
@entry.attributes = params[:entry]

case params[:update_entry][:status]
when 'draft':
@entry.make_draft
when 'publish_now' # if we want to publish the article now
@entry.publish_now
when 'draft': @entry.make_draft
when 'publish_now': @entry.publish_now
when 'preview': @entry.make_preview
when 'post_date'
@entry.publish(params[:entry][:published_at].blank? ? Time.now : (params[:entry][:published_at]))
end
Expand Down
14 changes: 10 additions & 4 deletions vendor/modules/blog/app/controllers/blog/page_controller.rb
Expand Up @@ -35,8 +35,9 @@ class Blog::PageController < ParagraphController
:inputs => [[:category, 'Selected Category', :blog_category_id]]

class EntryListOptions < HashModel
attributes :blog_id => 0, :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, :blog_ids => []

integer_array_options :blog_ids

def detail_page_id
self.detail_page
Expand All @@ -47,16 +48,21 @@ def detail_page_id

options_form(fld(:blog_id, :select, :options => :blog_options),
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),
fld('Advanced Options',:header),
fld(:blog_target_id, :select, :options => :blog_target_options, :description => 'Advanced use only'),
fld(:blog_ids, :ordered_array, :options => :blog_name_options, :label => 'For multiple blogs',:description => 'Leave blank to show all blogs'),
fld(:category,:text_field)
)

def blog_target_options; Blog::BlogTarget.select_options_with_nil; end

def blog_name_options
Blog::BlogBlog.find_select_options(:all,:order=>'name')
end

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

def include_in_path_options
Expand Down
8 changes: 5 additions & 3 deletions vendor/modules/blog/app/controllers/blog/page_renderer.rb
Expand Up @@ -78,7 +78,7 @@ def entry_list
pages,entries = blog.paginate_posts(page,items_per_page)
end
else
pages,entries = Blog::BlogPost.paginate_published(page,items_per_page)
pages,entries = Blog::BlogPost.paginate_published(page,items_per_page,@options.blog_ids)
end

cache[:output] = blog_entry_list_feature(:blog => blog,
Expand Down Expand Up @@ -106,16 +106,17 @@ def entry_detail
result = renderer_cache(blog, display_string) do |cache|
entry = nil
if editor?
entry = blog.blog_posts.find(:first,:conditions => ['blog_posts.status = "published" AND blog_blog_id=? ',blog.id])
entry = blog.blog_posts.find(:first,:conditions => ['blog_posts.status "published" AND blog_blog_id=? ',blog.id])
elsif conn_type == :post_permalink
entry = blog.find_post_by_permalink(conn_id) if conn_id
entry = blog.find_post_by_permalink(conn_id)
end

cache[:output] = blog_entry_detail_feature(:entry => entry,
:list_page => get_list_page,
:detail_page => site_node.node_path,
:blog => blog)
cache[:title] = entry ? entry.title : ''
cache[:keywords] = (entry && !entry.keywords.blank?) ? entry.keywords : nil
cache[:entry_id] = entry ? entry.id : nil
end

Expand All @@ -124,6 +125,7 @@ def entry_detail
set_page_connection(:post, result.entry_id )
set_title(result.title)
set_content_node(['Blog::BlogPost', result.entry_id])
html_include('meta_keywords',result.keywords) if result.keywords
else
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?
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules/blog/app/models/blog/blog_blog.rb
Expand Up @@ -89,7 +89,7 @@ def find_post_by_permalink(permalink)
Blog::BlogPost.find(:first,
:include => [ :active_revision ],
:order => 'published_at DESC',
:conditions => ["blog_posts.status = \"published\" AND blog_blog_id=? AND blog_posts.permalink=?",self.id,permalink])
:conditions => ["blog_posts.status in('published','preview') AND blog_blog_id=? AND blog_posts.permalink=?",self.id,permalink])
end

def content_type_name
Expand Down
62 changes: 55 additions & 7 deletions vendor/modules/blog/app/models/blog/blog_post.rb
Expand Up @@ -19,7 +19,7 @@ class Blog::BlogPost < DomainModel

validates_datetime :published_at, :allow_nil => true

has_options :status, [ [ 'Draft','draft'], ['Published','published']]
has_options :status, [ [ 'Draft','draft'],['Preview','preview'], ['Published','published']]

has_many :comments, :as => :target

Expand Down Expand Up @@ -88,12 +88,22 @@ 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)
def self.paginate_published(page,items_per_page,blog_ids = [])
if blog_ids.length > 0
Blog::BlogPost.paginate(page,
:include => [ :active_revision, :blog_categories ],
:order => 'published_at DESC',
:conditions => ["blog_posts.status = \"published\" AND blog_posts.published_at < ? AND blog_posts.blog_blog_id IN (?)",Time.now,blog_ids],
:per_page => items_per_page)

else
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

end

def generate_permalink!
Expand Down Expand Up @@ -227,14 +237,52 @@ def publish_now
end
end

def publish!
if self.publish_now
self.save
end
end

def unpublish!
self.status ='draft'
self.save
end

def publish(tm)
self.status = 'published'
self.published_at = tm
end

def preview!
self.status = 'preview'
self.save
end

def duplicate!
new_post = self.clone

[:media_file_id, :domain_file_id, :body, :end_user_id, :keywords,
:author, :embedded_media, :preview_title, :preview ].each do |fld|
new_post.send("#{fld}=",self.send(fld))
end
new_post.created_at = nil
new_post.updated_at = nil
new_post.title = "(COPY) " + self.title.to_s
new_post.permalink = nil
new_post.published_at = nil
new_post.status = 'draft'
new_post.save
new_post
end


def make_draft
self.status = 'draft'
end

def make_preview
self.status = 'preview'
end

def published?
self.status.to_s =='published' && self.published_at && self.published_at < Time.now
Expand Down
15 changes: 11 additions & 4 deletions vendor/modules/blog/app/views/blog/manage/_post_table.rhtml
Expand Up @@ -3,20 +3,27 @@
:refresh_url => url_for(:action => 'post_table', :path => @blog.id),
:class => 'active_table',
:style => 'width:100%',
:actions => [ [ 'Publish', 'publish', 'Publish the selected entries?' ] ],
:actions => [ [ 'Publish', 'publish', 'Publish the selected entries?' ],
[ 'Unpublish','unpublish','Unpublish the selected entries?'],
['Duplicate','duplicate','Duplicate the selected entries?']],
:more_actions => [
[ 'Delete', 'delete', 'Are you sure you want to permantently delete the selected entries?' ]

],
:update => 'post_table' do |t| %>
<tr <%= highlight_row 'post',t.id %> >
<td align='left' nowrap='1'><%= entry_checkbox "post", t.id %></td>
<td><a href='<%= url_for :action => 'post', :path => [ @blog.id, t.id ] %>'><%= t.active_revision.title %></a></td>
<td align='center'><%= t.status_display %><%= " (Post Dated)" if t.published_at && t.published_at > current_time %></td>
<td><a href='<%= url_for :action => 'post', :path => [ @blog.id, t.id ] %>'><%= h t.active_revision.title %></a></td>
<td >
<% if (t.status == 'published' || t.status == 'preview') && t.content_node_link %>
<%= link_to theme_icon("table","icons/table_actions/preview.gif"), t.content_node_link %>
<% end -%>
<%= t.status_display %><%= " (Post Dated)" if t.published_at && t.published_at > current_time %>
</td>
<td align='center'><%= t.published_at ? t.published_at.localize(DEFAULT_DATETIME_FORMAT.t) : '-' %></td>
<td><a href='<%= url_for :action => 'post', :path => [ @blog.id, t.id ] %>'><%= t.permalink %></a></td>
<td align='center'><%= t.updated_at ? t.updated_at.localize(DEFAULT_DATETIME_FORMAT.t) : '-' %></td>
<td><%= t.blog_categories.collect(&:name).join(", ") %></td>
<td><%= h t.blog_categories.collect(&:name).join(", ") %></td>
</tr>


Expand Down
1 change: 1 addition & 0 deletions vendor/modules/blog/app/views/blog/manage/post.rhtml
Expand Up @@ -128,6 +128,7 @@
</div>
<div class='sidebar_group'>
<label for='entry_status_draft'><input onclick='PostEditor.updateStatus();' id='entry_status_draft' name='update_entry[status]' value='draft' <%= "checked='checked'" if @entry.status == 'draft' %> type='radio'><%= "Draft".t %><br/>
<label for='entry_status_preview'><input onclick='PostEditor.updateStatus();' id='entry_status_preview' name='update_entry[status]' value='preview' <%= "checked='checked'" if @entry.status == 'preview' %> type='radio'><%= "Preview".t %><br/>
<label for='entry_status_published'><input onclick='PostEditor.updateStatus();' id='entry_status_published' name='update_entry[status]' value='publish_now' <%= "checked='checked'" if @entry.status == 'published' && @entry.published_at && @entry.published_at < Time.now %> type='radio'><%= "Published".t %><br/>
<label for='entry_status_post_date'><input onclick='PostEditor.updateStatus();' id='entry_status_post_date' name='update_entry[status]' value='post_date' type='radio' <%= "checked='checked'" if @entry.status == 'published' && ( !@entry.published_at || @entry.published_at > Time.now ) %> type='radio'><%= "Post Date".t %><br/>
<% if @entry.errors.on(:published_at) %>
Expand Down

0 comments on commit 53ab3e7

Please sign in to comment.