magic /wp-content/themes/nonus/framework/options/options.php

Language PHP Lines 934
MD5 Hash d830cb6da41896a65f1e86901dc3948d
Repository https://github.com/alniko009/magic.git View Raw File View Project SPDX
  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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
<?php
if (!class_exists('NHP_Options')) {

	// windows-proof constants: replace backward by forward slashes - thanks to: https://github.com/peterbouwmeester
	$fslashed_dir = trailingslashit(str_replace('\\', '/', dirname(__FILE__)));
	$fslashed_abs = trailingslashit(str_replace('\\', '/', ABSPATH));

	if (!defined('NHP_OPTIONS_DIR')) {
		define('NHP_OPTIONS_DIR', $fslashed_dir);
	}

	if (!defined('NHP_OPTIONS_URL')) {
		define('NHP_OPTIONS_URL', site_url(str_replace($fslashed_abs, '', $fslashed_dir)));
	}

	class NHP_Options {

		protected $framework_url = 'http://leemason.github.com/NHP-Theme-Options-Framework/';
		protected $framework_version = '1.0.6';

		public $dir = NHP_OPTIONS_DIR;
		public $url = NHP_OPTIONS_URL;
		public $page = '';
		public $args = array();
		public $sections = array();
		public $extra_tabs = array();
		public $errors = array();
		public $warnings = array();
		public $options = array();


		/**
		 * Class Constructor. Defines the args for the theme options class
		 *
		 * @since NHP_Options 1.0
		 *
		 * @param $array $args Arguments. Class constructor arguments.
		 */
		function __construct($sections = array(), $args = array(), $extra_tabs = array()) {

			$defaults = array();

			$defaults['opt_name'] = ''; //must be defined by theme/plugin

			$defaults['google_api_key'] = ''; //must be defined for use with google webfonts field type

			$defaults['menu_icon'] = NHP_OPTIONS_URL . '/img/menu_icon.png';
			$defaults['menu_title'] = __('Options', 'nhp-opts');
			$defaults['page_icon'] = 'icon-themes';
			$defaults['page_title'] = __('Options', 'nhp-opts');
			$defaults['page_slug'] = '_options';
			$defaults['page_cap'] = 'manage_options';
			$defaults['page_type'] = 'menu';
			$defaults['page_parent'] = '';
			$defaults['page_position'] = 100;
			$defaults['allow_sub_menu'] = true;

			$defaults['show_import_export'] = true;
			$defaults['dev_mode'] = true;
			$defaults['stylesheet_override'] = false;

			$defaults['help_tabs'] = array();
			$defaults['help_sidebar'] = __('', 'nhp-opts');

			//get args
			$this->args = wp_parse_args($args, $defaults);
			$this->args = apply_filters('nhp-opts-args-' . $this->args['opt_name'], $this->args);

			//get sections
			$this->sections = apply_filters('nhp-opts-sections-' . $this->args['opt_name'], $sections);

			//get extra tabs
			$this->extra_tabs = apply_filters('nhp-opts-extra-tabs-' . $this->args['opt_name'], $extra_tabs);

			//set option with defaults
			add_action('init', array(&$this, '_set_default_options'));

			//options page
			add_action('admin_menu', array(&$this, '_options_page'));

			//register setting
			add_action('admin_init', array(&$this, '_register_setting'));

			//add the js for the error handling before the form
			add_action('nhp-opts-page-before-form-' . $this->args['opt_name'], array(&$this, '_errors_js'), 1);

			//add the js for the warning handling before the form
			add_action('nhp-opts-page-before-form-' . $this->args['opt_name'], array(&$this, '_warnings_js'), 2);

			//hook into the wp feeds for downloading the exported settings
			add_action('do_feed_nhpopts-' . $this->args['opt_name'], array(&$this, '_download_options'), 1, 1);

			//get the options for use later on
			$this->options = get_option($this->args['opt_name']);

		}

		//function


		/**
		 * ->get(); This is used to return and option value from the options array
		 *
		 * @since NHP_Options 1.0.1
		 *
		 * @param $array $args Arguments. Class constructor arguments.
		 */
		function get($opt_name, $default = null) {
			return (!empty($this->options[$opt_name])) ? $this->options[$opt_name] : $default;
		}

		//function

		/**
		 * ->set(); This is used to set an arbitrary option in the options array
		 *
		 * @since NHP_Options 1.0.1
		 *
		 * @param string $opt_name the name of the option being added
		 * @param mixed $value the value of the option being added
		 */
		function set($opt_name = '', $value = '') {
			if ($opt_name != '') {
				$this->options[$opt_name] = $value;
				update_option($this->args['opt_name'], $this->options);
			}
			//if
		}

		/**
		 * ->show(); This is used to echo and option value from the options array
		 *
		 * @since NHP_Options 1.0.1
		 *
		 * @param $array $args Arguments. Class constructor arguments.
		 */
		function show($opt_name, $default = '') {
			$option = $this->get($opt_name);
			if (!is_array($option) && $option != '') {
				echo $option;
			} elseif ($default != '') {
				echo $default;
			}
		}

		//function


		/**
		 * Get default options into an array suitable for the settings API
		 *
		 * @since NHP_Options 1.0
		 *
		 */
		function _default_values() {

			$defaults = array();

			foreach ($this->sections as $k => $section) {

				if (isset($section['fields'])) {

					foreach ($section['fields'] as $fieldk => $field) {

						if (!isset($field['std'])) {
							$field['std'] = '';
						}

						$defaults[$field['id']] = $field['std'];

					}
					//foreach

				}
				//if

			}
			//foreach

			//fix for notice on first page load
			$defaults['last_tab'] = 0;

			return $defaults;

		}


		/**
		 * Set default options on admin_init if option doesnt exist (theme activation hook caused problems, so admin_init it is)
		 *
		 * @since NHP_Options 1.0
		 *
		 */
		function _set_default_options() {
			if (!get_option($this->args['opt_name'])) {
				add_option($this->args['opt_name'], $this->_default_values());
			}
			$this->options = get_option($this->args['opt_name']);
		}

		//function


		/**
		 * Class Theme Options Page Function, creates main options page.
		 *
		 * @since NHP_Options 1.0
		 */
		function _options_page() {
			if ($this->args['page_type'] == 'submenu') {
				if (!isset($this->args['page_parent']) || empty($this->args['page_parent'])) {
					$this->args['page_parent'] = 'themes.php';
				}
				$this->page = add_theme_page(
					$this->args['page_title'],
					$this->args['menu_title'],
					$this->args['page_cap'],
					$this->args['page_slug'],
					array(&$this, '_options_page_html')
				);
			}

			add_action('admin_print_styles-' . $this->page, array(&$this, '_enqueue'));
			add_action('load-' . $this->page, array(&$this, '_load_page'));
		}

		//function


		/**
		 * enqueue styles/js for theme page
		 *
		 * @since NHP_Options 1.0
		 */
		function _enqueue() {

			wp_register_style(
				'nhp-opts-css',
					$this->url . 'css/options.css',
				array('farbtastic'),
				time(),
				'all'
			);

			wp_register_style(
				'nhp-opts-jquery-ui-css',
				apply_filters('nhp-opts-ui-theme', $this->url . 'css/jquery-ui-aristo/aristo.css'),
				'',
				time(),
				'all'
			);


			if (false === $this->args['stylesheet_override']) {
				wp_enqueue_style('nhp-opts-css');
			}


			wp_enqueue_script(
				'nhp-opts-js',
					$this->url . 'js/options.js',
				array('jquery'),
				time(),
				true
			);
			wp_localize_script('nhp-opts-js', 'nhp_opts', array('reset_confirm' => __('Are you sure? Resetting will loose all custom values.', 'nhp-opts'), 'opt_name' => $this->args['opt_name']));

			do_action('nhp-opts-enqueue-' . $this->args['opt_name']);


			foreach ($this->sections as $k => $section) {

				if (isset($section['fields'])) {

					foreach ($section['fields'] as $fieldk => $field) {

						if (isset($field['type'])) {

							$field_class = 'NHP_Options_' . $field['type'];

							if (!class_exists($field_class)) {
								require_once($this->dir . 'fields/' . $field['type'] . '/field_' . $field['type'] . '.php');
							}
							//if

							if (class_exists($field_class) && method_exists($field_class, 'enqueue')) {
								$enqueue = new $field_class('', '', $this);
								$enqueue->enqueue();
							}
							//if

						}
						//if type

					}
					//foreach

				}
				//if fields

			}
			//foreach


		}

		//function

		/**
		 * Download the options file, or display it
		 *
		 * @since NHP_Options 1.0.1
		 */
		function _download_options() {
			//-'.$this->args['opt_name']
			if (!isset($_GET['secret']) || $_GET['secret'] != md5(AUTH_KEY . SECURE_AUTH_KEY)) {
				wp_die('Invalid Secret for options use');
				exit;
			}
			if (!isset($_GET['feed'])) {
				wp_die('No Feed Defined');
				exit;
			}
			$backup_options = get_option(str_replace('nhpopts-', '', $_GET['feed']));
			$backup_options['nhp-opts-backup'] = '1';
			$content = '###' . serialize($backup_options) . '###';


			if (isset($_GET['action']) && $_GET['action'] == 'download_options') {
				header('Content-Description: File Transfer');
				header('Content-type: application/txt');
				header('Content-Disposition: attachment; filename="' . str_replace('nhpopts-', '', $_GET['feed']) . '_options_' . date('d-m-Y') . '.txt"');
				header('Content-Transfer-Encoding: binary');
				header('Expires: 0');
				header('Cache-Control: must-revalidate');
				header('Pragma: public');
				echo $content;
				exit;
			} else {
				echo $content;
				exit;
			}
		}


		/**
		 * show page help
		 *
		 * @since NHP_Options 1.0
		 */
		function _load_page() {

			//do admin head action for this page
			add_action('admin_head', array(&$this, 'admin_head'));

			//do admin footer text hook
			add_filter('admin_footer_text', array(&$this, 'admin_footer_text'));

			$screen = get_current_screen();

			if (is_array($this->args['help_tabs'])) {
				foreach ($this->args['help_tabs'] as $tab) {
					$screen->add_help_tab($tab);
				}
				//foreach
			}
			//if

			if ($this->args['help_sidebar'] != '') {
				$screen->set_help_sidebar($this->args['help_sidebar']);
			}
			//if

			do_action('nhp-opts-load-page-' . $this->args['opt_name'], $screen);

		}

		//function


		/**
		 * do action nhp-opts-admin-head for theme options page
		 *
		 * @since NHP_Options 1.0
		 */
		function admin_head() {

			do_action('nhp-opts-admin-head-' . $this->args['opt_name'], $this);

		}

		//function


		function admin_footer_text($footer_text) {
			return $this->args['footer_credit'];
		}

		//function


		/**
		 * Register Option for use
		 *
		 * @since NHP_Options 1.0
		 */
		function _register_setting() {

			register_setting($this->args['opt_name'] . '_group', $this->args['opt_name'], array(&$this, '_validate_options'));

			foreach ($this->sections as $k => $section) {

				add_settings_section($k . '_section', $section['title'], array(&$this, '_section_desc'), $k . '_section_group');

				if (isset($section['fields'])) {

					foreach ($section['fields'] as $fieldk => $field) {

						if (isset($field['title'])) {

							$th = (isset($field['sub_desc'])) ? $field['title'] . '<span class="description">' . $field['sub_desc'] . '</span>' : $field['title'];
						} else {
							$th = '';
						}

						add_settings_field($fieldk . '_field', $th, array(&$this, '_field_input'), $k . '_section_group', $k . '_section', $field); // checkbox

					}
					//foreach

				}
				//if(isset($section['fields'])){

			}
			//foreach

			do_action('nhp-opts-register-settings-' . $this->args['opt_name']);

		}

		//function


		/**
		 * Validate the Options options before insertion
		 *
		 * @since NHP_Options 1.0
		 */
		function _validate_options($plugin_options) {

			set_transient('nhp-opts-saved', '1', 1000);

			if (!empty($plugin_options['import'])) {

				if ($plugin_options['import_code'] != '') {
					$import = $plugin_options['import_code'];
				} elseif ($plugin_options['import_link'] != '') {
					$import = wp_remote_retrieve_body(wp_remote_get($plugin_options['import_link']));
				}

				$imported_options = unserialize(trim($import, '###'));
				if (is_array($imported_options) && isset($imported_options['nhp-opts-backup']) && $imported_options['nhp-opts-backup'] == '1') {
					$imported_options['imported'] = 1;
					return $imported_options;
				}


			}


			if (!empty($plugin_options['defaults'])) {
				$plugin_options = $this->_default_values();
				return $plugin_options;
			}
			//if set defaults


			//validate fields (if needed)
			$plugin_options = $this->_validate_values($plugin_options, $this->options);

			if ($this->errors) {
				set_transient('nhp-opts-errors-' . $this->args['opt_name'], $this->errors, 1000);
			}
			//if errors

			if ($this->warnings) {
				set_transient('nhp-opts-warnings-' . $this->args['opt_name'], $this->warnings, 1000);
			}
			//if errors

			do_action('nhp-opts-options-validate-' . $this->args['opt_name'], $plugin_options, $this->options);


			unset($plugin_options['defaults']);
			unset($plugin_options['import']);
			unset($plugin_options['import_code']);
			unset($plugin_options['import_link']);

			return $plugin_options;

		}

		//function


		/**
		 * Validate values from options form (used in settings api validate function)
		 * calls the custom validation class for the field so authors can override with custom classes
		 *
		 * @since NHP_Options 1.0
		 */
		function _validate_values($plugin_options, $options) {
			foreach ($this->sections as $k => $section) {

				if (isset($section['fields'])) {

					foreach ($section['fields'] as $fieldk => $field) {
						$field['section_id'] = $k;

						if (isset($field['type']) && $field['type'] == 'multi_text') {
							continue;
						} //we cant validate this yet

						if (!isset($plugin_options[$field['id']]) || $plugin_options[$field['id']] == '') {
							continue;
						}

						//force validate of custom filed types

						if (isset($field['type']) && !isset($field['validate'])) {
							if ($field['type'] == 'color' || $field['type'] == 'color_gradient') {
								$field['validate'] = 'color';
							} elseif ($field['type'] == 'date') {
								$field['validate'] = 'date';
							}
						}
						//if

						if (isset($field['validate'])) {
							$validate = 'NHP_Validation_' . $field['validate'];

							if (!class_exists($validate)) {
								require_once($this->dir . 'validation/' . $field['validate'] . '/validation_' . $field['validate'] . '.php');
							}
							//if

							if (class_exists($validate)) {
								$validation = new $validate($field, $plugin_options[$field['id']], $options[$field['id']]);
								$plugin_options[$field['id']] = $validation->value;
								if (isset($validation->error)) {
									$this->errors[] = $validation->error;
								}
								if (isset($validation->warning)) {
									$this->warnings[] = $validation->warning;
								}
								continue;
							}
							//if
						}
						//if


						if (isset($field['validate_callback']) && function_exists($field['validate_callback'])) {

							$callbackvalues = call_user_func($field['validate_callback'], $field, $plugin_options[$field['id']], $options[$field['id']]);
							$plugin_options[$field['id']] = $callbackvalues['value'];
							if (isset($callbackvalues['error'])) {
								$this->errors[] = $callbackvalues['error'];
							}
							//if
							if (isset($callbackvalues['warning'])) {
								$this->warnings[] = $callbackvalues['warning'];
							}
							//if

						}
						//if


					}
					//foreach

				}
				//if(isset($section['fields'])){

			}
			//foreach
			return $plugin_options;
		}

		//function


		/**
		 * HTML OUTPUT.
		 *
		 * @since NHP_Options 1.0
		 */
		function _options_page_html() {

			echo '<div class="wrap">';
			echo '<div id="' . $this->args['page_icon'] . '" class="icon32"><br/></div>';
			echo '<h2 id="nhp-opts-heading">' . get_admin_page_title() . '</h2>';
			echo (isset($this->args['intro_text'])) ? $this->args['intro_text'] : '';

			do_action('nhp-opts-page-before-form-' . $this->args['opt_name']);

			echo '<form method="post" action="options.php" enctype="multipart/form-data" id="nhp-opts-form-wrapper">';
			settings_fields($this->args['opt_name'] . '_group');

			$this->options['last_tab'] = (isset($_GET['tab']) && !get_transient('nhp-opts-saved')) ? $_GET['tab'] : $this->options['last_tab'];

			echo '<input type="hidden" id="last_tab" name="' . $this->args['opt_name'] . '[last_tab]" value="' . $this->options['last_tab'] . '" />';

			echo '<div id="nhp-opts-header">';
			submit_button('', 'primary', '', false);
			submit_button(__('Reset to Defaults', 'nhp-opts'), 'secondary', $this->args['opt_name'] . '[defaults]', false);
			echo '<div class="clear"></div><!--clearfix-->';
			echo '</div>';

			if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-saved') == '1') {
				if (isset($this->options['imported']) && $this->options['imported'] == 1) {
					echo '<div id="nhp-opts-imported">' . apply_filters('nhp-opts-imported-text-' . $this->args['opt_name'], __('<strong>Settings Imported!</strong>', 'nhp-opts')) . '</div>';
				} else {
					echo '<div id="nhp-opts-save">' . apply_filters('nhp-opts-saved-text-' . $this->args['opt_name'], __('<strong>Settings Saved!</strong>', 'nhp-opts')) . '</div>';
				}
				delete_transient('nhp-opts-saved');
			}
			echo '<div id="nhp-opts-save-warn">' . apply_filters('nhp-opts-changed-text-' . $this->args['opt_name'], __('<strong>Settings have changed!, you should save them!</strong>', 'nhp-opts')) . '</div>';
			echo '<div id="nhp-opts-field-errors">' . __('<strong><span></span> error(s) were found!</strong>', 'nhp-opts') . '</div>';

			echo '<div id="nhp-opts-field-warnings">' . __('<strong><span></span> warning(s) were found!</strong>', 'nhp-opts') . '</div>';

			echo '<div class="clear"></div><!--clearfix-->';

			echo '<div id="nhp-opts-sidebar">';
			echo '<ul id="nhp-opts-group-menu">';
			foreach ($this->sections as $k => $section) {
				$icon = (!isset($section['icon'])) ? '<img src="' . $this->url . 'img/glyphicons/glyphicons_019_cogwheel.png" /> ' : '<img src="' . $section['icon'] . '" /> ';
				echo '<li id="' . $k . '_section_group_li" class="nhp-opts-group-tab-link-li">';
				echo '<a href="javascript:void(0);" id="' . $k . '_section_group_li_a" class="nhp-opts-group-tab-link-a" data-rel="' . $k . '">' . $icon . '<span>' . $section['title'] . '</span></a>';
				echo '</li>';
			}

			echo '<li class="divide">&nbsp;</li>';

			do_action('nhp-opts-after-section-menu-items-' . $this->args['opt_name'], $this);

			if (true === $this->args['show_import_export']) {
				echo '<li id="import_export_default_section_group_li" class="nhp-opts-group-tab-link-li">';
				echo '<a href="javascript:void(0);" id="import_export_default_section_group_li_a" class="nhp-opts-group-tab-link-a" data-rel="import_export_default"><img src="' . $this->url . 'img/glyphicons/glyphicons_082_roundabout.png" /> <span>' . __('Import / Export', 'nhp-opts') . '</span></a>';
				echo '</li>';
				echo '<li class="divide">&nbsp;</li>';
			}
			//if


			foreach ($this->extra_tabs as $k => $tab) {
				$icon = (!isset($tab['icon'])) ? '<img src="' . $this->url . 'img/glyphicons/glyphicons_019_cogwheel.png" /> ' : '<img src="' . $tab['icon'] . '" /> ';
				echo '<li id="' . $k . '_section_group_li" class="nhp-opts-group-tab-link-li">';
				echo '<a href="javascript:void(0);" id="' . $k . '_section_group_li_a" class="nhp-opts-group-tab-link-a custom-tab" data-rel="' . $k . '">' . $icon . '<span>' . $tab['title'] . '</span></a>';
				echo '</li>';
			}


			if (true === $this->args['dev_mode']) {
				echo '<li id="dev_mode_default_section_group_li" class="nhp-opts-group-tab-link-li">';
				echo '<a href="javascript:void(0);" id="dev_mode_default_section_group_li_a" class="nhp-opts-group-tab-link-a custom-tab" data-rel="dev_mode_default"><img src="' . $this->url . 'img/glyphicons/glyphicons_195_circle_info.png" /> <span>' . __('Dev Mode Info', 'nhp-opts') . '</span></a>';
				echo '</li>';
			}
			//if

			echo '</ul>';
			echo '</div>';

			echo '<div id="nhp-opts-main">';

			foreach ($this->sections as $k => $section) {
				echo '<div id="' . $k . '_section_group' . '" class="nhp-opts-group-tab">';
				do_settings_sections($k . '_section_group');
				echo '</div>';
			}


			if (true === $this->args['show_import_export']) {
				echo '<div id="import_export_default_section_group' . '" class="nhp-opts-group-tab">';
				echo '<h3>' . __('Import / Export Options', 'nhp-opts') . '</h3>';

				echo '<h4>' . __('Import Options', 'nhp-opts') . '</h4>';

				echo '<p><a href="javascript:void(0);" id="nhp-opts-import-code-button" class="button-secondary">Import from file</a> <a href="javascript:void(0);" id="nhp-opts-import-link-button" class="button-secondary">Import from URL</a></p>';

				echo '<div id="nhp-opts-import-code-wrapper">';

				echo '<div class="nhp-opts-section-desc">';

				echo '<p class="description" id="import-code-description">' . apply_filters('nhp-opts-import-file-description', __('Input your backup file below and hit Import to restore your sites options from a backup.', 'nhp-opts')) . '</p>';

				echo '</div>';

				echo '<textarea id="import-code-value" name="' . $this->args['opt_name'] . '[import_code]" class="large-text" rows="8"></textarea>';

				echo '</div>';


				echo '<div id="nhp-opts-import-link-wrapper">';

				echo '<div class="nhp-opts-section-desc">';

				echo '<p class="description" id="import-link-description">' . apply_filters('nhp-opts-import-link-description', __('Input the URL to another sites options set and hit Import to load the options from that site.', 'nhp-opts')) . '</p>';

				echo '</div>';

				echo '<input type="text" id="import-link-value" name="' . $this->args['opt_name'] . '[import_link]" class="large-text" value="" />';

				echo '</div>';


				echo '<p id="nhp-opts-import-action"><input type="submit" id="nhp-opts-import" name="' . $this->args['opt_name'] . '[import]" class="button-primary" value="' . __('Import', 'nhp-opts') . '"> <span>' . apply_filters('nhp-opts-import-warning', __('WARNING! This will overwrite any existing options, please proceed with caution!', 'nhp-opts')) . '</span></p>';
				echo '<div id="import_divide"></div>';

				echo '<h4>' . __('Export Options', 'nhp-opts') . '</h4>';
				echo '<div class="nhp-opts-section-desc">';
				echo '<p class="description">' . apply_filters('nhp-opts-backup-description', __('Here you can copy/download your themes current option settings. Keep this safe as you can use it as a backup should anything go wrong. Or you can use it to restore your settings on this site (or any other site). You also have the handy option to copy the link to yours sites settings. Which you can then use to duplicate on another site', 'nhp-opts')) . '</p>';
				echo '</div>';

				echo '<p><a href="javascript:void(0);" id="nhp-opts-export-code-copy" class="button-secondary">Copy</a> <a href="' . add_query_arg(array('feed' => 'nhpopts-' . $this->args['opt_name'], 'action' => 'download_options', 'secret' => md5(AUTH_KEY . SECURE_AUTH_KEY)), site_url()) . '" id="nhp-opts-export-code-dl" class="button-primary">Download</a> <a href="javascript:void(0);" id="nhp-opts-export-link" class="button-secondary">Copy Link</a></p>';
				$backup_options = $this->options;
				$backup_options['nhp-opts-backup'] = '1';
				$encoded_options = '###' . serialize($backup_options) . '###';
				echo '<textarea class="large-text" id="nhp-opts-export-code" rows="8">';
				print_r($encoded_options);
				echo '</textarea>';
				echo '<input type="text" class="large-text" id="nhp-opts-export-link-value" value="' . add_query_arg(array('feed' => 'nhpopts-' . $this->args['opt_name'], 'secret' => md5(AUTH_KEY . SECURE_AUTH_KEY)), site_url()) . '" />';

				echo '</div>';
			}


			foreach ($this->extra_tabs as $k => $tab) {
				echo '<div id="' . $k . '_section_group' . '" class="nhp-opts-group-tab">';
				echo '<h3>' . $tab['title'] . '</h3>';
				echo $tab['content'];
				echo '</div>';
			}


			if (true === $this->args['dev_mode']) {
				echo '<div id="dev_mode_default_section_group' . '" class="nhp-opts-group-tab">';
				echo '<h3>' . __('Dev Mode Info', 'nhp-opts') . '</h3>';
				echo '<div class="nhp-opts-section-desc">';
				echo '<textarea class="large-text" rows="24">' . print_r($this, true) . '</textarea>';
				echo '</div>';
				echo '</div>';
			}


			do_action('nhp-opts-after-section-items-' . $this->args['opt_name'], $this);

			echo '<div class="clear"></div><!--clearfix-->';
			echo '</div>';
			echo '<div class="clear"></div><!--clearfix-->';

			echo '<div id="nhp-opts-footer">';

			if (isset($this->args['share_icons'])) {
				echo '<div id="nhp-opts-share">';
				foreach ($this->args['share_icons'] as $link) {
					echo '<a href="' . $link['link'] . '" title="' . $link['title'] . '" target="_blank"><img src="' . $link['img'] . '"/></a>';
				}
				echo '</div>';
			}

			submit_button('', 'primary', '', false);
			submit_button(__('Reset to Defaults', 'nhp-opts'), 'secondary', $this->args['opt_name'] . '[defaults]', false);
			echo '<div class="clear"></div><!--clearfix-->';
			echo '</div>';

			echo '</form>';

			do_action('nhp-opts-page-after-form-' . $this->args['opt_name']);

			echo '<div class="clear"></div><!--clearfix-->';
			echo '</div><!--wrap-->';

		}

		//function


		/**
		 * JS to display the errors on the page
		 *
		 * @since NHP_Options 1.0
		 */
		function _errors_js() {

			if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-errors-' . $this->args['opt_name'])) {
				$errors = get_transient('nhp-opts-errors-' . $this->args['opt_name']);
				$section_errors = array();
				foreach ($errors as $error) {
					$section_errors[$error['section_id']] = (isset($section_errors[$error['section_id']])) ? $section_errors[$error['section_id']] : 0;
					$section_errors[$error['section_id']]++;
				}


				echo '<script type="text/javascript">';
				echo 'jQuery(document).ready(function(){';
				echo 'jQuery("#nhp-opts-field-errors span").html("' . count($errors) . '");';
				echo 'jQuery("#nhp-opts-field-errors").show();';

				foreach ($section_errors as $sectionkey => $section_error) {
					echo 'jQuery("#' . $sectionkey . '_section_group_li_a").append("<span class=\"nhp-opts-menu-error\">' . $section_error . '</span>");';
				}

				foreach ($errors as $error) {
					echo 'jQuery("#' . $error['id'] . '").addClass("nhp-opts-field-error");';
					echo 'jQuery("#' . $error['id'] . '").closest("td").append("<span class=\"nhp-opts-th-error\">' . $error['msg'] . '</span>");';
				}
				echo '});';
				echo '</script>';
				delete_transient('nhp-opts-errors-' . $this->args['opt_name']);
			}

		}

		//function


		/**
		 * JS to display the warnings on the page
		 *
		 * @since NHP_Options 1.0.3
		 */
		function _warnings_js() {

			if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && get_transient('nhp-opts-warnings-' . $this->args['opt_name'])) {
				$warnings = get_transient('nhp-opts-warnings-' . $this->args['opt_name']);
				$section_warnings = array();
				foreach ($warnings as $warning) {
					$section_warnings[$warning['section_id']] = (isset($section_warnings[$warning['section_id']])) ? $section_warnings[$warning['section_id']] : 0;
					$section_warnings[$warning['section_id']]++;
				}


				echo '<script type="text/javascript">';
				echo 'jQuery(document).ready(function(){';
				echo 'jQuery("#nhp-opts-field-warnings span").html("' . count($warnings) . '");';
				echo 'jQuery("#nhp-opts-field-warnings").show();';

				foreach ($section_warnings as $sectionkey => $section_warning) {
					echo 'jQuery("#' . $sectionkey . '_section_group_li_a").append("<span class=\"nhp-opts-menu-warning\">' . $section_warning . '</span>");';
				}

				foreach ($warnings as $warning) {
					echo 'jQuery("#' . $warning['id'] . '").addClass("nhp-opts-field-warning");';
					echo 'jQuery("#' . $warning['id'] . '").closest("td").append("<span class=\"nhp-opts-th-warning\">' . $warning['msg'] . '</span>");';
				}
				echo '});';
				echo '</script>';
				delete_transient('nhp-opts-warnings-' . $this->args['opt_name']);
			}

		}

		//function


		/**
		 * Section HTML OUTPUT.
		 *
		 * @since NHP_Options 1.0
		 */
		function _section_desc($section) {

			$id = rtrim($section['id'], '_section');

			if (isset($this->sections[$id]['desc']) && !empty($this->sections[$id]['desc'])) {
				echo '<div class="nhp-opts-section-desc">' . $this->sections[$id]['desc'] . '</div>';
			}

		}

		//function


		/**
		 * Field HTML OUTPUT.
		 *
		 * Gets option from options array, then calls the speicfic field type class - allows extending by other devs
		 *
		 * @since NHP_Options 1.0
		 */
		function _field_input($field) {


			if (isset($field['callback']) && function_exists($field['callback'])) {
				$value = (isset($this->options[$field['id']])) ? $this->options[$field['id']] : '';
				do_action('nhp-opts-before-field-' . $this->args['opt_name'], $field, $value);
				call_user_func($field['callback'], $field, $value);
				do_action('nhp-opts-after-field-' . $this->args['opt_name'], $field, $value);
				return;
			}

			if (isset($field['type'])) {

				$field_class = 'NHP_Options_' . $field['type'];

				if (class_exists($field_class)) {
					require_once($this->dir . 'fields/' . $field['type'] . '/field_' . $field['type'] . '.php');
				}
				//if

				if (class_exists($field_class)) {
					$value = (isset($this->options[$field['id']])) ? $this->options[$field['id']] : '';
					do_action('nhp-opts-before-field-' . $this->args['opt_name'], $field, $value);
					$render = '';
					$render = new $field_class($field, $value, $this);
					$render->render();
					do_action('nhp-opts-after-field-' . $this->args['opt_name'], $field, $value);
				}
				//if

			}
			//if $field['type']

		}
		//function


	}
	//class
}//if
?>
Back to Top