]> lifelog.hopto.org Git - LifeLog.git/commitdiff
Fix. merged new working tree with development.
authorWill Budic <redacted>
Mon, 20 May 2024 11:36:48 +0000 (21:36 +1000)
committerWill Budic <redacted>
Mon, 20 May 2024 11:36:48 +0000 (21:36 +1000)
htdocs/cgi-bin/system/modules/CNFParser.pm
htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm

index ad42b2ed34f1c94b0a1634b9e114928fa677ff8f..15bb4e0aa995fc2d22cdb6d0fe74d548d86778a6 100644 (file)
@@ -19,7 +19,8 @@ require CNFDateTime;
 ##no critic qw(Subroutines::RequireFinalReturn)
 ##no critic Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions
 
-use constant VERSION => '3.2';
+use constant VERSION  => '3.2';
+use constant APPSET   => 'APP_SETTINGS';
 our @files;
 our %lists;
 our %properties;
@@ -330,7 +331,7 @@ sub property { my($self, $name) = @_;
        if($ref eq 'ARRAY'){
           return  @{$ret}
        }elsif($ref eq 'PropertyValueStyle'){
-          return ${$ret->{plugin}} if $ret->{instructor} eq 'APP_SETTINGS';
+          return ${$ret->{plugin}} if $ret->{instructor} eq APPSET;
           return $ret;
        }
        else{
@@ -564,8 +565,8 @@ sub doInstruction { my ($self,$e,$t,$v) = @_;
     elsif($t eq 'MACRO'){
         $instructs{$e}=$v;
     }
-    elsif($t eq 'APP_SETTINGS'){
-        $self->instructPlugin(InstructedDataItem -> new($e, 'APP_SETTINGS', $v));
+    elsif($t eq 'APPSET'){
+        $self->instructPlugin(InstructedDataItem -> new($e, APPSET, $v));
     }
     elsif(exists $instructors{$t}){
         if(not $instructors{$t}->instruct($e, $v) && $self->{STRICT}){
@@ -756,22 +757,26 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
            my $t = $1;
            my $v = $2;
            if(isReservedWord($self, $t)){
+              my $isAppSts =  ($t eq APPSET);
               my $isVar = ($t eq 'VARIABLE' || $t eq 'VAR');
-              if($t eq 'CONST' or $isVar){ #constant multiple properties.
-                foreach my $line (split '\n', $v) {
-                     my $isMETAConst = $line =~ s/$meta_const//s;
+              if($t eq 'CONST' or $isVar or $isAppSts){ #multiple values property.
+                my %app_sts;
+                foreach  my $line(split '\n', $v) {
+                    my  $isMETAConst = $line =~ s/$meta_const//se;
                         $line =~ s/^\s+|\s+$//;  # strip unwanted spaces
                         $line =~ s/\s*>$//;
                         $line =~ m/([\$\w]*)(\s*=\s*)(.*)/g;
                         my $name = $1;
                            $line = $3; $line =~ s/^\s*(['"])(.*)\g{1}$/$2/ if $line;#strip quotes
                         if(defined $name){
-                            if($isVar && not $isMETAConst){
-                                 $anons ->{$name} = $line if $line
+                            if($isAppSts){
+                               $app_sts{$name} = $line if $line;
+                            }elsif($isVar && not $isMETAConst){
+                                $anons -> {$name} = $line if $line
                             }else{
                                 $name =~ s/^\$// if $isMETAConst;
                                 # It is NOT allowed to overwrite a constant, so check an issue warning.
-                                if($line and not $self->{$name}){
+                                if(not exists($self->{$name})){
                                    $self->{$name} = $line;
                                 }else{ my
                                    $w =  "Skipping and keeping a previously set constance of -> [$name] in ". $self->{CNF_CONTENT}." the new value ";
@@ -780,6 +785,9 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
                             }
                         }
                 }
+                if($isAppSts){
+                   $properties{CNFParser::APPSET} = \%app_sts
+                }
               }else{
                 doInstruction($self,$v,$t,undef);
               }
@@ -1207,7 +1215,7 @@ sub doPlugin {
     my $pck = $plugin->{package};
     my $prp = $plugin->{property};
     my $sub = $plugin->{subroutine};
-    if($instructor eq 'APP_SETTINGS'){
+    if($instructor eq APPSET){
         $pck = 'ClassicAppSettings' if ! $pck;
         ## no critic (RequireBarewordIncludes)
         require "$pck.pm";
@@ -1386,7 +1394,7 @@ sub log {
         my $logfile  = $log{file};
         my $tail_cnt = $log{tail};
         if($logfile){
-                        open (my $fh, ">>", $logfile) or die $!;
+                        open (my $fh, ">>", $logfile) or CNFParserException->throw(error=>"Error With accessing logfile: $logfile -> $!");
                         print $fh $time . " - " . $message ."\n";
                         close $fh;
                         if($tail_cnt>0 && !$LOG_TRIM_SUB){
index 9c1cafafe8327f9380dee1157645645ace338170..c026c2d80eedd554684563a25511fc90aea805be 100644 (file)
@@ -31,79 +31,84 @@ sub new ($class, $plugin){
     return bless $settings, $class
 }
 
-my %hdr;
+
 
 ###
 # Process config data to contain expected fields.
 ###
 sub process ($self, $parser, $property) {
-    my @data = @{$parser->data()->{$property}};
+
+     my $table = $parser->data()->{$property};
+    if(!$table){
+        $parser->error("RSSFeedsPlugin\@Error Table property not found -> $property"); return
+    }
     my $cgi  = $parser->const('CGI');
     $self->{date} = now();
+    my $ptr = $$table->{header};
+    my $ref = ref($ptr);
+        if($ref eq 'REF'){
+            $ptr = $$ptr;
+        }
+    my @header = @$ptr;
+    my @data = CNFMeta::_deRefArray($$table->{data});
     for my $idx (0 .. $#data){
         my @col = @{$data[$idx]};
-        if($idx>0){
-            $col[0] = $idx+1;
-            $col[@col] = $self-> {date} -> toTimestamp();
+        if($idx==0){
+            $col[4] = 'last_updated';
+            if(@header){
+               my @lbls =  CNFMeta::_deRefArray($header[0]);
+               my @spec =  CNFMeta::_deRefArray($header[3]);
+               $lbls[4] = $col[4];
+               $spec[4] = $CNFMeta::CNF_DATA_TYPES{DATE};
+               $$table->{header} = \[\@lbls,$header[1],$header[2],\@spec];
+            }
         }else{
-            $col[@col] = 'last_updated';
+            $col[0] = $idx+1;
+            $col[4] = $self-> {date} -> toTimestamp();
         }
         $data[$idx]=\@col;
     }
     if($cgi&&$cgi->param('action') eq 'list'){
-       my $page = _css().'<div class="feed"><h2>List Of Feeds</h2><ol>';
-       for my $idx (0 .. $#data){
+       my $page = '<div class="feed"><h2>List Of Feeds</h2><ol>';
+       for my $idx (1 .. $#data){
            my @col = @{$data[$idx]};
-
-            if($idx==0){
-                for my $i(0..$#col){ # Get the matching table column index names as scripted.
-                    $hdr{$col[$i]} = $i
-                }
-            }else{
-                $page .= qq|<li><span class="feeds_list_span">
-                <a onclick="return fetchFeed('$col[$hdr{Name}]')" style="cursor: pointer;"> <b>$col[$hdr{Name}]</b> </a></span>
-                    &nbsp;&nbsp;[ $col[$hdr{last_updated}] ]<dt style="padding:10px;">$col[$hdr{Description}]</dt></li>\n|;
-            }
+           $page .= qq|<li><span style="border: 1px solid black; padding: 5px; padding-bottom: 0px;">
+           <a onclick="return fetchFeed('$col[1]')" style="cursor: pointer;"> <b>$col[1]</b> </a></span>
+            &nbsp;&nbsp;[ $col[4] ]<dt style="padding:10px;">$col[3]</dt></li>\n|;
        }
        $page .= '</ol></div>';
        $parser->data()->{PAGE} = \$page
     }else{
        $parser->addPostParseProcessor($self,'collectFeeds');
     }
-    $parser->data()->{$property} = \@data
-}
-
-sub _css{
-<<__CSS;
-<style>
-.feeds_list_span{
-    border: 1px solid black; padding: 5px; padding-bottom: 0px;
-}
-.feeds_list_span:hover{
-    border-color:red;
-  background:#94cde7;;
-}
-</style>
-__CSS
+    $parser->data()->{$property} = \{name=>$property,header=>$$table->{header},auto=>0,data=>\@data}
 }
 
 sub collectFeeds($self, $parser) {
   my $property = $self->{property};
-  my @data = @{$parser->data()->{$property}};
-  my $cgi  = $parser->const('CGI');
+
+  my $table = $parser->data()->{$property};
+  my $ptr = $$table->{header};
+  my $ref = ref($ptr);
+        if($ref eq 'REF'){
+            $ptr = $$ptr;
+        }
   my $page;
+  my @header = @$ptr;
+  my @data   = @{$$table->{data}};
+  my $cgi  = $parser->const('CGI');
   my $feed = $cgi->param('feed') if $cgi;
-  $parser->log("Feed request:$feed");
+  my @lbls =  CNFMeta::_deRefArray($header[0]);
+  my %hdr;
+     for(my $i=0;$i<@lbls;$i++){ #<- Column names are set here, if names in script are changed, They must be changed bellow.
+         $hdr{$lbls[$i]} = $i
+     }
+  $parser->log("Feed request:$feed") if$feed;
   for my $idx (0 .. $#data){
-       my @col = @{$data[$idx]};
-      if($idx==0){
-        for my $i(0..$#col){ # Get the matching table column index names as scripted.
-               $hdr{$col[$i]} = $i
-        }
-      }else{
-         my $name = $col[$hdr{Name}]; #<- Now use the column names as coded, if names in script are changed, you must change here.
+         my @col = @{$data[$idx]};
+         my $name = $col[$hdr{Name}];
          next if($feed && $feed ne $name);
-         my $tree =  fetchFeed($self, $name, $col[$hdr{URL}], $col[$hdr{Expires}], $col[$hdr{Description}]);
+         my $tree =  fetchFeed($self, $name, $col[$hdr{URL}], $col[$hdr{Description}]);
          $parser->log("Fetched feed:".$name);
          if($tree && ref($$tree) eq 'CNFNode'){
             if(not isCNFTrue($self->{CNF_TREE_LOADED}) && isCNFTrue($self->{CNF_TREE_STORE})){
@@ -124,7 +129,6 @@ sub collectFeeds($self, $parser) {
          }else{
             $parser-> warn("Feed '$name' bailed to return a CNFNode tree.")
          }
-      }
   }
   $parser->data()->{PAGE} = \$page if $page;
 }