From d0e7b8d829676e31c4f76d69a6e5ba508643623f Mon Sep 17 00:00:00 2001 From: Will Budic Date: Mon, 20 May 2024 21:36:48 +1000 Subject: [PATCH] Fix. merged new working tree with development. --- htdocs/cgi-bin/system/modules/CNFParser.pm | 32 ++++--- .../cgi-bin/system/modules/RSSFeedsPlugin.pm | 94 ++++++++++--------- 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/htdocs/cgi-bin/system/modules/CNFParser.pm b/htdocs/cgi-bin/system/modules/CNFParser.pm index ad42b2e..15bb4e0 100644 --- a/htdocs/cgi-bin/system/modules/CNFParser.pm +++ b/htdocs/cgi-bin/system/modules/CNFParser.pm @@ -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){ diff --git a/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm b/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm index 9c1cafa..c026c2d 100644 --- a/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm +++ b/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm @@ -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().'

List Of Feeds

    '; - for my $idx (0 .. $#data){ + my $page = '

    List Of Feeds

      '; + 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|
    1. - $col[$hdr{Name}] -   [ $col[$hdr{last_updated}] ]
      $col[$hdr{Description}]
    2. \n|; - } + $page .= qq|
    3. + $col[1] +   [ $col[4] ]
      $col[3]
    4. \n|; } $page .= '
    '; $parser->data()->{PAGE} = \$page }else{ $parser->addPostParseProcessor($self,'collectFeeds'); } - $parser->data()->{$property} = \@data -} - -sub _css{ -<<__CSS; - -__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; } -- 2.34.1