-
Notifications
You must be signed in to change notification settings - Fork 4
/
qa-comment-voting-admin.php
92 lines (70 loc) · 1.98 KB
/
qa-comment-voting-admin.php
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
<?php
class qa_comment_voting_admin {
function option_default($option) {
switch($option) {
case 'permit_vote_c':
return qa_opt('permit_vote_a');
case 'permit_vote_c_points':
return qa_opt('permit_vote_a_points');
default:
return null;
}
}
function custom_badges() {
return array(
'nice_comment' => array('var'=>2, 'type'=>0),
'good_comment' => array('var'=>5, 'type'=>1),
'great_comment' => array('var'=>10, 'type'=>2)
);
}
function custom_badges_rebuild() {
$awarded = 0;
$posts = qa_db_query_sub(
'SELECT userid, postid, netvotes FROM ^posts WHERE type=$ AND netvotes>0',
'C'
);
while ( ($post=qa_db_read_one_assoc($posts,true)) !== null ) {
$badges = array('nice_comment','good_comment','excellent_comment');
$awarded += count(qa_badge_award_check($badges,(int)$post['netvotes'],$post['userid'],$post['postid'],2));
}
return $awarded;
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('comment_voting_save')) {
qa_opt('voting_on_cs',(bool)qa_post_text('voting_on_cs'));
qa_opt('voting_down_cs',(bool)qa_post_text('voting_down_cs'));
$ok = 'Settings Saved.';
}
// Create the form for display
$fields = array();
$fields[] = array(
'label' => 'Enable comment voting',
'tags' => 'NAME="voting_on_cs"',
'value' => qa_opt('voting_on_cs'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Enable comment down-voting',
'tags' => 'NAME="voting_down_cs"',
'value' => qa_opt('voting_down_cs'),
'type' => 'checkbox',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => 'Save',
'tags' => 'NAME="comment_voting_save"',
)
),
);
}
}