forked from pupi1985/q2a-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qa-wiki-admin.php
195 lines (169 loc) · 4.9 KB
/
qa-wiki-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
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
<?php
class qa_wiki_admin {
function option_default($option) {
switch($option) {
case 'wiki_edit_allow':
return 150;
case 'wiki_send_allow':
return 100;
case 'wiki_edit_allow_points':
return 0;
case 'wiki_send_allow_points':
return 0;
case 'wiki_page_css':
return '
#wiki_container .rbr {
background-color: #EEEEEE;
border-color: #777;
border-radius: 12px 0 0 12px;
border-style: solid none solid solid;
border-width: 2px 0 2px 2px;
clear: right;
color: #221003;
float: left;
margin-top: 8px;
padding: 6px;
}
#wiki_container .rbr a {
text-decoration:none;
}
#wiki_container .rbr ul {
list-style: none outside none;
padding:0;
}
#wiki_container .rbr li {
float:left;
padding:0 8px;
}
#wiki_container #wiki-main {
}
#wiki_container #wiki-main .action-links {
}
#wiki_container #wiki-main .action-links a {
background-color: #EEEEEE;
border: 1px solid silver;
border-radius: 4px 4px 4px 4px;
color: black;
padding: 3px 8px;
text-decoration: none;
}
#wiki-main .action-links a:hover {
background-color: #EFEFEF !important;
}
#wiki-main .control-links {
text-align:left;
}
#wiki-main .action-links-buttons {
float:right;
}
.qa-wiki-error {
font-weight:bold;
color:Maroon;
}
';
default:
return null;
}
}
function custom_badges() {
return array(
'wikifier' => array('var'=>1, 'type'=>0),
'wacky_wikifier' => array('var'=>5, 'type'=>1),
'wicked_wikifier' => array('var'=>20, 'type'=>2),
);
}
function custom_badges_rebuild() {
$awarded = 0;
qa_db_query_sub(
'CREATE TABLE IF NOT EXISTS ^usermeta (
meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
user_id bigint(20) unsigned NOT NULL,
meta_key varchar(255) DEFAULT NULL,
meta_value longtext,
PRIMARY KEY (meta_id),
UNIQUE (user_id,meta_key)
) ENGINE=MyISAM DEFAULT CHARSET=utf8'
);
$posts = qa_db_query_sub(
'SELECT user_id AS userid, meta_value FROM ^usermeta WHERE meta_key=$',
'wikified'
);
while ( ($post=qa_db_read_one_assoc($posts,true)) !== null ) {
$badges = array('wikifier','wacky_wikifier','wicked_wikifier');
$awarded += count(qa_badge_award_check($badges,(int)$post['meta_value'],$post['userid'],null,2));
}
return $awarded;
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('wiki_plugin_save')) {
qa_opt('wiki_send_enable',(bool)qa_post_text('wiki_send_enable'));
qa_opt('wiki_page_css',qa_post_text('wiki_page_css'));
$ok = qa_lang('admin/options_saved');
}
else if (qa_clicked('wiki_plugin_reset')) {
foreach($_POST as $i => $v) {
$def = $this->option_default($i);
if($def !== null) qa_opt($i,$def);
}
$ok = qa_lang('admin/options_reset');
}
if(qa_opt('wiki_send_allow')!=106) {
qa_set_display_rules($qa_content, array(
'wiki_send_allow_points' => 'wiki_send_allow_points_hidden',
));
}
if(qa_opt('wiki_edit_allow')!=106) {
qa_set_display_rules($qa_content, array(
'wiki_edit_allow_points' => 'wiki_send_allow_points_hidden',
));
}
// Create the form for display
$fields = array();
$fields[] = array(
'label' => 'Allow sending answers to wiki',
'note' => '',
'tags' => 'NAME="wiki_send_enable"',
'type' => 'checkbox',
'value' => qa_opt('wiki_send_enable'),
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Wiki page stylesheet',
'tags' => 'NAME="wiki_page_css"',
'value' => qa_opt('wiki_page_css'),
'rows' => 20,
'type' => 'textarea',
'note' => '^ will be replaced by location of this plugin directory',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'hidden' => array(
array(
'id' => 'wiki_send_allow_points_hidden',
'tags' => 'NAME="wiki_send_allow_points_hidden"',
'value' => 'false',
)
),
'buttons' => array(
array(
'label' => qa_lang_html('main/save_button'),
'tags' => 'NAME="wiki_plugin_save"',
),
array(
'label' => qa_lang_html('admin/reset_options_button'),
'tags' => 'NAME="wiki_plugin_reset"',
),
),
);
}
}