From c75a0923203aec7cf3874cc770657d96a53ca05b Mon Sep 17 00:00:00 2001 From: funderburkjim Date: Thu, 11 Jul 2024 13:36:42 -0400 Subject: [PATCH] 1. rev-sup display https://github.com/sanskrit-lexicon/MWS/issues/173 2. titular abbreviations https://github.com/sanskrit-lexicon/MWS/issues/172 --- v02/makotemplates/web/webtc/basicadjust.php | 62 ++++++++++++++----- v02/makotemplates/web/webtc/basicdisplay.php | 33 +++++++--- v02/makotemplates/web/webtc/dispitem.php | 34 +++++++--- v02/makotemplates/web/webtc/getwordClass.php | 18 +++--- v02/makotemplates/web/webtc/getword_data.php | 55 +++++++++------- .../web/webtc/readme_getwork.txt | 32 ++++++++++ v02/makotemplates/web/webtc1/listhierview.php | 24 ++++++- 7 files changed, 195 insertions(+), 63 deletions(-) create mode 100644 v02/makotemplates/web/webtc/readme_getwork.txt diff --git a/v02/makotemplates/web/webtc/basicadjust.php b/v02/makotemplates/web/webtc/basicadjust.php index 958757e..264e559 100644 --- a/v02/makotemplates/web/webtc/basicadjust.php +++ b/v02/makotemplates/web/webtc/basicadjust.php @@ -576,6 +576,11 @@ public function ls_callback_mw($matches) { $data1 = $data0; $data = $data0; } + if (preg_match('|tit="(.*?)"|',$ndata,$matchesn)) { + $titular = true; + } else { + $titular = false; + } dbgprint($dbg,"\nls_callback_mw BEGIN: ndata=$ndata, n=$n, data0=$data0, data1=$data1\n"); if (!$this->dal_auth->status) { return $ans; @@ -601,26 +606,36 @@ public function ls_callback_mw($matches) { } else if (in_array($this->dict,array('ap90','ben','sch','gra','bhs'))) { list($code,$text) = $rec; } - # Add lshead, so as to be able to style - // for mw and ap90, codecap = code + // be sure there is no xml in the text + if ($text == null) {$text = "";} + $text = preg_replace('/<.*?>/',' ',$text); + // convert special characters to html entities + // for instance, this handles cases when $text has single (or double) quotes + $tooltip = $this->htmlspecial($text); dbgprint($dbg,"ls_callback_mw : n=$n, data=$data\n"); if ($code == null) {$code = "";} $codecap = $code; $ncode = strlen($code); // use substr_replace in case $code has parens + if (! $titular) { + if ($code == $data0) { + $titular = true; + } + } + if ($titular) { + // 07-05-2024. display of 'empty' ls + // $style = 'font-size: 11pt; font-family:charterindocapital; border-bottom: 1px dotted #000; '; + $style = 'border-bottom: 1px dotted #000; color:#8080ff;'; + $ans = "$code"; + return $ans; + } + if ($n != '') { - //$datanew = substr_replace($data,"$data",0); $datanew = $data; dbgprint($dbg,"lshead 1: n=$n: datanew=$datanew\n"); } else { $datanew = substr_replace($data,"$codecap",0,$ncode); dbgprint($dbg,"lshead 2: n=$n: datanew=$datanew\n"); } - # be sure there is no xml in the text - if ($text == null) {$text = "";} - $text = preg_replace('/<.*?>/',' ',$text); - # convert special characters to html entities - # for instance, this handles cases when $tran has single (or double) quotes - $tooltip = $this->htmlspecial($text); // -------------------------------------------------------------- $href = null; //dbgprint(true,"before ls_callback_mw_href, dict=" . $this->dict . "\n"); @@ -1337,15 +1352,34 @@ public function move_L_mw($line) { name of the tag to */ $dbg=false; - dbgprint($dbg,"basicadjust.move_L_mw enter: line=\n$line\n"); - if (preg_match('|<(H[1-4].)>.*(.*?)|',$line,$matches)) { - $H = $matches[1]; - $Ltag = $matches[2]; + $dict = $this->getParms->dict; + dbgprint($dbg,"basicadjust.move_L_mw enter: dict=$dict, line=\n$line\n"); + //if (preg_match('|<(H[1-4].)>.*(.*?)|',$line,$matches)) { + if (preg_match('|(.*?)|',$line,$matches)) { + //$H = $matches[1]; + $Ltag = $matches[1]; + $revsup = ""; + if ($dict == "mw") { // 07-07-2024 + // Add markers for rev or sup Ⓡ, Ⓢ + if (preg_match('||',$line,$matches1)) { + $revsup = " sup"; + } else if (preg_match('||',$line,$matches1)) { + $pc = $matches1[1]; + $revsup = " rev ($pc)"; + } else { + $revsup = ""; + } + } + // remove L element $line = preg_replace("|$Ltag|","",$line); // construct L1 tag $L1tag = preg_replace("|L>|","L1>",$Ltag); - //dbgprint(true,"Ltag=$Ltag, L1tag=$L1tag\n"); + // add in $revsup + if ($revsup != "") { + $L1tag = preg_replace("||", "$revsup",$L1tag); + } + dbgprint(false,"basicadjust: Ltag=$Ltag, revsup=$revsup, L1tag=$L1tag\n"); // Insert L1tag before end of tail -- so at end of display $line = preg_replace("||","$L1tag",$line); } diff --git a/v02/makotemplates/web/webtc/basicdisplay.php b/v02/makotemplates/web/webtc/basicdisplay.php index 837422b..c02801d 100644 --- a/v02/makotemplates/web/webtc/basicdisplay.php +++ b/v02/makotemplates/web/webtc/basicdisplay.php @@ -446,7 +446,8 @@ public function sthndl($xp,$el,$attribs) { } else if ($el == "tail"){ } else if ($el == "L"){ } else if ($el == "L1"){ - // for MW only, work done in chrhndl + // for MW only, work done elsewhere + $this->row .= ""; } 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 @@ -455,7 +456,6 @@ public function sthndl($xp,$el,$attribs) { $this->row .= ""; } else if ($el == "info") { } else if ($el == "pc"){ - } else if ($el == "info") { } else if ($el == "to") { } else if ($el == "ns") { } else if ($el == "shortlong") { @@ -531,15 +531,22 @@ public function sthndl($xp,$el,$attribs) { $this->row .= " "; } } else if ($el == "span") { + // This could be generalized to do any attribute. + $temp = "row .= ""; - } else if (isset($attribs['style'])) { + $temp .= " class='$class'"; + } + if (isset($attribs['style'])) { $style = $attribs['style']; - $this->row .= ""; - } else { - $this->row .= ""; + $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;"; @@ -715,6 +722,9 @@ public function endhndl($xp,$el) { } else if ($el == "td"){ $this->row .= " "; } else if ($el == "br") { + // nothing + } else if (in_array($el,array("L","key1","h","info","tail","pc", + "body"))) { // nothing } else { $this->row .= ""; @@ -740,9 +750,12 @@ public function chrhndl($xp,$data) { $style = "font-size:normal; color:rgb(160,160,160);"; $this->row1 .= " [Cologne record ID=$data]"; } else if ($this->parentEl == "L1") { - // only applies to MW. L1 tag generated in basicadjust. - $style = "font-size:normal; color:rgb(160,160,160);"; - $this->row .= " [ID=$data]"; + // 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 .= " [ID=$data]"; + $this->row .= $data; } else if ($this->parentEl == 's') { $this->row .= "$data"; } else if ($this->inSanskrit) { diff --git a/v02/makotemplates/web/webtc/dispitem.php b/v02/makotemplates/web/webtc/dispitem.php index 465fae6..05fa0d1 100644 --- a/v02/makotemplates/web/webtc/dispitem.php +++ b/v02/makotemplates/web/webtc/dispitem.php @@ -32,6 +32,7 @@ public function __construct($dict,$dbrec) { controls whether the preg_match will work for the string. The default for the parameter is 1000000 (one million). */ + dbgprint(false,"dispitem: rec=\n $rec\n\n"); $ok = false; if (preg_match('|(.*?)(.*?)|',$rec,$matchrec)) { $ok = true; @@ -54,7 +55,8 @@ public function __construct($dict,$dbrec) { } $this->info = $matchrec[1]; $this->html = $matchrec[2]; - dbgprint($dbg,"this->info starts as {$this->info}\n"); + dbgprint(false,"dispItem: this->info starts as\n {$this->info}\n"); + dbgprint(false,"dispItem: this->html starts as\n {$this->html}\n"); //Some derived fields if($this->dictup == 'MW') { list($this->pginfo,$this->hcode,$this->key2,$this->hom) = preg_split('/:/',$this->info); @@ -197,7 +199,7 @@ public function basicRow1DefaultParts($prev) { if ($hrefdata == $hrefdata_prev) { $pageshow=""; } - // dbgprint(true,"dispitem: keyshow=$keyshow\n lnumshow=$lnumshow\n\n pageshow=$pageshow\n"); + // dbgprint(false,"dispitem: keyshow=$keyshow\n lnumshow=$lnumshow\n\n pageshow=$pageshow\n"); return array($keyshow,$lnumshow,$pageshow); } public function get_pageshow($hrefdata) { @@ -206,15 +208,31 @@ public function get_pageshow($hrefdata) { $ans = " [Printed book page $hrefdata]"; return $ans; } - public function get_lnumshow_id($lnum) { + public function get_lnumshow_id($lnum0) { // 08-04-2020 - $style = "font-size:normal; color:rgb(160,160,160);"; - $ans = "[ID=$lnum]"; + // 07-08-2024 + // dbgprint(true,"dispitem:get_lnumshow_id: html= \n{$this->html}\n"); + //if (preg_match("|(.*?)|",$this->html,$matches)) { + //if (preg_match("|([0-9.]+)(.*?)|",$this->html,$matches)) { + if (preg_match("|^([0-9.]+)(.*?)$|",$lnum0,$matches)) { + $lnum = $matches[1]; + $revsup = $matches[2]; + dbgprint(false," NO match for revsup\n"); + } else { + $lnum = $lnum0; + $revsup = ""; + } + dbgprint(false,"lnum0='$lnum0', lnum='$lnum', revsup='$revsup'\n"); + //$style1 = "font-size:normal; color:rgb(160,160,160);"; + //$ans = "[ID=$lnum]"; + $ans = "[" . + "ID=$lnum" . + "$revsup" . "]"; if (in_array($this->dictlo, array("abch", "acph", "acsj"))) { // 10-30-2023 $ans .= "
"; } - //dbgprint(true,"get_lnumshow_id. dict={$this->dict}, ans=\n$ans\n\n"); + //dbgprint(false,"get_lnumshow_id. dict={$this->dict}, ans=\n$ans\n\n"); return $ans; } public function basicRow1Default($prev) { @@ -264,7 +282,7 @@ public function basicDisplayRecord2($prev) { $pageshow = $this->get_pageshow($hrefdata); $pre="$keyshow $pageshow"; } - //dbgprint(true,"lnumshow=$lnumshow, dictup=" . $this->dictup . ", hom=" . $this->hom . "\n"); + //dbgprint(false,"lnumshow=$lnumshow, dictup=" . $this->dictup . ", hom=" . $this->hom . "\n"); if (($this->dictup == 'MW') and ($this->hom)) { // make a link to change list view to be centered at this lnum $symbol = "←"; // unicode left arrow @@ -307,7 +325,7 @@ public function getHrefPage() { }else { $serve = "../webtc/$serve"; } - //dbgprint(true,"dispitem.getHrefPage: serve=$serve\n"); + //dbgprint(false,"dispitem.getHrefPage: serve=$serve\n"); foreach($lnums as $lnum) { if ($ans == "") { $args = "dict=$dict&page=$lnum"; #"page=$page"; diff --git a/v02/makotemplates/web/webtc/getwordClass.php b/v02/makotemplates/web/webtc/getwordClass.php index 6627c9d..8af3f6a 100644 --- a/v02/makotemplates/web/webtc/getwordClass.php +++ b/v02/makotemplates/web/webtc/getwordClass.php @@ -148,9 +148,12 @@ public function getwordDisplay($parms,$matches) { $dbg=false; for($i=0;$i<$ntot;$i++) { $dbrec = $matches[$i]; - dbgprint($dbg,"disp.php. matches[$i] = \n"); - for ($j=0;$jerr) { @@ -203,14 +206,15 @@ public function getwordDisplay($parms,$matches) { $dispItemPrev=null; for($i=0;$i<$ntot;$i++) { $dispItem = $dispItems[$i]; - + $dispItem1 = ""; if ($options == '1') { - $table .= $dispItem->basicDisplayRecord1($dispItemPrev); + $dispItem1 = $dispItem->basicDisplayRecord1($dispItemPrev); }else if ($options == '2') { - $table .= $dispItem->basicDisplayRecord2($dispItemPrev); + $dispItem1 = $dispItem->basicDisplayRecord2($dispItemPrev); }else{ - $table .= $dispItem->basicDisplayRecordDefault($dispItemPrev); + $dispItem1 = $dispItem->basicDisplayRecordDefault($dispItemPrev); } + $table .= $dispItem1; $dispItemPrev=$dispItem; } $table .= "\n"; diff --git a/v02/makotemplates/web/webtc/getword_data.php b/v02/makotemplates/web/webtc/getword_data.php index 5fd8b86..08e3b9a 100644 --- a/v02/makotemplates/web/webtc/getword_data.php +++ b/v02/makotemplates/web/webtc/getword_data.php @@ -18,6 +18,7 @@ class Getword_data { - computed html string */ public $matches, $basicOption; + //public $basicdisplaydbg; public function __construct($basicOption = true) { $dbg=false; $getParms = new Parm(); @@ -39,30 +40,44 @@ public function __construct($basicOption = true) { list($key0,$lnum0,$xmldata0) = $xmlmatch; $xmldata[] = $xmldata0; } + $adjxml = new BasicAdjust($getParms,$xmldata); $adjmatches = $adjxml->adjxmlrecs; - $htmlmatches = []; + //$htmlbasics = []; // for debugging for($i=0;$igetword_data_html_adapter($key0,$lnum0,$adjxmldata0,$dict,$getParms,$xmldata0); - // dbgprint(true,"getword_data: i = $i, html=\n$html\n\n"); - // 10-23-2023 For dict abch, use $L instead of $lnum0. - if (in_array($dict,['abch', 'acph', 'acsj'])) { - if(preg_match('|(.*?)|',$xmldata0,$tempmatch)) { + dbgprint(false,"getword_data: html=\n $html\n"); + //$htmlbasics[] = $this->basicdisplaydbg; + $html1 = $html; + // dbgprint(false,"getword_data: i = $i, html=\n$html\n\n"); + // 10-23-2023 For koshas, use $L instead of $lnum0. + // 07-09-2024 For koshas, use $L1 + // Also,use L1 for mw (to get sup,rev) + if (in_array($dict,array('mw','abch', 'acph', 'acsj'))) { + if(preg_match('|(.*?)|',$html,$tempmatch)) { $lnum0 = $tempmatch[1]; + // remove L1 element from html1 + $html1 = preg_replace('|(.*?)|','',$html); } } - $htmlmatches[] = array($key0,$lnum0,$html); + $htmlmatches[] = array($key0,$lnum0,$html1); } if ($dbg) { dbgprint($dbg,"getword_data returns:\n"); for($i=0;$imatches = $htmlmatches; } /* ------------------------------ @@ -70,17 +85,12 @@ public function __construct($basicOption = true) { */ public function getword_data_html_adapter($key,$lnum,$adjxml,$dict,$getParms,$xmldata) { - // 08-07-2020. This is the only place where BasicAdjust and - // BasicDisplay are called. + // 08-07-2020. This is the only place where BasicDisplay is called. // We don't need to have arrays of strings, but only one string - // ($data is a string, one record from xxx.xml) // BasicDisplay is written to allow a string for the second argument. - /* - $matches1=array($data); - $adjxml = new BasicAdjust($getParms,$matches1); - $matches = $adjxml->adjxmlrecs; - */ + $filter = $getParms->filter; + dbgprint(false,"getword_data_html_adapter, adjxml=\n $adjxml\n"); $display = new BasicDisplay($key,array($adjxml),$filter,$dict); $row1 = $display->row1; $row1x = $display->row1x; @@ -95,8 +105,7 @@ public function getword_data_html_adapter($key,$lnum,$adjxml,$dict,$getParms,$xm dbgprint($dbg,"adapter\n"); dbgprint($dbg,"info = $info\n"); dbgprint($dbg,"body = $body\n"); - - + // $this->basicdisplaydbg = $body; if (in_array($dict,['abch', 'acph', 'acsj'])) { // no adjust body }else { @@ -108,10 +117,10 @@ public function getword_data_html_adapter($key,$lnum,$adjxml,$dict,$getParms,$xm $body = preg_replace('||','',$body); } } - // adjust $info - keep only the displayed page + // adjust $info - keep only the dislayed page if ($dict == 'mw') { if(!preg_match('|>([^<]*?),(.*?)\]|',$info,$matches)) { - dbgprint(true,"html ERROR 2: \n" . $info . "\n"); + dbgprint(false,"html ERROR 2: \n" . $info . "\n"); exit(1); } $page=$matches[1]; @@ -119,7 +128,7 @@ public function getword_data_html_adapter($key,$lnum,$adjxml,$dict,$getParms,$xm $pageref = "$page,$col"; }else { if(!preg_match('|>([^<]*?)|',$info,$matches)) { - dbgprint(true,"html ERROR 2: \n" . $info . "\n"); + dbgprint(false,"html ERROR 2: \n" . $info . "\n"); exit(1); } $pageref=$matches[1]; @@ -129,7 +138,7 @@ public function getword_data_html_adapter($key,$lnum,$adjxml,$dict,$getParms,$xm # construct return value as colon-separated values if ($this->basicOption) { - dbgprint(true,"getword_data: changing hom to blank; $key2,$hom\n"); + //dbgprint(false,"getword_data: changing hom to blank; $key2,$hom\n"); $hom=""; } $infoval = "$pageref:$hcode:$key2:$hom"; @@ -171,7 +180,7 @@ public function adjust_key2_mw($key2) { $ans1 = preg_replace('||','',$ans1); $ans1 = preg_replace('||','',$ans1); if (preg_match('|<|',$ans1)) { - //dbgprint(true,"adjust_key2: $ans1\n"); + //dbgprint(false,"adjust_key2: $ans1\n"); exit(1); } return $ans; diff --git a/v02/makotemplates/web/webtc/readme_getwork.txt b/v02/makotemplates/web/webtc/readme_getwork.txt new file mode 100644 index 0000000..b0211bc --- /dev/null +++ b/v02/makotemplates/web/webtc/readme_getwork.txt @@ -0,0 +1,32 @@ + +07-08-2024 + +getword.php The main entry point for generating html from xml. + Involved in main_webtc.js function 'getword' + calls getwordClass in getwordClass.php + Echoes $table1 +getwordClass.php + $temp = new Getword_data($basicOption); [class Getword_data] + + $matches = $temp->matches + Array of html string [variable $htmlmatches in Getword_data code] + $this->table1 = $this->getword_html(); + getword_html: + $table = $this->getwordDisplay($getParms,$matches); + $table1 transcodes the table + getwordDisplay: + For each $dbrec in $matches: + $dispItem = new DispItem($dict,$dbrec); + DO some adjustments to each of the html strings. + + + +getword_data.php + $xmlmatches = $dal->get1_mwalt($key); ## from xxx.xml + $xmldata array of the 'data' fields of xmlmatches. + $adjxml = new BasicAdjust($getParms,$xmldata) + This adjusts each of the $xmldata records + + getword_data_html_adapter applied to each + This done by BasicDisplay(...) + diff --git a/v02/makotemplates/web/webtc1/listhierview.php b/v02/makotemplates/web/webtc1/listhierview.php index b5eb7d7..578125c 100644 --- a/v02/makotemplates/web/webtc1/listhierview.php +++ b/v02/makotemplates/web/webtc1/listhierview.php @@ -22,6 +22,7 @@ public function __construct($listmatches,$getParms) { $i++; if ($code == 0) {$c="color:teal";} else {$c="color:black";} + /* // Apr 7, 2013. Color Supplement records. // Jun 29, 2018 This relevant for MW onlyu if (preg_match('/|',$data2,$matches)) { + $c = "color:red"; + } + if (preg_match('||',$data2,$matches)) { + // note for rev, the incoming form is + $c = "color:green"; + } + */ if (preg_match('/^$key2\");'>$key2show$hom2$xtraskip
\n"; + // 07-07-2024 revsup + $revsup = ""; + if (in_array($getParms->dict,array('mw'))) { + if (preg_match('||',$data2,$matches)) { + $revsup = " "; + } + else if (preg_match('|$key2\");'>$key2show$hom2$xtraskip $revsup
\n"; $table .= $out1; if ($i == count($listmatches)) {