=begin Camaleon CMS is a content management system Copyright (C) 2015 by Owen Peredo Diaz Email: owenperedo@gmail.com 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. =end module Plugins::VisibilityPost::VisibilityPostHelper 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 def plugin_visibility_on_active(plugin) # results = ActiveRecord::Base.connection.execute("ALTER TABLE posts ADD visibility varchar(100) default 'public'") # results = ActiveRecord::Base.connection.execute("ALTER TABLE posts ADD visibility_value text") end def plugin_visibility_on_inactive(plugin) # results = ActiveRecord::Base.connection.execute("ALTER TABLE posts drop column visibility") # results = ActiveRecord::Base.connection.execute("ALTER TABLE posts drop column visibility_value") end def plugin_visibility_post_list(args) args[:posts] = args[:posts].where(visibility: "private") if params[:s] == "private" args[:btns][:private] = "#{t('admin.table.private')} (#{args[:all_posts].where(visibility: "private").size})" end def plugin_visibility_create_post(args) save_visibility(args[:post]) end def plugin_visibility_new_post(args) args[:extra_settings] << form_html(args[:post]) end 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?(current_user.get_role(current_site).id) end def plugin_visibility_extra_columns(args) if args[:from_body] args[:content] = "