Skip to content

Commit

Permalink
Item15227: new lateInitPlugin() handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Nov 17, 2023
1 parent 872e4eb commit bb364b9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/lib/Foswiki.spec
Expand Up @@ -1833,6 +1833,11 @@ $Foswiki::cfg{HttpCompress} = $FALSE;
# of Foswiki.
$Foswiki::cfg{MergeHeadAndScriptZones} = $FALSE;

# **BOOLEAN LABEL="Obfuscate Zone IDs" EXPERT**
# Encrypt ids of assets added to the page, such as css and js instead
# of using plain text.
$Foswiki::cfg{ObfuscateZoneIDs} = $FALSE;

#############################################################################
#---+ Mail
# Settings controlling if and how Foswiki sends email. Mail is used by Foswiki
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Plugin.pm
Expand Up @@ -43,6 +43,7 @@ our @registrableHandlers = ( # Foswiki::Plugins::VERSION:
'initPlugin', # 1.000
'initializeUserHandler', # 1.010
'insidePREHandler', # 1.000 DEPRECATED
'lateInitPlugin', # 2.5
'modifyHeaderHandler', # 1.026
'mergeHandler', # 1.026
'outsidePREHandler', # 1.000 DEPRECATED
Expand Down
16 changes: 15 additions & 1 deletion core/lib/Foswiki/Plugins.pm
Expand Up @@ -36,7 +36,11 @@ if you have a recent enough version.
=cut

use version 0.77; our $VERSION = version->parse("2.4");
use version 0.77; our $VERSION = version->parse("2.5");

# 2.5 - Added lateInitPlugin
# 2.4 - Template names suport unicode characters
# 2.3 - Added registrationValidationHandler

our $inited = 0;

Expand Down Expand Up @@ -309,6 +313,16 @@ sub enable {
->logger->log( 'warning', join( "\n", @{ $plugin->{errors} } ) );
}
}

# lateInitPlugin
foreach my $plugin ( @{ $this->{plugins} } ) {
my $sub = $plugin->{module} . "::lateInitPlugin";
if ( defined &$sub ) {
no strict 'refs';
&$sub();
use strict 'refs';
}
}
}

=begin TML
Expand Down
7 changes: 5 additions & 2 deletions core/lib/Foswiki/Render/Zones.pm
Expand Up @@ -144,7 +144,7 @@ sub addToZone {

# add class to script and link data
$data =~ s/<script\s+((?![^>]*class=))/<script class='\$zone \$id' $1/g;
$data =~ s/<link\s+((?![^>]class=))/<link class='\$zone \$id' $1/g;
$data =~ s/<link\s+((?![^>]*class=))/<link class='\$zone \$id' $1/g;
$data =~ s/<style\s+((?![^>]*class=))/<style class='\$zone \$id' $1/g;

# override previous properties
Expand Down Expand Up @@ -173,7 +173,6 @@ sub _renderZoneById {
my $topicObject = $renderZone->{topicObject};
my $zone = $params->{_DEFAULT} || $params->{zone};

#return "\n<!--ZONE $id-->\n" . _renderZone( $this, $zone, $params, $topicObject ) . "\n<!--ENDZONE $id-->\n" ;
return _renderZone( $this, $zone, $params, $topicObject );
}

Expand Down Expand Up @@ -266,6 +265,10 @@ sub _renderZone {

next unless $text;
my $id = $item->{id} || '';
if ( $Foswiki::cfg{ObfuscateZoneIDs} ) {
$id =~ tr/N-ZA-Mn-za-m/A-Za-z/; # obfuscate ids
}

my $line = $params->{format};
if ( scalar(@missingids) ) {
$line =~ s/\$missing\b/$missingformat/g;
Expand Down

0 comments on commit bb364b9

Please sign in to comment.