-
Notifications
You must be signed in to change notification settings - Fork 0
/
qa-close-admin.php
146 lines (120 loc) · 4.96 KB
/
qa-close-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
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
<?php
class qa_close_admin {
function option_default($option) {
switch($option) {
case 'closed_question_title':
return '[closed]';
case 'closed_question_text':
return 'This question has been closed by # for the following reason: $';
case 'close_button_text':
return 'close';
case 'reopen_button_text':
return 'reopen';
case 'close_auto_close_reason':
return 'answer limit reached';
default:
return null;
}
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('close_save')) {
qa_db_query_sub(
'CREATE TABLE IF NOT EXISTS ^postmeta (
meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
post_id bigint(20) unsigned NOT NULL,
meta_key varchar(255) DEFAULT NULL,
meta_value longtext,
PRIMARY KEY (meta_id),
KEY post_id (post_id),
KEY meta_key (meta_key)
) ENGINE=MyISAM DEFAULT CHARSET=utf8'
);
qa_opt('close_enable',(bool)qa_post_text('close_enable'));
qa_opt('close_enable_own',(bool)qa_post_text('close_enable_own'));
qa_opt('close_selected',(bool)qa_post_text('close_selected'));
qa_opt('closed_question_title',qa_post_text('closed_question_title'));
qa_opt('closed_question_text',qa_post_text('closed_question_text'));
qa_opt('close_button_text',qa_post_text('close_button_text'));
qa_opt('reopen_button_text',qa_post_text('reopen_button_text'));
qa_opt('close_auto_close',(int)qa_post_text('close_auto_close'));
qa_opt('close_auto_close_reason',qa_post_text('close_auto_close_reason'));
$ok = 'Settings Saved.';
}
qa_set_display_rules($qa_content, array(
'close_enable_own' => 'close_enable',
));
// Create the form for display
$fields = array();
$fields[] = array(
'label' => 'Enable question closing',
'tags' => 'NAME="close_enable"',
'value' => qa_opt('close_enable'),
'type' => 'checkbox',
'note' => '<i>by default, only moderators and admin can close questions.</i>',
);
$fields[] = array(
'label' => 'Allow closing own questions',
'tags' => 'NAME="close_enable_own"',
'value' => qa_opt('close_enable_own'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Automatically close questions with selected answers',
'tags' => 'NAME="close_selected"',
'value' => qa_opt('close_selected'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Text to add to closed question title',
'tags' => 'NAME="closed_question_title"',
'value' => qa_opt('closed_question_title'),
);
$fields[] = array(
'label' => 'Closed question notice text',
'tags' => 'NAME="closed_question_text"',
'note' => '<i>$ will be replaced by the reason and # by the closing user.</i>',
'value' => qa_opt('closed_question_text'),
);
$fields[] = array(
'label' => 'Close button text',
'tags' => 'NAME="close_button_text"',
'value' => qa_opt('close_button_text'),
);
$fields[] = array(
'label' => 'Reopen button text',
'tags' => 'NAME="reopen_button_text"',
'value' => qa_opt('reopen_button_text'),
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Autoclose after # of questions',
'tags' => 'NAME="close_auto_close"',
'value' => qa_opt('close_auto_close'),
'type' => 'number',
);
$fields[] = array(
'label' => 'Reason text for autoclose',
'tags' => 'NAME="close_auto_close_reason"',
'value' => qa_opt('close_auto_close_reason'),
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => 'Save',
'tags' => 'NAME="close_save"',
)
),
);
}
}