-
Notifications
You must be signed in to change notification settings - Fork 0
/
bt_config.php
196 lines (189 loc) · 6.02 KB
/
bt_config.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
195
196
<?php
/*
* If you need any more options, just add it to $bt_options array. Simple, isn't it?
* When calling: get_options('bt_<id>');
*/
$pluginname = 'Bulletaeon';
$shortname = 'bt';
$bt_options = array(
array(
"name" => __('管理頁面每頁所顯示的公告數'),
"desc" => __(''),
"id" => $shortname."_msgs_per_page",
"std" => "15",
"type" => "text"),
array(
"name" => __('啓動舊系統相容模組?'),
"desc" => __(''),
"id" => $shortname."_compat",
"std" => 'false',
"type" => "checkbox"),
array(
"name" => __('Where do you insert the [btaeon cat=all] shortcode?'),
"desc" => __(''),
"id" => $shortname."_showall_url",
"std" => "",
"type" => "text"),
array(
"name" => __('Where do you insert the [btaeon cat=old] shortcode?'),
"desc" => __(''),
"id" => $shortname."_showold_url",
"std" => "",
"type" => "text"),
);
function bt_admin_redirect()
{
global $pluginname, $bt_options;
if ( isset($_GET['page']) && $_GET['page'] == 'btconf' )
{
if ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'save' )
{
foreach ($bt_options as $value)
{
update_option( $value['id'], $_REQUEST[ $value['id'] ] );
}
foreach ($bt_options as $value)
{
if( isset( $_REQUEST[ $value['id'] ] ) )
{
update_option( $value['id'], $_REQUEST[ $value['id'] ] );
} else {
delete_option( $value['id'] );
}
}
header("Location: admin.php?page=btconf&saved=true");
die;
} elseif ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset' ) {
foreach ($bt_options as $value)
{
delete_option( $value['id'] );
}
header("Location: admin.php?page=btconf&reset=true");
die;
} elseif ( isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset_widgets' ) {
$null = null;
update_option('sidebars_widgets',$null);
header("Location: admin.php?page=btconf&reset=true");
die;
}
}
}
function bt_config()
{
global $bt_options;
// Wrapper function for handling the ordinate Bulletaeon Options Admin Page
bt_admin_generator($bt_options);
}
function bt_admin_generator($options_to_generate)
{
// This function renders the actual admin page based on $options_to_generate
global $pluginname, $shortname;
if ( isset($_REQUEST['saved']) && $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$pluginname.' '.__('settings saved.','thematic').'</strong></p></div>';
if ( isset($_REQUEST['reset']) && $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$pluginname.' '.__('settings reset.','thematic').'</strong></p></div>';
if ( isset($_REQUEST['reset_widgets']) && $_REQUEST['reset_widgets'] ) echo '<div id="message" class="updated fade"><p><strong>'.$pluginname.' '.__('widgets reset.','thematic').'</strong></p></div>';
?>
<div="wrap">
<?php if ( function_exists('screen_icon') ) screen_icon(); ?>
<h2><?php echo $pluginname; ?> 設定</h2>
<form method="post" action="">
<table class="form-table">
<?php foreach ($options_to_generate as $value) {
switch ( $value['type'] )
{
case 'text': ?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo __($value['name'],'thematic'); ?></label></th>
<td>
<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>" />
<?php echo __($value['desc'],'thematic'); ?>
</td>
</tr>
<?php break;
case 'textarea':
$ta_options = $value['options']; ?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo __($value['name'],'thematic'); ?></label></th>
<td><textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" cols="<?php echo $ta_options['cols']; ?>" rows="<?php echo $ta_options['rows']; ?>"><?php
if ( get_option($value['id']) != '')
{
echo __(stripslashes(get_option($value['id'])),'thematic');
} else {
echo __($value['std'],'thematic');
} ?></textarea><br />
<?php echo __($value['desc'],'thematic'); ?>
</td>
</tr>
<?php break;
case 'nothing':
$ta_options = $value['options']; ?>
</table>
<?php echo __($value['desc'],'thematic'); ?>
<table class="form-table">
<?php break;
case 'radio': ?>
<tr valign="top">
<th scope="row"><?php echo __($value['name'],'thematic'); ?></th>
<td>
<?php foreach ( $value['options'] as $key=>$option )
{
$radio_setting = get_option($value['id']);
if ( $radio_setting != '' )
{
if ($key == get_option($value['id']) )
{
$checked = 'checked="checked"';
} else {
$checked = '';
}
} else {
if ( $key == $value['std'] )
{
$checked = 'checked="checked"';
} else {
$checked = '';
}
} ?>
<input type="radio" name="<?php echo $value['id']; ?>" id="<?php echo $value['id'] . $key; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> />
<label for="<?php echo $value['id'] . $key; ?>"><?php echo $option; ?></label><br />
<?php } ?>
</td>
</tr>
<?php break;
case 'checkbox': ?>
<tr valign="top">
<th scope="row"><?php echo __($value['name'],'thematic'); ?></th>
<td>
<?php
if ( get_option($value['id']) )
{
$checked = 'checked="checked"';
} else {
$checked = '';
}
?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
<label for="<?php echo $value['id']; ?>"><?php echo __($value['desc'],'thematic'); ?></label>
</td>
</tr>
<?php break;
default:
break;
}
}
?>
</table>
<p class="submit">
<input name="save" type="submit" value="<?php _e('Save changes','thematic'); ?>" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post" action="">
<p class="submit">
<input name="reset" type="submit" value="<?php _e('Reset'); ?>" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</div>
<?php
}
?>