-
Notifications
You must be signed in to change notification settings - Fork 616
Expand file tree
/
Copy pathadmin-moderate.php
More file actions
198 lines (144 loc) · 6.36 KB
/
Copy pathadmin-moderate.php
File metadata and controls
198 lines (144 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
Description: Controller for admin page showing questions, answers and comments waiting for approval
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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 General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../../');
exit;
}
require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
// Find queued questions, answers, comments
$userid = qa_get_logged_in_userid();
$start = qa_get_start();
$pageSize = (int)qa_opt('page_size_qs');
list($queuedquestions, $queuedanswers, $queuedcomments) = qa_db_select_with_pending(
qa_db_qs_selectspec($userid, 'created', $start, null, null, 'Q_QUEUED', true, $pageSize),
qa_db_recent_a_qs_selectspec($userid, $start, null, null, 'A_QUEUED', true, $pageSize),
qa_db_recent_c_qs_selectspec($userid, $start, null, null, 'C_QUEUED', true, $pageSize)
);
// Check admin privileges (do late to allow one DB query)
if (qa_user_maximum_permit_error('permit_moderate')) {
$qa_content = qa_content_prepare();
$qa_content['error'] = qa_lang_html('users/no_permission');
return $qa_content;
}
// Check to see if any were approved/rejected here
$pageerror = qa_admin_check_clicks();
// Combine sets of questions and remove those this user has no permission to moderate. Please note that we are not slicing the posts to $pageSize. So, we may have maximum of 3*$pageSize posts per page.
$questions = qa_any_sort_by_date(array_merge($queuedquestions, $queuedanswers, $queuedcomments));
if (qa_user_permit_error('permit_moderate')) { // if user not allowed to moderate all posts
foreach ($questions as $index => $question) {
if (qa_user_post_permit_error('permit_moderate', $question))
unset($questions[$index]);
}
}
// Get information for users
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
// Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/recent_approve_title');
$qa_content['error'] = isset($pageerror) ? $pageerror : qa_admin_page_error();
$qa_content['q_list'] = array(
'form' => array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'hidden' => array(
'code' => qa_get_form_security_code('admin/click'),
),
),
'qs' => array(),
);
if (count($questions)) {
foreach ($questions as $question) {
$postid = qa_html(isset($question['opostid']) ? $question['opostid'] : $question['postid']);
$elementid = 'p' . $postid;
$htmloptions = qa_post_html_options($question);
$htmloptions['voteview'] = false;
$htmloptions['tagsview'] = !isset($question['opostid']);
$htmloptions['answersview'] = false;
$htmloptions['viewsview'] = false;
$htmloptions['contentview'] = true;
$htmloptions['elementid'] = $elementid;
$htmlfields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, $htmloptions);
if (isset($htmlfields['what_url'])) // link directly to relevant content
$htmlfields['url'] = $htmlfields['what_url'];
$posttype = qa_strtolower(isset($question['obasetype']) ? $question['obasetype'] : $question['basetype']);
switch ($posttype) {
case 'q':
default:
$approveKey = 'question/approve_q_popup';
$rejectKey = 'question/reject_q_popup';
break;
case 'a':
$approveKey = 'question/approve_a_popup';
$rejectKey = 'question/reject_a_popup';
break;
case 'c':
$approveKey = 'question/approve_c_popup';
$rejectKey = 'question/reject_c_popup';
break;
}
$htmlfields['form'] = array(
'style' => 'light',
'buttons' => array(
// Possible values for popup: approve_q_popup, approve_a_popup, approve_c_popup
'approve' => array(
'tags' => 'name="admin_' . $postid . '_approve" onclick="return qa_admin_click(this);"',
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html($approveKey),
),
// Possible values for popup: reject_q_popup, reject_a_popup, reject_c_popup
'reject' => array(
'tags' => 'name="admin_' . $postid . '_reject" onclick="return qa_admin_click(this);"',
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html($rejectKey),
),
),
);
$qa_content['q_list']['qs'][] = $htmlfields;
}
// Manual count query - the following two methods will not work if we have 35 questions, 15 answer and 19 comments are there for moderation
//$totalQueued = qa_opt('cache_queuedcount');
//$totalQueued = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(*) FROM ^posts WHERE type IN ('Q_QUEUED', 'A_QUEUED', 'C_QUEUED')"),true);
// The workable solution is
$countQ = qa_db_read_one_value(
qa_db_query_sub("SELECT COUNT(*) FROM ^posts WHERE type = 'Q_QUEUED'"),
true
);
$countA = qa_db_read_one_value(
qa_db_query_sub("SELECT COUNT(*) FROM ^posts WHERE type = 'A_QUEUED'"),
true
);
$countC = qa_db_read_one_value(
qa_db_query_sub("SELECT COUNT(*) FROM ^posts WHERE type = 'C_QUEUED'"),
true
);
// the page list should be driven by the largest queue
$Max_posts = max($countQ, $countA, $countC);
// Add page links
$qa_content['page_links'] = qa_html_page_links(
qa_request(), // Current request
$start, // Current start offset
$pageSize, // It doesn't exactly reflect the no.of posts per page. It is used to calculate the number of page links.
$Max_posts, // Maximum posts of one type
2, // number of page links before and after current
array(), // Extra query params
'' // Anchor
);
} else
$qa_content['title'] = qa_lang_html('admin/no_approve_found');
$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
$qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
return $qa_content;