This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
forked from tmtrademark/cheezcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.php
315 lines (273 loc) · 7.25 KB
/
library.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
//
// CheezCap - Cheezburger Custom Administration Panel
// (c) 2008 - 2010 Cheezburger Network (Pet Holdings, Inc.)
// LOL: http://cheezburger.com
// Source: http://github.com/cheezburger/cheezcap/
// Authors: Kyall Barrows, Toby McKes, Stefan Rusek, Scott Porad
// License: GNU General Public License, version 2 (GPL), http://www.gnu.org/licenses/gpl-2.0.html
//
class Group {
var $name;
var $id;
var $options;
function Group( $_name, $_id, $_options ) {
$this->name = $_name;
$this->id = "cap_$_id";
$this->options = $_options;
}
function WriteHtml() {
?>
<table class="form-table" width="100%">
<tr valign="top">
<th scope="row">Option</th>
<th scope="row">Value</th>
</tr>
<?php
for ( $i=0; $i < count( $this->options ); $i++ ) {
$this->options[$i]->WriteHtml();
}
?>
</table>
<?php
}
}
class Option {
var $name;
var $desc;
var $id;
var $_key;
var $std;
function Option( $_name, $_desc, $_id, $_std ) {
$this->name = $_name;
$this->desc = $_desc;
$this->id = "cap_$_id";
$this->_key = $_id;
$this->std = $_std;
}
function WriteHtml() {
echo '';
}
function Update( $ignored ) {
$value = stripslashes_deep( $_POST[$this->id] );
update_option( $this->id, $value );
}
function Reset( $ignored ) {
update_option( $this->id, $this->std );
}
function Import( $data ) {
if ( array_key_exists( $this->id, $data->dict ) )
update_option( $this->id, $data->dict[$this->id] );
}
function Export( $data ) {
$data->dict[$this->id] = get_option( $this->id );
}
function get() {
return get_option( $this->id );
}
}
class TextOption extends Option {
var $useTextArea;
function TextOption( $_name, $_desc, $_id, $_std = '', $_useTextArea = false ) {
$this->Option( $_name, $_desc, $_id, $_std );
$this->useTextArea = $_useTextArea;
}
function WriteHtml() {
$stdText = $this->std;
$stdTextOption = get_option( $this->id );
if ( ! empty( $stdTextOption ) )
$stdText = $stdTextOption;
?>
<tr valign="top">
<th scope="row"><?php echo $this->name; ?>:</th>
<?php
$commentWidth = 2;
if ( $this->useTextArea ) :
$commentWidth = 1;
?>
<td rowspan="2"><textarea style="width:100%;height:100%;" name="<?php echo $this->id; ?>" id="<?php echo $this->id; ?>"><?php echo esc_attr( $stdText ); ?></textarea>
<?php
else :
?>
<td><input name="<?php echo $this->id; ?>" id="<?php echo $this->id; ?>" type="text" value="<?php echo esc_attr( $stdText ); ?>" size="40" />
<?php
endif;
?>
</td>
</tr>
<tr valign="top"><td colspan="<?php echo $commentWidth; ?>"><small><?php echo $this->desc; ?></small></td></tr><tr valign="top"><td colspan="2"><hr /></td></tr>
<?php
}
function get() {
$value = get_option( $this->id );
if ( empty( $value ) )
return $this->std;
return $value;
}
}
class DropdownOption extends Option {
var $options;
function DropdownOption( $_name, $_desc, $_id, $_options, $_stdIndex = 0 ) {
$this->Option( $_name, $_desc, $_id, $_stdIndex );
$this->options = $_options;
}
function WriteHtml() {
?>
<tr valign="top">
<th scope="row"><?php echo $this->name; ?></th>
<td>
<select name="<?php echo $this->id; ?>" id="<?php echo $this->id; ?>">
<?php
foreach( $this->options as $option ) :
?>
<option<?php if ( get_option( $this->id ) == $option || ( ! get_option( $this->id ) && $this->options[$this->std] == $option )) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
<?php
endforeach;
?>
</select>
</td>
</tr>
<tr valign="top">
<td colspan=2>
<small><?php echo $this->desc; ?></small><hr />
</td>
</tr>
<?php
}
function get() {
$value = get_option( $this->id, $this->std );
if ( strtolower( $value ) == 'disabled' )
return false;
return $value;
}
}
class BooleanOption extends DropdownOption {
var $default;
function BooleanOption( $_name, $_desc, $_id, $_default = false ) {
$this->default = $_default;
$this->DropdownOption( $_name, $_desc, $_id, array( 'Disabled', 'Enabled' ), $_default ? 1 : 0 );
}
function get() {
$value = get_option( $this->id, $this->default );
if ( is_bool( $value ) )
return $value;
switch ( strtolower( $value ) ) {
case 'true':
case 'enable':
case 'enabled':
return true;
default:
return false;
}
}
}
// This class is the handy short cut for accessing config options
//
// $cap->post_ratings is the same as get_bool_option("cap_post_ratings", false)
//
class autoconfig {
private $data = false;
private $cache = array();
function init() {
if ( $this->data )
return;
$this->data = array();
$options = cap_get_options();
foreach ($options as $group) {
foreach($group->options as $option) {
$this->data[$option->_key] = $option;
}
}
}
public function __get( $name ) {
$this->init();
if ( array_key_exists( $name, $this->cache ) )
return $this->cache[$name];
$option = $this->data[$name];
if ( empty($option) )
throw new Exception("Unknown key: $name");
$value = $this->cache[$name] = $option->get();
return $value;
}
}
function cap_admin_css() {
wp_enqueue_style( 'jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/themes/base/jquery-ui.css', false, '1.7.3' );
}
function cap_admin_js_libs() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-tabs' );
}
function cap_admin_js_footer() {
?>
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function($) {
$("#config-tabs").tabs();
});
/* ]]> */
</script>
<?php
}
function top_level_settings() {
global $themename;
if ( isset( $_REQUEST['saved'] ) )
echo "<div id='message' class='updated fade'><p><strong>$themename settings saved.</strong></p></div>";
if ( isset( $_REQUEST['reset'] ) )
echo "<div id='message' class='updated fade'><p><strong>$themename settings reset.</strong></p></div>";
?>
<div class="wrap">
<h2><b><?php echo $themename; ?> Theme Options</b></h2>
<form method="post">
<div id="config-tabs">
<ul>
<?php
$groups = cap_get_options();
foreach( $groups as $group ) :
?>
<li><a href='#<?php echo $group->id; ?>'><?php echo $group->name; ?></a></li>
<?php
endforeach;
?>
</ul>
<?php
foreach( $groups as $group ) :
?>
<div id='<?php echo $group->id;?>'>
<?php
$group->WriteHtml();
?>
</div>
<?php
endforeach;
?>
</div>
<p class="submit alignleft">
<input type="hidden" name="action" value="save" />
<input name="save" type="submit" value="Save changes" />
</p>
</form>
<form enctype="multipart/form-data" method="post">
<p class="submit alignleft">
<input name="action" type="submit" value="Reset" />
</p>
<p class="submit alignleft" style='margin-left:20px'>
<input name="action" type="submit" value="Export" />
</p>
<p class="submit alignleft">
<input name="action" type="submit" value="Import" />
<input type="file" name="file" />
</p>
</form>
<div class="clear"></div>
<h2>Preview (updated when options are saved)</h2>
<iframe src="<?php echo home_url( '?preview=true' ); ?>" width="100%" height="600" ></iframe>
<?php
}
class ImportData {
var $dict = array();
}
function cap_serialize_export( $data ) {
header( 'Content-disposition: attachment; filename=theme-export.txt' );
echo serialize( $data );
exit();
}