xforum 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +139 -0
- data/Rakefile +31 -0
- data/app/assets/images/xforum/addphoto.jpg +0 -0
- data/app/assets/images/xforum/bg-input-focus.png +0 -0
- data/app/assets/images/xforum/internet.png +0 -0
- data/app/assets/images/xforum/silver_selector.png +0 -0
- data/app/assets/javascripts/xforum/application.js +25 -0
- data/app/assets/javascripts/xforum/forum_admin.js.coffee +477 -0
- data/app/assets/javascripts/xforum/forum_basic.js.coffee +321 -0
- data/app/assets/javascripts/xforum/forum_translator.js.coffee +116 -0
- data/app/assets/javascripts/xforum/forum_user.js.coffee +403 -0
- data/app/assets/javascripts/xforum/global_java.js +141 -0
- data/app/assets/javascripts/xforum/help.js.coffee +10 -0
- data/app/assets/stylesheets/xforum/application.css.scss +15 -0
- data/app/assets/stylesheets/xforum/custom.css.scss +295 -0
- data/app/controllers/xforum/application_controller.rb +25 -0
- data/app/controllers/xforum/forums_controller.rb +123 -0
- data/app/helpers/xforum/application_helper.rb +4 -0
- data/app/mailers/xforum/user_mailer.rb +15 -0
- data/app/models/xforum/category.rb +76 -0
- data/app/models/xforum/forum.rb +217 -0
- data/app/models/xforum/hyperlink.rb +42 -0
- data/app/models/xforum/language.rb +104 -0
- data/app/models/xforum/people_list.rb +189 -0
- data/app/models/xforum/photo.rb +60 -0
- data/app/models/xforum/topic.rb +140 -0
- data/app/models/xforum/translation.rb +92 -0
- data/app/views/layouts/xforum/application.html.erb +14 -0
- data/app/views/user_mailer/xforum/note_to_forum_users.html.erb +32 -0
- data/app/views/xforum/forums/_dummy.html.erb +0 -0
- data/app/views/xforum/forums/_forum.html.erb +18 -0
- data/app/views/xforum/forums/_forum_admin.html.erb +139 -0
- data/app/views/xforum/forums/_forum_comments.html.erb +45 -0
- data/app/views/xforum/forums/_forum_entry.html.erb +44 -0
- data/app/views/xforum/forums/_forum_video.html.erb +7 -0
- data/app/views/xforum/forums/newphoto.js.erb +1 -0
- data/app/views/xforum/forums/the_page.html.erb +3 -0
- data/config/intiializers/xforum.rb +2 -0
- data/config/locales/forum.de.yml +93 -0
- data/config/locales/forum.en.yml +96 -0
- data/config/locales/forum.es.yml +94 -0
- data/config/locales/forum.fr.yml +94 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20140600_add_forum_to_users.rb +20 -0
- data/db/migrate/20140601_create_forum_forums.rb +147 -0
- data/db/migrate/20140602_add_restricted_to_category.rb +6 -0
- data/db/migrate/20140602_change_suggestion_default.rb +7 -0
- data/lib/tasks/xforum_tasks.rake +65 -0
- data/lib/xforum.rb +95 -0
- data/lib/xforum/engine.rb +6 -0
- data/lib/xforum/set.yml +209 -0
- data/lib/xforum/user_include.rb +13 -0
- data/lib/xforum/version.rb +3 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/xforum_test.rb +7 -0
- metadata +327 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Xforum
|
|
2
|
+
class ApplicationController < ActionController::Base
|
|
3
|
+
|
|
4
|
+
include ApplicationHelper
|
|
5
|
+
#before_filter :set_locale
|
|
6
|
+
# Prevent CSRF attacks by raising an exception.
|
|
7
|
+
# For APIs, you may want to use :null_session instead.
|
|
8
|
+
protect_from_forgery with: :exception
|
|
9
|
+
# Force signout to prevent CSRF attacks
|
|
10
|
+
|
|
11
|
+
def handle_unverified_request
|
|
12
|
+
sign_out
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
def set_locale
|
|
18
|
+
I18n.locale = params[:locale] if params[:locale].present?
|
|
19
|
+
end
|
|
20
|
+
def default_url_options(options = {})
|
|
21
|
+
{locale: I18n.locale}
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
|
|
2
|
+
require_dependency 'xforum/application_controller'
|
|
3
|
+
|
|
4
|
+
module Xforum
|
|
5
|
+
class ForumsController < ApplicationController
|
|
6
|
+
|
|
7
|
+
def the_page
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def forum_ajax
|
|
11
|
+
case params[:function]
|
|
12
|
+
when 'get list'
|
|
13
|
+
case params[:list]
|
|
14
|
+
when 'admin-actions' then
|
|
15
|
+
render json: Forum.get_forum_actions(params, current_user)
|
|
16
|
+
when 'admin-users' then
|
|
17
|
+
render json: PeopleList.get_forum_users(params, current_user)
|
|
18
|
+
when 'admin-emails' then
|
|
19
|
+
render json: PeopleList.get_forum_emails(params, current_user)
|
|
20
|
+
when 'forum-distribution-lists', 'forum-restricted-list' then
|
|
21
|
+
render json: PeopleList.get_forum_distribution_lists(params,current_user)
|
|
22
|
+
else
|
|
23
|
+
end
|
|
24
|
+
when 'forum admin action'
|
|
25
|
+
render json: Forum.do_admin_action(params, current_user)
|
|
26
|
+
when 'categories'
|
|
27
|
+
render json: Category.categories(params, current_user)
|
|
28
|
+
when 'post'
|
|
29
|
+
render json: Forum.add_comment(params, current_user)
|
|
30
|
+
when 'get forum photo'
|
|
31
|
+
render json: Photo.get_photo(params)
|
|
32
|
+
when 'add hot link'
|
|
33
|
+
render json: Hyperlink.add_one(params)
|
|
34
|
+
when 'get language set'
|
|
35
|
+
render json: Language.languages(params)
|
|
36
|
+
when 'toggle language'
|
|
37
|
+
render json: Language.toggle_language(params, current_user)
|
|
38
|
+
when 'get translations'
|
|
39
|
+
render json: Translation.get_translations(params)
|
|
40
|
+
when 'add to list'
|
|
41
|
+
case params[:list]
|
|
42
|
+
when 'category'
|
|
43
|
+
response= Category.add_category(params, current_user)
|
|
44
|
+
when 'topic'
|
|
45
|
+
response= Topic.add_topic(params, current_user)
|
|
46
|
+
when 'langauge'
|
|
47
|
+
response= Language.activate_language(params, current_user)
|
|
48
|
+
else
|
|
49
|
+
end
|
|
50
|
+
render json: response
|
|
51
|
+
when 'get senate'
|
|
52
|
+
render json: Forum.senate(params, current_user)
|
|
53
|
+
when 'get topics'
|
|
54
|
+
render json: Topic.topics(params, current_user)
|
|
55
|
+
when 'accept', 'reject'
|
|
56
|
+
render json: Forum.change_state(params, current_user)
|
|
57
|
+
when 'edit forum object'
|
|
58
|
+
case params[:which_list]
|
|
59
|
+
when 'forum-admins-category-list'
|
|
60
|
+
response= Category.edit_category(params, current_user)
|
|
61
|
+
when 'forum-admin-topic-list'
|
|
62
|
+
response=Topic.edit_topic(params, current_user)
|
|
63
|
+
else
|
|
64
|
+
response={}
|
|
65
|
+
end
|
|
66
|
+
render json: response
|
|
67
|
+
when 'remove forum object'
|
|
68
|
+
case params[:which_list]
|
|
69
|
+
when 'category'
|
|
70
|
+
response= Category.remove_object(params, current_user)
|
|
71
|
+
when 'topic'
|
|
72
|
+
response= Topic.remove_object(params, current_user)
|
|
73
|
+
when 'language'
|
|
74
|
+
response= Language.deactivate_language(params, current_user)
|
|
75
|
+
else
|
|
76
|
+
end
|
|
77
|
+
render json: response
|
|
78
|
+
when 'vote'
|
|
79
|
+
render json: {votes: Topic.cast_vote(params[:topic], current_user, params[:vote])}
|
|
80
|
+
when 'add voting'
|
|
81
|
+
render json: Topic.voting_booth?(params)
|
|
82
|
+
when 'subscribe'
|
|
83
|
+
render json: Topic.subscribe(params[:topic], current_user)
|
|
84
|
+
when 'get suggestions'
|
|
85
|
+
case params[:list]
|
|
86
|
+
when 'category'
|
|
87
|
+
response= Category.get_suggestions(params, current_user)
|
|
88
|
+
when 'topic'
|
|
89
|
+
response= Topic.get_suggestions(params, current_user)
|
|
90
|
+
when 'language'
|
|
91
|
+
response= Language.get_suggestions(params, current_user)
|
|
92
|
+
else
|
|
93
|
+
end
|
|
94
|
+
render json: response
|
|
95
|
+
when 'suggestion'
|
|
96
|
+
response= Category.suggestion(params, current_user) if params[:category] =='request new category'
|
|
97
|
+
response= Topic.suggestion(params, current_user) if params[:topic] =='request new topic'
|
|
98
|
+
response= Language.suggestion(params, current_user) if params[:language] =='request new language'
|
|
99
|
+
render json: response
|
|
100
|
+
when 'suggestion close'
|
|
101
|
+
case params[:list]
|
|
102
|
+
when 'forum-category-prososals-list'
|
|
103
|
+
response= Category.suggestion_close(params, current_user)
|
|
104
|
+
when 'forum-topic-prososals-list'
|
|
105
|
+
response= Topic.suggestion_close(params, current_user)
|
|
106
|
+
when 'forum-language-prososals-list'
|
|
107
|
+
response= Language.suggestion_close(params, current_user)
|
|
108
|
+
else
|
|
109
|
+
end
|
|
110
|
+
render json: response
|
|
111
|
+
when 'set_the_rest'
|
|
112
|
+
render json: Forum.set_the_rest(params, current_user)
|
|
113
|
+
else
|
|
114
|
+
render json: {answer: 'what did you want'}
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def newphoto
|
|
119
|
+
Photo.upload(params,current_user)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Xforum
|
|
2
|
+
class UserMailer < ActionMailer::Base
|
|
3
|
+
default from: 'bnacreationss@gmail.com'
|
|
4
|
+
|
|
5
|
+
def note_to_forum_users(params,user_ids)
|
|
6
|
+
emails=[]
|
|
7
|
+
users_ids.each{
|
|
8
|
+
emails.push(Xforum.user_class.where(id:id).pluck(:email)[0])
|
|
9
|
+
}
|
|
10
|
+
#attachments["notes"] =file.read("notes")
|
|
11
|
+
@content=params[:body].split("\n")
|
|
12
|
+
mail(to: emails, subject: params[:subject])
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
module Xforum
|
|
3
|
+
class Category < ActiveRecord::Base
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
has_many :topics, dependent: :destroy
|
|
7
|
+
has_many :people_lists, dependent: :destroy
|
|
8
|
+
|
|
9
|
+
def self.add_category(params,user)
|
|
10
|
+
params[:user.id]=user.id if params[:user_id] == 'me'
|
|
11
|
+
user.forum_admin? ? id= Category.create(name:params[:new_item],user_id:user.id,suggestion:false).id : id='not happening'
|
|
12
|
+
{id:id}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.remove_category(params,user)
|
|
16
|
+
case(params[:state_action])
|
|
17
|
+
when 'del' then Forum.where(id:params[:id]).update_all(closed:true)
|
|
18
|
+
when 'open' then Forum.where(id:params[:id]).update_all(closed:false)
|
|
19
|
+
else
|
|
20
|
+
# type code here
|
|
21
|
+
end if user.forum_admin?
|
|
22
|
+
{action:'nothing to do'}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.restrict_me(params,user)
|
|
26
|
+
if user.forum_admin?
|
|
27
|
+
category=Category.find_by(name:params[:category])
|
|
28
|
+
category.restricted= !category.restricted
|
|
29
|
+
category.save
|
|
30
|
+
invitation=PeopleList.find_or_create_by(category_id:category.id,list:'invitation')
|
|
31
|
+
invitation.people= PeopleList.find_by(id:params[:user_list]).people
|
|
32
|
+
invitation.save
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.get_suggestions(params,user)
|
|
37
|
+
data= Category.where(suggestion:true).pluck(:name, :user_id,:id)
|
|
38
|
+
data=ForumAssist.named_array(data, [:suggestion, :user,:id]) unless data.empty?
|
|
39
|
+
data=ForumAssist.add_user_name(data.clone) unless data.empty?
|
|
40
|
+
user.forum_admin? ? {data: data, list: 'forum-category-prososals-list'} : {response: 'nothing doing'}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.edit_category(params,user)
|
|
44
|
+
Category.where(id: params[:id]).update_all(name:params[:newline]) if user.forum_admin?
|
|
45
|
+
end
|
|
46
|
+
def self.suggestion(params,user) #add new category or topic
|
|
47
|
+
Category.create(suggestion:true,name:params[:suggestion],user_id:user.id)
|
|
48
|
+
{response:'nothing to do'}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.suggestion_close(params,user)
|
|
52
|
+
params[:result]=='Accept' ?
|
|
53
|
+
(Category.where(id: params[:id]).update_all(suggestion: false) if user.forum_admin?) :
|
|
54
|
+
Category.where(id: params[:id]).update_all(state: 'closed') if user.forum_admin?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.categories(params,user)
|
|
58
|
+
if Category.first.nil?
|
|
59
|
+
Category.create(name:'request new category',closed:false,suggestion:false)
|
|
60
|
+
Category.create(name:'select category',closed:false,suggestion:false)
|
|
61
|
+
end
|
|
62
|
+
params[:hold_test]=='true' ?
|
|
63
|
+
category_list= ForumAssist.named_array(Category.where(closed:false,suggestion:false).pluck(:id,:name,:closed,:restricted),[:id,:name,:closed,:restricted]) :
|
|
64
|
+
category_list= ForumAssist.named_array(Category.all.pluck(:id,:name,:closed,:restricted),[:id,:name,:closed,:restricted])
|
|
65
|
+
category_list=ForumAssist.make_last(category_list.clone, {key: :id,ref:Category.where(name:'request new category').pluck(:id)[0]})
|
|
66
|
+
category_list=ForumAssist.make_first(category_list.clone,{key: :id,ref:Category.where(name:'select category').pluck(:id)[0]})
|
|
67
|
+
category_list=PeopleList.check_restrictions(category_list.clone,user,'categories') unless user.forum_admin?
|
|
68
|
+
category_list=Translation.translate_list(category_list.clone,params[:language],'category')
|
|
69
|
+
category_list.push({id:0, item:'admin',value: I18n.t('xForum.Admin_name')}) if user.forum_admin?
|
|
70
|
+
{list_data:category_list,id:params[:list]}
|
|
71
|
+
end
|
|
72
|
+
def self.get_category_id(params)
|
|
73
|
+
Category.where(name:params[:category]).pluck(:id)[0]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
|
|
2
|
+
module Xforum
|
|
3
|
+
class Forum < ActiveRecord::Base
|
|
4
|
+
require 'json'
|
|
5
|
+
belongs_to :topic
|
|
6
|
+
has_many :translations, dependent: :destroy
|
|
7
|
+
has_many :photos, dependent: :destroy
|
|
8
|
+
has_many :people_lists, dependent: :destroy
|
|
9
|
+
has_many :hyperlinks, dependent: :destroy
|
|
10
|
+
|
|
11
|
+
USER_BLOCK_SIZE= 300
|
|
12
|
+
|
|
13
|
+
def self.do_admin_action(params,user)
|
|
14
|
+
params[:users1]=[] if params[:users1].nil?
|
|
15
|
+
params[:users2]=[] if params[:users2].nil?
|
|
16
|
+
user_ids=(params[:users1] + params[:users2])
|
|
17
|
+
user_ids.uniq!
|
|
18
|
+
(0...user_ids.size).each{|i| user_ids[i]=user_ids[i].to_i}
|
|
19
|
+
user_ids.delete(0)
|
|
20
|
+
case params[:forum_action]
|
|
21
|
+
when 'suspend posting'
|
|
22
|
+
users_ids.each { |user_id| Xforum.user_class.where(id: user_id).update_all(forum_posting_priviages: false) }
|
|
23
|
+
when 'suspend all'
|
|
24
|
+
users_ids.each { |user_id| Xforum.user_class.where(id: user_id).update_all(forum_reading_priviages: false) }
|
|
25
|
+
users_ids.each { |user_id| Xforum.user_class.where(id: user_id).update_all(forum_posting_priviages: false) }
|
|
26
|
+
when 'send email to'
|
|
27
|
+
UserMailer.note_to_forum_users(params, user_ids).deliver
|
|
28
|
+
when 'create distribution', 'add to distribution', 'remove from distro'
|
|
29
|
+
PeopleList.manage_list(params, user_ids)
|
|
30
|
+
when 'add topic monitor'
|
|
31
|
+
Topic.add_topic_monitor(params, user_ids)
|
|
32
|
+
when 'restrict topic'
|
|
33
|
+
Topic.restrict_me(params, user)
|
|
34
|
+
when 'restrict category'
|
|
35
|
+
Category.restrict_me(params, user)
|
|
36
|
+
else
|
|
37
|
+
# type code here
|
|
38
|
+
end if user.forum_admin?
|
|
39
|
+
{action:'nothing to do'}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.senate(params,user)
|
|
43
|
+
if params[:topic]== "select topic"
|
|
44
|
+
{to_do:'nothing'}
|
|
45
|
+
else
|
|
46
|
+
topic_id=Topic.where(name:params[:topic]).pluck(:id)[0]
|
|
47
|
+
index=Forum.clear_user_topic(user.id,topic_id)
|
|
48
|
+
the_list=[]
|
|
49
|
+
plucking= [:id, :parent, :content, :user_id,:owner_name,:state,:restricted,:tag,:has_photo]
|
|
50
|
+
plucking_names= [:id, :parent, :content,:owner,:owner_name,:comment_state,:restricted,:tag,:has_photo,:needs_translation,:empty_list] #we're going to append empty list to the reply
|
|
51
|
+
moderator=PeopleList.check_people({topic:topic_id,user_id:user.id,list:'moderator'}) || user.forum_admin?
|
|
52
|
+
if params[:review]=='true' && moderator
|
|
53
|
+
test=Forum.where(topic_id:topic_id,state:'new').pluck(:id)
|
|
54
|
+
unless test.empty?
|
|
55
|
+
item1=ForumAssist.named_array(Translation.get_localized_forum(Language.get_me(params),{lookup:{topic_id:topic_id},plucking:plucking,size:0}),plucking_names)
|
|
56
|
+
item1.store(:moderator,true)
|
|
57
|
+
item1.store(:review,true)
|
|
58
|
+
new_list= ForumAssist.named_array( Translation.get_localized_forum(Language.get_me(params),{lookup:{topic_id:topic_id,state:'new'},ordering:([:topic_id]),plucking:plucking,size:'all'}),plucking_names )
|
|
59
|
+
new_list.unshift(item1)
|
|
60
|
+
the_list=new_list
|
|
61
|
+
end
|
|
62
|
+
else
|
|
63
|
+
senate_list=ForumAssist.named_array(Translation.get_localized_forum(Language.get_me(params),{lookup:{topic_id:topic_id,hold:false},ordering:[:parent,:created_at],plucking:plucking,size:'all'}), plucking_names )
|
|
64
|
+
if senate_list.nil? || senate_list.empty?
|
|
65
|
+
[]
|
|
66
|
+
else
|
|
67
|
+
voting=ForumAssist.named_array(Topic.where(id:topic_id).pluck(:vote,:votes),[:vote,:votes])[0]
|
|
68
|
+
voting[:vote] ? votes=Topic.count_votes(JSON.load(voting[:votes])) : votes=0
|
|
69
|
+
parent=Forum.look_for_key(senate_list,:parent,0)
|
|
70
|
+
new_list=[]
|
|
71
|
+
subscribed=PeopleList.check_people({topic:topic_id,user_id:user.id,list:'subscribers'})
|
|
72
|
+
parent=set_new_senate_entry(senate_list,new_list,parent,user.id, {moderator:moderator,vote:voting[:vote],votes:votes,subscribed:subscribed,admin:user.forum_admin?}) unless parent.nil?
|
|
73
|
+
Forum.is_child_there?(senate_list,new_list,0,parent,user.id) #push first child
|
|
74
|
+
new_list.delete_if {|record|
|
|
75
|
+
test=PeopleList.check_people_list({topic:record[:id], user_id:user.id,list:'invitation'}) if (record[:restricted] && !record[:owner])
|
|
76
|
+
if test.nil?
|
|
77
|
+
case record[:state]
|
|
78
|
+
when 'reject' then test= false
|
|
79
|
+
when 'new' then test= !(ENV['XFORUM_NEW_RULE']=='no')
|
|
80
|
+
else test=true
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
!test
|
|
84
|
+
}
|
|
85
|
+
the_list=new_list
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
{the_list:the_list,index:index}
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def self.clear_user_topic(user_id,topic_id)
|
|
93
|
+
comments=ForumAssist.named_array(Forum.where(topic_id:topic_id).order(:tag).pluck(:id,:tag),[:id,:tag])
|
|
94
|
+
tags=[]
|
|
95
|
+
test_comments=comments.clone
|
|
96
|
+
test_comments.each{ |comment|
|
|
97
|
+
if (comment[:tag].to_i) < USER_BLOCK_SIZE*user_id && comment[:tag].to_i <= USER_BLOCK_SIZE*(user_id+1)
|
|
98
|
+
comments.delete_at(comments.index(comment))
|
|
99
|
+
else
|
|
100
|
+
tags.push((comment[:tag].to_i)%USER_BLOCK_SIZE )
|
|
101
|
+
comment[:tag]= tags.last
|
|
102
|
+
end
|
|
103
|
+
}
|
|
104
|
+
if tags.empty?
|
|
105
|
+
index=0
|
|
106
|
+
elsif tags.index(USER_BLOCK_SIZE*1/3).nil? && tags.index(USER_BLOCK_SIZE*2/3).nil?
|
|
107
|
+
index=USER_BLOCK_SIZE*1/3
|
|
108
|
+
elsif tags.index(USER_BLOCK_SIZE*2/3).nil?
|
|
109
|
+
index= USER_BLOCK_SIZE*2/3
|
|
110
|
+
(0...tags.size).each {|i|
|
|
111
|
+
Forum.where(id:comments[i][:id]).update_all(tag:-1) if tags[i] < USER_BLOCK_SIZE*1/3
|
|
112
|
+
}
|
|
113
|
+
elsif tags.index(USER_BLOCK_SIZE*0/3).nil?
|
|
114
|
+
index=0
|
|
115
|
+
(0...tags.size).each {|i|
|
|
116
|
+
Forum.where(id:comments[i][:id]).update_all(tag:-1) if tags[i] >= USER_BLOCK_SIZE*1/3 && tags[i]< USER_BLOCK_SIZE*2/3
|
|
117
|
+
}
|
|
118
|
+
else tags.index(USER_BLOCK_SIZE*1/3).nil?
|
|
119
|
+
index=USER_BLOCK_SIZE*1/3
|
|
120
|
+
(0...tags.size).each {|i|
|
|
121
|
+
Forum.where(id:comments[i][:id]).update_all(tag:-1) if tags[i] >= USER_BLOCK_SIZE*2/3
|
|
122
|
+
}
|
|
123
|
+
end
|
|
124
|
+
index+user_id*USER_BLOCK_SIZE
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def self.set_new_senate_entry(senate_list,new_list,index,user_id,options)
|
|
128
|
+
senate_list[index].store(:photos,Photo.get_photos(senate_list[index][:id])) if senate_list[index][:has_photo]
|
|
129
|
+
senate_list[index].store(:hyperlinks,Hyperlink.get_links(senate_list[index][:id]))
|
|
130
|
+
senate_list[index].store(:indent,Forum.get_indent(senate_list[index][:id],0) )
|
|
131
|
+
senate_list[index][:owner]= senate_list[index][:owner]==user_id
|
|
132
|
+
senate_list[index].store(:moderator,options[:moderator]) unless options[:moderator].nil?
|
|
133
|
+
senate_list[index].store(:vote,options[:vote]) unless options[:vote].nil?
|
|
134
|
+
senate_list[index].store(:votes,options[:votes]) unless options[:votes].nil?
|
|
135
|
+
senate_list[index].store(:admin,options[:admin]) unless options[:admin].nil?
|
|
136
|
+
senate_list[index].store(:subscribed,options[:subscribed]) unless options[:subscribed].nil?
|
|
137
|
+
new_list.push(senate_list[index])
|
|
138
|
+
id=senate_list[index][:id]
|
|
139
|
+
senate_list.delete_at(index)
|
|
140
|
+
id
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def self.get_indent(id,index)
|
|
144
|
+
parent=Forum.where(id:id).pluck(:parent)[0]
|
|
145
|
+
index=Forum.get_indent(parent,index+1) unless parent==0 || parent.nil?
|
|
146
|
+
index
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def self.look_for_key(list,key,test)
|
|
150
|
+
index_out=nil
|
|
151
|
+
(list.size-1).downto(0).each { |index|
|
|
152
|
+
index_out=index if list[index][key]==test
|
|
153
|
+
} unless list.empty?
|
|
154
|
+
index_out
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def self.add_comment(params,user)
|
|
158
|
+
topic_id=Topic.where(name:params[:topic]).pluck(:id)[0]
|
|
159
|
+
restricted=params[:restricted] == 'true'
|
|
160
|
+
unless params[:comment].nil? || params[:comment].empty? || !user.forum_posting_privileges?
|
|
161
|
+
has_photo=params[:already_has_photo] == 'true' || params[:needs_photo] == 'true'
|
|
162
|
+
params[:id]=Forum.where(user_id:user.id,tag:params[:tag].to_s).pluck(:id)[0] if params[:id].nil?
|
|
163
|
+
if params[:edit]=='true' && (user.id==Forum.where(id:params[:id]).pluck(:user_id)[0] || user.forum_admin?)
|
|
164
|
+
forum_id=params[:id]
|
|
165
|
+
Forum.where(id: params[:id]).update_all(content: params[:comment],has_photo:has_photo, parent: params[:parent],restricted:restricted)
|
|
166
|
+
else
|
|
167
|
+
owner_name=Xforum.user_class.where(id:user.id).pluck(:forum_post_name)[0]
|
|
168
|
+
forum_id= Forum.create(parent:params[:parent],topic_id:topic_id,tag:params[:tag], has_photo:has_photo, user_id:user.id,content:params[:comment],restricted:restricted,owner_name:owner_name).id
|
|
169
|
+
Translation.create(forum_id:forum_id,user_id:user.id,topic_id:topic_id, language_id:Language.get_locale(params), content:params[:translation],suggestion:false,state:'new')
|
|
170
|
+
end
|
|
171
|
+
Translation.add_one(params,topic_id,user.id,forum_id) if params[:translating] && user.forum_translating_privileges?
|
|
172
|
+
PeopleList.make_invitation(params,forum_id,user) if params[:restricted]=='true'
|
|
173
|
+
PeopleList.add_to_invitation(params,forum_id,user) unless params[:invitees].nil?
|
|
174
|
+
Hyperlink.add_set(params,forum_id) unless params[:link_ref].nil?
|
|
175
|
+
end
|
|
176
|
+
{parent:params[:parent],id:forum_id,topic_id:topic_id,tag:params[:tag],edit:params[:edit]=='true'}
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def self.get_forum_actions(params,user)
|
|
180
|
+
alist= []
|
|
181
|
+
alist.push(['select action',I18n.t('xForum.select_action')])
|
|
182
|
+
if user.forum_admin?
|
|
183
|
+
alist.push(['suspend posting',I18n.t('xForum.suspend_posting')])
|
|
184
|
+
alist.push(['suspend all',I18n.t('xForum.suspend_all')])
|
|
185
|
+
alist.push(['send email to',I18n.t('xForum.send_email_to')])
|
|
186
|
+
alist.push(['create distribution',I18n.t('xForum.create_distribution')])
|
|
187
|
+
alist.push(['add to distribution',I18n.t('xForum.add_to_distribution') ])
|
|
188
|
+
alist.push(['add topic monitor',I18n.t('xForum.Add_Topic_Monitor') ])
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
{list_data:ForumAssist.named_array(alist,[:item,:value]),id:'forum-actions'}
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def self.change_state(params,user)
|
|
195
|
+
Forum.where(id:params[:id]).update_all(state: params[:function],resolution:params[:resolution]) if PeopleList.check_people({topic:params[:id], user_id:user.id,list:'moderator'}) || user.forum_admin?
|
|
196
|
+
{action:'nothing to do'}
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def self.set_the_rest(params,user)
|
|
200
|
+
topic_id=Topic.where(name:params[:topic]).pluck(:id)[0]
|
|
201
|
+
Forum.where(topic_id:topic_id, state: 'new').update_all(state: params[:state]) if PeopleList.check_people({topic:topic_id,user_id:user.id,list:'moderator'}) || user.forum_admin?
|
|
202
|
+
{action:'nothing to do'}
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def self.is_child_there?(senate_list,new_list, parent,me,user_id)
|
|
206
|
+
child=Forum.look_for_key(senate_list,:parent,me)
|
|
207
|
+
unless child.nil?
|
|
208
|
+
child=Forum.set_new_senate_entry(senate_list, new_list, child, user_id, {})
|
|
209
|
+
is_child_there?(senate_list, new_list, me, child, user_id) unless senate_list.empty?
|
|
210
|
+
end
|
|
211
|
+
if me!=parent && me!=0
|
|
212
|
+
Forum.is_child_there?(senate_list, new_list,parent ,parent, user_id) unless senate_list.empty?
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
end
|
|
217
|
+
end
|