-
Notifications
You must be signed in to change notification settings - Fork 44
/
admin-page-class.php
3621 lines (3279 loc) · 121 KB
/
admin-page-class.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
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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Admin Page Class
*
* The Admin Page Class is used by including it in your plugin files and using its methods to
* create custom Admin Pages. It is meant to be very simple and
* straightforward.
*
* This class is derived from My-Meta-Box (https://github.com/bainternet/My-Meta-Box script) which is
* a class for creating custom meta boxes for WordPress.
*
*
* @version 1.3.0
* @copyright 2012 - 2014
* @author Ohad Raz (email: admin@bainternet.info)
* @link http://en.bainternet.info
*
* @license GNU General Public LIcense v3.0 - license.txt
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package Admin Page Class
*
* @Last Revised
*/
if ( ! class_exists( 'BF_Admin_Page_Class') ) :
/**
* Admin Page Class
*
* @package Admin Page Class
* @since 0.1
*
* @todo Nothing.
*/
class BF_Admin_Page_Class {
/**
* Contains all saved data for a page
*
* @access protected
* @var array
* @since 0.1
*/
protected $_saved;
/**
* Contains all arguments needed to build the page itself
*
* @access protected
* @var array
* @since 0.1
*/
protected $args;
/**
* Contains Options group name
* @access protected
* @var array
* @since 0.1
*/
protected $option_group;
/**
* Contains all the information needed to build the form structure of the page
*
* @access public
* @var array
* @since 0.1
*/
public $_fields;
/**
* True if the table is opened, false if it is not opened
*
* @access protected
* @var boolean
* @since 0.1
*/
protected $table = false;
/**
* True if the tab div is opened, false if it is not opened
*
* @access protected
* @var boolean
* @since 0.1
*/
protected $tab_div = false;
/**
* Contains the menu_slug for the current TopLeve-Menu
*
* @access public
* @var string
* @since 0.1
*/
public $Top_Slug;
/**
* Contains the menu_slug for the current page
*
* @access public
* @var string
* @since 0.1
*/
public $_Slug;
/**
* Contains all the information needed to build the Help tabs
*
* @access public
* @var array
* @since 0.1
*/
public $_help_tabs;
/**
* Use html table row or div for each field, true for row, false for div
*
* @access public
* @var boolean
* @since 0.1
*/
public $_div_or_row;
/**
* saved flag
* @var boolean
* @since 0.6
*/
public $saved_flag = false;
/**
* use google fonts for typo filed?
* @var boolean
* @since 0.9.9
* @access public
*/
public $google_fonts = false;
/**
* Holds used field types
* @var boolean
* @since 1.1.3
* @access public
*/
public $field_types = array();
/**
* Holds validation Errors
* @var boolean
* @since 1.1.9
* @access public
*/
public $errors = array();
/**
* Holds Errors flag
* @var boolean
* @since 1.1.9
* @access public
*/
public $errors_flag = false;
/**
* data_type holds type of data (options, post_meta, tax_meta, user_meta)
* @var string
* @since
*/
public $data_type = 'options';
/**
* Builds a new Page
* @param $args (string|mixed array) -
*
* Possible keys within $args:
* > menu (array|string) - (string) -> this the name of the parent Top-Level-Menu or a TopPage object to create
* this page as a sub menu to.
* (array) -> top - Slug for the New Top level Menu page to create.
* > page_title (string) - The name of this page (good for Top level and sub menu pages)
* > capability (string) (optional) - The capability needed to view the page (good for Top level and sub menu pages)
* > menu_title (string) - The name of the Top-Level-Menu (Top level Only)
* > menu_slug (string) - A unique string identifying your new menu (Top level Only)
* > icon_url (string) (optional) - URL to the icon, decorating the Top-Level-Menu (Top level Only)
* > position (string) (optional) - The position of the Menu in the ACP (Top level Only)
* > option_group (string) (required) - the name of the option to create in the database
*
*
*/
public function __construct($args) {
if(is_array($args)) {
if (isset($args['option_group'])){
$this->option_group = $args['option_group'];
}
$this->args = $args;
} else {
$array['page_title'] = $args;
$this->args = $array;
}
//add hooks for export download
add_action('template_redirect',array($this, 'admin_redirect_download_files'));
add_filter('init', array($this,'add_query_var_vars'));
// If we are not in admin area exit.
if ( ! is_admin() )
return;
//load translation
$this->load_textdomain();
//set defaults
$this->_div_or_row = true;
$this->saved = false;
//store args
$this->args = $args;
//google_fonts
$this->google_fonts = isset($args['google_fonts'])? true : false;
//sub $menu
if(!is_array($args['menu'])) {
if(is_object($args['menu'])) {
$this->Top_Slug = $args['menu']->Top_Slug;
}else{
switch($args['menu']) {
case 'posts':
$this->Top_Slug = 'edit.php';
break;
case 'dashboard':
$this->Top_Slug = 'index.php';
break;
case 'media':
$this->Top_Slug = 'upload.php';
break;
case 'links':
$this->Top_Slug = 'link-manager.php';
break;
case 'pages':
$this->Top_Slug = 'edit.php?post_type=page';
break;
case 'comments':
$this->Top_Slug = 'edit-comments.php';
break;
case 'theme':
$this->Top_Slug = 'themes.php';
break;
case 'plugins':
$this->Top_Slug = 'plugins.php';
break;
case 'users':
$this->Top_Slug = 'users.php';
break;
case 'tools':
$this->Top_Slug = 'tools.php';
break;
case 'settings':
$this->Top_Slug = 'options-general.php';
break;
default:
if(post_type_exists($args['menu'])) {
$this->Top_Slug = 'edit.php?post_type='.$args['menu'];
} else {
$this->Top_Slug = $args['menu'];
}
}
}
add_action('admin_menu', array($this, 'AddMenuSubPage'));
}else{
//top page
$this->Top_Slug = $args['menu']['top'];
add_action('admin_menu', array($this, 'AddMenuTopPage'));
}
// Assign page values to local variables and add it's missed values.
$this->_Page_Config = $args;
$this->_fields = $this->_Page_Config['fields'];
$this->_Local_images = (isset($args['local_images'])) ? true : false;
$this->_div_or_row = (isset($args['div_or_row'])) ? $args['div_or_row'] : false;
$this->add_missed_values();
if (isset($args['use_with_theme'])){
if ($args['use_with_theme'] === true){
$this->SelfPath = get_stylesheet_directory_uri() . '/admin-page-class';
}elseif($args['use_with_theme'] === false){
$this->SelfPath = plugins_url( 'admin-page-class', plugin_basename( dirname( __FILE__ ) ) );
}else{
$this->SelfPath = $args['use_with_theme'];
}
}else{
$this->SelfPath = plugins_url( 'admin-page-class', plugin_basename( dirname( __FILE__ ) ) );
}
// Load common js, css files
// Must enqueue for all pages as we need js for the media upload, too.
//add_action('admin_head', array($this, 'loadScripts'));
add_filter('attribute_escape',array($this,'edit_insert_to_post_text'),10,2);
// Delete file via Ajax
add_action( 'wp_ajax_apc_delete_mupload', array( $this, 'wp_ajax_delete_image' ) );
//import export
add_action( 'wp_ajax_apc_import_'.$this->option_group, array( $this, 'import' ) );
add_action( 'wp_ajax_apc_export_'.$this->option_group, array( $this, 'export' ) );
//plupload ajax
add_action('wp_ajax_plupload_action', array( $this,"Handle_plupload_action"));
}
/**
* Does all the complicated stuff to build the menu and its first page
*
* @since 0.1
* @access public
*/
public function AddMenuTopPage() {
$default = array(
'capability' => 'edit_themes',
'menu_title' => '',
'id' => 'id',
'icon_url' => '',
'position' => null
);
$this->args = array_merge($default, $this->args);
$id = add_menu_page($this->args['page_title'], $this->args['page_title'], $this->args['capability'], $this->args['id'], array($this, 'DisplayPage'), $this->args['icon_url'], $this->args['position']);
$page = add_submenu_page($id, $this->args['page_title'], $this->args['page_title'], $this->args['capability'], $this->args['id'], array($this, 'DisplayPage'));
if ($page){
$this->_Slug = $page;
// Adds my_help_tab when my_admin_page loads
add_action('load-'.$page, array($this,'Load_page_hooker'));
}
}
/**
* Does all the complicated stuff to build the page
*
* @since 0.1
* @access public
*/
public function AddMenuSubPage() {
$default = array(
'capability' => 'edit_themes',
);
$this->args = array_merge($default, $this->args);
$page = add_submenu_page($this->Top_Slug, $this->args['page_title'], $this->args['page_title'], $this->args['capability'], $this->createSlug(), array($this, 'DisplayPage'));
if ($page){
$this->_Slug = $page;
add_action('load-'.$page, array($this,'Load_page_hooker'));
}
}
/**
* loads scripts and styles for the page
*
* @author ohad raz
* @since 0.1
* @access public
*/
public function Load_page_hooker(){
$page = $this->_Slug;
//help tabs
add_action('admin_head-'.$page, array($this,'admin_add_help_tab'));
//pluploader code
add_action('admin_head-'.$page, array($this,'plupload_head_js'));
//scripts and styles
add_action( 'admin_print_styles', array( $this, 'load_scripts_styles' ) );
//panel script
add_action('admin_footer-' . $page, array($this,'panel_script'));
//add mising scripts
//add_action('admin_enqueue_scripts',array($this,'Finish'));
if(isset($_POST['action']) && $_POST['action'] == 'save') {
do_action('WP_EX_before_save',$this);
$this->save();
$this->saved_flag = true;
do_action('WP_EX_after_save',$this);
}
}
public function plupload_head_js(){
if ($this->has_field('plupload')){
$plupload_init = array(
'runtimes' => 'html5,silverlight,flash,html4',
'browse_button' => 'plupload-browse-button', // will be adjusted per uploader
'container' => 'plupload-upload-ui', // will be adjusted per uploader
'drop_element' => 'drag-drop-area', // will be adjusted per uploader
'file_data_name' => 'async-upload', // will be adjusted per uploader
'multiple_queues' => true,
'max_file_size' => wp_max_upload_size() . 'b',
'url' => admin_url('admin-ajax.php'),
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
'filters' => array(array('title' => __('Allowed Files','apc'), 'extensions' => '*')),
'multipart' => true,
'urlstream_upload' => true,
'multi_selection' => false, // will be added per uploader
// additional post data to send to our ajax hook
'multipart_params' => array(
'_ajax_nonce' => "", // will be added per uploader
'action' => 'plupload_action', // the ajax action name
'imgid' => 0 // will be added per uploader
)
);
echo '<script type="text/javascript">'."\n".'var base_plupload_config=';
echo json_encode($plupload_init)."\n".'</script>';
}
}
/**
* Creates an unique slug out of the page_title and the current menu_slug
*
* @since 0.1
* @access private
*/
private function createSlug() {
$slug = $this->args['page_title'];
$slug = strtolower($slug);
$slug = str_replace(' ','_',$slug);
return $this->Top_Slug.'_'.$slug;
}
/** add Help Tab
*
* @since 0.1
* @access public
* @param $args (mixed|array) contains everything needed to build the field
*
* Possible keys within $args:
* > id (string) (required)- Tab ID. Must be HTML-safe and should be unique for this menu
* > title (string) (required)- Title for the tab.
* > content (string) (required)- Help tab content in plain text or HTML.
*
*
* Will only work on wordpres version 3.3 and up
*/
public function HelpTab($args){
$this->_help_tabs[] = $args;
}
/* print Help Tabs for current screen
*
* @access public
* @since 0.1
* @author Ohad
*
* Will only work on wordpres version 3.3 and up
*/
public function admin_add_help_tab(){
$screen = get_current_screen();
/*
* Check if current screen is My Admin Page
* Don't add help tab if it's not
*/
if ( $screen->id != $this->_Slug )
return;
// Add help_tabs for current screen
foreach((array)$this->_help_tabs as $tab){
$screen->add_help_tab($tab);
}
}
/* print out panel Script
*
* @access public
* @since 0.1
*/
public function panel_script(){
?>
<script>
/* cookie stuff */
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {setCookie(name,"",-1);}
var last_tab = getCookie("apc_<?php echo $this->option_group; ?>last");
if (last_tab) {
var last_tab = last_tab;
}else{
var last_tab = null;
}
jQuery(document).ready(function() {
function show_tab(li){
if (!jQuery(li).hasClass("active_tab")){
//hide all
jQuery(".setingstab").hide("slow");
jQuery(".panel_menu li").removeClass("active_tab");
tab = jQuery(li).find("a").attr("href");
jQuery(li).addClass("active_tab");
jQuery(tab).show("fast");
setCookie("apc_<?php echo $this->option_group; ?>last",tab);
}
}
//hide all
jQuery(".setingstab").hide();
//set first_tab as active if no cookie found
if (last_tab == null){
jQuery(".panel_menu li:first").addClass("active_tab");
var tab = jQuery(".panel_menu li:first a").attr("href");
jQuery(tab).show();
}else{
show_tab(jQuery('[href="' + last_tab + '"]').parent());
}
//bind click on menu action to show the right tab.
jQuery(".panel_menu li").bind("click", function(event){
event.preventDefault()
show_tab(jQuery(this));
});
<?php
if ($this->has_Field('upload')){
?>
function load_images_muploader(){
jQuery(".mupload_img_holder").each(function(i,v){
if (jQuery(this).next().next().val() != ""){
jQuery(this).append('<img src="' + jQuery(this).next().next().val() + '" style="height: 150px;width: 150px;" />');
jQuery(this).next().next().next().val("Delete");
jQuery(this).next().next().next().removeClass("apc_upload_image_button").addClass("apc_delete_image_button");
}
});
}
//upload button
var formfield1;
var formfield2;
jQuery("#image_button").click(function(e){
if(jQuery(this).hasClass("apc_upload_image_button")){
formfield1 = jQuery(this).prev();
formfield2 = jQuery(this).prev().prev();
tb_show("", "media-upload.php?type=image&apc=insert_file&TB_iframe=true");
return false;
}else{
var field_id = jQuery(this).attr("rel");
var at_id = jQuery(this).prev().prev();
var at_src = jQuery(this).prev();
var t_button = jQuery(this);
data = {
action: "apc_delete_mupload",
_wpnonce: $("#nonce-delete-mupload_" + field_id).val(),
field_id: field_id,
attachment_id: jQuery(at_id).val()
};
$.post(ajaxurl, data, function(response) {
if ("success" == response.status){
jQuery(t_button).val("Upload Image");
jQuery(t_button).removeClass("apc_delete_image_button").addClass("apc_upload_image_button");
//clear html values
jQuery(at_id).val("");
jQuery(at_src).val("");
jQuery(at_id).prev().html("");
load_images_muploader();
}else{
alert(response.message);
}
}, "json");
return false;
}
});
//store old send to editor function
window.restore_send_to_editor = window.send_to_editor;
//overwrite send to editor function
window.send_to_editor = function(html) {
imgurl = jQuery("img",html).attr("src");
img_calsses = jQuery("img",html).attr("class").split(" ");
att_id = "";
jQuery.each(img_calsses,function(i,val){
if (val.indexOf("wp-image") != -1){
att_id = val.replace("wp-image-", "");
}
});
jQuery(formfield2).val(att_id);
jQuery(formfield1).val(imgurl);
load_images_muploader();
tb_remove();
//restore old send to editor function
window.send_to_editor = window.restore_send_to_editor;
}
<?php
}
?>
});
</script>
<?php
}
//rename insert to post button
/**
* edit_insert_to_post_text
*
* @author ohad raz
* @since 0.1
* @param string $input insert to post text
* @return string
*/
public function edit_insert_to_post_text( $safe_text, $text ) {
if( is_admin() && 'Insert into Post' == $safe_text){
if (isset($_REQUEST['apc']) && 'insert_file' == $_REQUEST['apc'] )
return str_replace(__('Insert into Post'), __('Use this File','apc'), $safe_text);
else
return str_replace(__('Insert into Post'), __('Use this Image','apc'), $safe_text);
}
return $safe_text;
}
/* print out panel Style (deprecated)
*
* @access public
* @since 0.1
*/
public function panel_style(){
//echo '<style></style>';
}
/**
* Outputs all the HTML needed for the new page
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*/
public function DisplayPage() {
do_action('admin_page_class_before_page');
echo '<div class="wrap">'."\n";
echo '<form method="post" name="'.apply_filters('apc_form_name', 'admin_page_class',$this).'" class="'.apply_filters('apc_form_class', 'admin_page_class',$this).'" id="'.apply_filters('apc_form_id', 'admin_page_class',$this).'" action="" enctype="multipart/form-data">
'."\n".'<div class="header_wrap">'."\n".'
<div style="float:left">'."\n";
echo apply_filters('admin_page_class_before_title','');
echo '<h2>'.apply_filters('admin_page_class_h2',$this->args['page_title']).'</h2>'."\n".((isset($this->args['page_header_text']))? $this->args['page_header_text'] : '').'
</div>'."\n".'
<div style="float:right;margin:32px 0 0 0">'."\n".'
<input type="submit" style="margin-left: 25px;" value="'.esc_attr(__('Save Changes','apc')).'" name="Submit" class="'.apply_filters('admin_page_class_submit_class', 'btn-info').' btn"><br><br>
</div>'."\n".'
<br style="clear:both"><br>
</div>'."\n";
wp_nonce_field( basename(__FILE__), 'BF_Admin_Page_Class_nonce' );
if ($this->saved_flag){
echo '<div class="update-status">'."\n";
$this->errors = apply_filters('admin_page_class_errors', $this->errors,$this);
if (is_array($this->errors) && count($this->errors) > 0 ){
$this->errors_flag = true;
$this->displayErrors();
}else{
echo '<div class="alert alert-success"><button data-dismiss="alert" class="close" type="button">×</button><strong>'.__('Settings saved.','apc').'</strong></div>'."\n";
}
echo '</div>'."\n";
}
$saved = get_option($this->option_group);
$this->_saved = $saved;
$skip = array('title','paragraph','subtitle','TABS','CloseDiv','TABS_Listing','OpenTab','custom','import_export');
foreach($this->_fields as $field) {
if (!in_array($field['type'],$skip)){
if(!$this->table) {
if ($this->_div_or_row){
echo '<table class="form-table">'."\n";
$this->table = true;
}else{
echo '<div class="form-table">'."\n";
$this->table = true;
}
}
}else{
if($this->table) {
if ($this->_div_or_row){echo '</table>'."\n";}else{echo '</div>'."\n";}
$this->table = false;
}
}
$data = '';
if(!$this->saved_flag && $saved === false)
$data = isset($field['std'])? $field['std'] : '';
if (isset($saved[$field['id']]))
$data = $saved[$field['id']];
if (method_exists($this,'show_field_' . $field['type'])){
if ($this->_div_or_row){echo '<td>'."\n";}else{echo apply_filters('admin_page_class_field_container_open','<div class="field">'."\n",$field);}
call_user_func ( array( $this, 'show_field_' . $field['type'] ), $field, $data );
if ($this->_div_or_row){echo '</td>'."\n";}else{echo apply_filters('admin_page_class_field_container_close','</div>'."\n",$field);}
}else{
switch($field['type']) {
case 'TABS':
echo '<div id="tabs">'."\n";
break;
case 'CloseDiv':
$this->tab_div = false;
echo '</div>'."\n";
break;
case 'TABS_Listing':
echo '<div class="panel_menu">'."\n".'<ul>'."\n";
foreach($field['links'] as $id => $name){
$extra_classes = strtolower(str_replace(' ','-',$name)).' '.strtolower(str_replace(' ','-',$id));
echo '<li class="'.apply_filters('APC_tab_li_extra_class',$extra_classes).'">'."\n\t".'<a class="nav_tab_link" href="#'.$id.'">'.$name.'</a>'."\n".'</li>'."\n";
}
echo '</ul>'."\n".'</div>'."\n".'<div class="sections">'."\n";
break;
case 'OpenTab':
$this->tab_div = true;
echo '<div class="setingstab" id="'.$field['id'].'">'."\n";
do_action('admin_page_class_after_tab_open');
break;
case 'title':
echo '<h2>'.$field['label'].'</h2>'."\n";
break;
case 'subtitle':
echo '<h3>'.$field['label'].'</h3>'."\n";
break;
case 'paragraph':
echo '<p>'.$field['text'].'</p>'."\n";
break;
case 'repeater':
do_action('admin_page_class_before_repeater');
$this->output_repeater_fields($field,$data);
do_action('admin_page_class_after_repeater');
break;
case 'import_export':
$this->show_import_export();
do_action('admin_page_class_import_export_tab');
break;
}
}
if (!in_array($field['type'],$skip)){ echo '</tr>'."\n";}
}
if($this->table) echo '</table>'."\n";
if($this->tab_div) echo '</div>'."\n";
echo '</div>'."\n".'<div style="clear:both"></div>'."\n".'<div class="footer_wrap">'."\n".'
<div style="float:right;margin:32px 0 0 0">'."\n".'
<input type="submit" style="margin-left: 25px;" name="Submit" class="'.apply_filters('admin_page_class_submit_class', 'btn-info').' btn" value="'.esc_attr(__('Save Changes','apc')).'" />'."\n".'
<br><br>
</div>'."\n".'
<br style="clear:both"><br>
</div>'."\n";
echo '<input type="hidden" name="action" value="save" />'."\n";
echo '</form>'."\n".'</div>'."\n".'</div>'."\n";
do_action('admin_page_class_after_page');
}
/**
* Adds tabs current page
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @since 0.1
*/
public function OpenTabs_container($text= null) {
$args['type'] = 'TABS';
$text = (null == $text)? '': $text;
$args['text'] = $text;
$args['id'] = 'TABS';
$args['std'] = '';
$this->SetField($args);
}
/**
* Close open Div
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*/
public function CloseDiv_Container() {
$args['type'] = 'CloseDiv';
$args['id'] = 'CloseDiv';
$args['std'] = '';
$this->SetField($args);
}
/**
* Adds tabs listing in ul li
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*/
public function TabsListing($args) {
$args['type'] = 'TABS_Listing';
$args['id'] = 'TABS_Listing';
$args['std'] = '';
$this->SetField($args);
}
/**
* Opens a Div
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*/
public function OpenTab($name) {
$args['type'] = 'OpenTab';
$args['id'] = $name;
$args['std'] = '';
$this->SetField($args);
}
/**
* close a Div
*
* @access public
* @since 0.1
*/
public function CloseTab() {
$args['type'] = 'CloseDiv';
$args['id'] = 'CloseDiv';
$args['std'] = '';
$this->SetField($args);
}
/**
* Does the repetive tasks of adding a field
*
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*
* @access private
*/
private function SetField($args) {
$default = array(
'std' => '',
'id' => ''
);
$args = array_merge($default, $args);
$this->buildOptions($args);
$this->_fields[] = $args;
}
/**
* Builds all the options with their std values
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @since 0.1
* @access private
*/
private function buildOptions($args) {
$default = array(
'std' => '',
'id' => ''
);
$args = array_merge($default, $args);
$saved = get_option($this->option_group);
if (isset($saved[$args['id']])){
if($saved[$args['id']] === false) {
$saved[$args['id']] = $args['std'];
update_option($this->args['option_group'],$saved);
}
}
}
/**
* Adds a heading to the current page
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*
* @param string $label simply the text for your heading
*/
public function Title($label,$repeater = false) {
$args['type'] = 'title';
$args['std'] = '';
$args['label'] = $label;
$args['id'] = 'title'.$label;
$this->SetField($args);
}
/**
* Adds a sub-heading to the current page
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*
* @param string $label simply the text for your heading
*/
public function Subtitle($label,$repeater = false) {
$args['type'] = 'subtitle';
$args['label'] = $label;
$args['id'] = 'title'.$label;
$args['std'] = '';
$this->SetField($args);
}
/**
* Adds a paragraph to the current page
*
* @access public
* @param $args (mixed|array) contains everything needed to build the field
* @param $repeater (boolean)
* @since 0.1
*
* @param string $text the text you want to display
*/
public function Paragraph($text,$repeater = false) {
$args['type'] = 'paragraph';
$args['text'] = $text;
$args['id'] = 'paragraph';
$args['std'] = '';
$this->SetField($args);
}
/**
* Load all Javascript and CSS
*
* @since 0.1
* @access public
*/
public function load_scripts_styles() {
// Get Plugin Path
$plugin_path = $this->SelfPath;
//this replaces the ugly check fields methods calls
foreach (array('upload','color','date','time','code','select','editor','plupload') as $type) {
call_user_func ( array( $this, 'check_field_' . $type ));
}
wp_enqueue_script('common');
if ($this->has_Field('TABS')){
wp_print_scripts('jquery-ui-tabs');
}
// Enqueue admin page Style
wp_enqueue_style( 'Admin_Page_Class', $plugin_path . '/css/Admin_Page_Class.css' );
wp_enqueue_style('iphone_checkbox',$plugin_path. '/js/FancyCheckbox/FancyCheckbox.css');
// Enqueue admin page Scripts
wp_enqueue_script( 'Admin_Page_Class', $plugin_path . '/js/Admin_Page_Class.js', array( 'jquery' ), null, true );
wp_enqueue_script('iphone_checkbox',$plugin_path. '/js/FancyCheckbox/FancyCheckbox.js',array('jquery'),null,true);
wp_enqueue_script('utils');
wp_enqueue_script( 'jquery-ui-sortable' );
}
/**
* Check Field code editor
*
* @since 0.1
* @access public
*/
public function check_field_code() {
if ( $this->has_field( 'code' ) && $this->is_edit_page() ) {
$plugin_path = $this->SelfPath;
// Enqueu codemirror js and css
wp_enqueue_style( 'at-code-css', $plugin_path .'/js/codemirror/codemirror.css',array(),null);
wp_enqueue_style( 'at-code-css-dark', $plugin_path .'/js/codemirror/solarizedDark.css',array(),null);