-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicdisplay.php
1011 lines (994 loc) · 32.9 KB
/
basicdisplay.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
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
?>
<?php
/*
// web/webtc/basicdisplay.php
// The main function basicDisplay constructs an HTML table from
// an array of data elements.
// Each of the data elements is a string which is valid XML.
// The XML is processed using the XML Parser routines (see PHP documentation)
// This XML string is further assumed to be in UTF-8 encoding.
// July 2, 2018 - begin universal version of BasicDisplay. Objective is
// for this to work for all Cologne dictionaries.
// Aug 7, 2020. Restructure under assumption that input to
// constructor is either a string or an array of strings.
// Nov 20, 2023. abch
*/
require_once("dbgprint.php");
require_once("parm.php");
class BasicDisplay {
public $parentEl;
public $row;
public $row1;
public $row1x;
public $pagecol;
public $dbg;
public $inSanskrit;
public $inkey2;
public $table;
public $dict;
public $sdata; // class to use for Sanskrit
public $filterin; // transcoding for output
public $key; // the original key being searched for
public $basicOption,$serve;
public $getParms,$status,$html;
public $mwx; // whitney/westergaard links
public function __construct($key,$string_or_array,$filterin,$dict) {
$this->key = $key;
$this->dict = $dict;
$this->filterin = $filterin;
$this->getParms = new Parm();
$this->basicOption = $this->getParms->basicOption;
$this->serve = $this->getHrefPage_serve();
$this->pagecol="";
$this->dbg=false;
$this->inSanskrit=false;
if ($filterin == "deva") {
/* use $filterin to generate the class to use for Sanskrit (<s>) text
This let's us use siddhanta font for Devanagari.
$this->sdata is used later.
*/
$this->sdata = "sdata_siddhanta"; // consistent with font.css
}else if (($filterin == 'roman')&&($this->dict == 'mw')) {
$this->sdata = "sdata_italic_iast";
} else {
$this->sdata = "sdata"; // default.
}
$sdata = $this->sdata;
// The constructed html is in public variable $table.
// $this->table is the instance variable
if (in_array($this->dict,array('ae','mwe','bor'))) {
// no transliteration of $key for English headword
$this->table = "<h1> $key</h1>\n";
}else {
$this->table = "<h1 class='$sdata'> <SA>$key</SA></h1>\n";
}
$this->table .= "<table class='display'>\n";
if (is_string($string_or_array)) {
$matches = array($string_or_array);
}else if (is_array($string_or_array)) {
if (count($string_or_array) == 0) {
$matches = array();
}else {
// take only first item
$matches = array($string_or_array[0]);
}
}else {
$matches = array();
}
$ntot = count($matches); // either 0 or 1.
// Associative array. keys are:
// status
// mw whitney/westergaard links -- currently requires dict == mw
//
$this->status = true;
$this->mwx = "";
$this->row = "";
$this->row1 = "";
$this->html = "";
$i = 0;
while($i<$ntot) {
$linein=$matches[$i];
// a line of data from xxx.xml, after adjustments by basicadjust.php
$line=$linein;
dbgprint($this->dbg,"basicdisplay: line[$i+1]=$line\n");
$line=trim($line);
$l0=strlen($line);
$this->row = "";
$this->row1 = "";
$this->row1x = "";
if ($dict == 'mw') {
$row1x = $this->mw_extra_line($line);
$this->row1x = $row1x;
}else if ($dict == 'mci') {
$row1x = $this->mci_extra_line($line);
$this->row1x = $row1x;
}else {
$row1x = "";
}
$this->inSanskrit=false;
$this->inkey2 = false;
// initialize parser
$p = xml_parser_create('UTF-8');
xml_set_element_handler($p,array($this,'sthndl'),array($this,'endhndl'));
xml_set_character_data_handler($p,array($this,'chrhndl'));
xml_parser_set_option($p,XML_OPTION_CASE_FOLDING,FALSE);
dbgprint($this->dbg,"chk 1\n");
// parse
if (!xml_parse($p,$line)) {
dbgprint(true,"basicdisplay.php: xml parse error\nline=$line\n");
$row = $line;
$this->status = false;
$this->html = "<p>basicdisplay.php: xml parse error</p>";
return;
}
dbgprint($this->dbg,"chk 2\n");
xml_parser_free($p);
dbgprint($this->dbg,"chk 3\n");
$this->table .= "<tr>";
$this->table .= "<td>";
// $style = "background-color:beige";
$style = ""; // none
// Since style is "", the use of $style below has no impact on display
// in browser.
$row1a = "";
if ($this->dict == 'mw') {
/* adjust $this->row */
$this->mw_row_key_adjust($line);
$row1a = "";
if ($this->row1 != "") {
$row1a = "<span style='$style'>{$this->row1}</span>";
}
if ($row1x != "") {
$row1a = "$row1a<br/>\n$row1x";
}
if ($row1a != "") {
$this->table .= "$row1a<br/>\n{$this->row}\n";
}else {
$this->table .= "{$this->row}\n";
}
/* Summary for MW. Note that row1 is NEVER the empty string
row1x can be empty (usual) or not-empty (Whitney, Westergaard links)
if row1x is not empty, then
table = row1 <br> row1x <br> row
if row1x is empty, then
table = row1 <br> row
*/
} else {
$row1a = "<span style='$style'>{$this->row1}</span>";
$this->table .= "$row1a\n<br/>{$this->row}\n";
/* table = row1 + <br> + row */
}
/* row1, row
*/
$this->table .= "</td>";
// This is so that there will be no need for a horizontal scroll. 12-14-2017
$this->table .= "<td> </td>";
$this->table .= "</tr>";
$i++;
}
$this->table .= "</table>\n";
// dbgprint(true,"basicdisplay: table=\n{$this->table}\n");
}
public function getline_key1($line) {
if (preg_match('|<key1>(.*?)</key1>|',$line,$matches)) {
$key1 = $matches[1];
return $key1;
}else {
return $this->key;
}
}
public function mw_row_key_adjust($line){
$keyline = $this->getline_key1($line);
if ($keyline == $this->key) {
return; // no adjustment
}
//Do something to visually distinguish (exclude) this line.
// modify $this->row
$row = $this->row;
$style = "background-color:rgb(235,235,235)"; # 235
$this->row = "<span style='$style'>$row</span>";
return; // not implemented
}
public function sthndl_div($attribs) {
// 07-05-2018. This function is still dictionary specific
// 07-06-2023. Change indent code for gra (see also endhdl function
$n=$attribs['n'];
if ($this->dict == 'gra') {
if ($n == 'H') {$indent = "1.0em";}
else if ($n == 'P') {$indent = "2.0em"; }
else if ($n == 'P1') {$indent = "3.0em";}
else {$indent = "";}
$style="padding-left:$indent;";
return "<div style='$style'>";
}else if ($this->dict == 'bur') {
// 07-13-2023
if ($n == '2') {
$indent = "1.0em";
} else if ($n == '3') {
$indent = "2.0em";
} else {
$indent = "0.1em";
}
$style="padding-left:$indent;";
return "<div style='$style'>";
}else if ($this->dict == 'stc') {
if ($n == 'P') {
$indent = "1.5em";
}else {
$indent = "0.1em";
}
$style="padding-left:$indent;";
return "<div style='$style'>";
}else if ($this->dict == 'pwg') {
if ($n == '1') {$indent = "1.0em";}
else if ($n == '2') {$indent = "2.0em"; }
else if ($n == '3') {$indent = "3.0em";}
else {$indent = "0.1em";}
$style="padding-left:$indent;";
return "<div style='$style'>";
}else if ($this->dict == 'pw') {
// n = 1 (number div), n = 2 (English letter), n = 3 (Greek letter)
// n = p (prefixed form, in verbs
if ($n == '1') {$indent = "1.5em";}
else if ($n == '2') {$indent = "3.0em";}
else if ($n == '3') {$indent = "4.5em";}
else {$indent = "0.1em";}
$style = "padding-left:$indent;";
return "<div style='$style'>";
}else if ($this->dict == 'ap') {
// line break, and
// indent, whether 'n' is '2' or 'P' (only values allowed) 05-04-2017
// also, n='3' 05-21-2017
// Examples: n=2: akulAgamatantra
// n=P paRqitasvAmin
// n=3 agastyasaMhitA
if ($n == '3') {
$indent = "2.0em";
} else if ($n == '2') {
$indent = "1.0em";
}else {
$indent = "0.1em";
}
$style = "padding-left:$indent;";
return "<div style='$style'>";
}else if (in_array($this->dict,array('pd','bhs','mwe','mw72','sch','snp','vei'))) {
// n = lb (line break)
// But for 'sch', there is no n attribute (so $n is null or undefined).
// snp has n=lb, P, HI. Currently all are rendered as line break.
// vei has n=lb, P. Both are rendered as line break.
$ans = "<div>";
return $ans;
}else if (in_array($this->dict,array('wil','shs'))) {
// line break, and
// indent, indent if 'n' is '2'
// no indent if n='1' , 'E', 'lex' (for wil)
// n='1' , 'E', 'Poem' (for wil)
if ($n == '2') {
$indent="1.5em;";
} else {
$indent="0.1em";
}
$style = "padding-left:$indent;";
return "<div style='$style'>";
}else if (in_array($this->dict,array('gst','ieg','inm','mci'))) {
if ($n == 'P') {$indent = "1.0em";}
else {$indent = "0.1em"; }
$style = "padding-left:$indent;";
return "<div style='$style'>";
}else if (in_array($this->dict,array('ben','pui'))) {
// in ben, this div is an empty div. The display
// should begin a new indented paragraph.
// Example under dIkz and garj.
if ($n == 'P') {$indent = "1.0em";}
else {$indent = "0.1em";}
$style = "padding-left:$indent;";
return "<div style='$style'>";
}else if (in_array($this->dict,array('skd','krm'))) {
// for skd (only for n="F", 5 cases as of 8/23/2017)
// Treat the same as "<F>"
if ($n == "F") {
$indent = "1.0em";
$style = "padding-left:$indent;";
return "<div style='$style' class='footnote'><b>Footnote</b> ";
} else {
return "<div>";
}
}else if ($this->dict == 'vcp') {
// vcp needs further revision, by change to make_xml.py
// <Picture> should not be changed to div
if ($n == 'Picture') {
$ans = "<div style='font-size:smaller;padding-left:1.0em;'>(Picture)";
} else { //P, H, HI
$ans = "<div>";
}
return $ans;
}else if ($this->dict == 'bop') {
// n = "pfx". Currently always a line break
return "<div>";
}else if ($this->dict == 'bor') {
// could be better.
if ($n == "lb") {
return "<div>";
} else {
return "<div style='display:inline;'>";
}
}else if ($this->dict == 'pe') {
// the div tag is empty for pe.
if ($n == 'P') {
// line break plus indent.
return "<br/> ";
}else if ($n == 'NI') {
// two line breaks, no indent
return "<br/><br/>";
}else {
// $n == "lb" . line break, no indent
return "<br/>";
}
} else if ($this->dict == 'pgn') {
// the div tag is empty for pgn.
if ($n == 'P') {
// line break plus indent.
return "<br/> ";
}else {
// $n == "lb" . line break, no indent
return "<br/>";
}
} else if ($this->dict == 'acc') {
// line break, and
// indent, whether 'n' is '2' or 'P' (only values allowed) 05-04-2017
// also, n='3' 05-21-2017
// Examples: n=2: akulAgamatantra
// n=P paRqitasvAmin
// n=3 agastyasaMhitA
if (($n == '2') || ($n=='P')) {
return "<div style='padding-left:1.5em'>";
}else {
return "<div>";
}
} else if (in_array($this->dict,array("abch", "acph", "acsj"))) {
if (isset($attribs['style'])) {
$style=$attribs['style'];
$ans = "<div style='$style'>";
} else {
$ans = "<div>";
}
return $ans;
}else { // default
// currently applies to:
// cae with <div n="p"/>
// mw
// ap90 with <div n="1"/> or <div n="P"/>. See basicadjust
return "<div style='margin-top:0.6em;'></div>";
}
}
public function sthndl_elt_attribs($attribs,$elt) {
// 11-20-2023 new function used for abch.
// But may have general use
$attrib_keys = array_keys($attribs);
$ar = array();
foreach($attrib_keys as $key) {
$val = $attribs[$key];
array_push($ar," $key='$val'");
}
$a = join("",$ar);
$ans = "<$elt$a>";
if (false) {
$keys = join(" ",$attrib_keys);
echo "dbg: elt = $elt<br/>\n";
foreach($ar as $x) {
echo " attrib: $x<br/>\n";
}
$ans1 = preg_replace('|<|','<',$ans);
echo "ans = $ans1<br/><br/>\n";
}
return $ans;
}
public function sthndl($xp,$el,$attribs) {
// $el is one of the elements of the xml record.
if (preg_match('/^H.+$/',$el)) {
// In general, don't display 'H1'. But MW has different
if ($this->dict == 'mw') {
// For mw, do display
// However, don't display HxA, HxB, HxC (? see 'agre')
if (preg_match('|^H[1-4]$|',$el)) {
$this->row1 .= "($el)";
}
}else {
// for other dictionaries, don't display
}
} else if ($el == "s") {
$this->inSanskrit = true;
} else if ($el == "key2"){
$this->inkey2 = true;
} else if ($el == "b"){
$this->row .= "<strong>";
} else if ($el == "graverse") {
$this->row .= "<span style='font-size:smaller; font-weight:100'>";
} else if ($el == "gralink") {
$href = $attribs['href'];
$tooltip = $attribs['n'];
$style = 'text-decoration: none; border-bottom: 1px dotted #000;';
$this->row .= "<a href='$href' title='$tooltip' style='$style' target='_rvlink'>";
} else if ($el == "lanlink") {
$href = $attribs['href'];
# A work around. Instead of real url parameter ('&page=...'),
# we have, in basicadjust, put '_page=...'. change back to '&page'
$href = preg_replace('|_page|','&page',$href);
# next so line number will appear in url of displayed page.
$href = preg_replace('|_line|','&line',$href);
$tooltip = $attribs['n'];
$target = $attribs['target'];
$this->row .= "<a href='$href' title='$tooltip' target='$target'>";
} else if ($el == "lex"){ // m. f., etc.
$this->row .= "<strong>";
} else if ($el == "i"){
$this->row .= "<i>";
} else if ($el == "br"){
$this->row .= "<br/>";
} else if ($el == "h"){
} else if ($el == "body"){
} else if ($el == "tail"){
} else if ($el == "L"){
} else if ($el == "L1"){
// for MW only, work done elsewhere
$this->row .= "<L1>";
} else if ($el == "s1") {
// currently only MW. This has an 'slp1' attribute which could be
// used to replace the IAST text with Devanagari. However currently
// we just display the IAST text, so do nothing with this element
} else if ($el == "etym") {
$this->row .= "<i>";
} else if ($el == "info") {
// 10-05-2024
if (in_array($this->dict,array('pwg'))) {
$attrval = $attribs["n"];
$x = ''; // text to add
if (in_array($attrval,array("rev","sup"))) {
if ($attrval == "rev") {
$y = "revision";
}else if ($attrval == "sup") {
$y = "supplement";
}
$x = "<span style='color:red'> ($y)</span>";
}
$this->row .= $x;
}
} else if ($el == "pc"){
} else if ($el == "to") {
} else if ($el == "ns") {
} else if ($el == "shortlong") {
} else if ($el == "srs") {
} else if ($el == "pcol") {
} else if ($el == "nsi") {
} else if ($el == "pb"){
if (in_array($this->dict,array("bur","stc","mw","pwg"))) {
# do nothing
}else {
$this->row .= "<br/>";
}
} else if ($el == "key1"){
} else if ($el == "hom"){ // handled wholly in chrhndl
} else if ($el == "F"){
$style = "font-weight:bold;";
$this->row .= "<br/>[<span style='$style'>Footnote: </span><span>";
} else if ($el == "symbol") {
} else if ($el == "div") {
$this->row .= $this->sthndl_div($attribs);
} else if ($el == "alt") {
// Alternate headword
$style = "font-size:smaller";
$this->row .= "<span style='$style'>(";
} else if ($el == "hwtype") {
// Ignore
} else if ($el == "sup") {
if (in_array($this->dict,array('gst','krm','mci'))) {
$this->row .= '<sup style="font-weight:bold;">';
} else {
$this->row .= "<sup>";
}
} else if ($el == "lbinfo") {
// empty tag.
} else if ($el == "lang") {
// nothing special here Greek remains to be filled in
// Depends on whether the text is filled in
if (isset($attribs['n'])) {
$n = $attribs['n'];
}else {
$n = "";
}
if (in_array($this->dict,array('pwg','mw','pw','wil','md','yat','mw72','snp','stc','gra','lan','inm','bur','bop','ben','sch'))) {
// nothing to do. Greek (and other) unicode has been provided.
}else if ($this->dict == 'bhs') {
// nothing to do. text in <lang>text</lang> is the name or abbreviation of
// a language.
}else {
# put a placeholder where the greek, arabic, etc. needs to be provided.
$this->row .= " ($n) ";
}
} else if ($el == "lb") {
$this->row .= "<br/>";
} else if ($el == "C") {
$n = $attribs['n'];
if ($this->dict == "vcp") {
// vcp specific
if ($n == '1') {
$this->row .= "<br/>";
}
}
$this->row .= "<strong>(C$n)</strong>"; // any dictionary
} else if ($el == "edit"){ // vcp
// no display
} else if ($el == "ls") {
if (isset($attribs['n'])) {
$tooltip = $attribs['n'];
$this->row .= "<span class='ls' title='$tooltip'>";
#$this->row .= "<span class='ls' title=\"$tooltip\">";
}else {
$this->row .= " <span class='ls'>";
}
} else if ($el == "span") {
// This could be generalized to do any attribute.
$temp = "<span";
if (isset($attribs['class'])) {
$class = $attribs['class'];
$temp .= " class='$class'";
}
if (isset($attribs['style'])) {
$style = $attribs['style'];
$temp .= " style='$style'";
}
if (isset($attribs['title'])) {
$title = $attribs['title'];
$temp .= " title='$title'";
}
$temp .= ">"; // close the span
$this->row .= $temp;
} else if ($el == "lshead") {
// pwg, pw
$style = "color:blue; border-bottom: 1px dotted #000; text-decoration: none;";
$style = "color:blue;";
$this->row .= "<span style='$style' class='ls'>";
} else if ($el == "is") {
//pwg, pw
if (isset($attribs['n'])) {
$tooltip = $attribs['n'];
$style = 'letter-spacing:2px; text-decoration: none; border-bottom: 1px dotted #000;';
$spantext .= " title='$tooltip' style='$style'";
}else {
$style = 'letter-spacing:2px;';
$spantext = "style='$style'";
}
$this->row .= "<span $spantext>";
} else if (in_array($el,array("bot","zoo"))) {
// 07-25-2023 allow tooltip at attribute n
// 12-23-2023 treat zoo like bot
if (isset($attribs['n'])) {
$tooltip = $attribs['n'];
$style = 'color: brown; text-decoration: none; border-bottom: 1px dotted #000;';
$spantext .= " title='$tooltip' style='$style'";
}else {
$style = 'color: brown;';
$spantext = "style='$style'";
}
$this->row .= "<span $spantext>"; # this is more like the text
} else if ($el == "bio") {
$this->row .= "<span style='color: brown'>";
} else if ($el == "sic") {
// no rendering
} else if ($el == "ab"){
if (isset($attribs['n'])) {
// local abbreviation <ab n="tooltip for X.">X.</ab>
$tran = $attribs['n'];
// this style provides a 'dotted underline'
$style = "border-bottom: 1px dotted #000; text-decoration: none;";
$this->row .= "<span title='$tran' style='$style'>";
}else {
// <ab>X.</ab> tooltip from dictionary abbreviations database
$this->row .= "<span>";
}
} else if (in_array($el,array("table","tr","td","th"))) {
$elt_with_attribs = $this->sthndl_elt_attribs($attribs,$el);
$this->row .= $elt_with_attribs;
} else if (in_array($el,array("hr"))) {
// empty elements
$elt_with_attribs = $this->sthndl_elt_attribs($attribs,$el);
$this->row .= $elt_with_attribs;
} else if ($el == "vlex"){ // no display
} else if ($el == "mark"){
// skd. n = H,P
$n = $attribs['n'];
$row .= "<strong>($n) </strong>";
// } else if ( ($el == "pic")&&($this->dict == "ben")) {
} else if ($el == "pic") {
$filename = $attribs['name'];
$path = "../../web/images/$filename";
$this->row .= "<img src='$path'/>";
} else if ($el == "note") {
// no action currently. For krm.
} else if ($el == "Poem") {
if ($this->dict == 'pe') {
$style = "position:relative; left:3.0em;";
$this->row .= "<br/><div style='$style'>";
}else {
// For krm.
$this->row .= "<br/>";
}
} else if ($el == "type") {
// displayed in chrhndl
} else if ($el == "fr") {
$this->row .= "<span style='color: brown;' title='French language'>";
} else if ($el == "ger") {
$this->row .= "<span style='color: brown;' title='German language'>";
} else if ($el == "tib") {
$this->row .= "<span style='color: brown;' title='Tibetan language'>";
} else if ($el == "toch") {
$this->row .= "<span style='color: brown;' title='Tocharian language'>";
} else if ($el == "lat") {
$this->row .= "<span style='color: brown;' title='Latin language'>";
} else if ($el == "gk") {
// 04-08-2024 different title for MW
if (in_array($this->getParms->dict,array('mw'))) {
$this->row .= "<span style='color: brown;' title='Greek script'>";
} else {
$this->row .= "<span style='color: brown;' title='Greek language'>";
}
} else if ($el == "arab") {
if (isset($attribs['lang'])) {
$lang = $attribs['lang'];
$this->row .= "<span style='color: brown;' title='Arabic script, $lang language'>";
} else {
$this->row .= "<span style='color: brown;' title='Arabic language'>";
}
} else if ($el == "rus") {
$this->row .= "<span style='color: brown;' title='Russian language'>";
} else if ($el == "mong") {
$this->row .= "<span style='color: brown;' title='Mongolian language'>";
} else {
// $el unrecognized
// $this->row .= "<br/><$el>";
$a = array();
foreach($attribs as $key=>$value) {
$a[] = "$key='$value'";
}
$astring = join(" ",$a);
$this->row .= "<$el $astring>";
}
$this->parentEl = $el; // used by chrhndl
}
public function endhndl($xp,$el) {
$this->parentEl = "";
if ($el == "s") {
$this->inSanskrit = false;
} else if ($el == "F") {
$this->row .= "]</span> <br/>";
} else if ($el == "b"){
$this->row .= "</strong>";
} else if ($el == "graverse") {
$this->row .= "</span>";
} else if ($el == "gralink") {
$this->row .= "</a>";
} else if ($el == "lanlink") {
$this->row .= "</a>";
} else if ($el == "lex"){
$this->row .= "</strong>";
} else if ($el == "i"){
$this->row .= "</i>";
} else if ($el == "pb"){
if (in_array($this->dict,array("mw","bur","stc","abch","acph","acsj","pwg"))) {
# do nothing
}else {
$this->row .= "<br/>";
}
} else if ($el == "key2") {
$this->inkey2 = false;
} else if ($el == "symbol") {
} else if ($el == "div") {
// close the div
$this->row .= "</div>";
} else if ($el == "alt") {
// close the span, and introduce line break
$this->row .= ")</span><br/>";
} else if ($el == "sup") {
$this->row .= "</sup>";
} else if ($el == "ls") {
$this->row .= "</span> ";
} else if ($el == "span") {
$this->row .= "</span>";
} else if ($el == "is") {
$this->row .= "</span>";
} else if (in_array($el,array("bot","zoo"))) {
$this->row .= "</span>";
} else if ($el == "bio") {
$this->row .= "</span>";
} else if ($el == "io") {
$this->row .= "</span>";
} else if ($el == "lshead") {
$this->row .= "</span>";
} else if ($el == "ab") {
$this->row .= "</span>";
} else if ($el == "etym") {
$this->row .= "</i>";
} else if (in_array($el,array('fr','ger','tib','toch','lat','gk','arab','rus','mong'))) {
$this->row .= "</span>";
} else if ($el == "table"){
$this->row .= " </table> ";
} else if ($el == "tr"){
$this->row .= " </tr> ";
} else if ($el == "td"){
$this->row .= " </td> ";
} else if ($el == "br") {
// nothing
} else if (in_array($el,array("L","key1","h","info","tail","pc",
"body"))) {
// nothing
} else {
$this->row .= "</$el>";
}
}
public function chrhndl($xp,$data) {
$sdata = $this->sdata;
if ($this->inkey2) { // no action
} else if ($this->parentEl == "key1"){ // nothing printed
} else if ($this->parentEl == "key2"){ // nothing printed
} else if ($this->parentEl == "pb") {
$hrefdata = $this->getHrefPage($data);
$style = "font-size:smaller; font-weight:bold;";
$this->row .= "<span style='$style'> $hrefdata</span>";
} else if ($this->parentEl == "pc") {
// 10-30-2023 Believed to be unused - handled in dispitem.php
$hrefdata = $this->getHrefPage($data);
$style = "font-size:normal; color:rgb(160,160,160);";
$this->row1 .= "<span style='$style'> [Printed book page $hrefdata]</span>";
} else if ($this->parentEl == 'pcol') {
// 11-14-2024
if (! preg_match('|p\. ([0-9]+), col\. ([0-9])|',$data,$matches)) {
return;
}
$page = $matches[1];
$col = $matches[2];
$hrefdata = $this->getHrefPage($page);
$pcoldata = "p. $hrefdata, col. $col";
$style = "font-size:smaller;";
$this->row .= "<span style='$style'> $pcoldata</span>";
} else if ($this->parentEl == 'pref') {
// 11-14-2024
if (! preg_match('|([0-9]+)|',$data,$matches)) {
return;
}
$page = $matches[1];
$hrefdata = $this->getHrefPage($page);
$pdata = $hrefdata;
$style = "font-size:smaller;";
$this->row .= "<span style='$style'> $pdata</span>";
} else if ($this->parentEl == 'cref') {
// 11-15-2024
// dbgprint(true,"basicdisplay cref: data = $data\n");
if (! preg_match('|([0-9]+) ([1-3])|',$data,$matches)) {
return;
}
$page = $matches[1];
$col = $matches[2];
$serve = $this->serve;
$dict = $this->dict;
$dictup = strtoupper($dict);
$args = "dict=$dict&page=$page";
$style = "";
$link = "<a href='$serve?$args' target='_$dictup' title='page $page'>$col</a>";
// $this->row .= "<span style='$style'>$ans</span>";
$this->row .= "<span style='$style'> $link</span>";
} else if ($this->parentEl == "L") {
// 10-30-2023 Believed to be unused - handled in dispitem.php
$style = "font-size:normal; color:rgb(160,160,160);";
$this->row1 .= "<span style='$style'> [Cologne record ID=$data]</span>";
} else if ($this->parentEl == "L1") {
// only applies to MW. L1 tag generated in basicadjust.
// This code is not used -- somehow over-riddenn by dispitem.php
// $style = "font-size:normal; color:rgb(160,160,160);";
//$this->row .= "<span class='lnum' style='$style'> [ID=$data]</span>";
$this->row .= $data;
} else if ($this->parentEl == 's') {
$this->row .= "<span class='$sdata'><SA>$data</SA></span>";
} else if ($this->inSanskrit) {
// probably not needed
$this->row .= "<span class='$sdata'><SA>$data</SA></span>";
} else if ($this->parentEl == "hom") {
/* for some dictionaries, show hom elements
if (in_array($this->dict,array('mw','pwkvn','md','gra'))) {
$this->row .= "<span class='hom' title='Homonym'>$data</span>";
}
10-31-2023. For ALL dictionaries, show hom element
*/
$this->row .= "<span class='hom' title='Homonym'>$data</span>";
} else if ($this->parentEl == 'div') {
$this->row .= $data;
} else if ($this->parentEl == 'pb') {
if (in_array($this->dict,array("bur","stc"))) {
# do nothing
}else {
$this->row .= $data;
}
} else if ($this->parentEl == "alt") {
$this->row .= $data ;
} else if ($this->parentEl == "lang") {
// Greek typically uncoded
//$data = $data . ' (greek)';
if ($this->dict == "mw") {
$this->row .= "<i>$data</i>"; # Greek italic for MW
} else {
$this->row .= $data;
}
} else if ($this->parentEl == "ab") {
$this->row .= "$data";
}else if ($this->parentEl == "ls") {
$this->row .= $data;
} else if ($this->parentEl == "type") {
// 08-07-2020: Which dictionaries have 'type' tag? SCH?
// prepend to $row1, so it precedes key2
$this->row1 = "<strong>$data</strong> " . $this->row1;
} else { // Arbitrary other text
$this->row .= $data;
dbgprint($this->dbg,"chrhdl: data = $data, parentEl = {$this->parentEl}\n");
}
}
public function getHrefPage_serve() {
/* 11-14-2024. Previous logic
*/
include("dictinfowhich.php");
if ($dictinfowhich == "cologne") {
// use apidev, even if in basic displays
$serve = "//www.sanskrit-lexicon.uni-koeln.de/scans/csl-apidev/servepdf.php";
}
else { // xampp. previous logic
if ($this->basicOption) {
$serve = "../webtc/servepdf.php";
} else { // local csl-apidev, currently
$serve = "servepdf.php";
}
// $this->serve probably not needed
}
return $serve;
}
public function getHrefPage($data) {
/* getHrefPage generates markup for the link to a program which displays a pdf, as
specified by the input argument '$data'.
In this implementation, the program which serves the pdf is
$serve = ../webtc/servepdf.php.
$data is assumed to be a string with a comma-delimited list of page numbers,
only the first of which is used to generate a link.
The markup returned for a given $lnum in the list $data is
<a href='$serve?page=$lnum' target='_Blank'>$lnum</a>
It is up to $serve to associate $lnum with a file.
*/
$ans="";
//$lnums = preg_split('/[,-]/',$data);
$serve = $this->serve;
$lnums = preg_split('/[,]/',$data); //%{pfx}
foreach($lnums as $lnum) {
// list($page,$col) = preg_split('/[-]/',$lnum);
$page = $lnum; # this may be dictionary specific.
if ($ans == "") {
$dict = $this->dict;
$args = "dict=$dict&page=$page";
#$ans = "<a href='$serve?$args' target='_Blank'>$lnum</a>";
$dictup = strtoupper($dict);
$style = "color:rgb(130,130,130);";
$ans = "<a href='$serve?$args' target='_$dictup' style='$style'>$lnum</a>";
}else {
$ans .= ",$lnum";
}
}
return $ans;
}
public function mw_extra_line($line) {
/* Currently only used in mw for links to Whitney and Westergaard.
Based on <info whitneyroots="X"/> or <info westergaard="X"/>
*/
include("dictinfowhich.php");
$href0_whit_cologne = "//www.sanskrit-lexicon.uni-koeln.de/scans/csl-whitroot/disp/index.php";
$href0_west_cologne = "//www.sanskrit-lexicon.uni-koeln.de/scans/csl-westergaard/disp/index.php";
$href0_whit_xampp = "//localhost/cologne/csl-whitroot/disp/index.php";
$href0_west_xampp = "//localhost/cologne/csl-westergaard/disp/index.php";
if ($dictinfowhich == "cologne") {
$href0_whit = $href0_whit_cologne;
$href0_west = $href0_west_cologne;
} else {
// use local module if it exists. Otherwise, use Cologne
// We are in cologne/xxx/web/webtc OR in cologne/csl-apidev/
if (preg_match("|webtc$|",__DIR__)) {
$href0_whit_rel = "../../../csl-whitroot/disp/index.php";
$href0_west_rel = "../../../csl-westergaard/disp/index.php";
}else {
// assume we are in cologne/csl-apidev
$href0_whit_rel = "../csl-whitroot/disp/index.php";
$href0_west_rel = "../csl-westergaard/disp/index.php";
}
if (file_exists($href0_whit_rel)) {
$href0_whit = $href0_whit_xampp;
} else {
$href0_whit = $href0_whit_cologne;
}
if (file_exists($href0_west_rel)) {
$href0_west = $href0_west_xampp;
} else {
$href0_west = $href0_west_cologne;
}
}
$ans1=""; // whitney
$ans2=""; // westergaard
if (preg_match('|<info whitneyroots="(.*?)"/>|',$line,$matches)) {
$x = $matches[1];
$href0=$href0_whit;
$results = preg_split("|;|",$x);
$elts=array();
foreach ($results as $rec) {
list($whitkey,$whitpage) = preg_split("|,|",$rec);
$href = "$href0" . "?page=$whitpage";
$whitkey1 = $whitkey;
$whitkey2 = "";
if (preg_match('|^([^1-9]*)([1-9]*)$|',$whitkey,$matches)) {
$whitkey1 = $matches[1];
$whitkey2 = $matches[2];
}
$sdata = $this->sdata;
$elt = "<a href='$href' target='_Whitney'><span class='$sdata'><SA>$whitkey1</SA></span>$whitkey2</a>";
$elts[] = $elt;
}
$ans1a = join(", ",$elts);
$ans1 = "<em>Whitney Roots links:</em> " . $ans1a;
//$ans1 = $ans1 . ' <br/>'; # dbg
//dbgprint($dbg,"basicdisplay.php mw_extra_line: ans1=$ans1\n");
}
if (preg_match('|<info westergaard="(.*?)"/>|',$line,$matches)) {
$x = $matches[1];
$href0=$href0_west;
$results = preg_split("|;|",$x);
$elts=array();
foreach ($results as $rec) {
list($westkey,$westsutra,$madhaviyasutra) = preg_split("|,|",$rec);
// westsutra is of form (section.rootnum)
// our links require the section
list($westsection,$westrootnum) = preg_split("|[.]|",$westsutra);
$href = "$href0" . "?section=$westsection";
$elt = "<a href='$href' target='_Westergaard'>$westsutra</a>";
$elts[] = $elt;
}
$ans2a = join(", ",$elts);
$ans2 = "<em>Westergaard Dhatupatha links:</em> " . $ans2a;
}
if (($ans1 != "") && ($ans2 != "")) {
$ans = "$ans1 & $ans2";
}else {
$ans = "$ans1$ans2";
}
return $ans;
}
public function mci_extra_line($line) {
/*
display section name
*/
$ans = "";
if (preg_match('|<info section="(.*?)"/>|',$line,$matches)) {
$x = $matches[1];
$section = array();
$section["1.1"] = "Names of Serpents, Birds, Animals etc.";
$section["1.2"] = "Names of Missiles, Weapons, Bows etc.";
$section["1.3"] = "Names of Literary Works, Parts of Works etc.";
$section["1.4"] = "Names of Divisions of Time, Planets, Nakṣatras etc.";
$section["1.5"] = "Names of Tīrthas, Rivers, Mountains, Forests etc.";
$section["1.5A"] = "Names of Āśramas, Villages, Cities etc.";
$section["1.6"] = "Names of Countries, Peoples, Islands etc.";
$section["1.7"] = "Miscellaneous Names";
if (isset($section[$x])) {