]> lifelog.hopto.org Git - LifeLog.git/commitdiff
.
authorWill Budic <redacted>
Fri, 17 Nov 2023 08:25:05 +0000 (19:25 +1100)
committerWill Budic <redacted>
Fri, 17 Nov 2023 08:25:05 +0000 (19:25 +1100)
.gitignore
htdocs/cgi-bin/system/modules/HTMLIndexProcessorPlugin.pm

index 134ba1bcb3551958bdd97dd2554b5760ca1fcfc6..7e202d5d4818d0e1672e84d12659262c139b90a4 100644 (file)
@@ -22,10 +22,9 @@ cgisess_*
 tags
 */bck/*
 bck_*
-dbLifeLog/current_theme
 lighttpd.conf
 dump_*
 *.rdf
 tree_*.cnf
 vscode_local_extensions/extensions.json
-
+dbLifeLog/current_theme
index afce2c18e737cedd82dbe67348c69a3b6f9094cc..7fe9625b146e7b23ade5dbe791991c0ea02b5252 100644 (file)
@@ -26,34 +26,34 @@ sub new ($class, $plugin){
 ###
 # Process config data to contain expected fields and data.
 ###
-sub convert ($self, $parser, $property) {    
+sub convert ($self, $parser, $property) {
     my ($buffer,$title, $link, $body_attrs, $body_on_load, $give_me);
     my $cgi          = CGI -> new();
-    my $cgi_action   = $cgi-> param('action');    
-    my $cgi_doc      = $cgi-> param('doc'); 
+    my $cgi_action   = $cgi-> param('action');
+    my $cgi_doc      = $cgi-> param('doc');
     my $tree         = $parser-> anon($property);
-    die "Tree property '$property' is not available!" if(!$tree or ref($tree) ne 'CNFNode');    
+    die "Tree property '$property' is not available!" if(!$tree or ref($tree) ne 'CNFNode');
 
 try{
 
 
-    if (exists $parser->{'HTTP_HEADER'}){            
+    if (exists $parser->{'HTTP_HEADER'}){
         $buffer .= $parser-> {'HTTP_HEADER'};
-    }else{ 
+    }else{
         if(exists $parser -> collections()->{'%HTTP_HEADER'}){
             my %http_hdr = $parser -> collection('%HTTP_HEADER');
             $buffer = $cgi->header(%http_hdr);
         }
     }
 
-    if ($cgi_action and $cgi_action eq 'load'){        
-        $buffer .= $cgi->start_html(); my 
-        $load = loadDocument($parser, $cgi_doc);
+    if ($cgi_action and $cgi_action eq 'load'){
+        $buffer .= $cgi->start_html(); my
+        $load = loadDocument($self, $parser, $cgi_doc);
         if($load){
-           $buffer .= $$load if $load;        
+           $buffer .= $$load if $load;
         }else{
            $buffer .= "Document is empty: $cgi_doc\n"
-        }        
+        }
     }else{
         $title  = $tree  -> {'Title'} if exists $tree->{'Title'};
         $link   = $tree  -> {'HEADER'};
@@ -64,13 +64,13 @@ try{
         if($link){
         if(ref($link) eq 'CNFNode'){
                 my $arr = $link->find('CSS/@@');
-                foreach (@$arr){                
-                    push  @hhshCSS, {-type => 'text/css', -src => $_->val()};                
+                foreach (@$arr){
+                    push  @hhshCSS, {-type => 'text/css', -src => $_->val()};
                 }
                 $arr = $link->find('JS/@@');
-                foreach (@$arr){                
-                    push  @hhshJS, {-type => 'text/javascript', -src => $_->val()};                
-                } 
+                foreach (@$arr){
+                    push  @hhshJS, {-type => 'text/javascript', -src => $_->val()};
+                }
                 $arr = $link  -> find('STYLE');
                 if(ref($arr) eq 'ARRAY'){
                     foreach (@$arr){
@@ -80,24 +80,24 @@ try{
                 }
                 $arr = $link  -> find('SCRIPT');
                 if(ref($arr) eq 'ARRAY'){
-                    foreach (@$arr){ 
+                    foreach (@$arr){
                         $give_me .= "\n<script>\n".$_ -> val()."\n</script>\n"
                     }}else{
                         $give_me .= "\n<script>\n".$arr -> val()."\n</script>\n"
                 }
-        }       
-        delete $tree -> {'HEADER'};       
-        }    
+        }
+        delete $tree -> {'HEADER'};
+        }
         $buffer .= $cgi->start_html(
                             -title   => $title,
                             -onload  => $body_on_load,
-                            # -BGCOLOR => $colBG,                        
+                            # -BGCOLOR => $colBG,
                             -style   => \@hhshCSS,
                             -script  => \@hhshJS,
                             -head=>$give_me,
                             $body_attrs
                         );
-        foreach my $node($tree->nodes()){      
+        foreach my $node($tree->nodes()){
         $buffer .= build($parser, $node)  if $node;
         }
         $buffer .= $cgi->end_html();
@@ -108,23 +108,23 @@ try{
  }
 }
 #
-sub loadDocument($parser, $doc) {
+sub loadDocument($self, $parser, $doc) {
     my $slurp = do {
                     open my $fh, '<:encoding(UTF-8)', $doc or HTMLIndexProcessorPluginException->throw("Document not avaliable: $doc");
                     local $/;
-                    <$fh>;       
+                    <$fh>;
     };
     if($doc =~/\.md$/){
-        require MarkdownPlugin;   
-        my @r = @{MarkdownPlugin->new()->parse($slurp)};
+        require MarkdownPlugin;
+        my @r = @{MarkdownPlugin->new($self)->parse($slurp)};
         return $r[0];
     }
-    return \$slurp        
+    return \$slurp
 }
 
 ###
 # Builds the html version out of a CNFNode.
-# CNFNode with specific tags here are converted also here, 
+# CNFNode with specific tags here are converted also here,
 # those that are out of the scope for normal standard HTML tags.
 # i.e. HTML doesn't have row and cell tags. Neither has meta links syntax.
 ###
@@ -138,14 +138,14 @@ sub build {
         $bf .= "\t"x$tabs."<div".placeAttributes($node).">\n"."\t"x$tabs."<div>";
             foreach my $n($node->nodes()){
                 if($n->{'_'} ne '#'){
-                    my $b = build($parser, $n, $tabs+1);     
+                    my $b = build($parser, $n, $tabs+1);
                     $bf .= "$b\n" if $b;
                 }
             }
             if($node->{'#'}){
                 my $v = $node->val();
                 $v =~ s/\n\n+/\<\/br>\n/gs;
-                $bf .= "\t<div>\n\t<p>\n".$v."</p>\n\t</div>\n"; 
+                $bf .= "\t<div>\n\t<p>\n".$v."</p>\n\t</div>\n";
             }
         $bf .= "\t</div>\t</div>\n"
     }elsif( $name eq 'row' || $name eq 'cell' ){
@@ -156,13 +156,13 @@ sub build {
                     $bf .= "$b\n" if $b;
                 }
             }
-        $bf .= $node->val()."\n" if $node->{'#'};   
+        $bf .= $node->val()."\n" if $node->{'#'};
         $bf .= "\t"x$tabs."</div>"
     }elsif( $name eq 'img' ){
         $bf .= "\t\t<img".placeAttributes($node)."/>\n";
     }elsif($name eq 'list_images'){
         my $paths = $node->{'@@'};
-        foreach my $ndp (@$paths){            
+        foreach my $ndp (@$paths){
             my $path = $ndp -> val();
             my @ext = split(',',"jpg,jpeg,png,gif");
             my $exp = " ".$path."/*.". join (" ".$path."/*.", @ext);
@@ -175,22 +175,22 @@ sub build {
                 $bf .= qq(\t<div class='row'><div class='cell'>);
                 $bf .= qq(\t<a href="$enc"><img src="$enc" with='120' height='120'><br>$fn</a>\n</div></div>\n);
             }
-        }    
+        }
     }elsif($name eq '!'){
       return "<!--".$node->val()."-->\n";
-        
+
     }elsif($node->{'*'}){ #Links are already captured, in future this might be needed as a relink from here for dynamic stuff?
             my $lval = $node->{'*'};
-            if($name eq 'file_list_html'){ #Special case where html links are provided.                
+            if($name eq 'file_list_html'){ #Special case where html links are provided.
                 foreach(split(/\n/,$lval)){
                      $bf .= qq( [ $_ ] |) if $_
                 }
                 $bf =~ s/\|$//g;
             }else{ #Generic included link value.
                 #is there property data for it?
-                my $prop = $parser->data()->{$node->name()};                
+                my $prop = $parser->data()->{$node->name()};
                 #if not has it been passed as an page constance?
-                $prop = $parser -> {$node->name()} if !$prop; 
+                $prop = $parser -> {$node->name()} if !$prop;
                 if ( !$prop ) {
                     if   ( $parser->{STRICT} ) { die "Not found as property link -> " . $node->name()}
                     else                       { warn "Not found as property link -> " . $node->name()}
@@ -209,20 +209,20 @@ sub build {
     }
     else{
         my $spaced = 1;
-           $bf .= "\t"x$tabs."<".$node->name().placeAttributes($node).">";            
-            foreach my $n($node->nodes()){                
-                    my $b = build($parser, $n,$tabs+1);                    
-                        if ($b){                            
+           $bf .= "\t"x$tabs."<".$node->name().placeAttributes($node).">";
+            foreach my $n($node->nodes()){
+                    my $b = build($parser, $n,$tabs+1);
+                        if ($b){
                             if($b =~/\n/){
                                $bf =~ s/\n$//gs;
                                $bf .= "\n$b\n"
                             }else{
-                               $spaced=0;                               
-                               $bf .= $b; 
+                               $spaced=0;
+                               $bf .= $b;
                             }
-                       }                    
+                       }
             }
-        
+
         if ($node->{'#'}){
             $bf .= $node->val();
             $bf .= "</".$node->name().">";
@@ -247,7 +247,7 @@ sub placeAttributes {
         if(@$_[0] ne '#' && @$_[0] ne '_'){
            if(@$_[1]){
               $ret .= " ".@$_[0]."=\"".@$_[1]."\"";
-           }else{ 
+           }else{
               $ret .= " ".@$_[0]." ";
            }
         }