aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/.gitkeep0
-rw-r--r--app/controllers/admin/blog/categories_controller.rb11
-rw-r--r--app/controllers/admin/blog/comments_controller.rb40
-rw-r--r--app/controllers/admin/blog/posts_controller.rb97
-rw-r--r--app/controllers/admin/blog/settings_controller.rb53
-rw-r--r--app/controllers/blog/categories_controller.rb13
-rw-r--r--app/controllers/blog/posts_controller.rb109
-rw-r--r--app/controllers/blog_controller.rb16
-rw-r--r--app/controllers/refinery/admin/blog/categories_controller.rb13
-rw-r--r--app/controllers/refinery/admin/blog/comments_controller.rb49
-rw-r--r--app/controllers/refinery/admin/blog/posts_controller.rb94
-rw-r--r--app/controllers/refinery/admin/blog/settings_controller.rb55
-rw-r--r--app/controllers/refinery/blog/base_controller.rb17
-rw-r--r--app/controllers/refinery/blog/categories_controller.rb12
-rw-r--r--app/controllers/refinery/blog/posts_controller.rb82
15 files changed, 322 insertions, 339 deletions
diff --git a/app/controllers/.gitkeep b/app/controllers/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/controllers/.gitkeep
diff --git a/app/controllers/admin/blog/categories_controller.rb b/app/controllers/admin/blog/categories_controller.rb
deleted file mode 100644
index 6933c44..0000000
--- a/app/controllers/admin/blog/categories_controller.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Admin
- module Blog
- class CategoriesController < Admin::BaseController
-
- crudify :blog_category,
- :title_attribute => :title,
- :order => 'title ASC'
-
- end
- end
-end
diff --git a/app/controllers/admin/blog/comments_controller.rb b/app/controllers/admin/blog/comments_controller.rb
deleted file mode 100644
index 1868206..0000000
--- a/app/controllers/admin/blog/comments_controller.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module Admin
- module Blog
- class CommentsController < Admin::BaseController
-
- crudify :blog_comment,
- :title_attribute => :name,
- :order => 'published_at DESC'
-
- def index
- @blog_comments = BlogComment.unmoderated
- render :action => 'index'
- end
-
- def approved
- unless params[:id].present?
- @blog_comments = BlogComment.approved
- render :action => 'index'
- else
- @blog_comment = BlogComment.find(params[:id])
- @blog_comment.approve!
- flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name)
- redirect_to :action => params[:return_to] || 'index'
- end
- end
-
- def rejected
- unless params[:id].present?
- @blog_comments = BlogComment.rejected
- render :action => 'index'
- else
- @blog_comment = BlogComment.find(params[:id])
- @blog_comment.reject!
- flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name)
- redirect_to :action => params[:return_to] || 'index'
- end
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/app/controllers/admin/blog/posts_controller.rb b/app/controllers/admin/blog/posts_controller.rb
deleted file mode 100644
index b2f2a79..0000000
--- a/app/controllers/admin/blog/posts_controller.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-module Admin
- module Blog
- class PostsController < Admin::BaseController
- require 'will_paginate/array'
-
- crudify :blog_post,
- :title_attribute => :title,
- :order => 'published_at DESC'
-
- def uncategorized
- @blog_posts = BlogPost.uncategorized.paginate({
- :page => params[:page],
- :per_page => BlogPost.per_page
- })
- end
-
- def tags
- op = case ActiveRecord::Base.connection.adapter_name.downcase
- when 'postgresql'
- '~*'
- else
- 'LIKE'
- end
- wildcard = case ActiveRecord::Base.connection.adapter_name.downcase
- when 'postgresql'
- '.*'
- else
- '%'
- end
- @tags = BlogPost.tag_counts_on(:tags).where(
- ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
- ).map { |tag| {:id => tag.id, :value => tag.name}}
- render :json => @tags.flatten
- end
-
- def create
- # if the position field exists, set this object as last object, given the conditions of this class.
- if BlogPost.column_names.include?("position")
- params[:blog_post].merge!({
- :position => ((BlogPost.maximum(:position, :conditions => "")||-1) + 1)
- })
- end
-
- if BlogPost.column_names.include?("user_id")
- params[:blog_post].merge!({
- :user_id => current_user.id
- })
- end
-
- if (@blog_post = BlogPost.create(params[:blog_post])).valid?
- (request.xhr? ? flash.now : flash).notice = t(
- 'refinery.crudify.created',
- :what => "'#{@blog_post.title}'"
- )
-
- unless from_dialog?
- unless params[:continue_editing] =~ /true|on|1/
- redirect_back_or_default(admin_blog_posts_url)
- else
- unless request.xhr?
- redirect_to :back
- else
- render :partial => "/shared/message"
- end
- end
- else
- render :text => "<script>parent.window.location = '#{admin_blog_posts_url}';</script>"
- end
- else
- unless request.xhr?
- render :action => 'new'
- else
- render :partial => "/shared/admin/error_messages",
- :locals => {
- :object => @blog_post,
- :include_object_name => true
- }
- end
- end
- end
-
- before_filter :find_all_categories,
- :only => [:new, :edit, :create, :update]
-
- before_filter :check_category_ids, :only => :update
-
- protected
- def find_all_categories
- @blog_categories = BlogCategory.find(:all)
- end
-
- def check_category_ids
- params[:blog_post][:category_ids] ||= []
- end
- end
- end
-end
diff --git a/app/controllers/admin/blog/settings_controller.rb b/app/controllers/admin/blog/settings_controller.rb
deleted file mode 100644
index 5f2b3be..0000000
--- a/app/controllers/admin/blog/settings_controller.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-module Admin
- module Blog
- class SettingsController < Admin::BaseController
-
- def notification_recipients
- @recipients = BlogComment::Notification.recipients
-
- if request.post?
- BlogComment::Notification.recipients = params[:recipients]
- flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients',
- :recipients => BlogComment::Notification.recipients)
- unless request.xhr? or from_dialog?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>",
- :layout => false
- end
- end
- end
-
- def moderation
- enabled = BlogComment::Moderation.toggle!
- unless request.xhr?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :json => {:enabled => enabled},
- :layout => false
- end
- end
-
- def comments
- enabled = BlogComment.toggle!
- unless request.xhr?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :json => {:enabled => enabled},
- :layout => false
- end
- end
-
- def teasers
- enabled = BlogPost.teaser_enabled_toggle!
- unless request.xhr?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :json => {:enabled => enabled},
- :layout => false
- end
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/app/controllers/blog/categories_controller.rb b/app/controllers/blog/categories_controller.rb
deleted file mode 100644
index efda778..0000000
--- a/app/controllers/blog/categories_controller.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module Blog
- class CategoriesController < BlogController
-
- def show
- @category = BlogCategory.find(params[:id])
- @blog_posts = @category.posts.live.includes(:comments, :categories).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
-
- end
-end \ No newline at end of file
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb
deleted file mode 100644
index 7eb167d..0000000
--- a/app/controllers/blog/posts_controller.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-module Blog
- class PostsController < BlogController
-
- before_filter :find_all_blog_posts, :except => [:archive]
- before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
- before_filter :find_tags
-
- respond_to :html, :js, :rss
-
- def index
- # Rss feeders are greedy. Let's give them every blog post instead of paginating.
- (@blog_posts = BlogPost.live.includes(:comments, :categories).all) if request.format.rss?
- respond_with (@blog_posts) do |format|
- format.html
- format.rss
- end
- end
-
- def show
- @blog_comment = BlogComment.new
- @canonical = url_for(:locale => ::Refinery::I18n.default_frontend_locale) if canonical?
-
- respond_with (@blog_post) do |format|
- format.html { present(@blog_post) }
- format.js { render :partial => 'post', :layout => false }
- end
- end
-
- def comment
- if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
- if BlogComment::Moderation.enabled? or @blog_comment.ham?
- begin
- Blog::CommentMailer.notification(@blog_comment, request).deliver
- rescue
- logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
- end
- end
-
- if BlogComment::Moderation.enabled?
- flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments')
- redirect_to blog_post_url(params[:id])
- else
- flash[:notice] = t('thank_you', :scope => 'blog.posts.comments')
- redirect_to blog_post_url(params[:id],
- :anchor => "comment-#{@blog_comment.to_param}")
- end
- else
- render :action => 'show'
- end
- end
-
- def archive
- if params[:month].present?
- date = "#{params[:month]}/#{params[:year]}"
- @archive_date = Time.parse(date)
- @date_title = @archive_date.strftime('%B %Y')
- @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- else
- date = "01/#{params[:year]}"
- @archive_date = Time.parse(date)
- @date_title = @archive_date.strftime('%Y')
- @blog_posts = BlogPost.live.by_year(@archive_date).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
- respond_with (@blog_posts)
- end
-
- def tagged
- @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
- @tag_name = @tag.name
- @blog_posts = BlogPost.tagged_with(@tag_name).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
-
- protected
-
- def find_blog_post
- unless (@blog_post = BlogPost.find(params[:id])).try(:live?)
- if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog")
- @blog_post = BlogPost.find(params[:id])
- else
- error_404
- end
- end
- end
-
- def find_all_blog_posts
- @blog_posts = BlogPost.live.includes(:comments, :categories).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
-
- def find_tags
- @tags = BlogPost.tag_counts_on(:tags)
- end
-
- def canonical?
- ::Refinery.i18n_enabled? && ::Refinery::I18n.default_frontend_locale != ::Refinery::I18n.current_frontend_locale
- end
- end
-end \ No newline at end of file
diff --git a/app/controllers/blog_controller.rb b/app/controllers/blog_controller.rb
deleted file mode 100644
index f51d5bb..0000000
--- a/app/controllers/blog_controller.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-class BlogController < ApplicationController
-
- helper :blog_posts
- before_filter :find_page, :find_all_blog_categories
-
-protected
-
- def find_page
- @page = Page.find_by_link_url("/blog")
- end
-
- def find_all_blog_categories
- @blog_categories = BlogCategory.all
- end
-
-end
diff --git a/app/controllers/refinery/admin/blog/categories_controller.rb b/app/controllers/refinery/admin/blog/categories_controller.rb
new file mode 100644
index 0000000..0fe4eec
--- /dev/null
+++ b/app/controllers/refinery/admin/blog/categories_controller.rb
@@ -0,0 +1,13 @@
+module Refinery
+ module Admin
+ module Blog
+ class CategoriesController < ::Refinery::AdminController
+
+ crudify :'refinery/blog/category',
+ :title_attribute => :title,
+ :order => 'title ASC'
+
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/admin/blog/comments_controller.rb b/app/controllers/refinery/admin/blog/comments_controller.rb
new file mode 100644
index 0000000..6c1417e
--- /dev/null
+++ b/app/controllers/refinery/admin/blog/comments_controller.rb
@@ -0,0 +1,49 @@
+module Refinery
+ module Admin
+ module Blog
+ class CommentsController < ::Refinery::AdminController
+
+ cache_sweeper Refinery::BlogSweeper
+
+ crudify :'refinery/blog/comment',
+ :title_attribute => :name,
+ :order => 'published_at DESC'
+
+ def index
+ @blog_comments = Refinery::Blog::Comment.unmoderated.page(params[:page])
+
+ render :action => 'index'
+ end
+
+ def approved
+ unless params[:id].present?
+ @blog_comments = Refinery::Blog::Comment.approved.page(params[:page])
+
+ render :action => 'index'
+ else
+ @blog_comment = Refinery::Blog::Comment.find(params[:id])
+ @blog_comment.approve!
+ flash[:notice] = t('approved', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
+
+ redirect_to main_app.url_for(:action => params[:return_to] || 'index')
+ end
+ end
+
+ def rejected
+ unless params[:id].present?
+ @blog_comments = Refinery::Blog::Comment.rejected.page(params[:page])
+
+ render :action => 'index'
+ else
+ @blog_comment = Refinery::Blog::Comment.find(params[:id])
+ @blog_comment.reject!
+ flash[:notice] = t('rejected', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
+
+ redirect_to main_app.url_for(:action => params[:return_to] || 'index')
+ end
+ end
+
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/admin/blog/posts_controller.rb b/app/controllers/refinery/admin/blog/posts_controller.rb
new file mode 100644
index 0000000..8b3816d
--- /dev/null
+++ b/app/controllers/refinery/admin/blog/posts_controller.rb
@@ -0,0 +1,94 @@
+module Refinery
+ module Admin
+ module Blog
+ class PostsController < ::Refinery::AdminController
+
+ cache_sweeper Refinery::BlogSweeper
+
+ crudify :'refinery/blog/post',
+ :title_attribute => :title,
+ :order => 'published_at DESC',
+ :redirect_to_url => "main_app.refinery_admin_blog_posts_path"
+
+ before_filter :find_all_categories,
+ :only => [:new, :edit, :create, :update]
+
+ before_filter :check_category_ids, :only => :update
+
+ def uncategorized
+ @blog_posts = Refinery::Blog::Post.uncategorized.page(params[:page])
+ end
+
+ def tags
+ if ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
+ op = '~*'
+ wildcard = '.*'
+ else
+ op = 'LIKE'
+ wildcard = '%'
+ end
+
+ @tags = Refinery::Blog::Post.tag_counts_on(:tags).where(
+ ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
+ ).map { |tag| {:id => tag.id, :value => tag.name}}
+ render :json => @tags.flatten
+ end
+
+ def create
+ # if the position field exists, set this object as last object, given the conditions of this class.
+ if Refinery::Blog::Post.column_names.include?("position")
+ params[:blog_post].merge!({
+ :position => ((Refinery::Blog::Post.maximum(:position, :conditions => "")||-1) + 1)
+ })
+ end
+
+ if Refinery::Blog::Post.column_names.include?("user_id")
+ params[:blog_post].merge!({
+ :user_id => current_refinery_user.id
+ })
+ end
+
+ if (@blog_post = Refinery::Blog::Post.create(params[:blog_post])).valid?
+ (request.xhr? ? flash.now : flash).notice = t(
+ 'refinery.crudify.created',
+ :what => "'#{@blog_post.title}'"
+ )
+
+ unless from_dialog?
+ unless params[:continue_editing] =~ /true|on|1/
+ redirect_back_or_default(main_app.refinery_admin_blog_posts_path)
+ else
+ unless request.xhr?
+ redirect_to :back
+ else
+ render :partial => "/shared/message"
+ end
+ end
+ else
+ render :text => "<script>parent.window.location = '#{admin_blog_posts_url}';</script>"
+ end
+ else
+ unless request.xhr?
+ render :action => 'new'
+ else
+ render :partial => "/refinery/admin/error_messages",
+ :locals => {
+ :object => @blog_post,
+ :include_object_name => true
+ }
+ end
+ end
+ end
+
+ protected
+ def find_all_categories
+ @blog_categories = Refinery::Blog::Category.find(:all)
+ end
+
+ def check_category_ids
+ params[:blog_post][:category_ids] ||= []
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/admin/blog/settings_controller.rb b/app/controllers/refinery/admin/blog/settings_controller.rb
new file mode 100644
index 0000000..ee71393
--- /dev/null
+++ b/app/controllers/refinery/admin/blog/settings_controller.rb
@@ -0,0 +1,55 @@
+module Refinery
+ module Admin
+ module Blog
+ class SettingsController < ::Refinery::AdminController
+
+ def notification_recipients
+ @recipients = Refinery::Blog::Comment::Notification.recipients
+
+ if request.post?
+ Refinery::Blog::Comment::Notification.recipients = params[:recipients]
+ flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients',
+ :recipients => Refinery::Blog::Comment::Notification.recipients)
+ unless request.xhr? or from_dialog?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>",
+ :layout => false
+ end
+ end
+ end
+
+ def moderation
+ enabled = Refinery::Blog::Comment::Moderation.toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ def comments
+ enabled = Refinery::Blog::Comment.toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ def teasers
+ enabled = Refinery::Blog::Post.teaser_enabled_toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/blog/base_controller.rb b/app/controllers/refinery/blog/base_controller.rb
new file mode 100644
index 0000000..919c180
--- /dev/null
+++ b/app/controllers/refinery/blog/base_controller.rb
@@ -0,0 +1,17 @@
+module Refinery
+ module Blog
+ class BaseController < ::ApplicationController
+
+ include ControllerHelper
+
+ helper :'refinery/blog/posts'
+ before_filter :find_page, :find_all_blog_categories
+
+ protected
+
+ def find_page
+ @page = Refinery::Page.find_by_link_url("/blog")
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/blog/categories_controller.rb b/app/controllers/refinery/blog/categories_controller.rb
new file mode 100644
index 0000000..60c8346
--- /dev/null
+++ b/app/controllers/refinery/blog/categories_controller.rb
@@ -0,0 +1,12 @@
+module Refinery
+ module Blog
+ class CategoriesController < BaseController
+
+ def show
+ @blog_category = Refinery::Blog::Category.find(params[:id])
+ @blog_posts = @blog_category.posts.live.includes(:comments, :categories).page(params[:page])
+ end
+
+ end
+ end
+end
diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb
new file mode 100644
index 0000000..1c8cffd
--- /dev/null
+++ b/app/controllers/refinery/blog/posts_controller.rb
@@ -0,0 +1,82 @@
+module Refinery
+ module Blog
+ class PostsController < BaseController
+
+ caches_page :index
+
+ before_filter :find_all_blog_posts, :except => [:archive]
+ before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
+ before_filter :find_tags
+
+ respond_to :html, :js, :rss
+
+ def index
+ # Rss feeders are greedy. Let's give them every blog post instead of paginating.
+ (@blog_posts = Refinery::Blog::Post.live.includes(:comments, :categories).all) if request.format.rss?
+ respond_with (@blog_posts) do |format|
+ format.html
+ format.rss
+ end
+ end
+
+ def show
+ @blog_comment = Refinery::Blog::Comment.new
+
+ @canonical = url_for(:locale => ::Refinery::I18n.default_frontend_locale) if canonical?
+
+ respond_with (@blog_post) do |format|
+ format.html { present(@blog_post) }
+ format.js { render :partial => 'post', :layout => false }
+ end
+ end
+
+ def comment
+ if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
+ if Refinery::Blog::Comment::Moderation.enabled? or @blog_comment.ham?
+ begin
+ Refinery::Blog::CommentMailer.notification(@blog_comment, request).deliver
+ rescue
+ logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
+ end
+ end
+
+ if Refinery::Blog::Comment::Moderation.enabled?
+ flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments')
+ redirect_to main_app.blog_post_url(params[:id])
+ else
+ flash[:notice] = t('thank_you', :scope => 'refinery.blog.posts.comments')
+ redirect_to main_app.blog_post_url(params[:id],
+ :anchor => "comment-#{@blog_comment.to_param}")
+ end
+ else
+ render :action => 'show'
+ end
+ end
+
+ def archive
+ if params[:month].present?
+ date = "#{params[:month]}/#{params[:year]}"
+ @archive_date = Time.parse(date)
+ @date_title = @archive_date.strftime('%B %Y')
+ @blog_posts = Refinery::Blog::Post.live.by_archive(@archive_date).page(params[:page])
+ else
+ date = "01/#{params[:year]}"
+ @archive_date = Time.parse(date)
+ @date_title = @archive_date.strftime('%Y')
+ @blog_posts = Refinery::Blog::Post.live.by_year(@archive_date).page(params[:page])
+ end
+ respond_with (@blog_posts)
+ end
+
+ def tagged
+ @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
+ @tag_name = @tag.name
+ @blog_posts = Refinery::Blog::Post.tagged_with(@tag_name).page(params[:page])
+ end
+
+ def canonical?
+ ::Refinery.i18n_enabled? && ::Refinery::I18n.default_frontend_locale != ::Refinery::I18n.current_frontend_locale
+ end
+ end
+ end
+end