Module: Plugins::VisibilityPost::VisibilityPostHelper

Defined in:
app/apps/plugins/visibility_post/visibility_post_helper.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Instance Method Details

#plugin_visibility_can_visit(args) ⇒ Object


36
37
38
39
40
41
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 36

def plugin_visibility_can_visit(args)
  post = args[:post]
  return args[:flag] = false if post.published_at.present? && post.published_at > Time.now
  return if post.visibility != 'private'
  args[:flag] = false unless signin? && post.visibility_value.split(",").include?(cama_current_user.get_role(current_site).id)
end

#plugin_visibility_create_post(args) ⇒ Object


28
29
30
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 28

def plugin_visibility_create_post(args)
  save_visibility(args[:post])
end

#plugin_visibility_extra_columns(args) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 43

def plugin_visibility_extra_columns(args)
  if args[:from_body]
    args[:content] = "<td><i class='fa fa-#{{"private"=>"lock", ""=>"lock", "public"=>"eye", "password"=>"eye-slash"}[args[:post].visibility]}'></i> #{args[:post].visibility}</td>"
    args[:content] = "<td>#{args[:post].the_created_at if args[:post].published_at.present?}</td>"
  else
    args[:content] = "<th>#{t('camaleon_cms.admin.table.visibility')}</th>"
    args[:content] = "<th>#{t('camaleon_cms.admin.table.date_published')}</th>"
  end
end

#plugin_visibility_filter_post(args) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 53

def plugin_visibility_filter_post(args)
  args[:active_record] = args[:active_record].where("(#{CamaleonCms::Post.table_name}.published_at is null or #{CamaleonCms::Post.table_name}.published_at <= ?)", Time.now)
  if signin?
    if ActiveRecord::Base.connection.adapter_name.downcase.include?("mysql")
      args[:active_record] = args[:active_record].where("visibility != 'private' or (visibility = 'private' and FIND_IN_SET(?, #{CamaleonCms::Post.table_name}.visibility_value))", current_site.visitor_role)
    else
      args[:active_record] = args[:active_record].where("visibility != 'private' or (visibility = 'private' and (',' || #{CamaleonCms::Post.table_name}.visibility_value || ',') LIKE '%,#{current_site.visitor_role},%')")
    end
  else
    args[:active_record] = args[:active_record].where("visibility != 'private'")
  end
end

#plugin_visibility_new_post(args) ⇒ Object


32
33
34
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 32

def plugin_visibility_new_post(args)
  args[:extra_settings] << form_html(args[:post])
end

#plugin_visibility_on_active(plugin) ⇒ Object


17
18
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 17

def plugin_visibility_on_active(plugin)
end

#plugin_visibility_on_inactive(plugin) ⇒ Object


20
21
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 20

def plugin_visibility_on_inactive(plugin)
end

#plugin_visibility_post_list(args) ⇒ Object


23
24
25
26
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 23

def plugin_visibility_post_list(args)
  args[:posts] = args[:posts].where(visibility: "private") if params[:s] == "private"
  args[:btns][:private] = "#{t('camaleon_cms.admin.table.private')} (#{args[:all_posts].where(visibility: "private").size})"
end

#plugin_visibility_post_the_content(args) ⇒ Object

object.content.translate(@_deco_locale), post: object


10
11
12
13
14
15
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 10

def plugin_visibility_post_the_content(args) #{content: object.content.translate(@_deco_locale), post: object}
  if args[:post].visibility == "password"
    return if params[:post_password].present? && params[:post_password] == args[:post].visibility_value
    args[:content] = _password_form
  end
end