-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
3812 lines (2628 loc) · 84.2 KB
/
index.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
/*
Plugin Name: CodeBard Help Desk
Plugin URI: https://codebard.com/codebard-help-desk-for-wordpress/
Description: Extremely easy to use, unlimited Help Desk system that just works. Unlimited Tickets, Unlimited Agents, Unlimited Users, Unlimited Departments. Works out of the box and easily extensible.
Version: 1.1.2
Author: CodeBard
License: GPLv2
Author URI: https://codebard.com
Text Domain: cb_p3
Domain Path: /lang
*/
class cb_p3_core {
protected static $instance = null;
public $info = array(
// Holds plugin info. Overridden by info from db by merging db info into this
);
public $internal = array(
// Holds internal and generated vars. Never saved.
);
public $opt=array(
// Holds plugin info. Overridden by options from db by merging db options into this
);
private function __construct()
{
// We need a few internal vars initialized here
$this->internal['plugin_path']=plugin_dir_path( __FILE__ );
$this->internal['template_path']=$this->internal['plugin_path'].'plugin/templates';
$this->internal['start']=microtime(true);
$this->internal['plugin_url'] = trailingslashit(plugin_dir_url(__FILE__));
$this->internal['template_url']=$this->internal['plugin_url'].'plugin/templates';
$this->internal['plugin_slug'] = basename(dirname(__FILE__)).'/index.php';
$this->internal['plugin_dir_name'] = basename(dirname(__FILE__));
$this->internal['admin_url'] = trailingslashit(get_admin_url());
$this->internal['site_url'] = get_site_url();
$this->internal['admin_page_url'] = get_admin_url();
require_once($this->internal['plugin_path'].'core/includes/default_internal_vars.php');
require_once($this->internal['plugin_path'].'plugin/includes/default_internal_vars.php');
require_once($this->internal['plugin_path'].'plugin/includes/hardcoded_vars.php');
if(isset($_REQUEST[$this->internal['prefix'].'action']))
{
$this->internal['requested_action'] = $_REQUEST[$this->internal['prefix'].'action'];
}
else
{
$this->internal['requested_action']=false;
}
$this->plugin_construct();
}
public static function get_instance()
{
if (!isset(self::$instance)) {
$obj = get_called_class();
self::$instance = new $obj;
}
return static::$instance;
}
private function __clone() { }
public function __wakeup() { }
public function __call($action,$vars)
{
// Runner Function - checks, processes and runs any action requested and distributes into core and plugin singleton objects in order. This function acts as a front controller. https://en.wikipedia.org/wiki/Front_controller
// $this->run('action') method does not work here because you cant pass vars to WordPress' add_action hence you cant pass the action name. So this Runner function has to be magic call.
// Normalize the action name
$action=str_replace($this->internal['prefix'],'',$action);
// Map the vars
for($varcount=1;$varcount<=11;$varcount++)
{
$var_name = 'v'.$varcount;
if(isset($vars[$varcount-1]))
{
$$var_name = $vars[$varcount-1];
}
else
{
$$var_name = false;
}
}
// Check if action exits in methods and return dud if it isnt
if(!method_exists($this,$action.'_c') AND !method_exists($this,$action.'_p'))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action END due to NO ACTION FOUND. false returned without processing action.', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
return false;
}
// Check if the action is coming from $_REQUEST and if so check if its in uncallable actions from $_REQUEST list
if(isset($this->internal['requested_action']))
{
if($this->internal['requested_action']==$action AND (!array_key_exists($this->internal['requested_action'], $this->internal['callable_from_request']) OR array_key_exists($this->internal['requested_action'], $this->internal['ignore_at_call'])))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action END due to UNCALLABLE FROM REQUEST or IGNORE AT CALL. false returned without processing action.', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
return false;
}
}
// Now check if function has any call limit. For functions like init, frontend_init and admin_init, for example, they should only be called once
// Set call limits to array if its too early in launch (to allow init_internal_vars and init not to trigger error)
if(!is_array($this->internal['calllimits']))
{
$this->internal['calllimits']=array();
}
if(array_key_exists($action, $this->internal['calllimits']))
{
if(!isset($this->internal['callcount'][$action]))
{
$this->internal['callcount'][$action]=0;
}
if($this->internal['calllimits'][$action] > $this->internal['callcount'][$action])
{
$this->internal['callcount'][$action]++;
}
else
{
if(array_key_exists($action, $this->internal['calllimits']))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action END due to CALL LIMIT. Action has '.$this->internal['calllimits'][$action].' call limit whereas it was called '.$this->internal['callcount'][$action].' times. returned false without processing action.', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
return false;
}
}
}
// Checks passed. Start processing the action request
// This is the action which runs before the actual action runs
if(has_action($this->internal['prefix'].'action_before_'.$action))
{
// Check if the action/function is set to dont execute hooks for itself:
if(array_key_exists($action, $this->hardcoded['dont_execute_hooks']))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action Hooks - BEFORE - Action '.$action.' is set to not execute hooks. Not running hooked functions', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
else
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action Hooks - BEFORE - START', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
do_action($this->internal['prefix'].'action_before_'.$action,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action Hooks - BEFORE - END', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
}
// This filter is used to filter variables before they are sent to actions
if(has_filter($this->internal['prefix'].'filter_vars_before_'.$action))
{
// Check if the action/function is set to do not filter
if(array_key_exists($action, $this->hardcoded['dont_filter']))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - Action '.$action.' is set to do not filter. Not filtering', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
else
{
// It can be filtered - log and apply filters
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - BEFORE - START', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
// In WP only var1 is filtered, so only var1 changes - all rest are context-providing variables in apply_filters - they stay the same
$v1 = apply_filters($this->internal['prefix'].'filter_vars_before_'.$action,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - BEFORE - END', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
}
if(!isset($this->internal['nobuffer']))
{
//ob_start();
}
if(method_exists($this,$action.'_c'))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>' CORE START - calling action from core method', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
////////// Here magic happens //////////
$return_c = $this->{$action.'_c'}($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
////////// Magic happened //////////
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>' CORE END - calling action from core method if exists', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
if(method_exists($this,$action.'_p'))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>' PLUGIN START - calling action from plugin method', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
// If there is any return for core function, assign it to an internal var so plugin function can see and ue it:
if(isset($return_c))
{
$this->internal['core_return']=$return_c;
}
else
{
$this->internal['core_return']=false;
}
////////// Here magic happens //////////
$return_p=$this->{$action.'_p'}($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
////////// Here magic happened //////////
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>' PLUGIN END - calling action from core method if exists', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
// Run post action actions and filters
if(!isset($this->internal['nobuffer']))
{
//$output=ob_get_clean();
}
if(!isset($output))
{
$output=false;
}
if(strlen($output)>0 AND !$this->internal['nobuffer'])
{
// Filter that runs after the action has been run and direct output is printed in case output buffering is not turned off before running the function
// Still checks for if nobuffer is turned on because some action may set $output variable inside their action code.
if(has_filter($this->internal['prefix'].'filter_output_after_'.$action))
{
// Check if the action/function is set to do not filter
if(array_key_exists($action, $this->hardcoded['dont_filter']))
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - Action '.$action.' is set to do not filter. Not filtering', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
else
{
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Output Filter - START', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
$output=apply_filters($this->internal['prefix'].'filter_output_after_'.$action,$output,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Output Filter - END', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
}
echo $output;
}
// Set internal nobuffer to false before return in case it was given
$this->internal['nobuffer']=false;
// This is the action hook which runs after the actual action completed
if(has_action($this->internal['prefix'].'action_after_'.$action))
{
if(array_key_exists($action, $this->hardcoded['dont_execute_hooks']))
{
if(isset($this->internal['do_log']) AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action Hooks - AFTER - Action '.$action.' is set to not execute hooks. Not running hooked functions', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
else
{
if(isset($this->internal['do_log']) AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action Hooks - AFTER - START', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
do_action($this->internal['prefix'].'action_after_'.$action,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
if(isset($this->internal['do_log']) AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Action Hooks - AFTER - END', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
}
// If there is return from plugin methods, send that to return. If there is no return from plugin methods but there is from core methods, set that one:
if(isset($return_p))
{
$return=$return_p;
}
else
{
if(isset($return_c))
{
$return=$return_c;
}
else
{
$return=false;
}
}
// Filter that runs after the action has been run and a return value is produced
if(has_filter($this->internal['prefix'].'filter_vars_after_'.$action))
{
// Check if the action/function is set to do not filter
if(array_key_exists($action, $this->hardcoded['dont_filter']))
{
if(isset($this->internal['do_log']) AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - Action '.$action.' is set to do not filter. Not filtering', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
else
{
if(isset($this->internal['do_log']) AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - AFTER - START', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
$return = apply_filters($this->internal['prefix'].'filter_vars_after_'.$action,$return,$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10);
if(isset($this->internal['do_log']) AND $action!=='do_log')
{
$this->do_log(array('action'=>$action, 'status'=>'Variable FILTERS - AFTER - END', 'time' => microtime(true), 'vars' => array($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10)));
}
}
}
unset($action);
return $return;
}
public function do_log_c($args)
{
$passed=$args['time']-$this->internal['start'];
if(isset($this->internal['write_log']))
{
file_put_contents('log', $this->internal['id'].' - Action '.$args['action'].' '.$args['status'].' at '.$passed.' msec with vars v1 '.serialize($args['vars'][0]).
' v2 '.serialize($args['vars'][1]).
' v3 '.serialize($args['vars'][2]).
' v4 '.serialize($args['vars'][3]).
' v5 '.serialize($args['vars'][4]).
' v6 '.serialize($args['vars'][5]).
' v7 '.serialize($args['vars'][6]).
' v8 '.serialize($args['vars'][7]).
' v9 '.serialize($args['vars'][8]).
' v10 '.serialize($args['vars'][9])
.PHP_EOL
, FILE_APPEND);
}
else
{
$this->internal['log'][]=$this->internal['id'].' - Action '.$args['action'].' '.$args['status'].' at '.$passed.' msec';
}
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//||||||||||||||||||| Here start the Core Methods |||||||||||||||||||||||
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function activate_c()
{
$this->require_admin_page();
if(!current_user_can('activate_plugins'))
{
return false;
}
// Get options just in case it is not loaded during activate or install - this will carry over to all other functions:
$this->opt=get_option($this->internal['prefix'].'options');
$this->create_tables();
$this->reset_languages();
$this->setup_languages();
}
public function add_options_c($v1)
{
$option_array_to_add=$v1;
$this->opt=array_replace_recursive(
$this->opt,
$option_array_to_add
);
}
public function admin_init_c()
{
if(!is_admin())
{
return;
}
add_action( 'admin_enqueue_scripts', array(&$this, 'enqueue_admin_styles'));
add_action( 'admin_enqueue_scripts', array(&$this, 'enqueue_admin_scripts'));
add_action('admin_menu', array(&$this,'add_admin_menus'));
add_action( 'admin_notices', array(&$this,'admin_notices'));
add_action( 'wp_ajax_'.$this->internal['prefix'].'dismiss_admin_notice', array( &$this, 'dismiss_admin_notice' ),10,1 );
if($this->internal['requested_action']!='')
{
$this->{$this->internal['requested_action']}($_REQUEST);
}
}
public function create_tables_c()
{
$this->require_admin_page();
global $wpdb;
global $wp_roles;
global $current_user;
$charset_collate = $wpdb->get_charset_collate();
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
foreach($this->internal['tables'] as $key => $value)
{
// If a table structure is not given, use default sql:
if(!isset($this->internal['tables'][$key]['structure']) OR $this->internal['tables'][$key]['structure']=='')
{
$table_structure=$this->internal['default_table_structure'];
}
else
{
$table_structure=$this->internal['tables'][$key]['structure'];
}
$prefix_structure = explode("\n", $table_structure);
$prefixed_table_structure='';
foreach($prefix_structure as $row_key => $row_value)
{
$prefix_structure[$row_key]=trim($prefix_structure[$row_key]);
if(substr($prefix_structure[$row_key],0,4)=='KEY ')
{
$key_it = str_replace('KEY ',"\n".'KEY '.$key.'_',$prefix_structure[$row_key]);
$key_it = str_replace(' (',' ('.$key.'_',$key_it);
$prefixed_table_structure .= $key_it;
}
else
{
$prefixed_table_structure .= $key.'_'.$prefix_structure[$row_key];
}
}
$sql="CREATE TABLE ".$wpdb->prefix.$this->internal['id']."_".$key." (
".$prefixed_table_structure."
PRIMARY KEY (".$key."_id)
) ".$charset_collate;
dbDelta( $sql );
}
// Create meta tables if they arent here
foreach($this->internal['meta_tables'] as $key => $value)
{
// If a table structure is not given, use default sql:
if($this->internal['meta_tables'][$key]['structure']=='')
{
$table_structure=$this->internal['default_meta_structure'];
}
else
{
$table_structure=$this->internal['meta_tables'][$key]['structure'];
}
$type_length='';
if($this->internal['meta_tables'][$key]['length']!='')
{
$type_length='('.$this->internal['meta_tables'][$key]['length'].')';
}
$type_default='';
if(isset($this->internal['meta_tables'][$key]['default']) AND $this->internal['meta_tables'][$key]['default']!='')
{
$type_default=' DEFAULT '.$this->internal['meta_tables'][$key]['default'];
}
if($this->internal['meta_tables'][$key]['type']=='longtext')
{
$table_structure=str_replace('{REPLACEVALUE}','value '.$this->internal['meta_tables'][$key]['type']." NOT NULL",$table_structure);
}
else
{
$table_structure=str_replace('{REPLACEVALUE}','value '.$this->internal['meta_tables'][$key]['type'].$type_length.$type_default,$table_structure);
}
$prefix_structure = explode("\n", $table_structure);
$prefixed_table_structure='';
foreach($prefix_structure as $row_key => $row_value)
{
$prefix_structure[$row_key]=trim($prefix_structure[$row_key]);
if(substr($prefix_structure[$row_key],0,4)=='KEY ')
{
$key_it='';
if($this->internal['meta_tables'][$key]['type']!='longtext')
{
$key_it = str_replace('KEY ',"\n".'KEY '.$key.'_',$prefix_structure[$row_key]);
$key_it = str_replace(' (',' ('.$key.'_',$key_it)."";
}
$prefixed_table_structure .= $key_it;
}
else
{
$prefixed_table_structure .= $key.'_'.$prefix_structure[$row_key];
}
}
$sql="CREATE TABLE ".$wpdb->prefix.$this->internal['id']."_".$key." (
".$prefixed_table_structure."
PRIMARY KEY (".$key."_id)
) ".$charset_collate;
dbDelta( $sql );
}
}
public function deactivate_c($v1)
{
$this->require_admin_page();
if(!current_user_can('activate_plugins'))
{
return false;
}
flush_rewrite_rules(true);
}
public function do_admin_page_tabs_c()
{
$this->require_admin_page();
unset($tab);
if(isset($_REQUEST[$this->internal['prefix'].'tab']))
{
$tab=$_REQUEST[$this->internal['prefix'].'tab'];
}
if(!isset($tab))
{
$tab='dashboard';
}
// Now lets explode the tab string to find what tab hierarchy is wanted:
$tab_hierarchy=explode('-',$tab);
// Top tab is whatever is on the top of the array :
$tab_hierarchy_array = array_values($tab_hierarchy);
$top_tab=array_shift( $tab_hierarchy_array );
$tabs = $this->internal['admin_tabs'];
echo '<div id="icon-themes" class="icon32"><br></div>';
echo '<h2 class="nav-tab-wrapper">';
foreach( $tabs as $key => $value )
{
$class = ( $key == $top_tab ) ? ' nav-tab-active' : '';
echo '<a class="nav-tab'.$class.'" href="?page=settings_'.$this->internal['id'].'&'.$this->internal['prefix'].'tab='.$key.'">'.$this->lang['admin_tab_'.$key].'</a>';
}
echo '</h2>';
// Now do sub-tabs for the active tab:
$keys = array_keys($tabs[$top_tab]);
// Fetch last key
$last = array_pop($keys);
if(count($tabs[$top_tab])>0)
{
foreach( $tabs[$top_tab] as $key => $value )
{
echo '<a href="?page=settings_'.$this->internal['id'].'&'.$this->internal['prefix'].'tab='.$top_tab.'-'.$key.'">'.$this->lang['admin_tab_'.$top_tab.'_'.$key].'</a>';
if($key!=$last)
{
echo ' | ';
}
}
}
// Level 3 for the active subtab if level 2 is selected and we have level 3
if(count($tab_hierarchy)>1)
{
$second_level = $tab_hierarchy[1];
$keys = array_keys($tabs[$top_tab][$second_level]);
$last = array_pop($keys);
echo '<hr>';
foreach( $tabs[$top_tab][$second_level] as $key => $value )
{
echo '<a href="?page=settings_'.$this->internal['id'].'&'.$this->internal['prefix'].'tab='.$top_tab.'-'.$second_level.'-'.$key.'">'.$this->lang['admin_tab_'.$top_tab.'_'.$second_level.'_'.$key].'</a>';
if($key!=$last)
{
echo ' | ';
}
}
echo '<hr>';
}
}
public function do_setting_section_c($v1)
{
$tab=$v1;
$this->internal['current_tab']=$tab;
if(file_exists($this->internal['plugin_path'].'plugin/includes/setting_sections/'.$tab.'.php'))
{
require_once($this->internal['plugin_path'].'plugin/includes/setting_sections/'.$tab.'.php');
}
}
public function do_setting_section_additional_settings_c($v1)
{
// This function is a wrapper to allow addons to be able to add their own setting entries to a section. Its included in sections.
}
public function do_settings_pages_c($v1)
{
$tab=$v1;
if(isset($this->internal['setup_is_being_done']))
{
return;
}
if(isset($_REQUEST[$this->internal['prefix'].'tab']))
{
$tab=$_REQUEST[$this->internal['prefix'].'tab'];
}
if($tab=='' OR !$tab)
{
$tab='dashboard';
}
$template_vars=array('tab'=>$tab,'referer'=>$_SERVER['HTTP_REFERER']);
// We don't want admin settings page headers and footers to be filtered by anyone. Therefore we don't use load_template here
$admin_settings_page_header = file_get_contents($this->internal['plugin_path'].'plugin/includes/setting_sections/admin_settings_page_header.php');
$admin_settings_page_header = $this->process_vars_to_template($this->internal, $admin_settings_page_header, array('id','prefix','plugin_url','admin_page_url','plugin_name'));
$admin_settings_page_header = $this->process_vars_to_template($template_vars, $admin_settings_page_header);
$admin_settings_page_header = $this->process_lang($admin_settings_page_header);
// We don't want admin settings page headers and footers to be filtered by anyone. Therefore we don't use load_template here
$admin_settings_page_footer = file_get_contents($this->internal['plugin_path'].'plugin/includes/setting_sections/admin_settings_page_footer.php');
$admin_settings_page_footer = $this->process_vars_to_template($this->internal, $admin_settings_page_footer, array('id','prefix','plugin_url','admin_page_url','plugin_name'));
$admin_settings_page_footer = $this->process_vars_to_template($template_vars, $admin_settings_page_footer);
$admin_settings_page_footer = $this->process_lang($admin_settings_page_footer);
echo $admin_settings_page_header;
echo $this->do_admin_page_tabs();
$this->do_setting_section($tab);
echo $admin_settings_page_footer;
}
public function do_admin_settings_form_header_c()
{
$admin_settings_form_header = file_get_contents($this->internal['plugin_path'].'plugin/includes/setting_sections/admin_settings_form_header.php');
$admin_settings_form_header = $this->process_vars_to_template($this->internal, $admin_settings_form_header, array('id','prefix','plugin_url','admin_page_url','plugin_name'));
if(isset($_REQUEST['tab']))
{
$tab=$_REQUEST['tab'];
}
else
{
$tab='';
}
$template_vars=array('tab'=>$tab,'referer'=> isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
$admin_settings_form_header = $this->process_vars_to_template($template_vars, $admin_settings_form_header);
$admin_settings_form_header = $this->process_lang($admin_settings_form_header);
return $admin_settings_form_header;
}
public function do_admin_settings_form_footer_c()
{
$admin_settings_form_footer = file_get_contents($this->internal['plugin_path'].'plugin/includes/setting_sections/admin_settings_form_footer.php');
$admin_settings_form_footer = $this->process_vars_to_template($this->internal, $admin_settings_form_footer, array('id','prefix','plugin_url','admin_page_url','plugin_name'));
if(isset($_REQUEST['tab']))
{
$tab=$_REQUEST['tab'];
}
else
{
$tab='';
}
$template_vars=array('tab'=>$tab,'referer'=>$_SERVER['HTTP_REFERER']);
$admin_settings_form_footer = $this->process_vars_to_template($template_vars, $admin_settings_form_footer);
$admin_settings_form_footer = $this->process_lang($admin_settings_form_footer);
return $admin_settings_form_footer;
}
public function frontend_init_c()
{
add_action( 'wp_enqueue_scripts', array(&$this, 'enqueue_frontend_styles'));
add_action( 'wp_enqueue_scripts', array(&$this, 'enqueue_frontend_scripts'));
// Sanitize $this->internal['requested_action'] before this!!!
if($this->internal['requested_action']!='')
{
$this->{$this->internal['requested_action']}($_REQUEST);
}
}
public function init_c()
{
// Initialize variables
$this->internal = $this->init_internal_vars();
$this->info = $this->init_info();
$this->opt = $this->init_options();
// Lets get the option tabs into an internal var so they wont be bloated by dormant option keys from old addons in db
$this->internal['tabs'] = array_flip(array_keys($this->opt));
// Load info from db
$this->info = $this->load_info();
// Load options from db
$this->opt = $this->load_options();
// Load language from db
$this->lang = $this->load_language();
// Hooks debug info to bottom of WP page if logging is true and the user is admin
if(isset($this->internal['do_log']) AND $this->internal['do_log'] AND $this->internal['requested_action']!=='do_log')
{
add_action('wp_footer', array(&$this, 'output_log'));
add_action('admin_footer', array(&$this, 'output_log'));
}
}
public function init_internal_vars_c()
{
// This function is mainly here so that addons can filter internal vars at init
return $this->internal;
}
public function init_info_c()
{
require_once($this->internal['plugin_path'].'core/includes/default_info.php');
require_once($this->internal['plugin_path'].'plugin/includes/default_info.php');
return $this->info;
}
public function init_options_c()
{
require_once($this->internal['plugin_path'].'core/includes/default_options.php');
require_once($this->internal['plugin_path'].'plugin/includes/default_options.php');
return $this->opt;
}
public function load_info_c()
{
if($this->internal['requested_action']=='reset_info')
{
$this->reset_info();
return $this->info;
}
$saved_info = get_option($this->internal['prefix'].'info');
if(!is_array($saved_info) OR count($saved_info)==0)
{
// No info saved. Save default info:
//$this->reset_info();
return $this->info;
}
// If info is saved, then override/merge default info with saved one
return array_replace_recursive
(
$this->info,
$saved_info
);
}
public function load_options_c()
{
if($this->internal['requested_action']=='reset_options')
{
$this->reset_options();
return $this->opt;
}
$saved_options = get_option($this->internal['prefix'].'options');
if(!is_array($saved_options) OR count($saved_options)==0)