# -- # Copyright (C) 2001-2019 OTRS AG, https://otrs.com/ # -- # This software comes with ABSOLUTELY NO WARRANTY. For details, see # the enclosed file COPYING for license information (GPL). If you # did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. # -- package Kernel::System::HTMLUtils; use strict; use warnings; use utf8; use MIME::Base64; our @ObjectDependencies = ( 'Kernel::Config', 'Kernel::System::Encode', 'Kernel::System::Log', ); =head1 NAME Kernel::System::HTMLUtils - creating and modifying html strings =head1 DESCRIPTION A module for creating and modifying html strings. =head1 PUBLIC INTERFACE =head2 new() Don't use the constructor directly, use the ObjectManager instead: my $HTMLUtilsObject = $Kernel::OM->Get('Kernel::System::HTMLUtils'); =cut sub new { my ( $Type, %Param ) = @_; # allocate new hash for object my $Self = {}; bless( $Self, $Type ); # get debug level from parent $Self->{Debug} = $Param{Debug} || 0; return $Self; } =head2 ToAscii() convert an HTML string to an ASCII string my $Ascii = $HTMLUtilsObject->ToAscii( String => $String ); =cut sub ToAscii { my ( $Self, %Param ) = @_; # check needed stuff for (qw(String)) { if ( !defined $Param{$_} ) { $Kernel::OM->Get('Kernel::System::Log')->Log( Priority => 'error', Message => "Need $_!" ); return; } } # make sure to flag the input string as unicode (utf8) because replacements below can # introduce unicode encoded characters (see bug#10970, bug#11596 and bug#12097 for more info) $Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$Param{String} ); # get length of line for forcing line breakes my $LineLength = $Kernel::OM->Get('Kernel::Config')->Get('Ticket::Frontend::TextAreaNote') || 78; # find and replace it with [x] my $LinkList = ''; my $Counter = 0; $Param{String} =~ s{ } { my $Link = $2; $Counter++; $LinkList .= "[$Counter] $Link\n"; "[$Counter]"; }egxi; # pre-process
and
(.+?)
} { my $Ascii = $Self->ToAscii( String => $2, ); # force line breaking if ( length $Ascii > $LineLength ) { $Ascii =~ s/(.{4,$LineLength})(?:\s|\z)/$1\n/gm; } $Ascii =~ s/^(.*?)$/> $1/gm; $Counter++; my $Key = "######Cite::$Counter######"; $Cite{$Key} = $Ascii; $Key; }segxmi; $Param{String} =~ s{ (.+?) } { my $Ascii = $Self->ToAscii( String => $1, ); # force line breaking if ( length $Ascii > $LineLength ) { $Ascii =~ s/(.{4,$LineLength})(?:\s|\z)/$1\n/gm; } $Ascii =~ s/^(.*?)$/> $1/gm; $Counter++; my $Key = "######Cite::$Counter######"; $Cite{$Key} = $Ascii; $Key; }segxmi; # remember
 and  tags
    my %One2One;
    $Counter = 0;
    $Param{String} =~ s{
        <(pre|code)(.*?)>(.+?)
    }
    {
        my $Content = $3;
        $Counter++;
        my $Key        = "######One2One::$Counter######";
        $One2One{$Key} = $Content;
        $Key;
    }segxmi;

    # remove comments at the first place to avoid to much work
    # for the regex engine
    $Param{String} =~ s{}{}xmgsi;

    # remove empty lines
    $Param{String} =~ s/^\s*//mg;

    # fix some bad stuff from opera and others
    $Param{String} =~ s/(\n\r|\r\r\n|\r\n)/\n/gs;

    # remove new line after 
$Param{String} =~ s/(\)(\n|\r)/$1/gsi; # replace new lines with one space $Param{String} =~ s/\n/ /gs; $Param{String} =~ s/\r/ /gs; # remove style tags $Param{String} =~ s{