refinerycms-whatson 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +48 -0
- data/.tork.rb +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +7 -0
- data/Rakefile +3 -0
- data/app/controllers/admin/whatson/categories_controller.rb +11 -0
- data/app/controllers/admin/whatson/comments_controller.rb +40 -0
- data/app/controllers/admin/whatson/posts_controller.rb +97 -0
- data/app/controllers/admin/whatson/settings_controller.rb +53 -0
- data/app/controllers/whatson/categories_controller.rb +13 -0
- data/app/controllers/whatson/posts_controller.rb +109 -0
- data/app/controllers/whatson_controller.rb +16 -0
- data/app/helpers/whatson_posts_helper.rb +56 -0
- data/app/mailers/whatson/comment_mailer.rb +13 -0
- data/app/models/categorization.rb +7 -0
- data/app/models/whatson/comment_mailer.rb +1 -0
- data/app/models/whatson_category.rb +19 -0
- data/app/models/whatson_comment.rb +137 -0
- data/app/models/whatson_post.rb +114 -0
- data/app/views/admin/whatson/_submenu.html.erb +96 -0
- data/app/views/admin/whatson/categories/_category.html.erb +16 -0
- data/app/views/admin/whatson/categories/_form.html.erb +19 -0
- data/app/views/admin/whatson/categories/_sortable_list.html.erb +7 -0
- data/app/views/admin/whatson/categories/edit.html.erb +1 -0
- data/app/views/admin/whatson/categories/index.html.erb +26 -0
- data/app/views/admin/whatson/categories/new.html.erb +1 -0
- data/app/views/admin/whatson/comments/_comment.html.erb +20 -0
- data/app/views/admin/whatson/comments/_sortable_list.html.erb +7 -0
- data/app/views/admin/whatson/comments/index.html.erb +35 -0
- data/app/views/admin/whatson/comments/show.html.erb +63 -0
- data/app/views/admin/whatson/posts/_form.css.erb +20 -0
- data/app/views/admin/whatson/posts/_form.html.erb +110 -0
- data/app/views/admin/whatson/posts/_form.js.erb +23 -0
- data/app/views/admin/whatson/posts/_form_part.html.erb +3 -0
- data/app/views/admin/whatson/posts/_post.html.erb +24 -0
- data/app/views/admin/whatson/posts/_sortable_list.html.erb +7 -0
- data/app/views/admin/whatson/posts/_teaser_part.html.erb +11 -0
- data/app/views/admin/whatson/posts/edit.html.erb +1 -0
- data/app/views/admin/whatson/posts/index.html.erb +28 -0
- data/app/views/admin/whatson/posts/new.html.erb +1 -0
- data/app/views/admin/whatson/posts/uncategorized.html.erb +26 -0
- data/app/views/admin/whatson/settings/notification_recipients.html.erb +24 -0
- data/app/views/shared/admin/_autocomplete.html.erb +55 -0
- data/app/views/whatson/categories/show.html.erb +21 -0
- data/app/views/whatson/comment_mailer/notification.html.erb +17 -0
- data/app/views/whatson/posts/_comment.html.erb +10 -0
- data/app/views/whatson/posts/_nav.html.erb +11 -0
- data/app/views/whatson/posts/archive.html.erb +20 -0
- data/app/views/whatson/posts/index.html.erb +24 -0
- data/app/views/whatson/posts/index.rss.builder +17 -0
- data/app/views/whatson/posts/show.html.erb +98 -0
- data/app/views/whatson/posts/tagged.html.erb +22 -0
- data/app/views/whatson/shared/_archive_list.html.erb +9 -0
- data/app/views/whatson/shared/_categories.html.erb +10 -0
- data/app/views/whatson/shared/_post.html.erb +46 -0
- data/app/views/whatson/shared/_related_posts.html.erb +10 -0
- data/app/views/whatson/shared/_rss_feed.html.erb +2 -0
- data/app/views/whatson/shared/_tags.html.erb +8 -0
- data/config/locales/bg.yml +158 -0
- data/config/locales/cs.yml +128 -0
- data/config/locales/de.yml +130 -0
- data/config/locales/en.yml +159 -0
- data/config/locales/es.yml +159 -0
- data/config/locales/fr.yml +154 -0
- data/config/locales/it.yml +156 -0
- data/config/locales/ja.yml +159 -0
- data/config/locales/nb.yml +30 -0
- data/config/locales/nl.yml +134 -0
- data/config/locales/pl.yml +134 -0
- data/config/locales/pt-BR.yml +143 -0
- data/config/locales/ru.yml +135 -0
- data/config/locales/sk.yml +128 -0
- data/config/locales/zh-CN.yml +128 -0
- data/config/routes.rb +47 -0
- data/db/migrate/1_create_whatson_structure.rb +54 -0
- data/db/migrate/2_add_user_id_to_whatson_posts.rb +11 -0
- data/db/migrate/3_acts_as_taggable_on_migration.rb +28 -0
- data/db/migrate/4_create_seo_meta_for_whatson.rb +25 -0
- data/db/migrate/5_add_cached_slugs.rb +11 -0
- data/db/migrate/6_add_custom_url_field_to_whatson_posts.rb +9 -0
- data/db/migrate/7_add_custom_teaser_field_to_whatson_posts.rb +10 -0
- data/db/migrate/8_add_primary_key_to_categorizations.rb +12 -0
- data/db/seeds/refinerycms_whatson.rb +20 -0
- data/features/authors.feature +15 -0
- data/features/category.feature +23 -0
- data/features/support/factories/whatson_categories.rb +5 -0
- data/features/support/factories/whatson_comments.rb +8 -0
- data/features/support/factories/whatson_posts.rb +9 -0
- data/features/support/paths.rb +24 -0
- data/features/support/step_definitions/authors_steps.rb +7 -0
- data/features/support/step_definitions/category_steps.rb +11 -0
- data/features/support/step_definitions/tags_steps.rb +13 -0
- data/features/tags.feature +26 -0
- data/lib/gemspec.rb +37 -0
- data/lib/generators/refinerycms_whatson_generator.rb +8 -0
- data/lib/refinery/whatson/tabs.rb +28 -0
- data/lib/refinery/whatson/version.rb +17 -0
- data/lib/refinerycms-whatson.rb +41 -0
- data/public/images/refinerycms-whatson/icons/cog.png +0 -0
- data/public/images/refinerycms-whatson/icons/comment.png +0 -0
- data/public/images/refinerycms-whatson/icons/comment_cross.png +0 -0
- data/public/images/refinerycms-whatson/icons/comment_tick.png +0 -0
- data/public/images/refinerycms-whatson/icons/comments.png +0 -0
- data/public/images/refinerycms-whatson/icons/down.gif +0 -0
- data/public/images/refinerycms-whatson/icons/folder.png +0 -0
- data/public/images/refinerycms-whatson/icons/folder_add.png +0 -0
- data/public/images/refinerycms-whatson/icons/folder_edit.png +0 -0
- data/public/images/refinerycms-whatson/icons/page.png +0 -0
- data/public/images/refinerycms-whatson/icons/page_add.png +0 -0
- data/public/images/refinerycms-whatson/icons/page_copy.png +0 -0
- data/public/images/refinerycms-whatson/icons/up.gif +0 -0
- data/public/images/refinerycms-whatson/rss-feed.png +0 -0
- data/public/javascripts/refinery/refinerycms-whatson.js +50 -0
- data/public/javascripts/refinerycms-whatson.js +25 -0
- data/public/stylesheets/refinery/refinerycms-whatson.css +57 -0
- data/public/stylesheets/refinerycms-whatson.css +93 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- data/public/stylesheets/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- data/public/stylesheets/ui-lightness/jquery-ui-1.8.13.custom.css +330 -0
- data/readme.md +41 -0
- data/refinerycms-whatson.gemspec +18 -0
- data/spec/models/whatson_category_spec.rb +41 -0
- data/spec/models/whatson_comment_spec.rb +21 -0
- data/spec/models/whatson_post_spec.rb +217 -0
- metadata +235 -0
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
.bundle
|
2
|
+
*.gem
|
3
|
+
*.DS_Store
|
4
|
+
|
5
|
+
# Documentation
|
6
|
+
doc/api
|
7
|
+
doc/app
|
8
|
+
doc/*
|
9
|
+
.yardoc
|
10
|
+
.yardopts
|
11
|
+
|
12
|
+
# Refinery Specific
|
13
|
+
*.tmproj
|
14
|
+
*.autobackupbyrefinery.*
|
15
|
+
/refinerycms-whatson*.gem
|
16
|
+
.autotest
|
17
|
+
|
18
|
+
# Mac
|
19
|
+
.DS_Store
|
20
|
+
|
21
|
+
# NetBeans
|
22
|
+
nbproject
|
23
|
+
|
24
|
+
# Eclipse
|
25
|
+
.project
|
26
|
+
|
27
|
+
# Redcar
|
28
|
+
.redcar
|
29
|
+
|
30
|
+
# Rubinius
|
31
|
+
*.rbc
|
32
|
+
|
33
|
+
# Vim
|
34
|
+
*.swp
|
35
|
+
*.swo
|
36
|
+
|
37
|
+
# RubyMine
|
38
|
+
.idea
|
39
|
+
|
40
|
+
# Backup
|
41
|
+
*~
|
42
|
+
|
43
|
+
# Capybara Bug
|
44
|
+
capybara-*html
|
45
|
+
|
46
|
+
# Future stuff
|
47
|
+
Gemfile.lock
|
48
|
+
spec/dummy
|
data/.tork.rb
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Admin
|
2
|
+
module Whatson
|
3
|
+
class CommentsController < Admin::BaseController
|
4
|
+
|
5
|
+
crudify :whatson_comment,
|
6
|
+
:title_attribute => :name,
|
7
|
+
:order => 'published_at DESC'
|
8
|
+
|
9
|
+
def index
|
10
|
+
@whatson_comments = WhatsonComment.unmoderated
|
11
|
+
render :action => 'index'
|
12
|
+
end
|
13
|
+
|
14
|
+
def approved
|
15
|
+
unless params[:id].present?
|
16
|
+
@whatson_comments = WhatsonComment.approved
|
17
|
+
render :action => 'index'
|
18
|
+
else
|
19
|
+
@whatson_comment = WhatsonComment.find(params[:id])
|
20
|
+
@whatson_comment.approve!
|
21
|
+
flash[:notice] = t('approved', :scope => 'admin.whatson.comments', :author => @whatson_comment.name)
|
22
|
+
redirect_to :action => params[:return_to] || 'index'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def rejected
|
27
|
+
unless params[:id].present?
|
28
|
+
@whatson_comments = WhatsonComment.rejected
|
29
|
+
render :action => 'index'
|
30
|
+
else
|
31
|
+
@whatson_comment = WhatsonComment.find(params[:id])
|
32
|
+
@whatson_comment.reject!
|
33
|
+
flash[:notice] = t('rejected', :scope => 'admin.whatson.comments', :author => @whatson_comment.name)
|
34
|
+
redirect_to :action => params[:return_to] || 'index'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Admin
|
2
|
+
module Whatson
|
3
|
+
class PostsController < Admin::BaseController
|
4
|
+
require 'will_paginate/array'
|
5
|
+
|
6
|
+
crudify :whatson_post,
|
7
|
+
:title_attribute => :title,
|
8
|
+
:order => 'published_at DESC'
|
9
|
+
|
10
|
+
def uncategorized
|
11
|
+
@whatson_posts = WhatsonPost.uncategorized.paginate({
|
12
|
+
:page => params[:page],
|
13
|
+
:per_page => WhatsonPost.per_page
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
def tags
|
18
|
+
op = case ActiveRecord::Base.connection.adapter_name.downcase
|
19
|
+
when 'postgresql'
|
20
|
+
'~*'
|
21
|
+
else
|
22
|
+
'LIKE'
|
23
|
+
end
|
24
|
+
wildcard = case ActiveRecord::Base.connection.adapter_name.downcase
|
25
|
+
when 'postgresql'
|
26
|
+
'.*'
|
27
|
+
else
|
28
|
+
'%'
|
29
|
+
end
|
30
|
+
@tags = WhatsonPost.tag_counts_on(:tags).where(
|
31
|
+
["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
|
32
|
+
).map { |tag| {:id => tag.id, :value => tag.name}}
|
33
|
+
render :json => @tags.flatten
|
34
|
+
end
|
35
|
+
|
36
|
+
def create
|
37
|
+
# if the position field exists, set this object as last object, given the conditions of this class.
|
38
|
+
if WhatsonPost.column_names.include?("position")
|
39
|
+
params[:whatson_post].merge!({
|
40
|
+
:position => ((WhatsonPost.maximum(:position, :conditions => "")||-1) + 1)
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
44
|
+
if WhatsonPost.column_names.include?("user_id")
|
45
|
+
params[:whatson_post].merge!({
|
46
|
+
:user_id => current_user.id
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
if (@whatson_post = WhatsonPost.create(params[:whatson_post])).valid?
|
51
|
+
(request.xhr? ? flash.now : flash).notice = t(
|
52
|
+
'refinery.crudify.created',
|
53
|
+
:what => "'#{@whatson_post.title}'"
|
54
|
+
)
|
55
|
+
|
56
|
+
unless from_dialog?
|
57
|
+
unless params[:continue_editing] =~ /true|on|1/
|
58
|
+
redirect_back_or_default(admin_whatson_posts_url)
|
59
|
+
else
|
60
|
+
unless request.xhr?
|
61
|
+
redirect_to :back
|
62
|
+
else
|
63
|
+
render :partial => "/shared/message"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
render :text => "<script>parent.window.location = '#{admin_whatson_posts_url}';</script>"
|
68
|
+
end
|
69
|
+
else
|
70
|
+
unless request.xhr?
|
71
|
+
render :action => 'new'
|
72
|
+
else
|
73
|
+
render :partial => "/shared/admin/error_messages",
|
74
|
+
:locals => {
|
75
|
+
:object => @whatson_post,
|
76
|
+
:include_object_name => true
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
before_filter :find_all_categories,
|
83
|
+
:only => [:new, :edit, :create, :update]
|
84
|
+
|
85
|
+
before_filter :check_category_ids, :only => :update
|
86
|
+
|
87
|
+
protected
|
88
|
+
def find_all_categories
|
89
|
+
@whatson_categories = WhatsonCategory.find(:all)
|
90
|
+
end
|
91
|
+
|
92
|
+
def check_category_ids
|
93
|
+
params[:whatson_post][:category_ids] ||= []
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Admin
|
2
|
+
module Whatson
|
3
|
+
class SettingsController < Admin::BaseController
|
4
|
+
|
5
|
+
def notification_recipients
|
6
|
+
@recipients = WhatsonComment::Notification.recipients
|
7
|
+
|
8
|
+
if request.post?
|
9
|
+
WhatsonComment::Notification.recipients = params[:recipients]
|
10
|
+
flash[:notice] = t('updated', :scope => 'admin.whatson.settings.notification_recipients',
|
11
|
+
:recipients => WhatsonComment::Notification.recipients)
|
12
|
+
unless request.xhr? or from_dialog?
|
13
|
+
redirect_back_or_default(admin_whatson_posts_path)
|
14
|
+
else
|
15
|
+
render :text => "<script type='text/javascript'>parent.window.location = '#{admin_whatson_posts_path}';</script>",
|
16
|
+
:layout => false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def moderation
|
22
|
+
enabled = WhatsonComment::Moderation.toggle!
|
23
|
+
unless request.xhr?
|
24
|
+
redirect_back_or_default(admin_whatson_posts_path)
|
25
|
+
else
|
26
|
+
render :json => {:enabled => enabled},
|
27
|
+
:layout => false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def comments
|
32
|
+
enabled = WhatsonComment.toggle!
|
33
|
+
unless request.xhr?
|
34
|
+
redirect_back_or_default(admin_whatson_posts_path)
|
35
|
+
else
|
36
|
+
render :json => {:enabled => enabled},
|
37
|
+
:layout => false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def teasers
|
42
|
+
enabled = WhatsonPost.teaser_enabled_toggle!
|
43
|
+
unless request.xhr?
|
44
|
+
redirect_back_or_default(admin_whatson_posts_path)
|
45
|
+
else
|
46
|
+
render :json => {:enabled => enabled},
|
47
|
+
:layout => false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Whatson
|
2
|
+
class CategoriesController < WhatsonController
|
3
|
+
|
4
|
+
def show
|
5
|
+
@category = WhatsonCategory.find(params[:id])
|
6
|
+
@whatson_posts = @category.posts.live.includes(:comments, :categories).paginate({
|
7
|
+
:page => params[:page],
|
8
|
+
:per_page => RefinerySetting.find_or_set(:whatson_posts_per_page, 10)
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Whatson
|
2
|
+
class PostsController < WhatsonController
|
3
|
+
|
4
|
+
before_filter :find_all_whatson_posts, :except => [:archive]
|
5
|
+
before_filter :find_whatson_post, :only => [:show, :comment, :update_nav]
|
6
|
+
before_filter :find_tags
|
7
|
+
|
8
|
+
respond_to :html, :js, :rss
|
9
|
+
|
10
|
+
def index
|
11
|
+
# Rss feeders are greedy. Let's give them every whatson post instead of paginating.
|
12
|
+
(@whatson_posts = WhatsonPost.live.includes(:comments, :categories).all) if request.format.rss?
|
13
|
+
respond_with (@whatson_posts) do |format|
|
14
|
+
format.html
|
15
|
+
format.rss
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
@whatson_comment = WhatsonComment.new
|
21
|
+
@canonical = url_for(:locale => ::Refinery::I18n.default_frontend_locale) if canonical?
|
22
|
+
|
23
|
+
respond_with (@whatson_post) do |format|
|
24
|
+
format.html { present(@whatson_post) }
|
25
|
+
format.js { render :partial => 'post', :layout => false }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def comment
|
30
|
+
if (@whatson_comment = @whatson_post.comments.create(params[:whatson_comment])).valid?
|
31
|
+
if WhatsonComment::Moderation.enabled? or @whatson_comment.ham?
|
32
|
+
begin
|
33
|
+
Whatson::CommentMailer.notification(@whatson_comment, request).deliver
|
34
|
+
rescue
|
35
|
+
logger.warn "There was an error delivering a whatson comment notification.\n#{$!}\n"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if WhatsonComment::Moderation.enabled?
|
40
|
+
flash[:notice] = t('thank_you_moderated', :scope => 'whatson.posts.comments')
|
41
|
+
redirect_to whatson_post_url(params[:id])
|
42
|
+
else
|
43
|
+
flash[:notice] = t('thank_you', :scope => 'whatson.posts.comments')
|
44
|
+
redirect_to whatson_post_url(params[:id],
|
45
|
+
:anchor => "comment-#{@whatson_comment.to_param}")
|
46
|
+
end
|
47
|
+
else
|
48
|
+
render :action => 'show'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def archive
|
53
|
+
if params[:month].present?
|
54
|
+
date = "#{params[:month]}/#{params[:year]}"
|
55
|
+
@archive_date = Time.parse(date)
|
56
|
+
@date_title = @archive_date.strftime('%B %Y')
|
57
|
+
@whatson_posts = WhatsonPost.live.by_archive(@archive_date).paginate({
|
58
|
+
:page => params[:page],
|
59
|
+
:per_page => RefinerySetting.find_or_set(:whatson_posts_per_page, 10)
|
60
|
+
})
|
61
|
+
else
|
62
|
+
date = "01/#{params[:year]}"
|
63
|
+
@archive_date = Time.parse(date)
|
64
|
+
@date_title = @archive_date.strftime('%Y')
|
65
|
+
@whatson_posts = WhatsonPost.live.by_year(@archive_date).paginate({
|
66
|
+
:page => params[:page],
|
67
|
+
:per_page => RefinerySetting.find_or_set(:whatson_posts_per_page, 10)
|
68
|
+
})
|
69
|
+
end
|
70
|
+
respond_with (@whatson_posts)
|
71
|
+
end
|
72
|
+
|
73
|
+
def tagged
|
74
|
+
@tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
|
75
|
+
@tag_name = @tag.name
|
76
|
+
@whatson_posts = WhatsonPost.tagged_with(@tag_name).paginate({
|
77
|
+
:page => params[:page],
|
78
|
+
:per_page => RefinerySetting.find_or_set(:whatson_posts_per_page, 10)
|
79
|
+
})
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def find_whatson_post
|
85
|
+
unless (@whatson_post = WhatsonPost.find(params[:id])).try(:live?)
|
86
|
+
if refinery_user? and current_user.authorized_plugins.include?("refinerycms_whatson")
|
87
|
+
@whatson_post = WhatsonPost.find(params[:id])
|
88
|
+
else
|
89
|
+
error_404
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_all_whatson_posts
|
95
|
+
@whatson_posts = WhatsonPost.live.includes(:comments, :categories).paginate({
|
96
|
+
:page => params[:page],
|
97
|
+
:per_page => RefinerySetting.find_or_set(:whatson_posts_per_page, 10)
|
98
|
+
})
|
99
|
+
end
|
100
|
+
|
101
|
+
def find_tags
|
102
|
+
@tags = WhatsonPost.tag_counts_on(:tags)
|
103
|
+
end
|
104
|
+
|
105
|
+
def canonical?
|
106
|
+
::Refinery.i18n_enabled? && ::Refinery::I18n.default_frontend_locale != ::Refinery::I18n.current_frontend_locale
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class WhatsonController < ApplicationController
|
2
|
+
|
3
|
+
helper :whatson_posts
|
4
|
+
before_filter :find_page, :find_all_whatson_categories
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def find_page
|
9
|
+
@page = Page.find_by_link_url("/whatson")
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_all_whatson_categories
|
13
|
+
@whatson_categories = WhatsonCategory.all
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module WhatsonPostsHelper
|
2
|
+
def whatson_archive_list
|
3
|
+
posts = WhatsonPost.live.select('published_at').all_previous
|
4
|
+
return nil if posts.blank?
|
5
|
+
html = ''
|
6
|
+
links = []
|
7
|
+
super_old_links = []
|
8
|
+
|
9
|
+
posts.each do |e|
|
10
|
+
if e.published_at >= Time.now.end_of_year.advance(:years => -3)
|
11
|
+
links << e.published_at.strftime('%m/%Y')
|
12
|
+
else
|
13
|
+
super_old_links << e.published_at.strftime('01/%Y')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
links.uniq!
|
17
|
+
super_old_links.uniq!
|
18
|
+
links.each do |l|
|
19
|
+
year = l.split('/')[1]
|
20
|
+
month = l.split('/')[0]
|
21
|
+
count = WhatsonPost.live.by_archive(Time.parse(l)).size
|
22
|
+
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
|
23
|
+
html << "<li>"
|
24
|
+
html << link_to(text, archive_whatson_posts_path(:year => year, :month => month))
|
25
|
+
html << "</li>"
|
26
|
+
end
|
27
|
+
super_old_links.each do |l|
|
28
|
+
year = l.split('/')[1]
|
29
|
+
count = WhatsonPost.live.by_year(Time.parse(l)).size
|
30
|
+
text = "#{year} (#{count})"
|
31
|
+
html << "<li>"
|
32
|
+
html << link_to(text, archive_whatson_posts_path(:year => year))
|
33
|
+
html << "</li>"
|
34
|
+
end
|
35
|
+
html.html_safe
|
36
|
+
end
|
37
|
+
|
38
|
+
def next_or_previous?(post)
|
39
|
+
post.next.present? or post.prev.present?
|
40
|
+
end
|
41
|
+
|
42
|
+
def whatson_post_teaser_enabled?
|
43
|
+
WhatsonPost.teasers_enabled?
|
44
|
+
end
|
45
|
+
|
46
|
+
def whatson_post_teaser(post)
|
47
|
+
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
|
48
|
+
post.custom_teaser.html_safe
|
49
|
+
else
|
50
|
+
truncate(post.body, {
|
51
|
+
:length => RefinerySetting.find_or_set(:whatson_post_teaser_length, 250),
|
52
|
+
:preserve_html_tags => true
|
53
|
+
}).html_safe
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|