-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.class.php
1742 lines (1521 loc) · 67.6 KB
/
core.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
/**
* Core SedLex Plugin
* VersionInclude : 3.0
*/
/* Prevent direct access to this file */
if (!defined('ABSPATH')) {
exit("Sorry, you are not allowed to access this file directly.");
}
if (!class_exists('pluginSedLex')) {
if (!defined('SL_FRAMEWORK_DIR')) {
define('SL_FRAMEWORK_DIR', dirname(__FILE__));
}
$sedlex_list_scripts = array() ;
$sedlex_list_styles = array() ;
$sedlex_adminJavascript_tobedisplayed = true ;
$sedlex_adminCSS_tobedisplayed = true ;
$SLtopLevel_alreadyInstalled = false ;
$SLpluginActivated = array() ;
/** =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
* This PHP class aims at simplifying the developement of new plugin for Wordpress and especially if you do not know how to develop it.
* Therefore, your plugin class should inherit from this class. Please refer to the HOW TO manual to learn more.
*
* @abstract
*/
abstract class pluginSedLex {
/** ====================================================================================================================================================
* This is our constructor, which is private to force the use of getInstance()
*
* @return void
*/
protected function __construct() {
if ( is_callable( array($this, '_init') ) ) {
$this->_init();
}
//Button for tinyMCE
add_action('init', array( $this, '_button_editor'));
add_action('parse_request', array($this,'create_js_for_tinymce') , 1);
add_action('admin_menu', array( $this, 'admin_menu'));
add_filter('plugin_row_meta', array( $this, 'plugin_actions'), 10, 2);
add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
add_action('init', array( $this, 'init_textdomain'));
add_action('init', array( $this, 'update_plugin'));
// Public Script
add_action('wp_enqueue_scripts', array( $this, 'javascript_front'), 5);
add_action('wp_enqueue_scripts', array( $this, 'css_front'), 5);
if (method_exists($this,'_public_js_load')) {
add_action('wp_enqueue_scripts', array($this,'_public_js_load'));
}
if (method_exists($this,'_public_css_load')) {
add_action('wp_enqueue_scripts', array($this,'_public_css_load'));
}
add_action('wp_enqueue_scripts', array( $this, 'flush_js'), 10000000);
add_action('wp_enqueue_scripts', array( $this, 'flush_css'), 10000000);
// Admin Script
add_action('admin_enqueue_scripts', array( $this, 'javascript_admin'), 5); // Only for SL page
add_action('admin_enqueue_scripts', array( $this, 'css_admin'), 5);// Only for SL page
if (method_exists($this,'_admin_js_load')) {
add_action('admin_enqueue_scripts', array($this,'_admin_js_load'));
}
if (method_exists($this,'_admin_css_load')) {
add_action('admin_enqueue_scripts', array($this,'_admin_css_load'));
}
add_action('admin_enqueue_scripts', array( $this, 'flush_js'), 10000000);// Only for SL page
add_action('admin_enqueue_scripts', array( $this, 'flush_css'), 10000000);// Only for SL page
// We add an ajax call for the translation class
add_action('wp_ajax_translate_add', array('SLFramework_Translation','translate_add')) ;
add_action('wp_ajax_translate_modify', array('SLFramework_Translation','translate_modify')) ;
add_action('wp_ajax_translate_create', array('SLFramework_Translation','translate_create')) ;
add_action('wp_ajax_send_translation', array('SLFramework_Translation','send_translation')) ;
add_action('wp_ajax_update_summary', array('SLFramework_Translation','update_summary')) ;
// We add an ajax call for the parameter class
add_action('wp_ajax_del_param', array($this,'del_param_callback')) ;
add_action('wp_ajax_add_param', array($this,'add_param_callback')) ;
// We add an ajax call for the feedback class
add_action('wp_ajax_send_feedback', array('SLFramework_Feedback','send_feedback')) ;
// Enable the modification of the content and of the excerpt
add_filter('the_content', array($this,'the_content_SL'), 1000);
add_filter('get_the_excerpt', array( $this, 'the_excerpt_SL'),1000000);
add_filter('get_the_excerpt', array( $this, 'the_excerpt_ante_SL'),2);
// To debug error
add_action('activated_plugin',array($this,'save_error_on_activation'));
$this->signature = '<p style="text-align:right;font-size:75%;">© SedLex - <a href="http://www.sedlex.fr/">http://www.sedlex.fr/</a></p>' ;
$this->frmk = new coreSLframework() ;
$this->excerpt_called_SL = false ;
}
/** ====================================================================================================================================================
* In order to save error that can be generated on activation
*
* @access private
* @return void
*/
function save_error_on_activation($plugin) {
update_option('plugin_error_on_activation', ob_get_contents());
}
/** ====================================================================================================================================================
* In order to install the plugin, few things are to be done ...
* This function is not supposed to be called from your plugin : it is a purely internal function called when you activate the plugin
*
* If you have to do some stuff when the plgin is activated (such as update the database format), please create an _update function in your plugin
*
* @access private
* @see subclass::_update
* @see pluginSedLex::uninstall
* @see pluginSedLex::deactivate
* @param boolean $network_wide true if a network activation is in progress (see http://core.trac.wordpress.org/ticket/14170#comment:30)
* @return void
*/
public function install ($network_wide) {
global $wpdb;
// If the website is multisite, we have to call each install manually to create the table because it is called only for the main site.
// (see http://core.trac.wordpress.org/ticket/14170#comment:18)
if (function_exists('is_multisite') && is_multisite() && $network_wide ){
$old_blog = $wpdb->blogid;
$old_prefix = $wpdb->prefix ;
// Get all blog ids
$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
foreach ($blogids as $blog_id) {
switch_to_blog($blog_id);
$this->singleSite_install(str_replace($old_prefix, $wpdb->prefix, $this->table_name)) ;
}
switch_to_blog($old_blog);
} else {
$this->singleSite_install($this->table_name) ;
}
}
/** ====================================================================================================================================================
* In order to install the plugin, few things are to be done ...
* This function is not supposed to be called from your plugin : it is a purely internal function called when you activate the plugin
*
* @access private
* @see subclass::_update
* @see pluginSedLex::uninstall_removedata
* @see pluginSedLex::deactivate
* @param string $table_name the SQL table name for the plugin
* @return void
*/
public function singleSite_install($table_name) {
global $wpdb ;
global $db_version;
// If there is only one sql table
if (!is_array($this->tableSQL)) {
if (strlen(trim($this->tableSQL))>0) {
if($wpdb->get_var("show tables like '".$table_name."'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (".$this->tableSQL. ") DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
// On montre les erreurs en cas de besoin
if ($wpdb->last_error) {
ob_start();
var_dump($wpdb->last_query) ;
echo 'SQL_Error=' . ob_get_clean() ;
ob_start() ;
var_dump($wpdb->last_error) ;
echo ' ==> ' . ob_get_clean() ;
}
add_option("db_version", $db_version);
// Gestion de l'erreur
ob_start() ;
$wpdb->print_error();
$result = ob_get_clean() ;
if (strlen($result)>0) {
echo $result ;
die() ;
}
}
}
} else {
for ($i=0 ; $i<count($this->tableSQL) ; $i++) {
if (strlen(trim($this->tableSQL[$i]))>0) {
if($wpdb->get_var("show tables like '".$table_name[$i]."'") != $table_name[$i]) {
$sql = "CREATE TABLE " . $table_name[$i] . " (".$this->tableSQL[$i]. ") DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("db_version", $db_version);
// Gestion de l'erreur
ob_start() ;
$wpdb->print_error();
$result = ob_get_clean() ;
if (strlen($result)>0) {
echo $result ;
die() ;
}
}
}
}
}
if (method_exists($this,'_update')) {
$this->_update() ;
}
}
/** ====================================================================================================================================================
* In order to update the plugin, few things are to be done ...
* This function is not supposed to be called from your plugin : it is a purely internal function called when you activate the plugin
*
* @access private
* @see subclass::_update
* @see pluginSedLex::uninstall_removedata
* @see pluginSedLex::deactivate
* @param string $table_name the SQL table name for the plugin
* @return void
*/
public function update_plugin() {
$hash_old = $this->get_param("hash_sha1_plugin") ;
$hash_new = sha1_file($this->path);
if ($hash_new!=$hash_old){
$this->set_param("hash_sha1_plugin", $hash_new) ;
if (method_exists($this,'_update')) {
$this->_update() ;
}
}
}
/** ====================================================================================================================================================
* Get the plugin ID
*
* @return string the plugin ID string. the string will be empty if it is not a plugin (i.e. the framework)
*/
public function getPluginID () {
$tmp = $this->pluginID ;
if ($tmp=="coreSLframework")
return "" ;
return $tmp ;
}
/** ====================================================================================================================================================
* In order to deactivate the plugin, few things are to be done ...
* This function is not supposed to be called from your plugin : it is a purely internal function called when you de-activate the plugin
*
* For now the function does nothing (but have to be declared)
*
* @access private
* @see pluginSedLex::install
* @see pluginSedLex::uninstall_removedata
* @return void
*/
public function deactivate () {
//Nothing to do
}
/** ====================================================================================================================================================
* Get the value of an option of the plugin
*
* For instance: <code> echo $this->get_param('opt1') </code> will return the value of the option 'opt1' stored for this plugin. Please note that two different plugins may have options with the same name without any conflict.
*
* @see pluginSedLex::set_param
* @see pluginSedLex::get_name_params
* @see pluginSedLex::del_param
* @see SLFramework_Parameters::SLFramework_Parameters
* @param string $option the name of the option
* @return mixed the value of the option requested
*/
public function get_param($option) {
if (is_multisite() && preg_match('/^global_/', $option)) {
$options = get_site_option($this->pluginID.'_options');
} else {
$options = get_option($this->pluginID.'_options');
}
if (!isset($options[$option])) {
if ( (is_string($this->get_default_option($option))) && (substr($this->get_default_option($option), 0, 1)=="*") ) {
$options[$option] = substr($this->get_default_option($option), 1) ;
} else {
$options[$option] = $this->get_default_option($option) ;
}
// Update with the default value
if (is_multisite() && preg_match('/^global_/', $option)) {
update_site_option($this->pluginID.'_options', $options);
} else {
update_option($this->pluginID.'_options', $options);
}
}
return $options[$option] ;
}
/** ====================================================================================================================================================
* Get the value of an option of the plugin (macro)
*
* For instance: <code> echo $this->get_param_macro('opt1') </code> will return all values of the option 'opt1' stored for this plugin. Please note that two different plugins may have options with the same name without any conflict.
*
* @see pluginSedLex::set_param
* @see pluginSedLex::get_name_params
* @see pluginSedLex::del_param
* @see SLFramework_Parameters::SLFramework_Parameters
* @param string $option the name of the option
* @return mixed the value of the option requested
*/
public function get_param_macro($option) {
$i = 0 ;
$results = array() ;
if (is_multisite() && preg_match('/^global_/', $option)) {
$options = get_site_option($this->pluginID.'_options');
} else {
$options = get_option($this->pluginID.'_options');
}
while (isset($options[$option."_macro".($i)])) {
$results[] = $options[$option."_macro".($i)] ;
$i++ ;
}
return $results ;
}
/** ====================================================================================================================================================
* Get name of all options
*
* For instance: <code> echo $this->get_name_params() </code> will return an array with the name of all the options of the plugin
*
* @see pluginSedLex::set_param
* @see pluginSedLex::get_param
* @see pluginSedLex::del_param
* @see SLFramework_Parameters::SLFramework_Parameters
* @return array an array with all option names
*/
public function get_name_params() {
if (is_multisite()) {
$options = get_site_option($this->pluginID.'_options');
} else {
$options = get_option($this->pluginID.'_options');
}
if (is_array($options)) {
$results = array() ;
foreach ($options as $o => $v) {
$results[] = $o ;
}
return $results ;
} else {
return array() ;
}
}
/** ====================================================================================================================================================
* Delete an option of the plugin
*
* For instance: <code> echo $this->get_param('opt1') </code> will return the value of the option 'opt1' stored for this plugin. Please note that two different plugins may have options with the same name without any conflict.
*
* @see pluginSedLex::set_param
* @see pluginSedLex::get_name_params
* @see pluginSedLex::gel_param
* @see SLFramework_Parameters::SLFramework_Parameters
* @param string $option the name of the option
* @param string $pluginID the plugin ID (or the current plugin ID by default)
* @return void
*/
public function del_param($option, $pluginID="") {
if ($pluginID=="") {
$pluginID = $this->pluginID ;
}
if (is_multisite()) {
$options = get_site_option($pluginID.'_options');
} else {
$options = get_option($pluginID.'_options');
}
// We handle the case where it is a macro param
if (preg_match("/^(.*)_macro([0-9]*)$/", $option, $match)) {
$name_param = $match[1] ;
$from_int = intval($match[2]) ;
$i = $from_int+1 ;
// We shift all the variable name
while (isset($options[$name_param."_macro".($i)])) {
$options[$name_param."_macro".($i-1)] = $options[$name_param."_macro".($i)] ;
$i++ ;
}
if (isset($options[$name_param."_macro".($i-1)])) {
unset($options[$name_param."_macro".($i-1)]) ;
}
if ($i==1) {
$instance_plugin = call_user_func(array($pluginID, 'getInstance')); ;
$options[$name_param."_macro0"] = $instance_plugin->get_default_option($name_param) ;
}
} else {
// It is not a macro param, then we just unset it
if (isset($options[$option])) {
unset($options[$option]) ;
}
}
if (is_multisite()) {
update_site_option($pluginID.'_options', $options);
} else {
update_option($pluginID.'_options', $options);
}
return ;
}
/** ====================================================================================================================================================
* Callback to remove a parameter
*
* It will also remove any comment for the same
*
* @access private
* @return void
*/
function del_param_callback() {
global $_POST ;
$options = $_POST['param'] ;
$pluginID = $_POST['pluginID'] ;
foreach ($options as $o) {
$this->del_param($o, $pluginID) ;
}
echo "ok" ;
die() ;
}
/** ====================================================================================================================================================
* Callback to add a parameter
*
* It will also remove any comment for the same
*
* @access private
* @return void
*/
function add_param_callback() {
global $_POST ;
$options = $_POST['param'] ;
$pluginID = $_POST['pluginID'] ;
if (is_multisite()) {
$options_to_be_updated = get_site_option($pluginID.'_options');
} else {
$options_to_be_updated = get_option($pluginID.'_options');
}
foreach ($options as $o) {
// We handle the case where it is a macro param
if (preg_match("/^(.*)_macro$/", $o, $match)) {
$name_param = $match[1] ;
$i = 1 ;
// We shift all the variable name
while (isset($options_to_be_updated[$name_param."_macro".($i)])) {
$i++ ;
}
$instance_plugin = call_user_func(array($pluginID, 'getInstance')); ;
$options_to_be_updated[$name_param."_macro".($i)] = $instance_plugin->get_default_option($name_param) ;
} else {
// It is not a macro param, then we just set it
$instance_plugin = call_user_func(array($pluginID, 'getInstance')); ;
$options_to_be_updated[$name_param] = $instance_plugin->get_default_option($name_param) ;
}
if (is_multisite()) {
update_site_option($pluginID.'_options', $options_to_be_updated);
} else {
update_option($pluginID.'_options', $options_to_be_updated);
}
}
echo "ok" ;
die() ;
}
/** ====================================================================================================================================================
* Set the option of the plugin
*
* For instance, <code>$this->set_param('opt1', 'val1')</code> will store the string 'val1' for the option 'opt1'. Any object may be stored in the options
*
* @see pluginSedLex::get_param
* @see SLFramework_Parameters::SLFramework_Parameters
* @param string $option the name of the option
* @param mixed $value the value of the option to be saved
* @return void
*/
public function set_param($option, $value) {
if (is_multisite() && preg_match('/^global_/', $option)) {
$options = get_site_option($this->pluginID.'_options');
} else {
$options = get_option($this->pluginID.'_options');
}
$options[$option] = $value ;
if (is_multisite() && preg_match('/^global_/', $option)) {
update_site_option($this->pluginID.'_options', $options);
} else {
update_option($this->pluginID.'_options', $options);
}
}
/** ====================================================================================================================================================
* Create the menu & submenu in the admin section
* This function is not supposed to be called from your plugin : it is a purely internal function called when you de-activate the plugin
*
* @access private
* @return void
*/
public function admin_menu() {
global $menu,$SLtopLevel_alreadyInstalled,$SLpluginActivated, $Custom_SLtopLevel ;
$tmp = explode('/',plugin_basename($this->path)) ;
$plugin = $tmp[0]."/".$tmp[0].".php" ;
$topLevel = "sedlex.php" ;
$glp = $this->frmk->get_param('global_location_plugin') ;
$selection_pos = "std" ;
foreach ($glp as $a) {
if (substr($a[0],0,1)=="*") {
$selection_pos = $a[1] ;
}
}
if (!$SLtopLevel_alreadyInstalled) {
$SLtopLevel_alreadyInstalled = true ;
if ($selection_pos=="plugins") {
$page = add_submenu_page('plugins.php', __('About SL plugins...', 'SL_framework'), __('About SL plugins...', 'SL_framework'), 'activate_plugins', $topLevel, array($this,'sedlex_information'));
} else if ($selection_pos=="tools") {
$page = add_submenu_page('tools.php', __('About SL plugins...', 'SL_framework'), __('About SL plugins...', 'SL_framework'), 'activate_plugins', $topLevel, array($this,'sedlex_information'));
} else if ($selection_pos=="settings") {
$page = add_submenu_page('options-general.php', __('About SL plugins...', 'SL_framework'), __('About SL plugins...', 'SL_framework'), 'activate_plugins', $topLevel, array($this,'sedlex_information'));
} else {
//add main menu
add_menu_page('SL Plugins', 'SL Plugins', 'activate_plugins', $topLevel, array($this,'sedlex_information'));
$page = add_submenu_page($topLevel, __('About...', 'SL_framework'), __('About...', 'SL_framework'), 'activate_plugins', $topLevel, array($this,'sedlex_information'));
}
}
// If there is a specific main menu
if ((isset($this->upper_level_menu))&&($this->upper_level_menu!="")) {
if (!isset($Custom_SLtopLevel[$this->upper_level_menu])) {
$Custom_SLtopLevel[$this->upper_level_menu] = $plugin ;
add_menu_page($this->upper_level_menu, $this->upper_level_menu, 'activate_plugins', $plugin, array($this,'configuration_page'));
}
}
//add sub menus
$number = "" ;
if (method_exists($this,'_notify')) {
$number = $this->_notify() ;
if (is_numeric($number)) {
if ($number>0) {
$number = "<span class='update-plugins count-1' title='title'><span class='update-count'>".$number."</span></span>" ;
} else {
$number = "" ;
}
} else {
$number = "" ;
}
}
$SLpluginActivated[] = $plugin ;
if ((isset($this->upper_level_menu))&&($this->upper_level_menu!="")) {
$page = add_submenu_page($Custom_SLtopLevel[$this->upper_level_menu], $this->pluginName, $this->pluginName . $number, 'activate_plugins', $plugin, array($this,'configuration_page'));
} else {
if ($selection_pos=="plugins") {
$page = add_submenu_page('plugins.php', $this->pluginName, $this->pluginName . $number, 'activate_plugins', $plugin, array($this,'configuration_page'));
} else if ($selection_pos=="tools") {
$page = add_submenu_page('tools.php', $this->pluginName, $this->pluginName . $number, 'activate_plugins', $plugin, array($this,'configuration_page'));
} else if ($selection_pos=="settings") {
$page = add_submenu_page('options-general.php', $this->pluginName, $this->pluginName . $number, 'activate_plugins', $plugin, array($this,'configuration_page'));
} else {
$page = add_submenu_page($topLevel, $this->pluginName, $this->pluginName . $number, 'activate_plugins', $plugin, array($this,'configuration_page'));
}
}
}
/** ====================================================================================================================================================
* Add a link in the new link along with the standard activate/deactivate and edit in the plugin admin page.
* This function is not supposed to be called from your plugin : it is a purely internal function
*
* @access private
* @param array $links links such as activate/deactivate and edit
* @param string $file the related file of the plugin
* @return array of new links set with a Settings link added
*/
public function plugin_actions($links, $file) {
// Ne pas mettre de lien pour la partie admin
if (is_network_admin()) {
return $links ;
}
$tmp = explode('/',plugin_basename($this->path)) ;
$plugin = $tmp[0]."/".$tmp[0].".php" ;
if ($file == $plugin) {
return array_merge(
$links,
array( '<a href="admin.php?page='.$plugin.'">'. __('Settings', 'SL_framework') .'</a>')
);
}
return $links;
}
/** ====================================================================================================================================================
* Handler for the 'plugin_action_links' hook. Adds a "Settings" link to this plugin's entry
* on the plugin list.
*
* @access private
* @param array $links
* @param string $file
* @return array
*/
function plugin_action_links($links, $file) {
$tmp = explode('/',plugin_basename($this->path)) ;
$plugin = $tmp[0]."/".$tmp[0].".php" ;
if ($file == $plugin) {
return array_merge(
$links,
array( '<a href="admin.php?page='.$plugin.'">'. __('Settings', 'SL_framework') .'</a>')
);
}
return $links;
}
/** ====================================================================================================================================================
* Translate the plugin with international settings
* This function is not supposed to be called from your plugin : it is a purely internal function
*
* In order to enable translation, please add .mo and .po files in the /lang folder of the plugin
*
* @access private
* @return void
*/
public function init_textdomain() {
load_plugin_textdomain($this->pluginID, false, dirname( plugin_basename( $this->path ) ). '/lang/') ;
load_plugin_textdomain('SL_framework', false, dirname( plugin_basename( $this->path ) ). '/core/lang/') ;
}
/** ====================================================================================================================================================
* Functions to add a button in the TinyMCE Editor
*
* @access private
* @return void
*/
function _button_editor() {
// Do not modify this function
if(is_admin()){
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
return;
if (is_callable( array($this, 'add_tinymce_buttons') ) ) {
if (count($this->add_tinymce_buttons())>0) {
if ( get_user_option('rich_editing') == 'true') {
add_filter('mce_external_plugins', array($this, 'add_custom_button'));
add_filter('mce_buttons', array($this, 'register_custom_button'), 999 );
add_filter('tiny_mce_version', array($this, 'my_refresh_mce'));
}
}
}
}
}
function register_custom_button($buttons) {
// Do not modify this function
if (is_callable( array($this, 'add_tinymce_buttons') ) ) {
if (count($this->add_tinymce_buttons())>0) {
array_push($buttons, "|");
}
$i = 0 ;
foreach ($this->add_tinymce_buttons() as $button) {
$i++ ;
array_push($buttons, "customButton_".$this->pluginID."_".$i) ;
}
}
return $buttons;
}
function add_custom_button($plugin_array) {
if (is_callable( array($this, 'add_tinymce_buttons') ) ) {
if (count($this->add_tinymce_buttons())>0) {
$plugin_array["customPluginButtons_".$this->pluginID] = site_url()."/?output_js_tinymce=customPluginButtons_".$this->pluginID ;
}
}
return $plugin_array;
}
function my_refresh_mce($ver) {
if (is_callable( array($this, 'add_tinymce_buttons') ) ) {
if (count($this->add_tinymce_buttons())>0) {
$ver += 1;
}
}
return $ver;
}
function create_js_for_tinymce() {
if ((isset($_GET["output_js_tinymce"]))&&($_GET["output_js_tinymce"]=="customPluginButtons_".$this->pluginID)) {
?>
(function(){
tinymce.create('tinymce.plugins.<?php echo "customPluginButtons_".$this->pluginID ; ?>', {
init : function(ed, url){
<?php
$i = 0 ;
foreach ($this->add_tinymce_buttons() as $button) {
$i++ ;
?>
ed.addCommand('<?php echo "customButton_".$this->pluginID."_".$i ; ?>', function(){
selected_content = tinyMCE.activeEditor.selection.getContent();
tinyMCE.activeEditor.selection.setContent('<?php echo $button[1] ; ?>' + selected_content + '<?php echo $button[2] ; ?>');
});
ed.addButton('<?php echo "customButton_".$this->pluginID."_".$i ; ?>', {
title: '<?php echo $button[0] ; ?>',
image: '<?php echo $button[3] ; ?>',
cmd: '<?php echo "customButton_".$this->pluginID."_".$i ; ?>'
});
<?php } ?>
},
createControl : function(n, cm){
return null;
}
});
tinymce.PluginManager.add('<?php echo "customPluginButtons_".$this->pluginID ; ?>', tinymce.plugins.<?php echo "customPluginButtons_".$this->pluginID ; ?>);
})();
<?php
die() ;
}
}
/** ====================================================================================================================================================
* Add a javascript file in the header
*
* For instance, <code> $this->add_js('http://www.monserveur.com/wp-content/plugins/my_plugin/js/foo.js') ; </code> will add the 'my_plugin/js/foo.js' in the header.
* In order to save bandwidth and boost your website, the framework will concat all the added javascript (by this function) and serve the browser with a single js file
* Note : you have to call this function in function <code>your_function</code> called by <code>add_action('wp_print_scripts', array( $this, 'your_function'));</code>
*
* @param string $url the complete http url of the javascript (this javascript should be an internal javascript i.e. stored by your blog and not, for instance, stored by Google)
* @see pluginSedLex::add_inline_js
* @see pluginSedLex::flush_js
* @return void
*/
public function add_js($url) {
global $sedlex_list_scripts ;
if ($url=="jquery-tokenize") {
// pour le plugin tokenize jQuery
$sedlex_list_scripts[] = str_replace(plugin_dir_url("/"),WP_PLUGIN_DIR, SL_FRAMEWORK_DIR . "/core/include/tokenize/jquery.tokenize.js") ;
} else {
$sedlex_list_scripts[] = str_replace(plugin_dir_url("/"),WP_PLUGIN_DIR,$url) ;
}
}
/** ====================================================================================================================================================
* Add inline javascript in the header
*
* For instance <code> $this->add_inline_js('alert("foo");') ; </code>
* In order to save bandwidth and boost your website, the framework will concat all the added javascript (by this function) and serve the browser with a single js file
* Note : you have to call this function in function <code>your_function</code> called by <code>add_action('wp_print_scripts', array( $this, 'your_function'));</code>
*
* @param string $text the javascript to be inserted in the header (without any <script> tags)
* @see pluginSedLex::add_js
* @see pluginSedLex::flush_js
* @return void
*/
public function add_inline_js($text) {
global $sedlex_list_scripts ;
$id = sha1($text) ;
// Repertoire de stockage des css inlines
$path = WP_CONTENT_DIR."/sedlex/inline_scripts";
$path_ok = false ;
if (!is_dir($path)) {
if (@mkdir("$path", 0755, true)) {
$path_ok = true ;
} else {
SLFramework_Debug::log(get_class(), "The folder ". WP_CONTENT_DIR."/sedlex/inline_scripts"." cannot be created", 2) ;
}
} else {
$path_ok = true ;
}
// On cree le machin
if ($path_ok) {
$css_f = $path."/".$id.'.js' ;
if (!@is_file($css_f)) {
@file_put_contents($css_f, $text) ;
}
@chmod($css_f, 0755);
$sedlex_list_scripts[] = $css_f ;
} else {
echo "\n<script type='text/javascript'>\n" ;
echo $text ;
echo "\n</script>\n" ;
}
}
/** ====================================================================================================================================================
* Insert the 'single' javascript file in the page
* This function is not supposed to be called from your plugin. This function is called automatically once during the rendering
*
* @access private
* @see pluginSedLex::add_inline_js
* @see pluginSedLex::add_js
* @return void
*/
public function flush_js($hook) {
global $sedlex_list_scripts ;
// If it not a plugin page SL page
if (is_admin()) {
$plugin = explode("_", $hook) ;
if (!isset($plugin[count($plugin)-1])) {
return ;
}
if ($plugin[count($plugin)-1]!="sedlex") {
$plugin = explode("/", $plugin[count($plugin)-1]) ;
if ((!isset($plugin[0]))||(!@is_file(WP_PLUGIN_DIR."/".$plugin[0]."/core.class.php")))
return;
}
}
// Repertoire de stockage des css inlines
$path = WP_CONTENT_DIR."/sedlex/inline_scripts";
if (!is_dir($path)) {
if (!@mkdir("$path", 0755, true)) {
SLFramework_Debug::log(get_class(), "The folder ". WP_CONTENT_DIR."/sedlex/inline_scripts"." cannot be created", 2) ;
}
}
if (!empty($sedlex_list_scripts)) {
// We create the file if it does not exist
$out = "" ;
foreach( $sedlex_list_scripts as $file ) {
if (@is_file($file)) {
$out .= "\n/*====================================================*/\n";
$out .= "/* FILE ".str_replace(WP_CONTENT_DIR,"",$file) ."*/\n";
$out .= "/*====================================================*/\n";
$out .= @file_get_contents($file) . "\n";
} else {
$out .= "\n/*====================================================*/\n";
$out .= "/* FILE NOT FOUND ".str_replace(WP_CONTENT_DIR,"",$file) ."*/\n";
$out .= "/*====================================================*/\n";
}
}
$md5 = sha1($out) ;
if (!@is_file(WP_CONTENT_DIR."/sedlex/inline_scripts/".$md5.".js")) {
@file_put_contents(WP_CONTENT_DIR."/sedlex/inline_scripts/".$md5.".js", $out) ;
}
@chmod(WP_CONTENT_DIR."/sedlex/inline_scripts/".$md5.".js", 0755);
//$url = plugin_dir_url("/").'/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__)).'core/load-scripts.php?c=0&load='.$md5 ;
$url = content_url("/").'sedlex/inline_scripts/'.$md5.".js" ;
wp_enqueue_script('sedlex_scripts', $url, array() ,date('Ymd'));
$sedlex_list_scripts = array();
}
}
/** ====================================================================================================================================================
* Insert the admin javascript files which is located in the core (you may NOT modify these files)
* This function is not supposed to be called from your plugin. This function is called automatically when you are in the admin page of the plugin
*
* @access private
* @return void
*/
public function javascript_admin($hook) {
global $sedlex_adminJavascript_tobedisplayed ;
// If it not a plugin page SL page
$plugin = explode("_", $hook) ;
if (!isset($plugin[count($plugin)-1])) {
return ;
}
if ($plugin[count($plugin)-1]!="sedlex") {
$plugin = explode("/", $plugin[count($plugin)-1]) ;
if ((!isset($plugin[0]))||(!@is_file(WP_PLUGIN_DIR."/".$plugin[0]."/core.class.php")))
return;
}
if ($sedlex_adminJavascript_tobedisplayed) {
$sedlex_adminJavascript_tobedisplayed = false ;
// For the tabs of the admin page
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core', '', array('jquery'), false );
wp_enqueue_script('jquery-ui-dialog', '', array('jquery'), false );
wp_enqueue_script('jquery-ui-tabs', '', array('jquery'), false );
wp_enqueue_script('jquery-ui-sortable', '', array('jquery'), false );
wp_enqueue_script('jquery-ui-effects', '', array('jquery', 'jquery-ui'), false );
// Pour accéder au media library
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
echo '<script> addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!=\'function\'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};</script>'."\r\n" ;
@chmod(WP_PLUGIN_DIR.'/'.str_replace(basename( __FILE__),"",plugin_basename( __FILE__)) .'core/js/', 0755);
$dir = @opendir(WP_PLUGIN_DIR.'/'.str_replace(basename( __FILE__),"",plugin_basename( __FILE__)) .'core/js/');
if ($dir !== false) {
while($file = readdir($dir)) {
if (preg_match('@\.js$@i',$file)) {
$path = WP_PLUGIN_DIR.'/'.str_replace(basename( __FILE__),"",plugin_basename( __FILE__)) .'core/js/'.$file ;
$url = plugin_dir_url("/").'/'.str_replace(basename( __FILE__),"",plugin_basename( __FILE__)) .'core/js/'.$file ;
if (@filesize($path)>0) {
$this->add_js($url) ;
}
}
}
}
// pour le plugin tokenize jQuery
$this->add_js("jquery-tokenize") ;
}
$name = 'js/js_admin.js' ;
$url = plugin_dir_url("/").'/'.str_replace(basename( $this->path),"",plugin_basename($this->path)) .$name ;
$path = WP_PLUGIN_DIR.'/'.str_replace(basename( $this->path),"",plugin_basename($this->path)) .$name ;
if (file_exists($path)) {
if (@filesize($path)>0) {
$this->add_js($url) ;
}
}
}
/** ====================================================================================================================================================
* Insert the admin javascript file which is located in js/js_front.js (you may modify this file in order to customize the rendering)
* This function is not supposed to be called from your plugin. This function is called automatically.
*
* @access private
* @return void
*/
public function javascript_front() {
$name = 'js/js_front.js' ;
$url = plugin_dir_url("/").'/'.str_replace(basename( $this->path),"",plugin_basename($this->path)) .$name ;
$path = WP_PLUGIN_DIR.'/'.str_replace(basename( $this->path),"",plugin_basename($this->path)) .$name ;
if (file_exists($path)) {
if (@filesize($path)>0) {
$this->add_js($url) ;
}
}
}
/** ====================================================================================================================================================
* Add a CSS file in the header
*
* For instance, <code>$this->add_css('http://www.monserveur.com/wp-content/plugins/my_plugin/js/foo.css') ;</code> will add the 'my_plugin/js/foo.css' in the header.