-
Notifications
You must be signed in to change notification settings - Fork 0
/
codebase.php
3036 lines (2868 loc) · 93.1 KB
/
codebase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
define("CODEBASE_VERSION", "5.8.10");
define('ECC_PHP_7_STRICT', 1);
define("DEBUG_FORM", 0);
define("DEBUG_REPORT", 0);
define("DEBUG_MEMORY", 0);
define("DEBUG_NO_INTERNET", 0);
define("PWD_LEN_MIN", 4);
define("SYS_LOG_SLOW", 5); // Flag queries longer than this (mS) as SLOW in debug file
define("PIWIK_DEV", 1); // '1' forces community modules to engage with Piwik stats
define("STATS_START_DATE", '2013-07-01');
// test for RSS calendar feed:
// http://desktop.stphilipsunionville.com/rss/shared_events?what=calendar&YYYY=2008&MM=12
// http://desktop.westmountparkchurch.org/rss/shared_events?what=calendar&YYYY=2007&MM=09
define(
"DOCTYPE",
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
);
//define("DOCTYPE", '<!DOCTYPE html SYSTEM "%HOST%/xhtml1-strict-with-iframe.dtd">');
/*
--------------------------------------------------------------------------------
5.8.10.2553 (2024-04-15)
Summary:
Report checksums now include filter_criteria and filter_settings - previously undetected
Final Checksums:
Classes CS:fe21285a
Database CS:ad95509b
Libraries CS:be056f2d
Reports CS:ff3f0823
Code Changes:
codebase.php 5.8.10 (2024-04-15)
1) Updated version information
classes/class.report_config.php 1.0.9 (2024-04-15)
1) Report_Config::get_overview_global() now includes report filter criteria and report_settings
classes/class.system_health.php 1.0.52 (2024-04-15)
1) System_Health::drawReportsTable() uses higher index for final checksum now that results contain more types
2553.sql
1) Added report filters for 'report_columns_for_report'
2) Added columns for Created and Modified and report filters for 'actions_for_custom_form'
3) Added columns for Created and Modified and report filters for 'actions_for_product'
4) Added columns for Created and Modified and report filters for 'membership_rules_for_system'
5) Renamed two filters for 'reports' to use isons
6) Set version information
Promote:
codebase.php 5.8.10
classes/ (2 files changed)
class.report_config.php 1.0.9 CS:811b76c
class.system_health.php 1.0.52 CS:9b67a1d
--------------------------------------------------------------------------------
Bug:
where two postings (e.g. gallery album and article) have same name and date
search results will be shown instead:
http://aoj.ecclesiact.com/2009/03/14/kariobangi-youth-center
An sql script could probably find more examples
Provide disambiguation based on ID?
--------------------------------------------------------------------------------
TODO:
IMPLEMENT NEW get_var() throughout to remove some crazy globals where possible
1) Make changing a gallery album parent remap all descendents
2) This should work: http://desktop.saministryresources.ca/page/784780593
3) When mysql 5.5 is on all servers, consider making tables InnoDB rather than MYISAM
http://www.oracle.com/partners/en/knowledge-zone/mysql-5-5-innodb-myisam-522945.pdf
4) Introduction of event registration limits to allow cutoff after so many bookings
have been made / sold
BUGS:
1.12.11.1289
Transformer button image files should ideally include system ID to prevent one
system with a button style of 'Main' clearing out cached images for another system whose buttons
use that systems 'Main' style when admin updates 'Main' style in the other system
Also transformer buttons cannot have apostrophes in text nor spaces in button style
1.12.2.1280
1) Report Filters do NOT work in Dashboard layers (or ajax reports come to that) -
1.9.12.1261
1) If IE7's zoom mode is other than 100%, current rating highlights stars in wrong location
1.9.8.1257
1) If a button is edited and moved from one suite to another and the original suite now
has NO buttons, system should delete original suite and remove mapping from parent button
1.8.7.1235
1) Doesn't prevent two postings with same name or posting with same name as a page
CODE CHANGES COMING:
1) Consider keyword mapping by value NOT ID
2) Look for newer version of treeview for XHTML Srict
PROPOSED ENHANCEMENTS:
1) Have sitemap show which pages are missing for admins - add option to generate missing pages
2) NEED TO TEST WITH MYSQL STRICT MODE - USE SERVER INSTANCE CONFIG
3) Ensure that orders for people are deleted when person is removed.
4) Make recursive copy / single item copy options for navbuttons and treenodes
5) Make recursive export for treenodes
6) Prevent deletions of events with actions
7) Consider default layout with signin for new system.
8) When you delete a navbar, have the system check for pages that reference it
and have these IDs set to 1 (no navbar)
9) When you delete a button, have the system check for navbars that have that
button as the parent button and have these set to 1 (no parent)
10) When you delete a button style, have the system prevent this if there
are navsuites defined using it.
11) Facebook: when user with a facebook profile registers for an event, have facebook
make an announcement
12) Have ability to configure context menus to choose shift right or other
combinations, based on user's preferences when editing (james' suggestion)
--------------------------------------------------------------------------------
Dialog selector colour, label and ordering conventions:
Order: (default), (none), Global, everything else
--------------------------------------------------------------------------------
MASTERADMIN SYSADMIN
--------------------------------------------------------------------------------
BGColor Label BGColor Label
Default = ffffff (default) ffffff (default)
None = d0d0d0 (none) d0d0d0 (none)
All Systems = e0e0ff * Item e0e0ff * Item
This System = c0ffc0 SYSTEM | Item c0ffc0 Item
Other system = ffe0e0 SYSTEM | Item (-never shown-)
Other value = ffe0c0 (Other...) ffe0c0 (Other...)
--------------------------------------------------------------------------------
Filter Icons:
[ICON]14 14 6912 (All Records - Unfiltered View)[/ICON](All)
[ICON]17 17 6751 Created Today[/ICON]
[ICON]17 17 6768 Modified Today[/ICON]
[ICON]21 21 7338 Created This Week[/ICON]
[ICON]21 21 7359 Modified This Week[/ICON]
[ICON]23 23 7380 Created This Month[/ICON]
[ICON]23 23 7403 Modified This Month[/ICON]
[ICON]22 22 7426 Created This Year[/ICON]
[ICON]22 22 7448 Modified This Year[/ICON]
[ICON]13 13 6598 Marked as Important - Yes[/ICON]
[ICON]13 13 6611 Marked as Important - No[/ICON]
[ICON]11 11 6576 Has Categories - Yes[/ICON]
[ICON]11 11 6587 Has Categories - No[/ICON]
[ICON]21 21 7506 Has been Published to Public - Yes[/ICON]
[ICON]21 21 7527 Has been Published to Public - No[/ICON]
[ICON]22 22 7548 Has been Published to Site Users - Yes[/ICON]
[ICON]22 22 7570 Has been Published to Site Users - No[/ICON]
[ICON]22 22 7592 Has been Published to Approved Site Members - Yes[/ICON]
[ICON]22 22 7614 Has been Published to Approved Site Members - No[/ICON]
[ICON]19 19 6370 Has been Published to Groups - Yes[/ICON]
[ICON]19 19 6389 Has been Published to Groups - No[/ICON]
[ICON]21 21 7674 Has been Shared - Yes[/ICON]
[ICON]21 21 7695 Has been Shared - No[/ICON]
[ICON]18 18 6334 Has Received Comments - Yes[/ICON]
[ICON]18 18 6352 Has Received Comments - No[/ICON]
[ICON]22 22 6444 Has Recurrences - Yes[/ICON]
[ICON]22 22 6466 Has Recurrences - No[/ICON]
[ICON]22 22 6488 Is a Recurrence - Yes[/ICON]
[ICON]22 22 6510 Is a Recurrence - No[/ICON]
[ICON]18 18 6408 Has Related Products - Yes[/ICON]
[ICON]18 18 6426 Has Related Products - No[/ICON]
[ICON]22 22 6532 Has Registrants - Yes[/ICON]
[ICON]22 22 6554 Has Registrants - No[/ICON]
[ICON]21 21 7041 Is a Podcast Root Folder[/ICON]
[ICON]23 23 7062 Is a Podcast Sub Folder[/ICON]
[ICON]17 17 7007 Contains Podcasts - Yes[/ICON]
[ICON]17 17 7024 Contains Podcasts - No[/ICON]
[ICON]20 20 6967 Contains other Podcast Albums - Yes[/ICON]
[ICON]20 20 6987 Contains other Podcast Albums - No[/ICON]
[ICON]20 20 7085 Inside a Podcast Album - Yes[/ICON]
[ICON]20 20 7105 Inside a Podcast Album - No[/ICON]
[ICON]21 21 7169 Is a Gallery Root Folder[/ICON]
[ICON]21 21 7190 Is a Gallery Sub Folder[/ICON]
[ICON]22 22 7214 Contains Gallery Images - Yes[/ICON]
[ICON]22 22 7236 Contains Gallery Images - No[/ICON]
[ICON]20 20 7258 Contains other Gallery Albums - Yes[/ICON]
[ICON]20 20 7278 Contains other Gallery Albums - No[/ICON]
[ICON]20 20 7298 Inside a Gallery Album - Yes[/ICON]
[ICON]20 20 7318 Inside a Gallery Album - No[/ICON]
[ICON]17 17 7470 Is a Top-Level Parent Page[/ICON]
[ICON]19 19 7487 Is a Nested Child Page[/ICON]
[ICON]19 19 7636 Is an Administrator - Yes[/ICON]
[ICON]19 19 7655 Is an Administrator - No[/ICON]
[ICON]16 16 8316 Enabled[/ICON]
[ICON]16 16 8332 Disabled[/ICON]
*/
if (PHP_MAJOR_VERSION >= 7 && !ECC_PHP_7_STRICT) {
set_error_handler(function ($errno, $errstr) {
return strpos($errstr, 'Declaration of') === 0;
}, E_WARNING);
}
// For when codebase is included without functions.php - e.g. ajax or cron
if (!function_exists('mem')) {
function mem($label = '')
{
static $mem_usage = array();
if ($label=='') {
return($mem_usage);
}
$mem_usage[] =
array(
'lbl' => $label,
'mem' => number_format(memory_get_usage()),
'class_files' => includes_monitor()
);
return;
}
}
if (!function_exists('includes_monitor')) {
function includes_monitor($className = '', $filePath = '')
{
static $includes = array();
if ($className=='') {
return $includes;
}
$includes[$className] = $filePath;
}
}
// ************************************
// * Definitions and Includes *
// ************************************
if (!defined('SYS_ID')) {
include_once(SYS_SHARED."system.php");
hvFF9mrhFbntrDgfGb9wc1gf('no_id');
}
session_name("ECC_".SYS_ID);
session_cache_limiter('must-revalidate');
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid', false);
session_start();
if (!defined("SYS_BUTTONS")) {
define("SYS_CACHE", SYS_SHARED."cache/");
define("SYS_BUTTONS", SYS_CACHE."buttons/");
define("MONO_FONT", "veramono.ttf");
define("SYS_CLASSES", SYS_SHARED."classes/");
define("SYS_FONTS", SYS_SHARED."fonts/");
define("SYS_IMAGES", SYS_SHARED."images/");
define("SYS_JS", SYS_SHARED."js/");
define("SYS_STYLE", SYS_SHARED."style/");
define("SYS_SWF", SYS_SHARED."swf/");
}
define(
"SYS_RESERVED_URL_PARTS",
"_popup_layer, .htaccess, article, ajax, category, command, cron, css, db_export,"
." details, email-view, event, export,"
." facebook, fck, img, index.php, java, job, js, js_context, logs, mode, news,"
." osd, page, piwik, podcast, print_form, report, resource, robots.txt, rss,"
." sitemap.xml, sysjs, tags, _ticket, userfiles, webmail, xhtml1-strict-with-iframe.dtd"
);
define("SYS_BUTTON_TEMPLATES", SYS_SHARED."button_templates/");
define("SYS_EXPORT", dirname($_SERVER["SCRIPT_FILENAME"])."/export/");
define("SYS_EXPORT_CODE", SYS_SHARED."export_code/");
define("SYS_FACEBOOK", SYS_SHARED."facebook/");
define("SYS_LOGS", "./logs/");
define("SYS_LOG_FILE", "debug.txt");
define("SYS_MODULES", SYS_SHARED."modules/");
define("OPTION_SEPARATOR", "[ECL]option_separator[/ECL]");
define(
"SYS_STANDARD_FIELDS",
"anchor,bulk_update,command,component_help,DD,filterExact,"
."filterField,filterValue,goto,limit,memberID,MM,mode,offset,print,report_name,rnd,"
."search_categories,search_date_end,search_date_start,search_keywords,search_offset,"
."search_text,search_type,selected_section,selectID,sortBy,source,submode,targetField,"
."targetFieldID,targetID,targetReportID,targetValue,topbar_search,YYYY"
);
define("SYS_UPGRADE_URL", "http://www.ecclesiact.com/");
// This is called whenever system tries to create a non existant class of the given name
spl_autoload_register(function($className) { return portal_autoload($className); });
define("DEV_STATUS", Portal::isDev());
mem('in codebase-1');
$_old_path = ini_get('include_path');
// Do this because encoded system.php blows away include_path for PEAR
include_once(SYS_SHARED."system.php");
ini_set('include_path', $_old_path);
include_once(SYS_SHARED."adodb-time.inc.php");
$custom_file = (defined("AJAX_VERSION") ? "../" : "./")."custom.php";
if (file_exists($custom_file)) {
include_once($custom_file);
}
function portal_autoload($className)
{
if (class_exists($className)) {
return;
}
$fileName = 'class.'.strToLower($className).'.php';
$filePath = SYS_CLASSES.$fileName;
if (file_exists($filePath)) {
require_once($filePath);
includes_monitor($className, $filePath);
return;
}
$filePath = SYS_SHARED.$fileName;
if (file_exists($filePath)) {
require_once($filePath);
includes_monitor($className, $filePath);
return;
}
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, strToLower($className).'.php');
$filePath = SYS_CLASSES.$fileName;
if (file_exists($filePath)) {
require_once($filePath);
includes_monitor($className, $filePath);
return;
}
// print 'looking for '.$include_file;
}
spl_autoload_register('portal_autoload');
mem('in codebase-2');
$component_result = array();
// ************************************
// * Extract variables *
// ************************************
extract($_REQUEST); // Extracts all request variables (GET, COOKIE and POST) into global scope.
Cart::initialise();
// Added for PCI Compliance, 2006/01/06
// Test: enter this URL:
// http://www.auroraonline.com/?report_name="><script>alert('ScanAlert')</script><"
if (isset($anchor)) {
$anchor = sanitize('html', $anchor);
}
if (isset($bulk_update)) {
$bulk_update = sanitize('range', $bulk_update, 0, 1, 0);
}
if (isset($columnID)) {
$columnID = sanitize('ID', $columnID);
}
if (isset($command)) {
$command = sanitize('html', $command);
}
if (isset($component_help)) {
$component_help = sanitize('range', $component_help, 0, 1, 0);
}
if (isset($DD)) {
$DD = sanitize('range', $DD, 1, 31, date('d'));
}
if (isset($filterExact)) {
$filterExact = sanitize('html', $filterExact);
}
if (isset($filterField)) {
$filterField = sanitize('html', $filterField);
}
if (isset($filterValue)) {
$filterValue = sanitize('html', $filterValue);
}
if (isset($goto)) {
$goto = sanitize('html', $goto);
}
if (isset($limit)) {
$limit = sanitize('html', $limit);
}
if (isset($memberID)) {
$memberID = sanitize('range', $memberID, 0, 'n', '');
}
if (isset($MM)) {
$MM = sanitize('range', $MM, 1, 12, date('m'));
}
if (isset($mode)) {
$mode = sanitize('html', $mode);
}
if (isset($offset)) {
$offset = sanitize('html', $offset);
}
if (isset($page)) {
$page = sanitize('html', (substr($page, -1)=='\\' ? '' : $page));
}
if (isset($preset_values)) {
$preset_values = sanitize('html', $preset_values);
}
if (isset($print)) {
$print = sanitize('html', $print);
}
if (isset($report_name)) {
$report_name = sanitize('html', $report_name);
}
if (isset($search_categories)) {
$search_categories = sanitize('html', $search_categories);
}
if (isset($search_date_end)) {
$search_date_end = sanitize('date-stamp', $search_date_end);
}
if (isset($search_date_start)) {
$search_date_start = sanitize('date-stamp', $search_date_start);
}
if (isset($search_keywords)) {
$search_keywords = sanitize('html', $search_keywords);
}
if (isset($search_name)) {
$search_name = sanitize('html', $search_name);
}
if (isset($search_offset)) {
$search_offset = sanitize('range', $search_offset, 0, 65535, 0);
}
if (isset($search_text)) {
$search_text = sanitize('html', $search_text);
}
if (isset($search_type)) {
$search_type = sanitize('enum', $search_type, array(
'*','article','event','gallery-image','news-item','job-posting','page','podcast','product'
));
}
if (isset($selectID)) {
$selectID = sanitize('ID', $selectID);
}
if (isset($selected_section)) {
$selected_section = sanitize('html', $selected_section);
}
if (isset($sortBy)) {
$sortBy = sanitize('html', $sortBy);
}
if (isset($source)) {
$source = sanitize('html', $source);
}
if (isset($submode)) {
$submode = sanitize('html', $submode);
}
if (isset($targetID)) {
$targetID = sanitize('ID', $targetID);
}
if (isset($targetField)) {
$targetField = sanitize('html', $targetField);
}
if (isset($targetFieldID)) {
$targetFieldID = sanitize('ID', $targetFieldID);
}
if (isset($targetReportID)) {
$targetReportID = sanitize('ID', $targetReportID);
}
if (isset($targetValue)) {
$targetValue = sanitize('html', $targetValue);
}
if (isset($topbar_search)) {
$topbar_search = sanitize('html', $topbar_search);
}
if (isset($YYYY)) {
$YYYY = sanitize('range', $YYYY, 100, 3000, date('Y'));
}
mem('in codebase-3');
//$memberID=564563;
// ************************************
// * Set Global Variables *
// ************************************
global $anchor,$YYYY,$MM,$DD,$mode,$page,$goto,$img,$color,$command,$username,$password,$bulk_update,$system_vars;
$now = time();
$YYYY = ($YYYY=="" ? adodb_date('Y', $now) : $YYYY);
$MM = ($MM=="" ? adodb_date('m', $now) : $MM);
$MM = (strlen($MM)==1 ? "0".$MM : $MM);
$DD = ($DD=="" ? adodb_date('d', $now) : $DD);
$DD = (strlen($DD)==1 ? "0".$DD : $DD);
$Obj = new System(SYS_ID);
$Obj->define_URL_params();
$system_vars = get_system_vars();
if (isset($system_vars['timezone'])) {
date_default_timezone_set($system_vars['timezone']);
Base::registerModules();
}
Portal::ParseRequest();
mem('in codebase-4');
function absolute_path($html, $host_url)
{
$html = str_replace('popWin(\'/', 'popWin(\''.$host_url, $html);
$html = str_replace('/resource/', $host_url.'resource/', $html);
$html = str_replace('&soundFile=', '&soundFile='.urlencode($host_url), $html);
return preg_replace(
"#(\/resource\/|action='|action=\"|href='|href=\"|src='|src=\"|background='|background=\"|url\()(\/)#",
"$1".$host_url,
$html
);
}
function array_remove_value(&$array, $val = '')
{
if (empty($array) || !is_array($array)) {
return;
}
if (!in_array($val, $array)) {
return;
}
$arr = $array;
foreach ($arr as $key => $value) {
if ($value == $val) {
unset($arr[$key]);
}
}
$array = array_values($arr);
}
function component_result($what, $supress_error = false)
{
global $component_result;
if (isset($component_result[$what])) {
return $component_result[$what];
}
if ($supress_error) {
return false;
}
return "<span style='color:#ff0000;font-weight:bold;'>".$what."</span>";
}
function component_result_set($var, $what)
{
global $component_result;
$component_result[$var] = $what;
}
function context($text, $search, $limit = -1)
{
$text = trim($text);
$search = trim($search);
$length = strlen($text);
if ($search=='') {
if ($limit==-1) {
return $text;
}
$context = substr($text, 0, $limit);
return $context.($text==$context ? "" : "…");
}
$text = convert_html_to_safe_view($text);
if ($limit==-1) {
return preg_replace("/($search)/i", "<span class='highlight'>\\1</span>", $text);
}
$pos = strpos(strtolower($text), strtolower($search));
if ($pos>($limit/2)) {
$pos = strpos($text, " ", ($pos-($limit/2)));
} else {
$pos = 0;
}
$search_preg_safe =
str_replace(
array(
'[',']','(',')','*'
),
array(
'\[','\]','\(','\)','\*'
),
$search
);
$out =
preg_replace(
"/($search_preg_safe)/i",
"<span class='highlight' style='color:red'>\\1</span>",
substr($text, $pos, $limit)
);
if (strip_tags($out)!=$text) {
if ($length> ($limit/2)+1+($pos>$limit? $pos : 0)) {
$out .= "…";
}
if ($pos>0) {
$out = "…".$out;
}
}
return $out;
}
function convert_a2r($num, $lower = false)
{
// Converts arabic to roman numerals
// Not optimised - 999 = CMXCIX not IM
// Only goes up to 1000
// To improve see http://www.howtocreate.co.uk/php/dnld.php?file=2&action=1
$a2r[1] = "i";
$a2r[5] = "v";
$a2r[10] = "x";
$a2r[50] = "l";
$a2r[100] = "c";
$a2r[500] = "d";
$a2r[1000] = "m";
$out = "";
for ($n = 1000; $n >= 1; $n=$n/10) {
switch(floor($num / $n)) {
case 1:
$out .= $a2r[$n];
break;
case 2:
$out .= $a2r[$n].$a2r[$n];
break;
case 3:
$out .= $a2r[$n].$a2r[$n].$a2r[$n];
break;
case 4:
$out .= $a2r[$n].$a2r[5 * $n];
break;
case 5:
$out .= $a2r[5 * $n];
break;
case 6:
$out .= $a2r[5 * $n].$a2r[$n];
break;
case 7:
$out .= $a2r[5 * $n].$a2r[$n].$a2r[$n];
break;
case 8:
$out .= $a2r[5 * $n].$a2r[$n].$a2r[$n].$a2r[$n];
break;
case 9:
$out .= $a2r[$n].$a2r[10 * $n];
break;
}
//Repeat with what is left
$num = $num % $n;
}
return $lower ? $out : strToUpper($out);
}
function convert_embedded_audio($string)
{
// return $string;
// Replaces [audio: file.mp3|param-1|param-n]
$pagebits = preg_split("/\[audio:/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$plaintext = true;
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
$bit_arr = preg_split("/\]/", $bit);
$params = trim(urldecode(array_shift($bit_arr)), ": {}");
$Obj_AP = new Media_Audioplayer($params);
$out .= $Obj_AP->draw_clip().implode("]", $bit_arr);
}
$plaintext = false;
}
return $out;
}
function convert_embedded_video($string)
{
// Replaces [video: file.flv|file.jpg|width|height]
$pagebits = preg_split("/\[video:/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$plaintext = true;
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
$bit_arr = preg_split("/\]/", $bit);
$params = trim(urldecode(array_shift($bit_arr)), ": {}");
$params_arr = explode('|', $params);
$Obj_VP = new Component_Video_Player;
$params = array(
'path_flv' => (isset($params_arr[0]) ? $params_arr[0] : ''),
'path_jpg' => (isset($params_arr[1]) ? $params_arr[1] : ''),
'width' => (isset($params_arr[2]) ? $params_arr[2] : ''),
'height' => (isset($params_arr[3]) ? $params_arr[3] : '')
);
$out.= $Obj_VP->draw('', $params, true).implode("]", $bit_arr);
}
$plaintext = false;
}
return $out;
}
function convert_embedded_youtube($string)
{
// Replaces [youtube: URL|width|height|start]
$pagebits = preg_split("/\[youtube/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$plaintext = true;
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
$bit_arr = preg_split("/\]/", $bit);
$params = trim(urldecode(array_shift($bit_arr)), ": {}");
$params_arr = explode('|', $params);
$url = (isset($params_arr[0]) ? $params_arr[0] : '');
$width = (isset($params_arr[1]) ? $params_arr[1] : 240);
$height = (isset($params_arr[2]) ? $params_arr[2] : 180);
$start = (isset($params_arr[3]) ? $params_arr[3] : 0);
$Obj_YT = new Media_Youtube($url, $width, $height, $start);
$out .= $Obj_YT->draw_clip().implode("]", $bit_arr);
}
$plaintext = false;
}
return $out;
}
function convert_html_to_plaintext($html)
{
return nl2br(strip_tags(preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $html)));
}
function convert_html_to_safe_view($value, $limit = 500)
{
$value = preg_replace('/\[LANG\]([^\|]*)\|/i', '[LANG]${1}|', $value);
$value = preg_replace('/\[\/LANG\]/i', '[/LANG]', $value);
$value = preg_replace('/\[ECL\]option_separator\[\/ECL\]/i', '[br]', $value);
$value = preg_replace('/<img[^>]*>/', '<img> ', $value);
$value = preg_replace('/<h([1-6])[^>]*>([^<]*)<\/h([1-6])>/', '[h${1}]${2}[/h${3}]', $value);
$value = preg_replace('/\[ECL\]field_([^\[]*)\[\/ECL\]/is', '[FIELD]${1}[/FIELD]', $value);
$value = preg_replace('/\[ECL\]([^\[]*)\[\/ECL\]/is', '[ECL]${1}[/ECL]', $value);
$value = preg_replace('/(\[ICON\]([^\[]*)\[\/ICON\])/is', '${1} [ICON]${2}[/ICON]', $value);
$value = preg_replace(
'/(\[TRANSFORM\]([^\[]*)\[\/TRANSFORM\])/is',
'[TRANSFORM]',
$value
); // Strip Transformer tags
$value = preg_replace(
'/(\[audio([^\[]*)\])/is',
'[AUDIO]',
$value
); // Strip Audio
$value = preg_replace(
'/(\[youtube([^\[]*)\])/is',
'[YOUTUBE]',
$value
); // Strip Audio
$value = preg_replace(
'/\s\s+/',
' ',
strip_tags($value)
);
$value = preg_replace(
'/([LANG])([^\|]*)\|/i',
"<span style='background-color:#ff8080;font-weight:bold;'>\${1}\${2}</span>",
$value
); // Represent Lang tags
$value = preg_replace(
'/([\/LANG])/i',
"",
$value
); // Represent Lang tags
$value = preg_replace(
'/<img>/',
"<span style='background-color:#c0ffc0;font-weight:bold;'><img></span>",
$value
);
$value = preg_replace(
'/\[h([1-6]*)\]([^\[]*)\[\/h([1-6])\]/',
"<span style='background-color:#c0c0ff;font-weight:bold;'><h\${1}>\${2}</h\${3}></span>",
$value
);
$value = preg_replace(
'/([FIELD])([^&]*)([\/FIELD])/is',
"<span style='background-color:#ffe0e0;color:#ff0000;font-weight:bold;'>\${2}</span>",
$value
); // Represent ECL Script tags
$value = preg_replace(
'/([ECL])([^&]*)([\/ECL])/is',
"<span style='background-color:#ffff00;font-weight:bold;'>\${1}\${2}\${3}</span>",
$value
); // Represent ECL Script tags
$value = preg_replace(
'/([ICON])([^\[]*)([\/ICON])/is',
"<span style='background-color:#ffc0ff;font-weight:bold;'>\${1}\${2}\${3}</span>",
$value
); // Represent ICON tags
$value = preg_replace(
'/([AUDIO])/is',
"<span style='background-color:#ffc0ff;font-weight:bold;'>\${1}</span>",
$value
); // Display AUDIO tags
$value = preg_replace(
'/([YOUTUBE])/is',
"<span style='background-color:#ffc0ff;font-weight:bold;'>\${1}</span>",
$value
); // Display YOUTUBE tags
$value = preg_replace('/\[br\]/is', "<br />", $value); // Strip ICON tags
if ($limit) {
$value = (strlen($value) > $limit ? substr($value, 0, $limit)."..." : substr($value, 0, $limit));
}
return $value;
}
function convert_icons($string)
{
// Replaces [ICON]aa bb cc title[/ICON]
// aa=width
// bb=padded width
// cc=source image offset
// title=title
$pagebits = preg_split("/\[ICON\]|\[\/ICON\]/", $string);
if (count($pagebits)<=1) {
return $string;
}
$checksum = System::get_item_version('icons');
$renderedbit = array();
$out = "";
$plaintext = true;
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
if (in_array($bit, $renderedbit)) {
$out.= $renderedbit[$bit];
} else {
$bit_arr = explode(' ', $bit);
$width = array_shift($bit_arr);
$padded_width = array_shift($bit_arr);
$padding = $padded_width-$width;
$offset = array_shift($bit_arr);
$text = implode(' ', $bit_arr);
$out.=
"<img class=\"toolbar_icon\" src=\"".BASE_PATH."img/spacer\""
." alt=\"".$bit."\" title=\"".$text."\" width=\"".$width."\" height=\"16\""
." style=\"background-position:-".$offset."px 0px\" />"
.($padding>0 ?
"<img class='b fl' style=\"border:none;\" src=\"".BASE_PATH."img/spacer\""
." width=\"".$padding."\" height=\"16\" alt=\"\"/>"
:
""
);
}
}
$plaintext = !$plaintext;
}
return $out;
}
function convert_labels($string)
{
// Replaces [LBL]aa|bb|title[/LBL]
// aa = classname
// bb = height (blank if not forced)
// title = title
$pagebits = preg_split("/\[LBL\]|\[\/LBL\]/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$renderedbit = array();
$plaintext = true;
$checksum = System::get_item_version('labels');
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
if (in_array($bit, $renderedbit)) {
$out.= $renderedbit[$bit];
} else {
$bit_arr = explode('|', $bit);
$class = array_shift($bit_arr);
$height = array_shift($bit_arr);
$text = str_replace("\\n", "\n", implode(' ', $bit_arr));
$out.=
"<img class='label lbl_".$class."'"
.($height ? " style=\"height:".$height."px\"" : "")
." src=\"".BASE_PATH."img/spacer\""
." title=\"".$text."\""
." alt=\"".$class."\" />";
}
}
$plaintext = !$plaintext;
}
return $out;
}
function convert_language_tags($string)
{
return Language::convert_tags($string);
}
function convert_ssi_tokens($string)
{
// Replaces [ssi:ID|PUsername] with SSI link
$pagebits = preg_split("/\[ssi:/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$plaintext = true;
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
$bit_arr = preg_split("/\]/", $bit);
$params = explode('|', array_shift($bit_arr));
if (count($params)==2) {
$credentials = serialize(
array(
'i' => sanitize('html', $params[0]),
'p' => sanitize('html', $params[1])
)
);
$out.=
BASE_PATH
."?command=ssi&token="
.XOREncrypt($credentials)
.implode("]", $bit_arr);
}
}
$plaintext = false;
}
return $out;
}
function convert_transforms($string)
{
// J.F. - added in version 1.9.17
// replaces [TRANSFORM]JSON Parameters[/TRANSFORM]
// with its output as we want it to be seen
$pagebits = preg_split("/\[TRANSFORM\]|\[\/TRANSFORM\]/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$plaintext = true;
// set up a variable to contain and keep track of any javascript that needs added
$transformJS = array();
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
// we have to keep transforms in single-quoted strings or FCKEditor messes them up:
// [TRANSFORM]'method':'fieldtype','name':'customButton','data':"
// {'text':'Smiles','width':'70','style':'Main','height':'26','cssclass':'','url':'http://www.cicbv.ca'}
// [/TRANSFORM]
// Problem is, this is not valid JSON - see Example 3 at http://php.net/manual/en/function.json-decode.php
// So we have to play this game to convert them here before attempting to JSON decode
$bit = str_replace("'", '"', $bit);
$params = json_decode("{".$bit."}", true);
if ($params['method'] == 'fieldtype') {
// we use the fieldtype class to transform this thing
$context = isset($params['data']['context']) ? $params['data']['context'] : 'page';
$ft = new Transformer($context, $params['name'], $params['data']);
if ($ft->error) {
$out .= "Transform error: " . $ft->error;
} else {
if (!array_key_exists($params['name'], $transformJS)) {
$out .= $ft->JS;
$transformJS[$params['name']] = 'done';
}
$out .= $ft->HTML;
}
}
}
$plaintext = !$plaintext;
}
return $out;
}
function convert_safe_to_php($string)
{
// May occur more than once - ECL tags can recurse
$string = convert_icons($string);
$string = convert_labels($string);
$string = convert_embedded_audio($string);
$string = convert_embedded_youtube($string);
$string = convert_embedded_video($string);
$string = convert_ssi_tokens($string);
$string = convert_transforms($string);
$string = convert_ecl_tags($string);
$string = convert_language_tags($string);
return $string;
}
function convert_ecl_tags($string)
{
// Thanks Vic for the great ideas here!
static $global_ECL_arr;
// If first pass, load ECL tags and PHP code into $global_ECL_arr array:
if (!isset($global_ECL_arr)) {
$Obj = new ECL_Tag;
$global_ECL_arr = $Obj->get_all();
}
// Split on any remaining unconverted ECL tags
// Exit if none found
$pagebits = preg_split("/\[ECL\]|\[\/ECL\]/", $string);
if (count($pagebits)<=1) {
return $string;
}
$out = "";
$renderedbit = array();
$plaintext = true; // Assume we are starting as plain text
foreach ($pagebits as $bit) {
if ($plaintext) {
$out.= $bit;
} else {
$instance_name = '';
$_bit = $bit;
$bit_arr = explode(":", $bit);
if (count($bit_arr)>1) {