forked from NoahY/q2a-theme-switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qa-theme-admin.php
127 lines (100 loc) · 3.18 KB
/
qa-theme-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
<?php
class qa_theme_admin {
function option_default($option) {
switch($option) {
case 'theme_switch_title':
return 'Theme';
case 'theme_switch_text':
return 'Choose theme:';
case 'theme_switch_default':
return qa_opt('site_theme');
default:
return null;
}
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('theme_switch_save')) {
if(!qa_post_text('theme_switch_enable')) {
qa_opt('site_theme',qa_opt('theme_switch_default'));
}
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'
);
qa_opt('theme_switch_enable',(bool)qa_post_text('theme_switch_enable'));
qa_opt('theme_switch_default',qa_post_text('theme_switch_default'));
qa_opt('theme_switch_title',qa_post_text('theme_switch_title'));
qa_opt('theme_switch_text',qa_post_text('theme_switch_text'));
qa_opt('theme_switch_enable_mobile',(bool)qa_post_text('theme_switch_enable_mobile'));
qa_opt('theme_switch_mobile',qa_post_text('theme_switch_mobile'));
global $qa_request;
qa_redirect($qa_request,array('ok'=>qa_lang_html('admin/options_saved')));
}
// Create the form for display
$themes = qa_admin_theme_options();
$fields = array();
$fields[] = array(
'label' => 'Enable theme switching',
'tags' => 'NAME="theme_switch_enable"',
'value' => qa_opt('theme_switch_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Default theme',
'tags' => 'NAME="theme_switch_default"',
'type' => 'select',
'options' => qa_admin_theme_options(),
'value' => @$themes[qa_opt('theme_switch_default')],
);
$fields[] = array(
'label' => 'Theme switch title',
'type' => 'text',
'value' => qa_html(qa_opt('theme_switch_title')),
'tags' => 'NAME="theme_switch_title"',
);
$fields[] = array(
'label' => 'Theme switch text',
'type' => 'text',
'value' => qa_html(qa_opt('theme_switch_text')),
'tags' => 'NAME="theme_switch_text"',
);
if(!function_exists('qa_register_plugin_overrides')) { // 1.4
$fields[] = array(
'label' => 'Enable mobile theme',
'tags' => 'NAME="theme_switch_enable_mobile"',
'value' => qa_opt('theme_switch_enable_mobile'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Mobile theme',
'tags' => 'NAME="theme_switch_mobile"',
'type' => 'select',
'options' => qa_admin_theme_options(),
'value' => @$themes[qa_opt('theme_switch_mobile')],
);
}
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => 'Save',
'tags' => 'NAME="theme_switch_save"',
)
),
);
}
}