Class: BlogController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/blog_controller.rb

Instance Method Summary collapse

Instance Method Details

#archiveObject



71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/blog_controller.rb', line 71

def archive
  if Spud::Core.config.multisite_mode_enabled
    @posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date])
  else
    @posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
  end
  respond_with @posts do |format|
    format.html { render 'index' }
  end
end

#categoryObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/blog_controller.rb', line 55

def category
  if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
    if Spud::Core.config.multisite_mode_enabled
      @posts = @post_category.posts_with_children.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).for_spud_site(current_site_id).from_archive(params[:archive_date])
    else
      @posts = @post_category.posts_with_children.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
    end
  else
    redirect_to blog_path
    return
  end
  respond_with @posts do |format|
    format.html { render 'index' }
  end
end

#create_commentObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/blog_controller.rb', line 89

def create_comment
  unless params[:comment_validation].blank? # trap spam bots
    render :nothing => true
    return
  end
  @post = SpudPost.find(params[:id])
  if @post.blank?
    flash[:error] = "Post not found!"
    redirect_to blog_path and return false
  end
  @comment = @post.comments.new(params[:spud_post_comment])
  @comment.user_agent = request.env["HTTP_USER_AGENT"]
  @comment.user_ip = request.remote_ip
  @comment.referrer = request.referrer
  @comment.approved = true
  @comment.permalink = blog_post_url(@post.url_name)
  flash[:notice] = 'Your comment has been posted.' if @comment.save
  respond_with @comment do |format|
  	format.html { redirect_to blog_post_path(@post.url_name, :anchor => 'spud_post_comment_form') }
  end
end

#filterObject

The sole purpose of this action is to redirect from a POST to an seo-friendly url



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/blog_controller.rb', line 43

def filter
  if !params[:category_url_name].blank? && !params[:archive_date].blank?
    redirect_to blog_category_archive_path(params[:category_url_name], params[:archive_date])
  elsif !params[:category_url_name].blank?
    redirect_to blog_category_path(params[:category_url_name])
  elsif !params[:archive_date].blank?
    redirect_to blog_archive_path(params[:archive_date])
  else
    redirect_to blog_path
  end
end

#indexObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/blog_controller.rb', line 24

def index
  page = 1
  if params[:page].blank? == false && params[:page].to_i > 1
    page = params[:page].to_i
    if(page.to_s != params[:page] && page > 1)
      redirect_to blog_path(:page => page),:status => :moved_permanently and return
    end
  end


  logger.debug("Page = #{page}")
  @posts = SpudPost.public_blog_posts(page, Spud::Blog.config.posts_per_page)
  if Spud::Core.config.multisite_mode_enabled
    @posts = @posts.for_spud_site(current_site_id)
  end
  respond_with @posts
end

#showObject



82
83
84
85
86
87
# File 'app/controllers/blog_controller.rb', line 82

def show
  if @post.comments_enabled
    @comment = SpudPostComment.new(:spud_post_id => params[:id])
  end
	respond_with @post
end