-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.settings.php
474 lines (392 loc) · 20.7 KB
/
class.settings.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?php
/**
* 3pagination settings page class
*
* @version 1.0
* @author Michael Schröder
*
* @TODO:
* - Set placement template globally, not for each option
* - Contextual help
*
*
*/
if ( !class_exists( 'threepagination_settings' ) ) {
class threepagination_settings extends threepagination {
/**
* Plugin's textdomain string
*
* @var string $textdomain
*/
protected $textdomain;
/**
* Set filters
*
* @since 0.1
*/
public function __construct() {
// Management page submenu
add_filter( 'admin_menu', array( $this, 'add_submenu' ) );
// Settings API
add_filter( 'admin_init', array( $this, 'settings_api_init' ) );
// Contextual help
add_filter( 'contextual_help', array( $this, 'contextual_help'), 10, 3 );
}
/**
* Add management page submenu
*
* @since 0.1
*/
public function add_submenu() {
global $threepagination_screen;
$threepagination_screen = add_options_page( __( '3pagination Configuration', parent::$_object->textdomain ), '3pagination', 'activate_plugins', '3pagination', array( $this, 'draw_settings_page' ) );
}
public function contextual_help( $content, $screen_id, $screen ) {
global $threepagination_screen;
if ( $screen_id == $threepagination_screen ) {
$content = '<p><strong>' . __( 'Preview', parent::$_object->textdomain ) . '</strong>';
$content.= __( ' - See a preview of the pagination according to your current settings', parent::$_object->textdomain ) . '</p>';
$content.= '<p><strong>' . __( 'Labels', parent::$_object->textdomain ) . '</strong>';
$content.= __( ' - Enable navigation labels. Set navigation labels: first and last, previous and next page. Leave empty to revert to defaults', parent::$_object->textdomain ) . '</p>';
$content.= '<p><strong>' . __( 'Placement', parent::$_object->textdomain ) . '</strong>';
$content.= __( ' - Determine where the pagination should appear on your site. <br /><i>Inject:</i> You can "inject" the navigation bar below the header or above the footer div. Your theme needs to have an according HTML structure (which most WordPress themes do).<br /><i>Append/prepend:</i> You can specifiy a container into which the pagination will be prepended/appended. Write it CSS-style, i.e. #mycontainer', parent::$_object->textdomain ) . '</p>';
$content.= '<p><strong>' . __( 'DOM & CSS', parent::$_object->textdomain ) . '</strong>';
$content.= __( ' - Define the CSS class that will be attributed to the main pagination container div.', parent::$_object->textdomain ) . '</p>';
$content.= '<p><strong>' . __( 'Other options', parent::$_object->textdomain ) . '</strong>';
$content.= __( ' - Limit the pagination to a maximum number of pages, enable pagination links for pretty URLs (checked by default).', parent::$_object->textdomain ) . '</p>';
$content = apply_filters( 'threepagination_help', $content );
$screen->add_help_tab( array( 'id' => 'threepagination-help', 'title' => __( '3pagination' ), 'content' => $content ) );
}
//return $content;
}
/**
* Settings page output
*
* @since 0.1
*/
public function draw_settings_page() {
?>
<div class="wrap">
<?php screen_icon( 'options-general' ); ?>
<h2><?php _e( '3pagination Settings', parent::$_object->textdomain ); ?></h2>
<p>
<span class="description"><?php _e( 'See "Help" tab for further explanations', parent::$_object->textdomain ); ?></span>
</p>
<form action="options.php" method="post">
<?php
settings_fields( '3pagination_settings' );
do_settings_sections( '3pagination' );
submit_button( __( 'Save Changes', parent::$_object->textdomain ), 'button-primary', 'submit', TRUE );
?>
</form>
</div>
<?php
}
/**
* Init the settings API
*
* @TODO checkbox "I am using pretty URLS"
*
* @since 0.1
*/
public function settings_api_init() {
// Register our setting so that $_POST handling is done for us and
// our callback function just has to echo the <input>
register_setting( '3pagination_settings', '3pagination_settings', array( $this, 'threepagination_validate' ) );
// Add the section to reading settings so we can add our
// fields to it
add_settings_section( '3pagination_preview', __( 'Preview', parent::$_object->textdomain ), array( $this, 'section_preview' ), '3pagination' );
add_settings_section( '3pagination_labels', __( 'Labels', parent::$_object->textdomain ), array( $this, 'section_labels' ), '3pagination' );
add_settings_section( '3pagination_placement', __( 'Placement', parent::$_object->textdomain ), array( $this, 'section_placement' ), '3pagination' );
add_settings_section( '3pagination_css', __( 'DOM & CSS', parent::$_object->textdomain ), array( $this, 'section_css' ), '3pagination' );
add_settings_section( '3pagination_other', __( 'Other options', parent::$_object->textdomain ), array( $this, 'section_other' ), '3pagination' );
// Add the field with the names and function to use for our new
// settings, put it in our new section
add_settings_field( 'threepagination_preview', __( 'Preview of pagination', parent::$_object->textdomain ), array( $this, 'preview' ), '3pagination', '3pagination_preview' );
add_settings_field( 'threepagination_labels_show', __( 'Show labels', parent::$_object->textdomain ), array( $this, 'labels_show' ), '3pagination', '3pagination_labels' );
add_settings_field( 'threepagination_labels_previous', __( 'Previous page', parent::$_object->textdomain ), array( $this, 'labels_previous' ), '3pagination', '3pagination_labels' );
add_settings_field( 'threepagination_labels_next', __( 'Next page', parent::$_object->textdomain ), array( $this, 'labels_next' ), '3pagination', '3pagination_labels' );
add_settings_field( 'threepagination_labels_first', __( 'First page', parent::$_object->textdomain ), array( $this, 'labels_first' ), '3pagination', '3pagination_labels' );
add_settings_field( 'threepagination_labels_last', __( 'Last page', parent::$_object->textdomain ), array( $this, 'labels_last' ), '3pagination', '3pagination_labels' );
add_settings_field( 'threepagination_css_class', __( 'Set CSS class', parent::$_object->textdomain ), array( $this, 'css_class' ), '3pagination', '3pagination_css' );
add_settings_field( 'threepagination_placement_header', __( 'Inject below header', parent::$_object->textdomain ), array( $this, 'placement_header' ), '3pagination', '3pagination_placement' );
add_settings_field( 'threepagination_placement_footer', __( 'Inject above footer', parent::$_object->textdomain ), array( $this, 'placement_footer' ), '3pagination', '3pagination_placement' );
add_settings_field( 'threepagination_placement_prepend', __( 'Prepend to', parent::$_object->textdomain ), array( $this, 'placement_prepend' ), '3pagination', '3pagination_placement' );
add_settings_field( 'threepagination_placement_append', __( 'Append to', parent::$_object->textdomain ), array( $this, 'placement_append' ), '3pagination', '3pagination_placement' );
add_settings_field( 'threepagination_other_maxnumpages', __( 'Max no. of pages', parent::$_object->textdomain ), array( $this, 'other_maxnumpages' ), '3pagination', '3pagination_other' );
add_settings_field( 'threepagination_other_pretty', __( 'Pretty URLs enabled?', parent::$_object->textdomain ), array( $this, 'other_pretty' ), '3pagination', '3pagination_other' );
}
/**
* Head of "preview" section
*
* @since 0.1
*/
public function section_preview() {
?>
<!--<span class="description"><?php _e( 'Preview of pagination', parent::$_object->textdomain ); ?></span>-->
<?php
}
/**
* Head of "labels" section
*
* @since 0.1
*/
public function section_labels() {
?>
<span class="description"><?php _e( 'Define the navigation labels characters', parent::$_object->textdomain ); ?></span>
<?php
}
/**
* Head of "CSS" section
*
* @since 0.1
*/
public function section_css() {
?>
<span class="description"><?php _e( 'Set your stylesheet for the pagination', parent::$_object->textdomain ); ?></span>
<?php
}
/**
* Head of "Other options" section
*
* @since 0.1
*/
public function section_other() {
?>
<span class="description"><?php _e( '', parent::$_object->textdomain ); ?></span>
<?php
}
/**
* Head of "placement" section
*
* @since 0.1
*/
public function section_placement() {
?>
<p>
<span class="description"><?php _e( '<b>Note:</b> If you want your site to degrade gracefully, you should additionaly hardcode the pagination function into your theme files: <input style="background-color:lightgrey" size="45" type="text" value="<noscript><?php threepagination::draw(); ?></noscript>"', parent::$_object->textdomain ); ?></span>
</p>
<?php
}
/**
* Display a preview of the pagination
*
* @since 0.1
*/
public function preview() {
set_query_var( 'paged', 3 );
parent::draw( TRUE, 999 );
}
/**
* Show pagination labels or not
*
* @since 0.1
*/
public function labels_show() {
$settings = get_option( '3pagination_settings', TRUE );
?>
<input type="checkbox" name="3pagination_settings[labels_show]" <?php checked( $this->init_var( $settings, 'labels_show', 'on' ), 'on' ); ?> />
<?php
}
/**
* Set 'previous page' label
*
* @since 0.1
*/
public function labels_previous() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[labels_previous]" value="<?php echo $this->init_var( $settings, 'labels_previous', '‹', TRUE ); ?>" />
<?php
}
/**
* Set 'next page' label
*
* @since 0.1
*/
public function labels_next() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[labels_next]" value="<?php echo $this->init_var( $settings, 'labels_next', '›', TRUE ); ?>" />
<?php
}
/**
* Set 'first page' label
*
* @since 0.1
*/
public function labels_first() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[labels_first]" value="<?php echo $this->init_var( $settings, 'labels_first', '«', TRUE ); ?>" />
<?php
}
/**
* Set 'last page' label
*
* @since 0.1
*/
public function labels_last() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[labels_last]" value="<?php echo $this->init_var( $settings, 'labels_last', '»', TRUE ); ?>" />
<?php
}
/**
* Inject below header
*
* @since 0.1
*/
public function placement_header() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="checkbox" name="3pagination_settings[placement_header_index]" <?php checked( $this->init_var( $settings, 'placement_header_index', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_header_index]"><?php _e( 'Index pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_header_archive]" <?php checked( $this->init_var( $settings, 'placement_header_archive', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_header_archive]"><?php _e( 'Archive pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_header_category]" <?php checked( $this->init_var( $settings, 'placement_header_category', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_header_category]"><?php _e( 'Category pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_header_search]" <?php checked( $this->init_var( $settings, 'placement_header_search', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_header_search]"><?php _e( 'Search pages', parent::$_object->textdomain ); ?></label>
<?php
}
/**
* Inject above footer
*
* @since 0.1
*/
public function placement_footer() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="checkbox" name="3pagination_settings[placement_footer_index]" <?php checked( $this->init_var( $settings, 'placement_footer_index', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_footer_index]"><?php _e( 'Index pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_footer_archive]" <?php checked( $this->init_var( $settings, 'placement_footer_archive', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_footer_archive]"><?php _e( 'Archive pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_footer_category]" <?php checked( $this->init_var( $settings, 'placement_footer_category', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_footer_category]"><?php _e( 'Category pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_footer_search]" <?php checked( $this->init_var( $settings, 'placement_footer_search', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_footer_search]"><?php _e( 'Search pages', parent::$_object->textdomain ); ?></label>
<?php
}
/**
* Prepend to custom container
*
* @since 0.1
*/
public function placement_prepend() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[placement_prepend_id]" value="<?php echo $this->init_var( $settings, 'placement_prepend_id', FALSE ); ?>" />
<label for="3pagination_settings[placement_prepend_id]"><?php _e( 'in', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_prepend_index]" <?php checked( $this->init_var( $settings, 'placement_prepend_index', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_prepend_index]"><?php _e( 'Index pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_prepend_archive]" <?php checked( $this->init_var( $settings, 'placement_prepend_archive', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_prepend_archive]"><?php _e( 'Archive pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_prepend_category]" <?php checked( $this->init_var( $settings, 'placement_prepend_category', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_prepend_category]"><?php _e( 'Category pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_prepend_search]" <?php checked( $this->init_var( $settings, 'placement_prepend_search', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_prepend_search]"><?php _e( 'Search pages', parent::$_object->textdomain ); ?></label>
<?php
}
/**
* Append to custom container
*
* @since 0.1
*/
public function placement_append() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[placement_append_id]" value="<?php echo $this->init_var( $settings, 'placement_append_id', FALSE ); ?>" />
<label for="3pagination_settings[placement_append_id]"><?php echo _x( 'in', 'Zeige Pagination "in" diesen Seiten an', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_append_index]" <?php checked( $this->init_var( $settings, 'placement_append_index', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_append_index]"><?php _e( 'Index pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_append_archive]" <?php checked( $this->init_var( $settings, 'placement_append_archive', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_append_archive]"><?php _e( 'Archive pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_append_category]" <?php checked( $this->init_var( $settings, 'placement_append_category', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_append_category]"><?php _e( 'Category pages', parent::$_object->textdomain ); ?></label>
<input type="checkbox" name="3pagination_settings[placement_append_search]" <?php checked( $this->init_var( $settings, 'placement_append_search', FALSE ), 'on' ); ?> />
<label for="3pagination_settings[placement_append_search]"><?php _e( 'Search pages', parent::$_object->textdomain ); ?></label>
<?php
}
/**
* Set CSS class
*
* @since 0.1
*/
public function css_class() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[css_class]" value="<?php echo $this->init_var( $settings, 'css_class', 'classic', TRUE ); ?>" />
<br />
<span class="description"><?php _e( 'Default classes: classic, classic-glow, classic-small', parent::$_object->textdomain ); ?></span>
<?php
}
public function other_maxnumpages() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="text" name="3pagination_settings[other_maxnumpages]" value="<?php echo $this->init_var( $settings, 'other_maxnumpages', '999', TRUE ); ?>" />
<br />
<span class="description"><?php _e( 'Limit to a maximum number of pagelinks', parent::$_object->textdomain ); ?></span>
<?php
}
public function other_pretty() {
$settings = (array) get_option( '3pagination_settings', TRUE );
?>
<input type="checkbox" name="3pagination_settings[other_pretty]" <?php checked( $this->init_var( $settings, 'other_pretty', 'on' ), 'on' ); ?> />
<?php
}
/**
* Validate user input
*
* @TODO add_settings_error()
* @param type $data
* @return type
*
* @since 0.1
*/
public function threepagination_validate( $data ) {
$settings = (array) get_option( '3pagination_settings' );
$settings[ 'labels_show' ] = esc_attr( $data[ 'labels_show' ] );
$settings[ 'labels_previous' ] = esc_attr( $data[ 'labels_previous' ] );
$settings[ 'labels_next' ] = esc_attr( $data[ 'labels_next' ] );
$settings[ 'labels_first' ] = esc_attr( $data[ 'labels_first' ] );
$settings[ 'labels_last' ] = esc_attr( $data[ 'labels_last' ] );
$settings[ 'css_class' ] = esc_attr( $data[ 'css_class' ] );
$settings[ 'placement_header_index' ] = esc_attr( $data[ 'placement_header_index' ] );
$settings[ 'placement_header_archive' ] = esc_attr( $data[ 'placement_header_archive' ] );
$settings[ 'placement_header_search' ] = esc_attr( $data[ 'placement_header_search' ] );
$settings[ 'placement_header_category' ] = esc_attr( $data[ 'placement_header_category' ] );
$settings[ 'placement_footer_index' ] = esc_attr( $data[ 'placement_footer_index' ] );
$settings[ 'placement_footer_archive' ] = esc_attr( $data[ 'placement_footer_archive' ] );
$settings[ 'placement_footer_category' ] = esc_attr( $data[ 'placement_footer_category' ] );
$settings[ 'placement_footer_search' ] = esc_attr( $data[ 'placement_footer_search' ] );
$settings[ 'placement_prepend_id' ] = esc_attr( $data[ 'placement_prepend_id' ] );
$settings[ 'placement_prepend_index' ] = esc_attr( $data[ 'placement_prepend_index' ] );
$settings[ 'placement_prepend_archive' ] = esc_attr( $data[ 'placement_prepend_archive' ] );
$settings[ 'placement_prepend_category' ] = esc_attr( $data[ 'placement_prepend_category' ] );
$settings[ 'placement_prepend_search' ] = esc_attr( $data[ 'placement_prepend_search' ] );
$settings[ 'placement_append_id' ] = esc_attr( $data[ 'placement_append_id' ] );
$settings[ 'placement_append_index' ] = esc_attr( $data[ 'placement_append_index' ] );
$settings[ 'placement_append_archive' ] = esc_attr( $data[ 'placement_append_archive' ] );
$settings[ 'placement_append_search' ] = esc_attr( $data[ 'placement_append_search' ] );
$settings[ 'placement_append_category' ] = esc_attr( $data[ 'placement_append_category' ] );
$settings[ 'other_maxnumpages' ] = intval( $data[ 'other_maxnumpages' ] );
$settings[ 'other_pretty' ] = esc_attr( $data[ 'other_pretty' ] );
return $settings;
}
/**
* Unregister and delete settings; clean database
*
* @uses unregister_setting, delete_option
* @access public
* @since 0.1
* @return void
*/
public function unregister_settings() {
unregister_setting( $this->option_string . '_group', $this->option_string );
delete_option( $this->option_string );
}
}
new threepagination_settings();
}
?>