-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa-plugin.php
137 lines (114 loc) · 3.59 KB
/
qa-plugin.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
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
<?php
/*
Plugin Name: q2apro Flag Reasons
Plugin URI: https://github.com/q2apro/q2apro-flag-reasons
Plugin Description: Adds choice of flag reasons and notice option to each flag vote
Plugin Version: 0.2
Plugin Date: 2018-03-05
Plugin Author: q2apro.com
Plugin License: GPLv3
Plugin Minimum Question2Answer Version: 1.7
Plugin Update Check URI:
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 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 General Public License for more details.
More about this license: http://www.gnu.org/licenses/gpl.html
*/
if(!defined('QA_VERSION'))
{
header('Location: ../../');
exit;
}
// language file
qa_register_plugin_phrases('q2apro-flag-reasons-lang-*.php', 'q2apro_flagreasons_lang');
// page
qa_register_plugin_module('page', 'q2apro-flag-reasons-page.php', 'q2apro_flag_reasons_page', 'q2apro flag reasons Page');
// layer
qa_register_plugin_layer('q2apro-flag-reasons-layer.php', 'q2apro flag reasons layer');
// admin
qa_register_plugin_module('module', 'q2apro-flag-reasons-admin.php', 'q2apro_flagreasons_admin', 'q2apro flag reasons Admin');
// track events
qa_register_plugin_module('event', 'q2apro-flag-reasons-event.php','q2apro_flagreasons_event','q2apro flag reasons Event');
function q2apro_flag_reasonid_to_readable($reasonid)
{
/*
Reasonids for Flags:
1 - spam
2 - quality
3 - rude
4 - edit
5 - duplicate
6 - migrate
*/
switch($reasonid)
{
case 1:
return qa_lang('q2apro_flagreasons_lang/reason_quality');
break;
case 2:
return qa_lang('q2apro_flagreasons_lang/reason_spam');
break;
case 3:
return qa_lang('q2apro_flagreasons_lang/reason_rude');
break;
case 4:
return qa_lang('q2apro_flagreasons_lang/reason_edit');
break;
case 5:
return qa_lang('q2apro_flagreasons_lang/reason_duplicate');
break;
case 6:
return qa_lang('q2apro_flagreasons_lang/reason_migrate');
break;
default:
return '';
}
}
function q2apro_get_postflags($postid)
{
return qa_db_read_all_assoc( qa_db_query_sub('
SELECT userid, postid, reasonid, notice
FROM ^flagreasons
WHERE postid = #
', $postid
));
}
function q2apro_count_postflags_output($postid)
{
$flags = q2apro_get_postflags($postid);
$flagoutput = '';
// count reasons
foreach($flags as $flag)
{
$handle = '';
if(qa_get_logged_in_level()>49) {
$handle = ' <a href="'.qa_path('user').'/'.qa_userid_to_handle($flag['userid']).'">'.qa_userid_to_handle($flag['userid']).'</a>'; //qa_userid_to_handle($flag['userid']);
}
$flagoutput .= (empty($flagoutput) ? '' : '<br>');
$flagoutput .= '✌ '.q2apro_flag_reasonid_to_readable($flag['reasonid']).''.$handle;
if(!empty($flag['notice']))
{
$flagoutput .= ' “'.$flag['notice'].'”';
}
$flagoutput .= '';
}
return $flagoutput;
}
function q2apro_save_flagreasons($userid, $postid, $reasonid, $notice)
{
$notice = strip_tags($notice);
qa_db_query_sub('
INSERT INTO `^flagreasons` (`userid`, `postid`, `reasonid`, `notice`)
VALUES (#, #, #, $)
ON DUPLICATE KEY
UPDATE `userid`=#, `postid`=#, `reasonid`=#, `notice`=$
',
$userid, $postid, $reasonid, $notice,
$userid, $postid, $reasonid, $notice
);
}