forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_test.plugin.php
More file actions
1004 lines (853 loc) · 26.3 KB
/
_test.plugin.php
File metadata and controls
1004 lines (853 loc) · 26.3 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-2015 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 = '5.0.0';
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 = 'test';
/**
* 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');
}
}
/**
* Get the settings that the plugin can use.
*
* Those settings are transfered into a Settings member object of the plugin
* and can be edited in the backoffice (Settings / Plugins).
*
* @see Plugin::GetDefaultSettings()
* @see PluginSettings
* @see Plugin::PluginSettingsValidateSet()
* @return array
*/
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',
'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,
'default_value' => 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.',
),
);
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;
}
/**
* User settings.
*
* @see Plugin::GetDefaultUserSettings()
* @see PluginUserSettings
* @see Plugin::PluginUserSettingsValidateSet()
* @return array
*/
function GetDefaultUserSettings()
{
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',
),
);
}
/**
* We trigger an extra event ourself (which we also provide ourselves).
*
* @return array
*/
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.',
);
}
/**
* Define a test cron job
*/
function GetCronJobs( & $params )
{
return array(
array(
'name' => 'TEST plugin - cron job',
'ctrl' => 'test_job',
'params' => array( 'param' => 1 ),
),
);
}
/**
* Execute/Handle a test/sample cronjob.
*/
function ExecCronJob( & $params )
{
if( $params['ctrl'] == 'test_job' )
{
return array( 'code' => 1, 'message' => 'Test successful.' );
}
}
/**
* Deactive the plugin for the current request if the user wants it so.
* @see Plugin::AppendLoginRegisteredUser()
*/
function AppendLoginRegisteredUser()
{
if( $this->UserSettings->get('deactivate') )
{
$this->forget_events();
}
}
/**
* Define some dependencies.
*
* @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.
),
);
}
/**
* Gets asked for, if user settings get updated.
*
* We just add a note.
*
* @see Plugin::PluginUserSettingsUpdateAction()
*/
function PluginUserSettingsUpdateAction()
{
if( $this->UserSettings->get('echo_random') )
{
$this->msg( 'TEST plugin: Random numbers have been disabled.' );
}
else
{
$this->msg( 'TEST plugin: Random numbers have been enabled.' );
}
return true;
}
/**
* Event handlers:
*/
/**
* 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 -->';
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 toolbars.
*
* @see Plugin::AdminDisplayToolbar()
* @param array Associative array of parameters
* @return boolean did we display a toolbar?
*/
function AdminDisplayToolbar( & $params )
{
echo '<div class="edit_toolbar">This is the TEST Toolbar</div>';
return true;
}
/**
* Event handler: Called when displaying editor buttons (in back-office).
*
* @see Plugin::AdminDisplayEditorButton()
* @param array Associative array of parameters
* @return boolean did we display ?
*/
function AdminDisplayEditorButton( & $params )
{
?>
<input type="button" value="TEST" onclick="alert('Hi! This is the TEST plugin (AdminDisplayEditorButton)!');" />
<?php
return true;
}
/**
* Event handler: Called when displaying editor buttons (in front-office).
*
* @see Plugin::DisplayEditorButton()
* @param array Associative array of parameters
* @return boolean did we display ?
*/
function DisplayEditorButton( & $params )
{
?>
<input type="button" value="TEST" onclick="alert('Hi! This is the TEST plugin (DisplayEditorButton)!');" />
<?php
return true;
}
/**
* @see Plugin::AdminDisplayItemFormFieldset()
*/
function AdminDisplayItemFormFieldset( & $params )
{
$params['Form']->begin_fieldset( 'TEST plugin' );
$params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the AdminDisplayItemFormFieldset event.' );
$params['Form']->end_fieldset( 'Foo' );
}
/**
* @see Plugin::DisplayItemFormFieldset()
*/
function DisplayItemFormFieldset( & $params )
{
$params['Form']->begin_fieldset( 'TEST plugin' );
$params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the DisplayItemFormFieldset event.' );
$params['Form']->end_fieldset( 'Foo' );
}
/**
* @see Plugin::SkinBeginHtmlHead()
*/
function SkinBeginHtmlHead()
{
require_js( '#jquery#', 'blog' );
}
/**
* @see Plugin::AdminBeforeItemEditCreate()
*/
function AdminBeforeItemEditCreate( & $params )
{
$this->msg( 'This is the TEST plugin responding to the AdminBeforeItemEditCreate event.' );
}
/**
* @see Plugin::AdminBeforeItemEditUpdate()
*/
function AdminBeforeItemEditUpdate( & $params )
{
$this->msg( 'This is the TEST plugin responding to the AdminBeforeItemEditUpdate event.' );
}
/**
* @see Plugin::AdminDisplayCommentFormFieldset()
*/
function AdminDisplayCommentFormFieldset( & $params )
{
$params['Form']->begin_fieldset( 'TEST plugin' );
$params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the AdminDisplayCommentFormFieldset event.' );
$params['Form']->end_fieldset( 'Foo' );
}
/**
* 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 /admin.php for every backoffice page after
* the menu structure is built. You can 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 handling actions for the "Tools" menu.
*
* Use {@link $Messages} to add Messages for the user.
*
* @see Plugin::AdminToolAction()
*/
function AdminToolAction( $params )
{
global $Messages;
$Messages->add( 'Hello, This is the AdminToolAction for the TEST plugin.' );
}
/**
* Event handler: Called when displaying the block in the "Tools" menu.
*
* @see Plugin::AdminToolPayload()
*/
function AdminToolPayload( $params )
{
echo 'Hello, This is the AdminToolPayload for the TEST plugin.';
}
/**
* Event handler: Method that gets invoked when our tab (?tab=plug_ID_X) is selected.
*
* You should catch params (GET/POST) here and do actions (no output!).
* Use {@link $Messages} 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.
*
* @see Plugin::AdminTabPayload()
*/
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();
}
/**
* 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 when rendering item/post contents as HTML.
*
* Note: return value is ignored. You have to change $params['data'].
*
* @see Plugin::RenderItemAsHtml()
*/
function RenderItemAsHtml( & $params )
{
$params['data'] = 'TEST['.$params['data'].']TEST';
}
/**
* Event handler: Called when rendering item/post contents as XML.
*
* Note: return value is ignored. You have to change $params['data'].
*
* @see Plugin::RenderItemAsXml()
*/
function RenderItemAsXml( & $params )
{
// Do the same as with HTML:
$this->RenderItemAsHtml( $params );
}
/**
* Event handler: Called when rendering item/post contents as text.
*
* Note: return value is ignored. You have to change $params['data'].
*
* @see Plugin::RenderItemAsText()
*/
function RenderItemAsText( & $params )
{
// Do nothing.
}
/**
* Event handler: Called when displaying item/post contents as HTML.
*
* Note: return value is ignored. You have to change $params['data'].
*
* @see Plugin::DisplayItemAsHtml()
*/
function DisplayItemAsHtml( & $params )
{
$params['data'] = $params['data']."\n<br />-- test_plugin::DisplayItemAsHtml()";
}
/**
* Event handler: Called when displaying item/post contents as XML.
*
* Note: return value is ignored. You have to change $params['data'].
*
* @see Plugin::DisplayItemAsXml()
*/
function DisplayItemAsXml( & $params )
{
$params['data'] = $params['data']."\n<br />-- test_plugin::DisplayItemAsXml()";
}
/**
* Event handler: Called when displaying item/post contents as text.
*
* Note: return value is ignored. You have to change $params['data'].
*
* @see Plugin::DisplayItemAsText()
*/
function DisplayItemAsText( & $params )
{
$params['data'] = $params['data']."\n<br />-- test_plugin::DisplayItemAsText()";
}
/**
* Wrap a to be displayed IP address.
* @see Plugin::FilterIpAddress()
*/
function FilterIpAddress( & $params )
{
$params['data'] = '[[IP:'.$params['data'].' (TEST plugin)]]';
}
/**
* Event handler: Called before the plugin is installed.
* @see Plugin::BeforeInstall()
*/
function BeforeInstall()
{
global $Plugins;
$this->msg( 'TEST plugin: BeforeInstall event.' );
return true;
}
/**
* Event handler: Called when the plugin has been installed.
* @see Plugin::AfterInstall()
*/
function AfterInstall()
{
$this->msg( 'TEST plugin sucessfully installed. All the hard work we did was adding this message in the AfterInstall event.. ;)' );
}
/**
* Event handler: Called before the plugin is going to be un-installed.
* @see Plugin::BeforeUninstall()
*/
function BeforeUninstall()
{
$this->msg( 'TEST plugin sucessfully un-installed. All the hard work we did was adding this message.. ;)' );
return true;
}
/**
* Event handler: called when a new user has registered.
* @see Plugin::AfterUserRegistration()
*/
function AfterUserRegistration( $params )
{
$this->msg( 'The TEST plugin welcomes the new user '.$params['User']->dget('login').'!' );
}
/**
* Event handler: Called at the end of the "Login" form.
* @see Plugin::DisplayLoginFormFieldset()
*/
function DisplayLoginFormFieldset( & $params )
{
$params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin hooking the DisplayLoginFormFieldset event.' );
}
/**
* Event handler: Called when a user tries to login.
* @see Plugin::LoginAttempt()
*/
function LoginAttempt()
{
$this->msg( 'This is the TEST plugin responding to the LoginAttempt event.', 'note' );
}
/**
* Event handler: Do we need a raw password in {@link LoginAttempt()}?
* @see Plugin::LoginAttemptNeedsRawPassword()
*/
function LoginAttemptNeedsRawPassword()
{
return false; // No we don't need raw. (do not implement this method if the answer is no)
}
/**
* Automagically login every user as "demouser" who is not logged in and does not
* try to currently.
*
* To enable/test it, change the "if-0" check below to "if( 1 )".
*
* @see Plugin::AlternateAuthentication()
*/
function AlternateAuthentication()
{
if( 0 ) // you should only enable it for test purposes, because it automagically logs every user in as "demouser"!
{
global $Session, $Messages;
$UserCache = & get_UserCache();
if( $demo_User = & $UserCache->get_by_login('demouser') )
{ // demouser exists:
$Session->set_User( $demo_User );
$Messages->add( 'Logged in as demouser.', 'success' );
return true;
}
}
}
/**
* @see Plugin::DisplayValidateAccountFormFieldset()
*/
function DisplayValidateAccountFormFieldset( & $params )
{
$params['Form']->info( 'TEST plugin', 'This is the TEST plugin responding to the ValidateAccountFormSent event.' );
}
/**
* 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
*
* @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)
*
* @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>';
}
/**
* @see Plugin::BeforeSessionsDelete()
*/
function BeforeSessionsDelete( $params )
{
$this->debug_log('BeforeSessionsDelete: Could have prevented the deletion of all sessions older than ' ).date('Y-m-d H:i:s', $params['cutoff_timestamp' ] );
return;
}
/**
* Event handler: Defines blog kinds, their names and description.
* Define blog settings in {@link Plugin::InitCollectionKinds()} method of your plugin.
*
* Note: You can change default blog kinds $params['default_kinds'] (which get passed by reference).
*
* @param array Associative array of parameters
* - 'kinds': dafault blog kinds (by reference)
* @retun: array
*/
function GetCollectionKinds( & $params )
{
$params['kinds'] = array_merge( $params['kinds'], array(
'test_kind' => array(
'name' => 'Just another blog type',
'desc' => 'This is the TEST plugin handling the GetCollectionKinds event.',
),
'std' => array( // override standard blog settings
'name' => 'Non-standard blog',
'desc' => 'Description is changed by TEST plugin.',
),
) );
return $params['kinds'];
}
/**
* Event handler: Defines blog settings by its kind. Use {@link get_collection_kinds()} to return
* an array of available blog kinds and their names.
* Define new blog kinds in {@link Plugin::GetCollectionKinds()} method of your plugin.
*
* Note: You have to change $params['Blog'] (which gets passed by reference).
*
* @param array Associative array of parameters
* - 'Blog': created Blog (by reference)
* - 'kind': the kind of created blog (by reference)
*/
function InitCollectionKinds( & $params )
{
// Load blog functions
load_funcs( 'collections/model/_blog.funcs.php' );
// Get all available blog kinds
$kinds = get_collection_kinds();
switch( $params['kind'] )
{
case 'std': // override standard blog settings
$params['Blog']->set( 'name', $kinds[$params['kind']]['name'] );
break;
case 'test_kind':
$params['Blog']->set( 'name', $kinds[$params['kind']]['name'] );
$params['Blog']->set( 'shortname', 'Test blog' );
break;
}
}
/**
* Event handler: called at the end of {@link DataObject::dbinsert() inserting an object in the database}.
*
* @param array Associative array of parameters
* - 'Object': the related Object (by reference)
* - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)
*/
function AfterObjectInsert( & $params )
{
$this->msg( sprintf('This is the TEST plugin responding to the AfterObjectInsert event. You have just created new [%s]', $params['type']), 'note' );
}
/**
* Event handler: called at the end of {@link DataObject::dbupdate() updating an object in the database}.
*
* @param array Associative array of parameters
* - 'Object': the related Object (by reference)
* - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)
*/
function AfterObjectUpdate( & $params )
{
$this->msg( sprintf('This is the TEST plugin responding to the AfterObjectUpdate event. You have just changed a [%s]', $params['type']), 'note' );
}
/**
* Event handler: called at the end of {@link DataObject::dbdelete() deleting an object from the database}.
*
* @param array Associative array of parameters
* - 'Object': the related Object (by reference)
* - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)
*/
function AfterObjectDelete( & $params )
{
$this->msg( sprintf('This is the TEST plugin responding to the AfterObjectDelete event. You have just deleted a [%s]', $params['type']), 'note' );
}
/**
* Event handler: Called when a MainList object gets created.
*
* Note: you must create your own MainList object here, set filters and query the database, see init_MainList() for detailes.
*
* @param array Associative array of parameters
* - 'MainList': The "MainList" object (by reference).
* - 'limit': The number of posts to display
*
* @return boolean True if you've created your own MainList object and queried the database, false otherwise.
*/
function InitMainList( & $params )
{
global $Blog;
global $preview, $disp;
global $postIDlist, $postIDarray, $cat_array;
$params['MainList'] = new ItemList2( $Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), $params['limit'] ); // COPY (FUNC)
if( ! $preview )
{
if( $disp == 'page' )
{ // Get pages:
$params['MainList']->set_default_filters( array(
'types' => '1000', // pages
) );
}
if( $disp == 'search' && param('s', 'string') )
{ // Here we allow b2evolution to search in posts and in pages
$this->msg( 'TEST plugin: InitMainList() method allows us to search in both posts and pages.', 'note' );
$params['MainList']->set_default_filters( array(
'types' => '1,1000',
) );
}
$params['MainList']->load_from_Request( false );
// Save aggregate setting
$saved_aggregate_state = $Blog->get_setting( 'aggregate_coll_IDs' );
if( $disp == 'posts' && !empty($params['MainList']->filters['tags']) )
{ // If the MainList if filtered by tag we search for posts in all public blogs
if( !empty($params['MainList']->filters['tags']) )
{ // All public blogs
$BlogCache = & get_BlogCache();
$Blog->set_setting( 'aggregate_coll_IDs', implode( ',', $BlogCache->load_public() ) );
$this->msg( 'TEST plugin: InitMainList() method allows us to display tagged posts from all public blogs.', 'note' );
}
}
// Run the query:
$params['MainList']->query();
// Restore aggregate setting to its original value
$Blog->set_setting( 'aggregate_coll_IDs', $saved_aggregate_state );
// Old style globals for category.funcs:
$postIDlist = $params['MainList']->get_page_ID_list();
$postIDarray = $params['MainList']->get_page_ID_array();
}
else
{ // We want to preview a single post, we are going to fake a lot of things...
$params['MainList']->preview_from_request();
// Legacy for the category display
$cat_array = array();
}
return true; // This is required!