-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions_outputfilter.php
More file actions
1601 lines (1385 loc) · 65 KB
/
Copy pathfunctions_outputfilter.php
File metadata and controls
1601 lines (1385 loc) · 65 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
/*
functions_outputfilter.php
*/
/**
*
* @category tool
* @package Outputfilter Dashboard
* @version 1.5.10
* @authors Thomas "thorn" Hornik <thorn@nettest.thekk.de>, Christian M. Stefan (Stefek) <stefek@designthings.de>, Martin Hecht (mrbaseman) <mrbaseman@gmx.de>
* @copyright (c) 2009,2010 Thomas "thorn" Hornik, 2010 Christian M. Stefan (Stefek), 2019 Martin Hecht (mrbaseman)
* @link https://github.com/WebsiteBaker-modules/outputfilter_dashboard
* @link http://forum.websitebaker.org/index.php/topic,28926.0.html
* @link https://forum.wbce.org/viewtopic.php?id=176
* @link http://addons.wbce.org/pages/addons.php?do=item&item=53
* @license GNU General Public License, Version 3
* @platform WebsiteBaker 2.8.x
* @requirements PHP 5.4 and higher
*
* This file is part of OutputFilter-Dashboard, a module for Website Baker CMS.
*
* OutputFilter-Dashboard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OutputFilter-Dashboard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OutputFilter-Dashboard. If not, see <http://www.gnu.org/licenses/>.
*
**/
/*
File: Filter functions
*/
// prevent this file from being accessed directly
if(!defined('WB_PATH')) die(header('Location: ../index.php'));
// obtain module directory
$mod_dir = basename(dirname(__FILE__));
require(WB_PATH.'/modules/'.$mod_dir.'/info.php');
// include module.functions.php
include_once(WB_PATH . '/framework/module.functions.php');
// include the module language file depending on the backend language of the current user
if (!include(get_module_language_file($mod_dir))) return;
require_once(dirname(__FILE__).'/functions.php');
/*
Topic: The Filter-Function itself
The Filter function must have an unique name, and should have a "opff_"-prefix
Prototype:
%bool% opff_unique_name( %string% &$content, %int% $page_id, %int% $section_id, %string% $module, %object% $wb )
Parameters:
&$content - %(string)% The page's or section's Content, per reference!
$page_id - %(int)% Actual Page ID.
$section_id - %(int)% Actual Section ID. For Filters of type !OPF_TYPE_PAGE_FIRST!, !OPF_TYPE_PAGE! or !OPF_TYPE_PAGE_LAST! or !OPF_TYPE_PAGE_FINAL! this is always !FALSE!.
$module - %(string)% Name of actual module (== !$module_directory! ). For Filters of type !OPF_TYPE_PAGE_FIRST!, !OPF_TYPE_PAGE! or !OPF_TYPE_PAGE_LAST! or !OPF_TYPE_PAGE_FINAL! this is always !FALSE!.
$wb - %(object)% Instance of Class wb.
Returns:
Should return always !TRUE!. Only in case the content may be damaged or undefined the function *must* return !FALSE!.
Examples:
(start code)
// simple filter which will convert all U to X in $content
function opff_x_as_u(&$content, $page_id, $section_id, $module, $wb) {
$content = str_replace('U', 'X', $content);
return(TRUE);
}
(end)
(start code)
function opff_prettify(&$content, $page_id, $section_id, $module, $wb) {
$PATH = WB_URL.'/modules/opf_prettify/prettify';
if(opf_find_class($content, 'prettyprint', '(pre|code)')) {
opf_register_frontend_files($PATH.'/prettify.css','css');
opf_register_frontend_files($PATH.'/prettify.js','js');
if(opf_find_class($content, 'lang-sql', '(pre|code)'))
opf_register_frontend_files($PATH.'/lang-sql.js','js');
opf_register_onload_event('prettyPrint');
}
return(TRUE);
}
(end)
*/
/*
Function: opf_register_filter
Register a new Filter.
This function is used for plugin- and module-filters to install the filter.
*You don't need this function for inline-filters!*
Prototype:
%bool% opf_register_filter( %array% $filter, %bool% $serialized=FALSE )
Parameters:
$filter - %(array)% An array that contains all filter data.
$serialized - %(bool)% Whether the filter-data is passed serialized.
Returns:
!TRUE! on success, !FALSE! otherwise.
Additionaly it will emit an error-message (level: E_USER_WARNING) in case of failure.
Examples:
(start code)
$filter = array(
'name' => 'PrettyPrint: Google-Code-Prettify',
'type' => OPF_TYPE_SECTION,
'file' => WB_PATH.'/modules/opf_prettify/filter.php',
'funcname' => 'opff_prettify',
'csspath' => WB_PATH.'/modules/opf_prettify/prettify/prettify.css',
'modules' => 'download_gallery,manual,news,wysiwyg'
);
opf_register_filter($filter);
(end)
$filter-Array:
name - %(string)% - Unique name of Filter, e.g. !Correct Date filter!.
type - %(string)% - Type of Filter (see below).
funcname - %(string)% - Unique name of Filter-Function. This function is called to apply the filter.
It has to be an unique name and should begin with "opff_", e.g. !opff_correct_date()!.
func - %(string)% - "Inline-Function" (see below).
file - %(string)% - Name and absolute path of file containing the Filter-Function.
Use either !func! or !file!.
active - %(int)% - Set Filter active (!1!), or inactive (!0!) after installation. Defaults to !1!.
allowedit - %(int)% - Set Filter-Settings editable (!1!), or not editable (!0!) (see below). Defaults to !0!.
allowedittarget - %(int)% - Set additional Filter-Settings editable (see below). Defaults to !0!.
desc - %(string/array)% - Description of Filter (see below).
configurl - %(string)% - URL to Filter-Settings (e.g. to an Admin-Tool).
E.g.: !'configurl' => ADMIN_URL.'/admintools/tool.php?tool=output_filter'!. Default: "".
csspath - %(string)% - Name and absolute path of CSS-file.
E.g.: !'csspath' => '{SYSVAR:WB_PATH}/modules/opf_prettify/prettify/prettify.css'!. Default: "".
helppath - %(array)% - Array of name and absolute path to Help-files.
E.g.: !'helppath' => array('DE'=>'{SYSVAR:WB_URL}/modules/opf_prettify/help_de.html',
'EN'=>'{SYSVAR:WB_URL}/modules/opf_prettify/help_en.html')!. Default: "".
modules - %(string/array)% - List of modules (see below).
pages - %(string/array)% - List of pages (see below).
pages_parent - %(string/array)% - List of pages (see below).
additional_fields - %(array)% - List of additional Settings-Fields (see below).
type:
Determines on which type of content the filter is applied to.
OPF_TYPE_SECTION_FIRST - Apply filter on section-content, but *before* all filters of type OPF_TYPE_SECTION.
OPF_TYPE_SECTION - Apply filter on section-content.
OPF_TYPE_SECTION_LAST - Like OPF_TYPE_SECTION, but applied *after* all filters of type OPF_TYPE_SECTION.
OPF_TYPE_PAGE_FIRST - Like OPF_TYPE_PAGE, but applied *before* all filters of type OPF_TYPE_PAGE.
OPF_TYPE_PAGE - Apply filter on page-content, i.e. on all sections, snippets on that page, and the entire template, too.
OPF_TYPE_PAGE_LAST - Like OPF_TYPE_PAGE, but applied *after* all filters of type OPF_TYPE_PAGE.
OPF_TYPE_PAGE_FINAL - Like OPF_TYPE_PAGE_LAST, but applied even *after* all filters of type OPF_TYPE_PAGE_LAST.
Filter of type OPF_TYPE_SECTION are applied on section-content before the content gets inserted into the template.
Filter of type OPF_TYPE_PAGE are applied on the finished page just before the page is sent to the browser.
func:
A string containing the filter-function. Convenient for very short functions.
Use !file! for larger filter-functions.
(start code)
$function = '
function opff_search_highlight(&$content, $page_id, $section_id, $module, $wb) {
if(isset($_GET["searchresult"]) && is_numeric($_GET["searchresult"])
&& !isset($_GET["nohighlight"]) && isset($_GET["sstring"])
&& !empty($_GET["sstring"])) {
$arr_string = explode(" ", $_GET["sstring"]);
if($_GET["searchresult"]==2) // exact match
$arr_string[0] = str_replace("_", " ", $arr_string[0]);
$content = search_highlight($content, $arr_string);
}
return(TRUE);
}
';
$filter = array(
'name' => 'Searchresult Highlighting',
'type' => OPF_TYPE_SECTION_LAST,
'funcname' => 'opff_search_highlight',
'func' => $function,
'modules' => 'all'
);
opf_register_filter($filter);
(end)
file:
Name and absolute path of file containing the Filter-Function.
(start code)
$filter = array(
'name' => 'Searchresult Highlighting',
'type' => OPF_TYPE_SECTION_LAST,
'funcname' => 'opff_search_highlight',
'file' => '{SYSVAR:WB_PATH}/modules/myfilter/filter.php',
'modules' => 'all'
);
opf_register_filter($filter);
(end)
With filter.php
(start code)
<?php
// content of filter.php
function opff_search_highlight(&$content, $page_id, $section_id, $module, $wb) {
if(isset($_GET["searchresult"]) && is_numeric($_GET["searchresult"])
&& !isset($_GET["nohighlight"]) && isset($_GET["sstring"])
&& !empty($_GET["sstring"])) {
$arr_string = explode(" ", $_GET["sstring"]);
if($_GET["searchresult"]==2) // exact match
$arr_string[0] = str_replace("_", " ", $arr_string[0]);
$content = search_highlight($content, $arr_string);
}
return(TRUE);
}
?>
(end)
allowedit:
If set to !1! following settings are changeable through Admin-Tool
* Name of filter
* Type of Filter
* Name of filter-function
* Filter-function itself (in case it's a "inline-filter")
* List of modules, and
* List of pages the filter is applied to.
Suggestion: use !'allowedit' => 0! always (default).
allowedittarget:
Extension for !allowedit!: If !allowedit! is set to !0! and allowedittarget set to !1!
the user is allowed to change only
* List of modules, and
* List of pages the filter is applied to.
Suggestion: use !'allowedittarget' => 1! always (default).
In case !allowedit! is set to !1! !allowedittarget! is meaningless.
desc:
Description of filter. Use either
> 'desc' => "Description follows here.\nText..."
or
> 'desc' => array(
> 'EN' => "Description\n...",
> 'DE' => "Beschreibung\n..."
> )
Using the latter form, there has to be at least an English ( !'EN'! ) entry.
modules:
List of modules the filter (of type OPF_TYPE_SECTION_FIRST, OPF_TYPE_SECTION or OPF_TYPE_SECTION_LAST ) is applied to.
In the following two examples, the filter will be applied to all WYSIWYG- and News-sections.
> 'modules' => 'wysiwyg,news'
or
> 'modules' => array('wysiwyg', 'news')
There are some aliases defined
'all' - all installed modules
'all_page_types' - all page-type modules: wysiwyg, news, guestbook, download_gallery, manual, mapbaker, newsarc
'all_form_types' - form, formx, mpform, miniform
'all_gallery_types' - Auto_Gallery, fancy_box, flickrgallery, foldergallery, gallery, gdpics, imageflow, imagegallery, lightbox2, lightbox, minigallery, minigal2, panoramic_image, pickle, picturebox, tiltviewer, smoothgallery, swift, slideshow
'all_wrapper_types' - curl, inlinewrapper, wrapper
'all_calendar_types' - calendar, concert, event, event_calendar, extcal, procalendar
'all_shop_types' - bakery, gocart, anyitems, lastitems
'all_code_types' - code, code2, show_code, show_code_geshi, color4code
'all_poll_types' - doodler, polls
'all_listing_types' - accordion, addressbok, aggregator, bookings_v2, bookmarks, cabin, dirlist, enhanced_aggregator, faqbaker, faqmaker, glossary, jqCollapse, members, mfz, sitemap
'all_various_types' - audioplayer, feedback, forum, newsreader, shoutbox, simpleviewer, small_ads, wb-forum, zitate
See <opf_modules_categories> for the actual module -> category relation.
pages:
List of pages (PAGE_IDs) the filter is applied to. Alias 'all' for all present pages.
> // apply filter on page 12, 121 and 16 only
> 'pages' => '21,121,16' // written as list
> 'pages' => array('21', '121', '16') // written as array
> // apply filter to all pages
> 'pages' => 'all'
pages_parent:
List of pages (PAGE_IDs) the filter is applied to. Additionaly the filter is applied to
all sub-pages, too.
Alias 'all' for all present pages.
> // apply filter on page 12 and 21, and all sub-pages of page 12 and 21
> 'pages_parent' => '12,21' // written as list
> 'pages_parent' => array('12', '21') // written as array
additional_fields:
Arrays of additional configuration elements.
In case the filter needs some additional config-elements but it doesn't have its own Settings-Page / Admin-Tool,
you can add some fields using !additional_fields!. Possible field-types are
text - normal HTML text-field
textarea - normal HTML textarea
editarea - textarea with activated editarea (Editor)
radio - normal HTML radio-fields
checkbox - normal HTML checkbox-fields
select - normal HTML select-field
array - simple array broken up into several text-fields
!allowedit! has no affect on these fields.
See <opf_filter_get_additional_values> on how to retrieve values from these fields.
Example: Adding various fields
(start code)
'additional_fields' => array(
array( // add text-field "Name"
'type' => 'text', // type of field
'label' => 'Name', // Label for the text-field
'variable' => 'name', // name of variable
'name' => 'af_name', // name for HTML name-attribute
'value' => '', // default-value
'style' => 'width: 98%;' // style (only for text, textarea and editarea for width and height)
),
array( // add textarea "Long-text"
'type' => 'textarea',
'label' => 'Long-Text',
'variable' => 'text',
'name' => 'af_long_text',
'value' => 'Default text',
'style' => 'width: 98%;'
),
array( // add select-field "Colour"
'type' => 'select',
'label' => 'Colour',
'variable' => 'colour',
'name' => 'af_colour',
'value' => array( // options
'red' => 'Red',
'blue' => 'Blue',
'green' => 'Green'
),
'checked'=> 'blue' // selected option
)
),
array( // add checkbox
'type' => 'checkbox',
'label' => 'Use ECMA-variant',
'variable' => 'use_ecma',
'name' => 'af_use_ecma',
'value' => 'use_ecma',
'checked' => 1
)
)
(end)
Example: Adding fields with language-support
(start code)
'additional_fields' => array(
array(
'type' => 'text', // type of field
'label' => array( // Language-dependent string
'EN'=>'Locale',
'DE'=>'Spracheinstellung'
),
'variable' => 'locale', // name of variable
'name' => 'af_locale', // name for name-attribute
'value' => 'de_DE.utf-8', // default-value
'style' => 'width: 98%;' // style (only for text, textarea and editarea for width and height)
),
array(
'type' => 'array',
'label' => array(
'EN'=>'Date format',
'DE'=>'Datumsformat'
),
'variable' => 'date_formats',
'name' => 'af_date_formats',
'value' => array(
'D M d, Y' => '%a %b %d %Y',
'M d Y' => '%b %d. %Y',
'd M Y' => '%d. %b %Y',
'jS F, Y' => '%e. %B %Y',
'l, jS F, Y'=> '%A, %e. %B %Y')
),
array(
'type' => 'select',
'label' => array('EN'=>'Colour','DE'=>'Farbe'),
'variable' => 'colour',
'name' => 'af_colour',
'value' => array( // options
'red' => array('EN'=>'Red','DE'=>'Rot'),
'blue' => array('EN'=>'Blue','DE'=>'Blau'),
'green' => array('EN'=>'Green','DE'=>'Grün')
),
'checked'=> 'blue' // selected option
)
)
)
(end)
label - Label of field. !label! can be an ordinary string "!Enter Date!", or a language-specific array.
variable - Name of variable to be used for this field. Radio-buttons uses the same name.
type - Type of field: '!text!', '!textarea!', '!editarea!', '!radio!', '!checkbox!', '!select!' or '!array!'.
name - Value for the HTML name-attribute. Radio-buttons uses the same name.
value - Default-value. 'select' and '!array!' requires an array.
checked - For '!radio!' or '!checkbox!': use !'checked' => 1! to mark this field checked.
For '!select!': use !'checked' => 'value'! i.e. repeat the selected value.
style - (optional) For '!text!', '!textarea!', '!editarea!': add !width:! and/or !height:! attributes.
*/
function opf_register_filter($filter, $serialized=FALSE) {
$now = time();
$sql_where = '';
// get variables
if($serialized)
$filter = unserialize($filter);
$filter = opf_insert_sysvar($filter);
if(isset($filter['id'])) $id = opf_fetch_clean( $filter['id'], 0, 'int'); else $id = 0; // id is set from opf_edit_filter() only
if(isset($filter['type'])) $type = opf_fetch_clean( $filter['type'], '', 'string'); else $type = '';
if(isset($filter['name'])) $name = opf_fetch_clean( $filter['name'], '', 'string'); else $name = '';
if(isset($filter['file'])) $file = opf_fetch_clean( $filter['file'], '', 'string'); else $file = '';
if(isset($filter['func'])) $func = opf_fetch_clean( $filter['func'], '', 'unchanged'); else $func = '';
if(isset($filter['funcname'])) $funcname = opf_fetch_clean( $filter['funcname'], '', 'string'); else $funcname = '';
if(isset($filter['userfunc'])) $userfunc = opf_fetch_clean( $filter['userfunc'], 0, 'int'); else $userfunc = 0;
if(isset($filter['plugin'])) $plugin = opf_fetch_clean( $filter['plugin'], '', 'string'); else $plugin = '';
if(isset($filter['active'])) $active = opf_fetch_clean( $filter['active'], 0, 'int'); else $active = 1;
if(isset($filter['allowedit'])) $allowedit = opf_fetch_clean( $filter['allowedit'], 0, 'int'); else $allowedit = 0;
if(isset($filter['allowedittarget'])) $allowedittarget = opf_fetch_clean( $filter['allowedittarget'], 0, 'int'); else $allowedittarget = 1;
if(isset($filter['configurl'])) $configurl = opf_fetch_clean( $filter['configurl'], '', 'string'); else $configurl = '';
if(isset($filter['csspath'])) $csspath = opf_fetch_clean( $filter['csspath'], '', 'string'); else $csspath = '';
if(isset($filter['force']) && $filter['force']) $force = TRUE; else $force = FALSE;
if(isset($filter['filter_installed']) && !$filter['filter_installed']) $filter_installed = FALSE; else $filter_installed = TRUE;
if(isset($filter['modules'])) $modules = $filter['modules']; else $modules = array();
if(isset($filter['targets'])) $targets = $filter['targets']; else $targets = array(); // allow "targets" as alias for "modules"
if(isset($filter['pages'])) $pages = $filter['pages']; else $pages = array('all');
if(isset($filter['pages_parent'])) $pages_parent = $filter['pages_parent']; else $pages_parent = array('all');
if(isset($filter['additional_fields_languages'])) $additional_fields_languages = $filter['additional_fields_languages']; // else unset
if(isset($filter['additional_fields'])) $additional_fields = $filter['additional_fields']; // else unset
if(isset($filter['additional_values'])) $additional_values = $filter['additional_values']; else $additional_values = serialize('');
// description may be an array of different languages
if(!isset($filter['desc']) || empty($filter['desc'])) $desc = array();
elseif(is_string($filter['desc'])) $desc = array('EN'=>$filter['desc']); // use EN as default
else $desc = $filter['desc'];
$desc = serialize($desc);
if(!isset($filter['helppath']) || empty($filter['helppath'])) $helppath = array();
elseif(is_string($filter['helppath'])) $helppath = array('EN'=>$filter['helppath']);
else $helppath = $filter['helppath'];
$helppath = serialize($helppath);
// prepare modules-list
if(!opf_type_uses_sections($type)) // not a section-filter - no need to check for modules
$modules = array();
else { // section-filter
if(!isset($modules) && isset($targets))
$modules = $targets;
elseif(!isset($modules))
$modules = array();
if(!is_array($modules)) $modules = explode(',', $modules);
$tmp = array();
foreach($modules as $module)
$tmp[] = trim($module);
$modules = $tmp;
if(in_array('all', $modules)) $all_modules = TRUE; else $all_modules = FALSE;
foreach(opf_modules_categories('relations') as $m_type => $m_list) {
if($all_modules || in_array($m_type, $modules)) {
$modules = array_merge($modules, $m_list);
}
}
$modules = array_unique($modules);
}
// fix some values
if($userfunc) $allowedit = 1;
$modules = serialize($modules);
if(!is_array($pages)) $pages = explode(',', $pages);
$pages_parent = str_replace('search', '0', $pages_parent);
if(!is_array($pages_parent)) $pages_parent = explode(',', $pages_parent);
if(empty($pages) && empty($pages_parent)) {
$pages = array('9999999');
$pages_parent = array('9999999');
}
$tmp = array();
foreach($pages as $page)
$tmp[] = trim($page);
$pages = $tmp;
$tmp = array();
foreach($pages_parent as $page)
$tmp[] = trim($page);
$pages_pages = $tmp;
$pages = serialize($pages);
$pages_parent = serialize($pages_parent);
if(isset($additional_fields_languages) && !empty($additional_fields_languages)) {
$additional_fields_languages = serialize($additional_fields_languages);
} else
$additional_fields_languages = serialize('');
if($filter_installed) {
if(isset($additional_fields) && !empty($additional_fields)) {
$additional_values = array();
foreach($additional_fields as $field) {
switch ($field['type']) {
case 'text':
case 'textarea':
case 'editarea':
case 'array':
$additional_values[$field['variable']] = $field['value'];
break;
case 'checkbox':
case 'radio':
if(isset($field['checked']) && $field['checked']) $additional_values[$field['variable']] = $field['value'];
else {
if(!isset($additional_values[$field['variable']]) || !($additional_values[$field['variable']]))
$additional_values[$field['variable']] = FALSE;
}
break;
case 'select':
if(isset($field['checked']) && isset($field['value'][$field['checked']]))
$additional_values[$field['variable']] = $field['checked'];
else
$additional_values[$field['variable']] = FALSE;
break;
}
}
} else
$additional_values = '';
}
if(isset($additional_fields) && !empty($additional_fields)) {
$additional_fields = serialize($additional_fields);
} else
$additional_fields = serialize('');
$additional_values = serialize($additional_values);
// check some variables
if($type=='' || $name=='' || $funcname=='') {
trigger_error('Needed Argument missing or empty', E_USER_WARNING);
if($force) { // store it nevertheless, but set it inactive
$active = 0;
if($name=='') $name = uniqid('filter_');
if($funcname=='') $funcname = uniqid('opff_');
} else
return(FALSE);
}
$fileCheck = opf_replace_sysvar($file,$plugin);
if(($fileCheck=='' && $func=='') || (($fileCheck!='' && $func!=''))) {
trigger_error('File OR Function needed', E_USER_WARNING);
if($force) { // store it nevertheless, but set it inactive
$active = 0;
if($func=='') $func = '// Please enter a function.';
} else
return(FALSE);
}
if($fileCheck && (!file_exists($fileCheck) || !is_file($fileCheck) || !is_readable($fileCheck))) {
trigger_error("Can\'t read file ($file)", E_USER_WARNING);
return(FALSE);
}
if($func!='' && !preg_match("~$funcname\s*\(~", $func)) {
trigger_error('wrong funcname', E_USER_WARNING);
if($force) { // store it nevertheless, but set it inactive
$active = 0;
$func = preg_replace('/\?>\s*<\?php/','',"<?php // ATTN: given funcname and used name differ.\n?>".$func);
} else
return(FALSE);
}
if($func!='' && preg_match("/$funcname\s*\(/", $func)) {
// remove warning again when funcname is corrected
$func = preg_replace('/\s*\/\/\s*ATTN: given funcname and used name differ.\s*/',"\n",$func);
}
// insert values into DB
// get next free position for type
$position = opf_db_query_vars( "SELECT MAX(`position`) FROM `".TABLE_PREFIX."mod_outputfilter_dashboard` WHERE `type`='%s'", $type);
if($position===NULL) $position = 0; // NULL -> no entries
else ++$position;
// new entry or update?
if($id>0)
$update = opf_is_registered($id);
else
$update = opf_is_registered($name);
if($update) { // update, fetch some old values from db
$sql_action = 'UPDATE';
if($id>0) $sql_where = "WHERE `id`=".(int)$id;
else $sql_where = "WHERE `name`='".addslashes($name)."'"; // keep this addslashes()-call!
$old = opf_db_query( "SELECT * FROM `".TABLE_PREFIX."mod_outputfilter_dashboard` $sql_where");
if($old===FALSE)return(FALSE);
$old = $old[0];
$old_type = $old['type'];
$old_pos = $old['position'];
if($type==$old_type) { // type unchanged, so keep position
$position = $old_pos;
} else { // change of type
// correct positions for old type
opf_db_run_query( "UPDATE `".TABLE_PREFIX."mod_outputfilter_dashboard` SET `position`=`position`-1 WHERE `type`='%s' AND `position`>%d", $old_type, $old_pos);
}
if($force==FALSE) {
// update - keep some old values
$active = (int)$old['active'];
$modules = $old['modules'];
$pages = $old['pages'];
$pages_parent = $old['pages_parent'];
}
if(!$filter_installed) { // filter from edit. Fetch old values from DB
$additional_fields_languages = $old['additional_fields_languages'];
$additional_fields = $old['additional_fields'];
} else $additional_values = $old['additional_values'];
} else {
$sql_action = 'INSERT INTO';
}
$res = opf_db_run_query( "$sql_action `".TABLE_PREFIX."mod_outputfilter_dashboard` SET
`userfunc`=%d,
`plugin`='%s',
`position`=%d,
`active`=%d,
`type`='%s',
`name`='%s',
`file`='%s',
`func`='%s',
`funcname`='%s',
`modules`='%s',
`desc`='%s',
`pages`='%s',
`pages_parent`='%s',
`allowedit`=%d,
`allowedittarget`=%d,
`configurl`='%s',
`csspath`='%s',
`helppath`='%s',
`additional_values`='%s',
`additional_fields`='%s',
`additional_fields_languages`='%s'
$sql_where",
$userfunc,$plugin,$position,$active,$type,$name,$file,$func,$funcname,
$modules,$desc,$pages,$pages_parent,$allowedit,$allowedittarget,
$configurl,$csspath,$helppath,$additional_values,$additional_fields,
$additional_fields_languages);
if(class_exists('Settings') && defined('WBCE_VERSION')){
// force refresh the filter definitions
global $opf_FILTERS;
unset($opf_FILTERS);
opf_set_active($name, $active);
}
return($res);
}
/*
Function: opf_move_up_before
Upon registration move a filter up to a position before another one.
This function can be used after <opf_register_filter()> to adjust its position
in the filter list. By default, freshly installed filters are appended to the
end of the list of filters of the same type. Use this function inside the
<install.php> to move the filter up to a target position denoted by the
name of another filter. You can repeat this with different names of filters
from which you know that they have to be applied after the one you are installing.
Alternatively, if !$ref_name! is an array, the filter denoted by !$name!
is moved upwards to the position of the upper-most entry of the whole list.
If !$ref_name! is ommited, the filter !$name! is moved up to the
top of the whole list. In this case the return value is the new position of
the filter !$name!
Prototype:
%bool% opf_move_up_before( %string% $name, %string% $ref_name )
%array% opf_move_up_before( %string% $name, %array% $ref_name )
%int% opf_move_up_before( %string% $name )
Parameters:
$name - %(string)% the name of the filter to move up in the list
$ref_name - %(string)% name of the filter at the target position or
$ref_name - %(array)% names of the filters at the target positions
Returns:
!TRUE! on success, !FALSE! if the types don't match or the filters were not found
or an array of bools, corresponding to the return values for each filter
or the position of !$name! if !$ref_name! is ommitted
Example:
> opf_move_up_before('opf CSS to head', 'Searchengine Highlighter');
*/
function opf_move_up_before($name, $ref_name=""){
if(is_array($ref_name)){
$ret=array();
foreach($ref_name as $rn){
$ret[]=opf_move_up_before($name, $rn);
}
return($ret);
}
$name = opf_check_name($name);
if(!$name) return(FALSE);
if($ref_name==""){
$pos=0;
while(opf_move_up_one($name,FALSE)){
$pos = opf_get_position($name,FALSE);
}
return($pos);
}
$pos = opf_get_position($name,FALSE);
$type = opf_get_type($name,FALSE);
if($pos!==FALSE && $type!==FALSE && $pos>0) {
$ref_name = opf_check_name($ref_name);
if(!$ref_name) return(FALSE);
$ref_pos = opf_get_position($ref_name, FALSE);
$ref_type = opf_get_type($ref_name,FALSE);
while($ref_pos!==FALSE && $pos!==FALSE && $ref_type==$type && $ref_pos>0 && $pos>$ref_pos) {
if(opf_move_up_one($name,FALSE)===FALSE)
return(FALSE);
$pos = opf_get_position($name,FALSE);
}
}
return(TRUE);
}
/*
Function: opf_unregister_filter
Un-Register a Filter.
This function is used to remove a filter.
Use this for Module-Filters in the module's !uninstall.php!-file.
Prototype:
%bool% opf_unregister_filter( %string% $name )
Parameters:
$name - %(string)% Name of filter to un-register.
Returns:
!TRUE! on success, !FALSE! otherwise.
Example:
> opf_unregister_filter('PrettyPrint: Google-Code-Prettify');
*/
function opf_unregister_filter($name) {
if(!function_exists('opf_unregister_call_uninstall')) {
function opf_unregister_call_uninstall($file) {
include $file;
}
}
static $old_name = FALSE;
$now = time();
$name = opf_check_name($name);
if(!$name) return(FALSE);
if($old_name==$name) return(FALSE); // prevent usage of opf_unregister_filter() in plugin_uninstall.php
$old_name = $name;
// check whether $name is in DB
if(opf_is_registered($name)) {
$pos = opf_get_position($name);
$type = opf_get_type($name);
// delete plugin-dir if present
if($plugin_dir = opf_db_query_vars( "SELECT `plugin` FROM `".TABLE_PREFIX."mod_outputfilter_dashboard` WHERE `name`='%s'", $name)) {
if($plugin_dir && file_exists(WB_PATH.'/modules/outputfilter_dashboard/plugins/'.$plugin_dir)) {
// uninstall.php present? include it
if(file_exists(WB_PATH.'/modules/outputfilter_dashboard/plugins/'.$plugin_dir.'/plugin_uninstall.php'))
opf_unregister_call_uninstall(WB_PATH.'/modules/outputfilter_dashboard/plugins/'.$plugin_dir.'/plugin_uninstall.php');
opf_io_rmdir(WB_PATH.'/modules/outputfilter_dashboard/plugins/'.$plugin_dir);
}
}
$res = opf_db_run_query( "DELETE FROM `".TABLE_PREFIX."mod_outputfilter_dashboard` WHERE `name`='%s'", $name);
if($res) {
if(class_exists('Settings') && defined('WBCE_VERSION')){
Settings::Del( opf_filter_name_to_setting($name));
Settings::Del( opf_filter_name_to_setting($name).'_be');
}
if(opf_db_run_query( "UPDATE `".TABLE_PREFIX."mod_outputfilter_dashboard` SET `position`=`position`-1
WHERE `type`='%s' AND `position`>%d", $type, $pos))
return(TRUE);
}
}
return(FALSE);
}
/*
Function: opf_register_frontend_files
Register JS- or CSS-files to be loaded into the page's <head>-section.
Prototype:
%bool% opf_register_frontend_files( %string% $file, %string% $type, %string% $target='head', %string% $media='screen', %string% $iehack )
Parameters:
$file - %(string)% URL of file to register, or "inline" JS-script or CSS-style.
$type - %(string)% Type: '!js!' or '!css!'.
$target - %(string)% Where to insert the file: '!head!' or '!body!'.
$media - %(string)% media, for stylesheets only, e.g.: '!screen!' or '!screen,print!'. Use '' (empty string) otherwise.
$iehack - %(string)% Special IE-Hack (for type !js! only).
Returns:
Always !TRUE!.
Examples:
> // register JS-script
> opf_register_frontend_files(WB_URL.'modules/opf_prettify/prettify.js', 'js');
> // register JS-script in <body>
> opf_register_frontend_files(WB_URL.'modules/opf_prettify/prettify.js', 'js', 'body');
> // register CSS-Stylesheet
> opf_register_frontend_files(WB_URL.'/modules/opf_pcdtr/pcdtr/styles.css', 'css');
> // IE-Hack
> opf_register_frontend_files(WB_URL.'/modules/opf_fix_png_ie6/sl.js', 'js', 'head', '', '[if lte IE 6]');
> // output: <!--[if lte IE 6]><script ...></script><![endif]-->
> // usage of "inline"-script
> opf_register_frontend_files('
> <script type="text/javascript">function do_highlight() { highlighter.highlight(); }</script>
> ','js');
*/
function opf_register_frontend_files($file, $type, $target='head', $media='screen', $iehack='') {
global $opf_HEADER; // global storage for all entries
global $opf_BODY; // global storage for all entries
if(!isset($opf_HEADER) || !is_array($opf_HEADER)) $opf_HEADER = array();
if(!isset($opf_BODY) || !is_array($opf_BODY)) $opf_BODY = array();
$str = '';
// file?
if(($type=='js' && !preg_match('~\s*<script~',$file)) || ($type=='css' && !preg_match('~\s*<style~',$file))) {
if($type=='js') {
$str = '<script type="text/javascript" src="'.$file.'"></script>'."\n";
if($iehack)
$str = "<!--$iehack>\n".$str."\n<![endif]-->\n";
}
else
$str = '<link rel="stylesheet" href="'.$file.'" type="text/css" media="'.$media.'" />'."\n";
} else { // script
if($type=='js' || $type=='css')
$str = $file;
}
if($target=='head' && !in_array($str, $opf_HEADER) && !in_array($str, $opf_BODY))
$opf_HEADER[] = $str;
if($target=='body' && !in_array($str, $opf_BODY) && !in_array($str, $opf_HEADER))
$opf_BODY[] = $str;
return(TRUE);
}
/*
Function: opf_register_onload_event
Register an Javascript onload-function inside
page's <head>-section, using window.attachEvent() or window.addEventListener().
Prototype:
%bool% opf_register_onload_event( %string% $function_name )
Parameters:
$function_name - %(string)% Name of JS-function to register.
Returns:
Always !TRUE!.
Example:
> opf_register_onload_event('prettyPrint');
Notes:
There is no way to supply arguments to the function, yet. Use <opf_register_onload> in
case the function call needs arguments.
*/
function opf_register_onload_event($function_name) {
global $opf_HEADER; // global storage for all entries
if(!isset($opf_HEADER) || !is_array($opf_HEADER))
$opf_HEADER = array();
$str = '';
if($function_name) {
$str = "<script type=\"text/javascript\">if(window.attachEvent) window.attachEvent('onload',$function_name); else window.addEventListener('DOMContentLoaded',$function_name,false);</script>";
if(!in_array($str, $opf_HEADER))
$opf_HEADER[] = $str;
}
return(TRUE);
}
/*
Function: opf_register_onload
Register an Javascript script onload-function inside page's <body>-section.
Prototype:
%bool% opf_register_onload( %string% $script )
Parameters:
$script - %(string)% JS-script to register.
Returns:
Always !TRUE!.
Example:
> opf_register_onload('prettyPrint();');
> opf_register_onload("supersleight.run('".WB_URL."/modules/opf_fix_png_ie6/x.gif');");
> opf_register_onload('$(\'#tagSphere\').tagSphere();');
*/
function opf_register_onload($script) {
global $opf_BODY; // global storage for all entries
if(!isset($opf_BODY) || !is_array($opf_BODY))
$opf_BODY = array();
$str = '';
if($script) {
$str = "<script type=\"text/javascript\">$script</script>";
if(!in_array($str, $opf_BODY))
$opf_BODY[] = $str;
}
return(TRUE);
}
/*
Function: opf_register_document_ready
Register an Javascript onload-event inside
page's <head>-section, using jquery's !jQuery(document).ready()! method.
Prototype:
%bool% opf_register_document_ready( %string% $js )
Parameters:
$js - %(string)% The Javascript-Code to use inside !$(document).ready()!.
Returns:
Always !TRUE!.
Requires:
This function requires that jQuery is loaded in the page's <head>-section.
Example:
>opf_register_document_ready('alert("OK!");');
>opf_register_document_ready('$(\'#tagSphere\').tagSphere();');
*/
function opf_register_document_ready($js) {
global $opf_HEADER; // global storage for all entries
if(!isset($opf_HEADER) || !is_array($opf_HEADER))
$opf_HEADER = array();
$str = '';
if($js) {
$str = '<script type="text/javascript">jQuery(document).ready(function() {'.$js.'});</script>';
if(!in_array($str, $opf_HEADER))
$opf_HEADER[] = $str;
}
return(TRUE);
}
/*
Function: opf_find_class
Check whether a class (or any other attribute) is present in content.
Prototype:
%bool% opf_find_class( %string% $content, %string% $match, %string% $tag='', %string% $attr='class' )
Parameters:
$content - %(string)% Content.
$match - %(string/regex)% String to search for.
$tag - %(string/regex)% HTML-tag. Defaults to '' (nothing).
$attr - %(string/regex)% Attribute to check. Defaults to '!class!'.
Returns:
!1! if !$match! is present, !0! otherwise. In case of error, this function returns !FALSE!.
Example:
(start code)
// apply filter only if class 'special_class' is present somewhere in $content
if(opf_find_class($content, 'special_class')) {
// ... apply filter
return(TRUE);
} else {
return(TRUE); // quit
}
(end)
(start code)
// apply filter only if class 'php_highlighter' is present inside a <pre>-tag
// <pre class="class1 php_highlighter">...</pre>
if(opf_find_class($content, 'php_highlighter', 'pre')) {
// ... apply filter
(end)
(start code)
// apply filter only if id 'tagSphere' is present inside a <div>-tag
// <div class="class2" id="tagSphere">...</div>
if(opf_find_class($content, 'tagSphere', 'div', 'id')) {
// ... apply filter
(end)
Regular expressions are allowed, too. Those regexs are performed ungreedy (PCRE_UNGREEDY).
(start code)
// search for class "cpp", "c" or "c++" in HTML-tag <pre> or <textarea>
if(opf_find_class($content, '(cpp|c|c\+\+)', '(pre|textarea)')) {
// ... apply filter
(end)
*/