Repository navigation
Expand file tree
/
Copy path_test.plugin.php
More file actions
3498 lines (3033 loc) · 114 KB
/
Copy path_test.plugin.php
File metadata and controls
3498 lines (3033 loc) · 114 KB
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
/**
* This file implements the TEST plugin.
*
* For the most recent and complete Plugin API documentation
* see {@link Plugin} in ../inc/plugins/_plugin.class.php.
*
* This file is part of the evoCore framework - {@link http://evocore.net/}
* See also {@link https://github.com/b2evolution/b2evolution}.
*
* @license GNU GPL v2 - {@link http://b2evolution.net/about/gnu-gpl-license}
*
* @copyright (c)2003-2020 by Francois Planque - {@link http://fplanque.com/}
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
*
* @package plugins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* TEST Plugin
*
* This plugin responds to virtually all possible plugin events :P
*
* @package plugins
*/
class test_plugin extends Plugin
{
/**
* Variables below MUST be overriden by plugin implementations,
* either in the subclass declaration or in the subclass constructor.
*/
var $name = 'Test';
var $code = 'evo_TEST';
var $priority = 50;
var $version = '7.2.5';
var $author = 'The b2evo Group';
var $help_url = ''; // empty URL defaults to manual wiki
/*
* These variables MAY be overriden.
*/
var $number_of_installs = 1;
var $group = 'rendering';
/**
* Init
*
* This gets called after a plugin has been registered/instantiated.
*/
function PluginInit( & $params )
{
$this->short_desc = T_('Test plugin');
$this->long_desc = T_('This plugin responds to virtually all possible plugin events :P');
// Trigger plugin settings instantiation (for testing).
if( $params['is_installed'] )
{
$this->Settings->get('foo');
}
}
/**
* Define the GLOBAL settings of the plugin here. These can then be edited in the backoffice in System > Plugins.
*
* @see Plugin::GetDefaultSettings()
* @param array Associative array of parameters (since v1.9).
* 'for_editing': true, if the settings get queried for editing;
* false, if they get queried for instantiating {@link Plugin::$Settings}.
* @return array see {@link Plugin::GetDefaultSettings()}.
* The array to be returned should define the names of the settings as keys (max length is 30 chars)
* and assign an array with the following keys to them (only 'label' is required):
*/
function GetDefaultSettings( & $params )
{
$r = array(
'click_me' => array(
'label' => 'Click me!',
'defaultvalue' => '1',
'type' => 'checkbox',
),
'input_me' => array(
'label' => 'How are you?',
'defaultvalue' => '',
'note' => 'Welcome to b2evolution',
),
'number' => array(
'label' => 'Number',
'defaultvalue' => '8',
'note' => '1-9',
'valid_range' => array( 'min'=>1, 'max'=>9 ),
),
'my_select' => array(
'label' => 'Selector',
'id' => $this->classname.'_my_select_id',
'class' => $this->classname.'_my_select_class',
'onchange' => 'document.getElementById("'.$this->classname.'_a_disabled_one").disabled = ( this.value == "sun" );',
'defaultvalue' => 'one',
'type' => 'select',
'options' => array( 'sun' => 'Sunday', 'mon' => 'Monday' ),
'note' => 'This combo is connected with the next field',
),
'a_disabled_one' => array(
'label' => 'This one is disabled',
'id' => $this->classname.'_a_disabled_one',
'type' => 'checkbox',
'defaultvalue' => '1',
'disabled' => true, // this can be useful if you detect that something cannot be changed. You probably want to add a 'note' then, too.
'note' => 'Change the above select input to "Monday" to enable it.',
),
'select_multiple' => array(
'label' => $this->T_( 'Multiple select' ),
'type' => 'select',
'multiple' => true,
'allow_none' => true,
'options' => array( 'sci' => $this->T_( 'Scissors' ), 'pap' => $this->T_( 'Paper' ), 'sto' => $this->T_( 'Stone') ),
'defaultvalue' => array( 'sci', 'sto' ),
'note' => $this->T_( 'This is a free style Multiple Select. You can choose zero or one or more items' )
),
/*
* note: The $this->T_( string )function tanslates the string.
* However since it inherits from the class Plugin you will need
* to provide the translation on a per plugin basis. In other
* words: this will not be translated through B2evolution.
*/
'blog' => array(
'label' => 'A blog',
'type' => 'select_blog', // TODO: does not scale with 500 blogs
'allow_none' => true,
),
'blogs' => array(
'label' => 'A set of blogs',
'type' => 'select_blog', // TODO: BROKEN + does not scale with 500 blogs
'multiple' => true,
'allow_none' => true,
),
'single_user' => array(
'label' => 'A single user',
'type' => 'select_user',
'users_limit' => 5,
'allow_none' => true,
'defaultvalue' => 0,
'note' => 'Allows chosing none or one user'
),
'sets' => array(
'label' => 'Multiple users',
'type' => 'select_user',
'users_limit' => 10,
'min_count' => 0,
'max_count' => 3,
'multiple' => 'true',
'allow_none' => true,
'note' => 'Allows none or one or more than one user (up to three in this example)',
'entries' => array(
'user' => array(
'label' => 'A user',
'type' => 'select_user', // TODO: does not scale with 500 users
'allow_none' => true,
),
),
),
'maxlen' => array(
'label' => 'Max',
'type' => 'textarea',
'maxlength' => 10,
'note' => 'Maximum length is 10 here.',
),
'plug_color' => array(
'label' => 'Plugin color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#F60',
),
);
if( $params['for_editing'] )
{ // we're asked for the settings for editing:
if( $this->Settings->get('my_select') == 'mon' )
{
$r['a_disabled_one']['disabled'] = false;
}
}
return $r;
}
/**
* Define here default custom settings that are to be made available
* in the backoffice for collections, private messages and newsletters.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::get_custom_setting_definitions()}.
*/
function get_custom_setting_definitions( & $params )
{
return array(
'custom' => array(
'label' => 'Custom setting',
'note' => 'Custom plugin setting for collections, private messages and newsletters.',
'defaultvalue' => 'Custom value',
),
'custom_color' => array(
'label' => 'Custom color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#033',
),
);
}
/**
* Define here default collection/blog settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::get_coll_setting_definitions()}.
*/
function get_coll_setting_definitions( & $params )
{
$default_params = array_merge( $params,
array(
'default_comment_rendering' => 'stealth',
'default_post_rendering' => 'opt-out'
)
);
$r = array_merge( parent::get_coll_setting_definitions( $default_params ),
array(
'coll_custom' => array(
'label' => 'Collection setting',
'note' => 'Custom plugin setting ONLY for collections.',
'defaultvalue' => 'Collection value',
),
'coll_color' => array(
'label' => 'Collection color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#0C9',
),
)
);
return $r;
}
/**
* Define here default message settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::GetDefaultSettings()}.
*/
function get_msg_setting_definitions( & $params )
{
// set params to allow rendering for messages by default
$default_params = array_merge( $params, array( 'default_msg_rendering' => 'stealth' ) );
$r = array_merge( parent::get_msg_setting_definitions( $default_params ),
array(
'custom_msg' => array(
'label' => 'Message setting',
'note' => 'Custom plugin setting ONLY for messages.',
'defaultvalue' => 'Message value',
),
'msg_color' => array(
'label' => 'Message color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#393',
),
)
);
return $r;
}
/**
* Define here default email settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::GetDefaultSettings()}.
*/
function get_email_setting_definitions( & $params )
{
// set params to allow rendering for emails by default:
$default_params = array_merge( $params, array( 'default_email_rendering' => 'stealth' ) );
$r = array_merge( parent::get_email_setting_definitions( $default_params ),
array(
'custom_email' => array(
'label' => 'Email setting',
'note' => 'Custom plugin setting ONLY for emails.',
'defaultvalue' => 'Email value',
),
'email_color' => array(
'label' => 'Email color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#DDF',
),
)
);
return $r;
}
/**
* Define here default shared settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::GetDefaultSettings()}.
*/
function get_shared_setting_definitions( & $params )
{
// set params to allow rendering for shared container widgets by default:
$default_params = array_merge( $params, array( 'default_shared_rendering' => 'stealth' ) );
$r = array_merge( parent::get_shared_setting_definitions( $default_params ),
array(
'custom_shared' => array(
'label' => 'Shared setting',
'note' => 'Custom plugin setting ONLY for shared container widgets.',
'defaultvalue' => 'Shared value',
),
'shared_color' => array(
'label' => 'Shared color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#DDF',
),
)
);
return $r;
}
/**
* Get definitions for widget specific editable params
*
* @see Plugin::GetDefaultSettings()
* @param array Local params like 'for_editing' => true
* @return array
*/
function get_widget_param_definitions( $params )
{
$r = array(
'title' => array(
'label' => T_('Block title'),
'note' => T_('Title to display in your skin.'),
'size' => 60,
'defaultvalue' => 'Test plugin widget',
),
'widget_color' => array(
'label' => 'Widget color',
'type' => 'color',
'note' => 'Click on the field to display a color selector.',
'defaultvalue' => '#F66',
),
);
return $r;
}
/**
* Get keys for block/widget caching
*
* Maybe be overriden by some widgets, depending on what THEY depend on..
*
* @param integer Widget ID
* @return array of keys this widget depends on
*/
function get_widget_cache_keys( $widget_ID = 0 )
{
global $Blog;
return array(
'wi_ID' => $widget_ID, // Have the widget settings changed ?
'set_coll_ID' => $Blog->ID, // Have the settings of the blog changed ? (ex: new skin)
'cont_coll_ID' => empty( $this->disp_params['blog_ID'] ) ? $Blog->ID : $this->disp_params['blog_ID'], // Has the content of the displayed blog changed ?
);
}
/**
* Define the PER-USER settings of the plugin here. These can then be edited by each user.
*
* You can access them in the plugin through the member object
* {@link $UserSettings}, e.g.:
* <code>$this->UserSettings->get( 'my_param' );</code>
*
* This method behaves exactly like {@link Plugin::GetDefaultSettings()},
* except that it defines user specific settings instead of global settings.
*
* @todo 3.0 fp> 1) This is not an event: RENAME to lowercase (in b2evo 3.0)
* @todo 3.0 fp> 2) This defines more than Default values :: confusing name
* @todo name tentative get_user_param_definitions()
*
* @see Plugin::GetDefaultUserSettings()
* @param array Associative array of parameters.
* 'for_editing': true, if the settings get queried for editing;
* false, if they get queried for instantiating {@link Plugin::$UserSettings}.
* @return array See {@link Plugin::GetDefaultSettings()}.
*/
function GetDefaultUserSettings( & $params )
{
return array(
'echo_random' => array(
'label' => 'Echo a random number in AdminBeginPayload event',
'type' => 'checkbox',
'defaultvalue' => '0',
),
'deactivate' => array(
'label' => 'Deactivate',
'type' => 'checkbox',
'defaultvalue' => '0',
),
);
}
/**
* Get the list of dependencies that the plugin has.
*
* This gets checked on install or uninstall of a plugin.
*
* There are two <b>classes</b> of dependencies:
* - 'recommends': This is just a recommendation. If it cannot get fulfilled
* there will just be a note added on install.
* - 'requires': A plugin cannot be installed if the dependencies cannot get
* fulfilled. Also, a plugin cannot get uninstalled, if another
* plugin depends on it.
*
* Each <b>class</b> of dependency can have the following types:
* - 'events_by_one': A list of eventlists that have to be provided by a single plugin,
* e.g., <code>array( array('RequestCaptcha', 'ValidateCaptcha') )</code>
* to look for a plugin that provides both events.
* - 'plugins':
* A list of plugins, either just the plugin's classname or an array with
* classname and minimum version of the plugin (see {@link Plugin::$version}).
* E.g.: <code>array( 'test_plugin', '1' )</code> to require at least version "1"
* of the test plugin.
* - 'app_min': Minimum application (b2evo) version, e.g. "1.9".
* This way you can make sure that the hooks you need are implemented
* in the core.
* (Available since b2evo 1.8.3. To make it work before 1.8.2 use
* "api_min" and check for array(1, 2) (API version of 1.9)).
* - 'api_min': You can require a specific minimum version of the Plugins API here.
* If it's just a number, only the major version is checked against.
* To check also for the minor version, you have to give an array:
* array( major, minor ).
* Obsolete since 1.9! Used API versions: 1.1 (b2evo 1.8.1) and 1.2 (b2evo 1.9).
*
* @see Plugin::GetDependencies()
* @return array
*/
function GetDependencies()
{
return array(
'recommends' => array(
'events_by_one' => array( array('Foo', 'Bar'), array('FooBar', 'BarFoo') ), // a plugin that provides "Foo" and "Bar", and one (may be the same) that provides "FooBar" and "BarFoo"
'events' => array( 'some_event', 'some_other_event' ),
'plugins' => array( array( 'some_plugin', '1' ) ), // at least version 1 of some_plugin
),
'requires' => array(
// Same syntax as with the 'recommends' class above, but would prevent the plugin from being installed.
),
);
}
/**
* This method should return your DB schema, consisting of a list of CREATE TABLE
* queries.
*
* The DB gets changed accordingly on installing or enabling your Plugin.
*
* If you want to change your DB layout in a new version of your Plugin, simply
* adjust the queries here and increase {@link Plugin::$version}, because this will
* request to check the current DB layout against the one you require.
*
* For restrictions see {@link db_delta()}.
*
* @see Plugin::GetDbLayout()
*/
function GetDbLayout()
{
global $DB;
return array(
'CREATE TABLE '.$this->get_sql_table( 'test_table_name' ).' (
test_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
test_name VARCHAR( 255 ) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY( test_ID )
) ENGINE = innodb DEFAULT CHARSET = '.$DB->get_connection_charset()
);
}
/**
* This method gets asked when plugins get installed and allows you to return a list
* of extra events, which your plugin triggers itself (e.g. through
* {@link $Plugins->trigger_event()}).
*
* NOTE: PLEASE use a distinct prefix for the event name, e.g. "$this->classname".
*
* NOTE: The length of event names is limited to 40 chars.
*
* NOTE: Please comment the params and the return value here with the list
* that you return. Only informal as comment, but makes it easier for
* others.
*
* @see Plugin::GetExtraEvents()
* @return NULL|array "event_name" => "description"
*/
function GetExtraEvents()
{
return array(
// Gets "min" and "max" as params and should return a random number in between:
'test_plugin_get_random' => 'TEST event that returns a random number.',
);
}
/**
* Gets provided as plugin event (and gets also used internally for demonstration).
*
* @param array Associative array of parameters
* 'min': mininum number
* 'max': maxinum number
* @return integer
*/
function test_plugin_get_random( & $params )
{
return rand( $params['min'], $params['max'] );
}
/**
* Return list of custom disp types handled by this plugin
*
* @see Plugin::GetHandledDispModes()
* @return array list of disp modes handled by this plugin
*/
function GetHandledDispModes()
{
return array(
'disp_test', // display our test disp
);
}
/**
* Display our custom disp mode(s)
*
* @see Plugin::HandleDispMode()
* @param mixed array $params
* disp > display mode requested
* @return did we display?
*/
function HandleDispMode( $params )
{
echo '<p>This is the test plugin handling the ['.$params['disp'].'] disp mode.</p>';
}
/**
* Override this method to define methods/functions that you want to make accessible
* through /htsrv/call_plugin.php, which allows you to call those methods by HTTP request.
*
* This is useful for things like AJAX or displaying an IFRAME element, where the content
* should get provided by the plugin itself.
*
* E.g., the image captcha plugin uses this method to serve a generated image.
*
* NOTE: the Plugin's method must be prefixed with "htsrv_", but in this list (and the URL) it
* is not. E.g., to have a method "disp_image" that should be callable through this method
* return <code>array('disp_image')</code> here and implement it as
* <code>function htsrv_disp_image( $params )</code> in your plugin.
* This is used to distinguish those methods from others, but keep URLs nice.
*
* @see Plugin::GetHtsrvMethods()
* @return array
*/
function GetHtsrvMethods()
{
return array( 'test_action' );
}
/**
* AJAX callback to test action.
*
* @param array Params
*/
function htsrv_test_action( $params )
{
global $DB;
// To call this action use URL which is generated by code:
// $htsrv_plugin_url = $this->get_htsrv_url( 'test_action', array( 'param_1' => 'value_1' ) );
if( empty( $params['param_1'] ) )
{ // Nothing to do:
return;
}
$param2 = param( 'param2', 'string' );
$DB->query( 'INSERT INTO '.$this->get_sql_table( 'test_table_name' ).'
( test_name ) VALUES ( '.$DB->quote( 'param_1 = '.$params['param_1'].'; param2 = '.$param2 ).' ) ' );
}
/**
* This method gets asked for a list of cronjobs that the plugin
* provides.
* If a user installs a cron job out of this list, the
* {@link Plugin::ExecCronJob()} of the plugin gets called.
*
* @see Plugin::GetCronJobs()
* @return array Array of arrays with keys "name", "ctrl" and "params".
* "name" gets used for display. "ctrl" (string) and
* "params" (array) get passed to the
* {@link Plugin::ExecCronJob()} method when the cronjob
* gets executed.
*/
function GetCronJobs( & $params )
{
return array(
array(
'name' => 'TEST plugin - cron job',
'ctrl' => 'test_job',
'params' => array( 'param' => 1 ),
),
);
}
/**
* Execute/handle a cron job, which has been scheduled by the admin out
* of the list that the Plugin provides (see {@link GetCronJobs()}).
*
* @see Plugin::ExecCronJob()
* @param array Associative array of parameters
* - 'ctrl': The "ctrl" name as defined in {@link GetCronJobs()}
* - 'params': The "params" value as defined in {@link GetCronJobs()},
* plus "ctsk_ID" which holds the cron task ID.
* @return array with keys "code" (integer, 1 is ok), "message" (gets logged)
*/
function ExecCronJob( & $params )
{
if( $params['ctrl'] == 'test_job' )
{
return array( 'code' => 1, 'message' => 'Test successful.' );
}
}
// }}}
/*
* Event handlers. These are meant to be implemented by your plugin. {{{
*/
// Admin/backoffice events (without events specific to Items or Comments): {{{
/**
* Event handler: Gets invoked in /toolbar.inc.php after the menu structure is built.
*
* @see Plugin::AdminAfterEvobarInit()
*/
function AdminAfterEvobarInit()
{
// The following is a tiny bit hackish and should probably be abstracted a bit, but just a little bit
// The idea is too let plugins hook pretty much anywhere into the menu structure, including Left AND Right menus.
global $topleft_Menu;
$topleft_Menu->add_menu_entries( 'tools', array(
'urls_sep' => array(
'separator' => true,
),
'urls' => array(
'text' => 'Test plugin…',
'href' => $this->get_tools_tab_url(),
),
) );
}
/**
* Event handler: Gets invoked in /evoadm.php for every backoffice page after
* the menu structure is built. You could use the {@link $AdminUI} object
* to modify it.
*
* This is the hook to register menu entries. See {@link register_menu_entry()}.
*
* @see Plugin::AdminAfterMenuInit()
*/
function AdminAfterMenuInit()
{
$this->register_menu_entry( 'Test tab' );
}
/**
* Event handler: Called when ending the admin html head section.
*
* @see Plugin::AdminEndHtmlHead()
* @param array Associative array of parameters
* @return boolean did we do something?
*/
function AdminEndHtmlHead( & $params )
{
echo '<!-- This comment was added by the TEST plugin event "AdminEndHtmlHead" with function "echo" -->';
add_headline( '<!-- This comment was added by the TEST plugin event "AdminEndHtmlHead" with function "add_headline"-->' );
add_js_headline( 'console.log( "This JavaScript log was added by the TEST plugin event \'AdminEndHtmlHead\' with function \'add_js_headline\'" )' );
add_css_headline( '/* This CSS was added by the TEST plugin event \'AdminEndHtmlHead\' with function "add_css_headline" */' );
return true;
}
/**
* Event handler: Called right after displaying the admin page footer.
*
* @see Plugin::AdminAfterPageFooter()
* @param array Associative array of parameters
* @return boolean did we do something?
*/
function AdminAfterPageFooter( & $params )
{
echo '<p class="footer">This is the TEST plugin responding to the AdminAfterPageFooter event!</p>';
return true;
}
/**
* Event handler: Called when displaying editor buttons (in back-office).
*
* This method, if implemented, should output the buttons (probably as html INPUT elements)
* and return true, if button(s) have been displayed.
*
* You should provide an unique html ID with each button.
*
* @see Plugin::AdminDisplayEditorButton()
* @param array Associative array of parameters.
* - 'target_type': either 'Comment' or 'Item' or 'EmailCampaign'.
* - 'edit_layout': "inskin", "expert", etc. (users, hackers, plugins, etc. may create their own layouts in addition to these)
* NOTE: Please respect the "inskin" mode, which should display only the most simple things!
* @return boolean did we display a button?
*/
function AdminDisplayEditorButton( & $params )
{
?>
<input type="button" value="TEST" onclick="alert('Hi! This is the TEST plugin (AdminDisplayEditorButton)!');" class="btn btn-default" />
<?php
return true;
}
/**
* Event handler: Called when displaying editor buttons (in front-office).
*
* This method, if implemented, should output the buttons (probably as html INPUT elements)
* and return true, if button(s) have been displayed.
*
* You should provide an unique html ID with each button.
*
* @see Plugin::DisplayEditorButton()
* @param array Associative array of parameters.
* - 'target_type': either 'Comment' or 'Item'.
* - 'edit_layout': "inskin", "expert", etc. (users, hackers, plugins, etc. may create their own layouts in addition to these)
* NOTE: Please respect the "inskin" mode, which should display only the most simple things!
* @return boolean did we display a button?
*/
function DisplayEditorButton( & $params )
{
?>
<input type="button" value="TEST" onclick="alert('Hi! This is the TEST plugin (DisplayEditorButton)!');" class="btn btn-default" />
<?php
return true;
}
/**
* Event handler: Called when displaying editor toolbars on post/item form.
*
* This is for post/item edit forms only. Comments, PMs and emails use different events.
*
* @see Plugin::AdminDisplayToolbar()
* @param array Associative array of parameters
* - 'edit_layout': "inskin", "expert", etc. (users, hackers, plugins, etc. may create their own layouts in addition to these)
* NOTE: Please respect the "inskin" mode, which should display only the most simple things!
* @return boolean did we display a toolbar?
*/
function AdminDisplayToolbar( & $params )
{
echo $this->get_template( 'toolbar_before', array( '$toolbar_class$' => $this->code.'_toolbar' ) );
echo $this->get_template( 'toolbar_title_before' );
echo 'TEST toolbar for Item:';
echo $this->get_template( 'toolbar_title_after' );
echo $this->get_template( 'toolbar_group_before' );
echo '<input type="button" class="'.$this->get_template( 'toolbar_button_class' ).'" value="TEST 1" onclick="alert(\'TEST 1\')" />';
echo '<input type="button" class="'.$this->get_template( 'toolbar_button_class' ).'" value="TEST 2" onclick="alert(\'TEST 2\')" />';
echo $this->get_template( 'toolbar_group_after' );
echo $this->get_template( 'toolbar_group_before' );
echo '<input type="button" class="'.$this->get_template( 'toolbar_button_class' ).'" value="TEST 3" onclick="alert(\'TEST 3 from second group\')" />';
echo $this->get_template( 'toolbar_group_after' );
echo $this->get_template( 'toolbar_after' );
return true;
}
/**
* Event handler: Called when handling actions for the "Tools" menu.
*
* Use {@link msg()} to add messages for the user.
*
* @see Plugin::AdminToolAction()
*/
function AdminToolAction()
{
$this->msg( 'Hello, This is the AdminToolAction for the TEST plugin.' );
}
/**
* Event handler: Called when displaying the block in the "Tools" menu.
*
* @see Plugin::AdminToolPayload()
* @return boolean did we display something?
*/
function AdminToolPayload()
{
echo 'Hello, This is the AdminToolPayload for the TEST plugin.';
return true;
}
/**
* Event handler: Method that gets invoked when our tab is selected.
*
* You should catch (your own) params (using {@link param()}) here and do actions
* (but no output!).
*
* Use {@link msg()} to add messages for the user.
*
* @see Plugin::AdminTabAction()
*/
function AdminTabAction()
{
global $Plugins;
$this->text_from_AdminTabAction = '<p>This is text from AdminTabAction for the TEST plugin.</p>'
.'<p>Here is a random number: '
.$Plugins->get_trigger_event_first_return('test_plugin_get_random', array( 'min'=>-1000, 'max'=>1000 )).'</p>';
if( $this->param_text = param( $this->get_class_id('text') ) )
{
$this->text_from_AdminTabAction .= '<p>You have said: '.$this->param_text.'</p>';
}
}
/**
* Event handler: Gets invoked when our tab is selected and should get displayed.
*
* Do your output here.
*
* @see Plugin::AdminTabPayload()
* @return boolean did we display something?
*/
function AdminTabPayload()
{
echo 'Hello, this is the AdminTabPayload for the TEST plugin.';
echo $this->text_from_AdminTabAction;
// TODO: this is tedious.. should either be a global function (get_admin_Form()) or a plugin helper..
$Form = new Form();
$Form->begin_form();
$Form->add_crumb( 'plugin_test' );
$Form->hidden_ctrl(); // needed to pass the "ctrl=tools" param
$Form->hiddens_by_key( get_memorized() ); // needed to pass all other memorized params, especially "tab"
$Form->text_input( $this->get_class_id().'_text', $this->param_text, '20', 'Text' );
$Form->button_input(); // default "submit" button
$Form->end_form();
return true;
}
/**
* Event handler: Gets invoked before the main payload in the backoffice.
*
* @see Plugin::AdminBeginPayload()
*/
function AdminBeginPayload()
{
global $Plugins;
echo '<div class="panelblock center">TEST plugin: AdminBeginPayload event.</div>';
if( $this->UserSettings->get('echo_random') )
{
echo '<div class="panelblock center">TEST plugin: A random number requested by user setting: '
.$Plugins->get_trigger_event_first_return('test_plugin_get_random', array( 'min'=>0, 'max'=>1000 ) ).'</div>';
}
}
/**
* Event handler: Called at the beginning of the "Edit wdiget" form on back-office.
*
* @param array Associative array of parameters
* - 'Form': the {@link Form} object (by reference)
* - 'ComponentWidget': the Widget which gets edited (by reference)
* @return boolean did we display something?
*/
function WidgetBeginSettingsForm( & $params )
{
$params['Form']->begin_fieldset( 'TEST plugin', array( 'id' => 'WidgetBeginSettingsForm' ) );
$params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the WidgetBeginSettingsForm event for widget #'.$params['ComponentWidget']->ID.'.' );
$params['Form']->end_fieldset( 'Foo' );
return true;
}
/**
* Event handler: Called at the end of the "Edit wdiget" form on back-office.
*
* @param array Associative array of parameters
* - 'Form': the {@link Form} object (by reference)
* - 'ComponentWidget': the Widget which gets edited (by reference)
* @return boolean did we display something?
*/
function WidgetEndSettingsForm( & $params )
{
$params['Form']->begin_fieldset( 'TEST plugin', array( 'id' => 'WidgetEndSettingsForm' ) );
$params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the WidgetEndSettingsForm event for widget #'.$params['ComponentWidget']->ID.'.' );
$params['Form']->end_fieldset( 'Foo' );
return true;
}
// }}}
// Skin/Blog events: {{{
/**
* Event handler: Called before a blog gets displayed (in _blog_main.inc.php).
*
* @see Plugin::BeforeBlogDisplay()
*/
function BeforeBlogDisplay( & $params )
{
$this->msg( 'This is the TEST plugin responding to the BeforeBlogDisplay event.' );
}
/**
* Event handler: Gets invoked when an action request was called which should be blocked in specific cases
*
* Blocakble actions: comment post, user login/registration, email send/validation, account activation
*
* @see Plugin::BeforeBlockableAction()
*/
function BeforeBlockableAction()
{
$this->msg( 'This is the TEST plugin responding to the BeforeBlockableAction event.' );
}
/**
* Event handler: Called when a MainList object gets created.
*