tb_blog 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +29 -0
- data/Readme.markdown +130 -0
- data/app/assets/images/spud/admin/news_thumb.png +0 -0
- data/app/assets/images/spud/admin/news_thumb@2x.png +0 -0
- data/app/assets/images/spud/admin/posts_thumb.png +0 -0
- data/app/assets/javascripts/spud/admin/post_categories.js +116 -0
- data/app/assets/javascripts/spud/admin/posts.js +71 -0
- data/app/assets/javascripts/spud/blog/sitemaps.js +2 -0
- data/app/assets/javascripts/spud/blog.js +41 -0
- data/app/assets/stylesheets/news.css +4 -0
- data/app/assets/stylesheets/spud/admin/posts.css +113 -0
- data/app/assets/stylesheets/spud/blog/sitemaps.css +4 -0
- data/app/assets/stylesheets/spud/blog/validity.css +3 -0
- data/app/controllers/blog_controller.rb +135 -0
- data/app/controllers/news_controller.rb +80 -0
- data/app/controllers/spud/admin/news_posts_controller.rb +62 -0
- data/app/controllers/spud/admin/post_categories_controller.rb +59 -0
- data/app/controllers/spud/admin/post_comments_controller.rb +68 -0
- data/app/controllers/spud/admin/posts_controller.rb +62 -0
- data/app/controllers/spud/blog/sitemaps_controller.rb +9 -0
- data/app/helpers/blog_helper.rb +25 -0
- data/app/helpers/news_helper.rb +2 -0
- data/app/helpers/spud/admin/news_posts_helper.rb +2 -0
- data/app/helpers/spud/admin/post_categories_helper.rb +2 -0
- data/app/helpers/spud/admin/post_comments_helper.rb +2 -0
- data/app/helpers/spud/admin/posts_helper.rb +22 -0
- data/app/helpers/spud/blog/sitemaps_helper.rb +2 -0
- data/app/models/spud_post.rb +171 -0
- data/app/models/spud_post_categories_post.rb +5 -0
- data/app/models/spud_post_category.rb +70 -0
- data/app/models/spud_post_category_sweeper.rb +41 -0
- data/app/models/spud_post_comment.rb +19 -0
- data/app/models/spud_post_comment_sweeper.rb +33 -0
- data/app/models/spud_post_site.rb +9 -0
- data/app/models/spud_post_sweeper.rb +47 -0
- data/app/views/blog/_comment.html.erb +4 -0
- data/app/views/blog/_comment_form.html.erb +20 -0
- data/app/views/blog/index.html.erb +35 -0
- data/app/views/blog/index.rss.builder +18 -0
- data/app/views/blog/show.html.erb +37 -0
- data/app/views/news/index.html.erb +35 -0
- data/app/views/news/index.rss.builder +18 -0
- data/app/views/news/show.html.erb +27 -0
- data/app/views/spud/admin/news_posts/edit.html.erb +3 -0
- data/app/views/spud/admin/news_posts/index.html.erb +44 -0
- data/app/views/spud/admin/news_posts/new.html.erb +3 -0
- data/app/views/spud/admin/post_categories/_category.html.erb +14 -0
- data/app/views/spud/admin/post_categories/_form.html.erb +23 -0
- data/app/views/spud/admin/post_categories/edit.html.erb +1 -0
- data/app/views/spud/admin/post_categories/index.html.erb +9 -0
- data/app/views/spud/admin/post_categories/new.html.erb +1 -0
- data/app/views/spud/admin/post_comments/index.html.erb +47 -0
- data/app/views/spud/admin/posts/_category.html.erb +9 -0
- data/app/views/spud/admin/posts/_form.html.erb +117 -0
- data/app/views/spud/admin/posts/edit.html.erb +3 -0
- data/app/views/spud/admin/posts/index.html.erb +50 -0
- data/app/views/spud/admin/posts/new.html.erb +3 -0
- data/app/views/spud/blog/sitemaps/show.xml.builder +16 -0
- data/config/routes.rb +94 -0
- data/db/migrate/20120125180945_create_spud_posts.rb +15 -0
- data/db/migrate/20120125181022_create_spud_post_categories.rb +13 -0
- data/db/migrate/20120125181359_create_spud_post_comments.rb +13 -0
- data/db/migrate/20120127143054_add_url_to_spud_posts.rb +6 -0
- data/db/migrate/20120127144942_add_url_to_spud_post_categories.rb +8 -0
- data/db/migrate/20120210165540_add_is_news_to_spud_posts.rb +6 -0
- data/db/migrate/20120309181917_add_meta_to_posts.rb +6 -0
- data/db/migrate/20120413020437_add_comments_counter_to_spud_posts.rb +12 -0
- data/db/migrate/20120713150446_create_spud_post_sites.rb +11 -0
- data/db/migrate/20120825142547_add_spam_fields_to_spud_post_comments.rb +8 -0
- data/db/migrate/20120825144506_add_permalink_to_spud_post_comments.rb +5 -0
- data/db/migrate/20121113135812_add_nested_set_to_post_categories.rb +21 -0
- data/db/migrate/20130120151857_add_content_format_to_spud_posts.rb +5 -0
- data/db/migrate/20130121130612_add_content_processed_to_spud_post.rb +5 -0
- data/lib/generators/spud/blog/random_posts_generator.rb +60 -0
- data/lib/generators/spud/blog/views_generator.rb +19 -0
- data/lib/spud_blog/configuration.rb +25 -0
- data/lib/spud_blog/engine.rb +64 -0
- data/lib/spud_blog/version.rb +5 -0
- data/lib/tasks/spud_blog_tasks.rake +4 -0
- data/lib/tb_blog.rb +6 -0
- data/test/fixtures/spud_post_sites.yml +9 -0
- data/test/unit/spud_post_site_test.rb +7 -0
- metadata +338 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
class BlogController < ApplicationController
|
2
|
+
|
3
|
+
respond_to :html, :xml, :json, :rss
|
4
|
+
layout Spud::Blog.base_layout
|
5
|
+
|
6
|
+
before_filter :find_post, :only => :show
|
7
|
+
|
8
|
+
caches_action :show, :index,
|
9
|
+
:expires => Spud::Blog.config.action_caching_duration,
|
10
|
+
:if => Proc.new{ |c|
|
11
|
+
Spud::Blog.cache_mode == :action && !(c.params[:page] && c.params[:page].to_i > 1) && (SpudPost.where(:is_news => false).future_posts.count == 0)
|
12
|
+
}
|
13
|
+
|
14
|
+
after_filter :only => [:show, :index] do |c|
|
15
|
+
if Spud::Blog.cache_mode == :full_page && !(c.params[:page] && c.params[:page].to_i > 1)
|
16
|
+
if (SpudPost.where(:is_news => false).future_posts.count == 0)
|
17
|
+
c.cache_page(nil, nil, false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
cache_sweeper :spud_post_comment_sweeper, :only => [:create_comment]
|
23
|
+
|
24
|
+
def index
|
25
|
+
page = 1
|
26
|
+
if params[:page].blank? == false
|
27
|
+
page = params[:page].to_i
|
28
|
+
if page.to_s != params[:page].to_s
|
29
|
+
if(page > 1)
|
30
|
+
redirect_to blog_path(:page => page),:status => :moved_permanently and return
|
31
|
+
else
|
32
|
+
redirect_to blog_path(:page => nil),:status => :moved_permanently and return
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@posts = SpudPost.public_blog_posts(page, Spud::Blog.config.posts_per_page)
|
38
|
+
if Spud::Core.config.multisite_mode_enabled
|
39
|
+
@posts = @posts.for_spud_site(current_site_id)
|
40
|
+
end
|
41
|
+
respond_with @posts
|
42
|
+
end
|
43
|
+
|
44
|
+
# The sole purpose of this action is to redirect from a POST to an seo-friendly url
|
45
|
+
def filter
|
46
|
+
if !params[:category_url_name].blank? && !params[:archive_date].blank?
|
47
|
+
redirect_to blog_category_archive_path(params[:category_url_name], params[:archive_date])
|
48
|
+
elsif !params[:category_url_name].blank?
|
49
|
+
redirect_to blog_category_path(params[:category_url_name])
|
50
|
+
elsif !params[:archive_date].blank?
|
51
|
+
redirect_to blog_archive_path(params[:archive_date])
|
52
|
+
else
|
53
|
+
redirect_to blog_path
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def category
|
58
|
+
page = 1
|
59
|
+
if params[:page].blank? == false
|
60
|
+
page = params[:page].to_i
|
61
|
+
if page.to_s != params[:page].to_s
|
62
|
+
if(page > 1)
|
63
|
+
redirect_to blog_category_path(:page => page),:status => :moved_permanently and return
|
64
|
+
else
|
65
|
+
redirect_to blog_category_path(:page => nil),:status => :moved_permanently and return
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
|
71
|
+
if Spud::Core.config.multisite_mode_enabled
|
72
|
+
@posts = @post_category.posts_with_children.public_blog_posts(page, Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date])
|
73
|
+
else
|
74
|
+
@posts = @post_category.posts_with_children.public_blog_posts(page, Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
|
75
|
+
end
|
76
|
+
else
|
77
|
+
redirect_to blog_path
|
78
|
+
return
|
79
|
+
end
|
80
|
+
respond_with @posts do |format|
|
81
|
+
format.html { render 'index' }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def archive
|
86
|
+
if Spud::Core.config.multisite_mode_enabled
|
87
|
+
@posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date])
|
88
|
+
else
|
89
|
+
@posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
|
90
|
+
end
|
91
|
+
respond_with @posts do |format|
|
92
|
+
format.html { render 'index' }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def show
|
97
|
+
if @post.comments_enabled
|
98
|
+
@comment = SpudPostComment.new(:spud_post_id => params[:id])
|
99
|
+
end
|
100
|
+
respond_with @post
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_comment
|
104
|
+
unless params[:comment_validation].blank? # trap spam bots
|
105
|
+
render :nothing => true
|
106
|
+
return
|
107
|
+
end
|
108
|
+
@post = SpudPost.find(params[:id])
|
109
|
+
if @post.blank?
|
110
|
+
flash[:error] = "Post not found!"
|
111
|
+
redirect_to blog_path and return false
|
112
|
+
end
|
113
|
+
@comment = @post.comments.new(params[:spud_post_comment])
|
114
|
+
@comment.user_agent = request.env["HTTP_USER_AGENT"]
|
115
|
+
@comment.user_ip = request.remote_ip
|
116
|
+
@comment.referrer = request.referrer
|
117
|
+
@comment.approved = true
|
118
|
+
@comment.permalink = blog_post_url(@post.url_name)
|
119
|
+
flash[:notice] = 'Your comment has been posted.' if @comment.save
|
120
|
+
respond_with @comment do |format|
|
121
|
+
format.html { redirect_to blog_post_path(@post.url_name, :anchor => 'spud_post_comment_form') }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def find_post
|
128
|
+
@post = SpudPost.find_by_url_name(params[:id])
|
129
|
+
if @post.blank? || @post.is_private? || (Spud::Core.config.multisite_mode_enabled && !@post.spud_site_ids.include?(current_site_id))
|
130
|
+
flash[:error] = "Post not found!"
|
131
|
+
redirect_to blog_path and return false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class NewsController < ApplicationController
|
2
|
+
|
3
|
+
respond_to :html, :xml, :json, :rss
|
4
|
+
layout Spud::Blog.news_layout
|
5
|
+
|
6
|
+
caches_action :show, :index,
|
7
|
+
:expires => Spud::Blog.config.action_caching_duration,
|
8
|
+
:if => Proc.new{ |c|
|
9
|
+
Spud::Blog.cache_mode == :action && !(c.params[:page] && c.params[:page].to_i > 1) && (SpudPost.where(:is_news => true).future_posts.count == 0)
|
10
|
+
}
|
11
|
+
|
12
|
+
after_filter :only => [:show, :index] do |c|
|
13
|
+
if Spud::Blog.cache_mode == :full_page && !(c.params[:page] && c.params[:page].to_i > 1)
|
14
|
+
if (SpudPost.where(:is_news => true).future_posts.count == 0)
|
15
|
+
c.cache_page(nil, nil, false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
cache_sweeper :spud_post_comment_sweeper, :only => [:create_comment]
|
21
|
+
|
22
|
+
def index
|
23
|
+
@posts = SpudPost.public_news_posts(params[:page], Spud::Blog.config.posts_per_page)
|
24
|
+
if Spud::Core.config.multisite_mode_enabled
|
25
|
+
@posts = @posts.for_spud_site(current_site_id)
|
26
|
+
end
|
27
|
+
respond_with @posts
|
28
|
+
end
|
29
|
+
|
30
|
+
# The sole purpose of this action is to redirect from a POST to an seo-friendly url
|
31
|
+
def filter
|
32
|
+
if !params[:category_url_name].blank? && !params[:archive_date].blank?
|
33
|
+
redirect_to news_category_archive_path(params[:category_url_name], params[:archive_date])
|
34
|
+
elsif !params[:category_url_name].blank?
|
35
|
+
redirect_to news_category_path(params[:category_url_name])
|
36
|
+
elsif !params[:archive_date].blank?
|
37
|
+
redirect_to news_archive_path(params[:archive_date])
|
38
|
+
else
|
39
|
+
redirect_to news_path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def category
|
44
|
+
if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
|
45
|
+
if Spud::Core.config.multisite_mode_enabled
|
46
|
+
@posts = @post_category.posts_with_children.public_news_posts(params[:page], Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date])
|
47
|
+
else
|
48
|
+
@posts = @post_category.posts_with_children.public_news_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
redirect_to news_path
|
52
|
+
return
|
53
|
+
end
|
54
|
+
respond_with @posts do |format|
|
55
|
+
format.html { render 'index' }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def archive
|
60
|
+
if Spud::Core.config.multisite_mode_enabled
|
61
|
+
@posts = SpudPost.public_news_posts(params[:page], Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date])
|
62
|
+
else
|
63
|
+
@posts = SpudPost.public_news_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
|
64
|
+
end
|
65
|
+
respond_with @posts do |format|
|
66
|
+
format.html { render 'index' }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def show
|
71
|
+
@post = SpudPost.find_by_url_name(params[:id])
|
72
|
+
if @post.blank? || @post.is_private? || (Spud::Core.config.multisite_mode_enabled && !@post.spud_site_ids.include?(current_site_id))
|
73
|
+
flash[:error] = "Post not found!"
|
74
|
+
redirect_to news_path and return false
|
75
|
+
else
|
76
|
+
respond_with @post
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
2
|
+
|
3
|
+
layout 'spud/admin/detail'
|
4
|
+
respond_to :html, :xml, :json
|
5
|
+
before_filter :find_post, :only => [:show, :edit, :update, :destroy]
|
6
|
+
add_breadcrumb 'News Posts', :spud_admin_news_posts_path
|
7
|
+
belongs_to_spud_app :news_posts
|
8
|
+
cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]
|
9
|
+
|
10
|
+
def index
|
11
|
+
@posts = SpudPost.where(:is_news => true).order('published_at desc').includes(:comments).paginate(:page => params[:page], :per_page => 15)
|
12
|
+
respond_with @posts
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
@categories = SpudPostCategory.grouped
|
17
|
+
respond_with @post
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@categories = SpudPostCategory.grouped
|
22
|
+
params[:spud_post][:spud_site_ids] ||= []
|
23
|
+
if @post.update_attributes(params[:spud_post])
|
24
|
+
flash[:notice] = 'News Post was successfully updated.'
|
25
|
+
end
|
26
|
+
respond_with @post, :location => spud_admin_news_posts_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def new
|
30
|
+
@categories = SpudPostCategory.grouped
|
31
|
+
@post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id, :is_news => true, :comments_enabled => false, :spud_site_ids => [current_site_id])
|
32
|
+
respond_with @post
|
33
|
+
end
|
34
|
+
|
35
|
+
def create
|
36
|
+
@categories = SpudPostCategory.grouped
|
37
|
+
params[:spud_post][:spud_site_ids] ||= []
|
38
|
+
@post = SpudPost.new(params[:spud_post])
|
39
|
+
if @post.save
|
40
|
+
flash[:notice] = 'News Post was successfully created.'
|
41
|
+
end
|
42
|
+
respond_with @post, :location => spud_admin_news_posts_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
if @post.destroy
|
47
|
+
flash[:notice] = 'News Post was successfully deleted.'
|
48
|
+
end
|
49
|
+
respond_with @post, :location => spud_admin_news_posts_path
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def find_post
|
55
|
+
@post = SpudPost.find(params[:id])
|
56
|
+
if @post.blank?
|
57
|
+
flash[:error] = 'News Post not found!'
|
58
|
+
redirect_to spud_admin_news_posts_path and return false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
2
|
+
|
3
|
+
layout false
|
4
|
+
respond_to :html, :json
|
5
|
+
|
6
|
+
before_filter :find_category, :only => [:show, :edit, :update, :destroy]
|
7
|
+
cache_sweeper :spud_post_category_sweeper, :only => [:create, :update, :destroy]
|
8
|
+
|
9
|
+
def index
|
10
|
+
@post_categories = SpudPostCategory.grouped
|
11
|
+
respond_with @post_categories
|
12
|
+
end
|
13
|
+
|
14
|
+
def edit
|
15
|
+
respond_with @post_category
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
if @post_category.update_attributes(params[:spud_post_category])
|
20
|
+
flash[:notice] = 'Post Category was successfully updated'
|
21
|
+
respond_with @post_category, :location => spud_admin_post_categories_path
|
22
|
+
else
|
23
|
+
render 'new', :status => 422
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def new
|
28
|
+
@post_category = SpudPostCategory.new
|
29
|
+
respond_with @post_category
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
@post_category = SpudPostCategory.new(params[:spud_post_category])
|
34
|
+
if @post_category.save
|
35
|
+
flash[:notice] = 'Post Category was successfully created'
|
36
|
+
respond_with @post_category, :location => spud_admin_post_categories_path
|
37
|
+
else
|
38
|
+
render 'new', :status => 422
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
if @post_category.destroy
|
44
|
+
flash[:notice] = 'Post Category was successfully deleted'
|
45
|
+
@post_categories = SpudPostCategory.grouped
|
46
|
+
render 'index'
|
47
|
+
else
|
48
|
+
respond_with @post_category, :location => spud_admin_post_categories_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def find_category
|
55
|
+
@post_category = SpudPostCategory.find(params[:id])
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class Spud::Admin::PostCommentsController < Spud::Admin::ApplicationController
|
2
|
+
|
3
|
+
respond_to :html, :xml, :json
|
4
|
+
layout 'spud/admin/detail'
|
5
|
+
belongs_to_spud_app :blog_posts
|
6
|
+
before_filter :find_comment, :only => [:show, :edit, :update, :destroy, :approve, :spam]
|
7
|
+
add_breadcrumb 'Blog Posts', :spud_admin_posts_path
|
8
|
+
add_breadcrumb 'Comments', :spud_admin_post_comments_path
|
9
|
+
|
10
|
+
|
11
|
+
def index
|
12
|
+
@page_name = "Comments"
|
13
|
+
if params[:post_id]
|
14
|
+
@post_comments = SpudPost.find(params[:post_id]).comments
|
15
|
+
else
|
16
|
+
@post_comments = SpudPostComment
|
17
|
+
end
|
18
|
+
@post_comments = @post_comments.paginate :page => params[:page]
|
19
|
+
respond_with @post_comments
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
respond_with @post_comment
|
24
|
+
end
|
25
|
+
|
26
|
+
def edit
|
27
|
+
respond_with @post_comment
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def create
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def approve
|
39
|
+
|
40
|
+
if Spud::Blog.enable_rakismet && @post_comment.spam
|
41
|
+
@post_comment.ham!
|
42
|
+
end
|
43
|
+
@post_comment.update_attributes(:spam => false)
|
44
|
+
redirect_to request.referer || spud_admin_post_comments_path
|
45
|
+
end
|
46
|
+
|
47
|
+
def spam
|
48
|
+
if Spud::Blog.enable_rakismet && !@post_comment.spam
|
49
|
+
@post_comment.spam!
|
50
|
+
end
|
51
|
+
@post_comment.update_attributes(:spam => true)
|
52
|
+
redirect_to request.referer || spud_admin_post_comments_path
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy
|
56
|
+
if !@post_comment.destroy
|
57
|
+
flash[:error] = "Whoops! Something odd happened while trying to delete that comment. Thats not fun. please try again."
|
58
|
+
end
|
59
|
+
respond_with @post_comment, :location => request.referer || spud_admin_post_comments_path
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def find_comment
|
65
|
+
@post_comment = SpudPostComment.find(params[:id])
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
2
|
+
|
3
|
+
layout 'spud/admin/detail'
|
4
|
+
respond_to :html, :xml, :json
|
5
|
+
before_filter :find_post, :only => [:show, :edit, :update, :destroy]
|
6
|
+
add_breadcrumb 'Blog Posts', :spud_admin_posts_path
|
7
|
+
belongs_to_spud_app :blog_posts
|
8
|
+
cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]
|
9
|
+
|
10
|
+
def index
|
11
|
+
@posts = SpudPost.where(:is_news => false).order('published_at desc').includes(:visible_comments, :spam_comments, :author).paginate(:page => params[:page], :per_page => 15)
|
12
|
+
respond_with @posts
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
@categories = SpudPostCategory.grouped
|
17
|
+
respond_with @post
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@categories = SpudPostCategory.grouped
|
22
|
+
params[:spud_post][:spud_site_ids] ||= []
|
23
|
+
if @post.update_attributes(params[:spud_post])
|
24
|
+
flash[:notice] = 'Post was successfully updated.'
|
25
|
+
end
|
26
|
+
respond_with @post, :location => spud_admin_posts_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def new
|
30
|
+
@categories = SpudPostCategory.grouped
|
31
|
+
@post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id, :spud_site_ids => [session[:admin_site] || 0])
|
32
|
+
respond_with @post
|
33
|
+
end
|
34
|
+
|
35
|
+
def create
|
36
|
+
@categories = SpudPostCategory.grouped
|
37
|
+
params[:spud_post][:spud_site_ids] ||= []
|
38
|
+
@post = SpudPost.new(params[:spud_post])
|
39
|
+
if @post.save
|
40
|
+
flash[:notice] = 'Post was successfully created.'
|
41
|
+
end
|
42
|
+
respond_with @post, :location => spud_admin_posts_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
if @post.destroy
|
47
|
+
flash[:notice] = 'Post was successfully deleted.'
|
48
|
+
end
|
49
|
+
respond_with @post, :location => spud_admin_posts_path
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def find_post
|
55
|
+
@post = SpudPost.find(params[:id])
|
56
|
+
if @post.blank?
|
57
|
+
flash[:error] = "Post not found!"
|
58
|
+
redirect_to spud_admin_posts_path and return false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Spud::Blog::SitemapsController < Spud::ApplicationController
|
2
|
+
respond_to :xml
|
3
|
+
caches_action :show, :expires_in => 1.day, :if => Proc.new{ |c| Spud::Blog.cache_mode == :action }
|
4
|
+
caches_page :show, :if => Proc.new{ |c| Spud::Blog.cache_mode == :full_page }
|
5
|
+
def show
|
6
|
+
@posts = SpudPost.publicly.all
|
7
|
+
respond_with @pages
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BlogHelper
|
2
|
+
|
3
|
+
def spud_post_category_select
|
4
|
+
return select_tag 'category_url_name',
|
5
|
+
options_for_select(SpudPostCategory.options_for_categories(:value => :url_name), params[:category_url_name]),
|
6
|
+
:include_blank => true,
|
7
|
+
:rel => 'category'
|
8
|
+
end
|
9
|
+
|
10
|
+
def spud_post_archive_select
|
11
|
+
dates = SpudPost.months_with_public_posts
|
12
|
+
return select_tag 'archive_date', options_for_select(SpudPost.months_with_public_posts.collect{ |d|
|
13
|
+
[d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
|
14
|
+
}, params[:archive_date]), :include_blank => true, :rel => 'archive'
|
15
|
+
end
|
16
|
+
|
17
|
+
def spud_blog_rss_link
|
18
|
+
return tag :link, :rel => 'alternate', :type => 'application/rss+xml', :title => "#{Spud::Core.site_name} Blog RSS", :href => blog_url(:format => :rss)
|
19
|
+
end
|
20
|
+
|
21
|
+
def spud_news_rss_link
|
22
|
+
return tag(:link, :rel => 'alternate', :type => 'application/rss+xml', :title => "#{Spud::Core.site_name} News RSS", :href => news_url(:format => :rss))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spud::Admin::PostsHelper
|
2
|
+
|
3
|
+
def options_for_parent_category(parent_id = 0)
|
4
|
+
if @categories[parent_id]
|
5
|
+
return @categories[parent_id].collect{ |c|
|
6
|
+
opts = [c.name, c.id]
|
7
|
+
opts += options_for_parent_category(c.id)
|
8
|
+
}
|
9
|
+
else
|
10
|
+
return []
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def spud_post_site_check_box_tag(site, post)
|
15
|
+
return check_box_tag 'spud_post[spud_site_ids][]', site[:site_id], post.spud_site_ids.include?(site[:site_id]), :id => "spud_post_site_id_#{site[:site_id]}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def spud_post_site_label_tag(site)
|
19
|
+
return label_tag "spud_post_site_id_#{site[:site_id]}", site[:site_name], :class => 'checkbox inline'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|