-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqa-cp-admin.php
103 lines (79 loc) · 2 KB
/
qa-cp-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
<?php
/*
Question2Answer (c) Gideon Greenspan
http://www.question2answer.org/
Community Posts Plugin by Bruno Vandekerkhove © 2015
*/
/*
ADMIN PANEL
*/
class qa_cp_admin {
// Default options
function option_default($option) {
switch($option) {
case 'cp_enable':
return true;
case 'permit_create_cp':
return QA_PERMIT_USERS;
case 'permit_edit_cp':
return QA_PERMIT_USERS;
default:
return null;
}
}
// Template to allow
function allow_template($template) {
return ($template != 'admin');
}
// Create the admin form
function admin_form(&$qa_content) {
// Process form input
$ok = null;
if (qa_clicked('cp_save')) { // 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 \'\',
meta_value longtext,
PRIMARY KEY (meta_id),
KEY post_id (post_id),
KEY meta_key (meta_key)
) ENGINE=MyISAM DEFAULT CHARSET=utf8'
);
qa_opt('cp_enable', (bool)qa_post_text('cp_enable'));
$ok = qa_lang('admin/options_saved');
}
else if (qa_clicked('cp_reset')) { // Reset
foreach($_POST as $i => $v) {
$def = $this->option_default($i);
if ($def !== null)
qa_opt($i,$def);
}
qa_opt('cp_enable', true);
$ok = qa_lang('admin/options_reset');
}
// Create the form for display
$fields = array();
$fields[] = array(
'label' => qa_lang('cp/enable_community_posts'),
'tags' => 'NAME="cp_enable"',
'value' => qa_opt('cp_enable'),
'type' => 'checkbox',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang_html('main/save_button'),
'tags' => 'NAME="cp_save"',
),
array(
'label' => qa_lang_html('admin/reset_options_button'),
'tags' => 'NAME="cp_reset"',
),
),
);
}
}