Last active
February 14, 2018 10:16
-
-
Save reneeb/93a8c7bb724caf4ba9570221beb1d1df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- | |
# Copyright (C) 2018 Perl-Services.de | |
# -- | |
# This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
# the enclosed file COPYING for license information (AGPL). If you | |
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. | |
# -- | |
package Kernel::Output::HTML::Layout::RichText; | |
use strict; | |
use warnings; | |
use Kernel::Language qw(Translatable); | |
our $ObjectManagerDisabled = 1; | |
no warnings 'redefine'; | |
=head2 SetRichTextParameters() | |
set properties for rich text editor and send them to JS via AddJSData() | |
$LayoutObject->SetRichTextParameters( | |
Data => \%Param, | |
); | |
=cut | |
sub Kernel::Output::HTML::Layout::SetRichTextParameters { | |
my ( $Self, %Param ) = @_; | |
$Param{Data} ||= {}; | |
# get and check param Data | |
if ( ref $Param{Data} ne 'HASH' ) { | |
$Kernel::OM->Get('Kernel::System::Log')->Log( | |
Priority => 'error', | |
Message => "Need HashRef in Param Data! Got: '" . ref( $Param{Data} ) . "'!", | |
); | |
$Self->FatalError(); | |
} | |
# get needed objects | |
my $LanguageObject = $Kernel::OM->Get('Kernel::Language'); | |
my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); | |
# get needed variables | |
my $ScreenRichTextHeight = $Param{Data}->{RichTextHeight} || $ConfigObject->Get("Frontend::RichTextHeight"); | |
my $ScreenRichTextWidth = $Param{Data}->{RichTextWidth} || $ConfigObject->Get("Frontend::RichTextWidth"); | |
my $RichTextType = $Param{Data}->{RichTextType} || ''; | |
my $PictureUploadAction = $Param{Data}->{RichTextPictureUploadAction} || ''; | |
my $TextDir = $Self->{TextDirection} || ''; | |
my $EditingAreaCSS = 'body.cke_editable { ' . $ConfigObject->Get("Frontend::RichText::DefaultCSS") . ' }'; | |
# decide if we need to use the enhanced mode (with tables) | |
my @Toolbar; | |
my @ToolbarWithoutImage; | |
if ( $RichTextType eq 'CodeMirror' ) { | |
@Toolbar = @ToolbarWithoutImage = [ | |
[ 'autoFormat', 'CommentSelectedRange', 'UncommentSelectedRange', 'AutoComplete' ], | |
[ 'Find', 'Replace', '-', 'SelectAll' ], | |
['Maximize'], | |
]; | |
} | |
elsif ( $ConfigObject->Get("Frontend::RichText::EnhancedMode") == '1' ) { | |
@Toolbar = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', | |
'-', 'NumberedList', 'BulletedList', 'Table', '-', 'Outdent', | |
'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', | |
'-', 'Link', 'Unlink', 'Undo', 'Redo', 'SelectAll' | |
], | |
'/', | |
[ | |
'Image', 'HorizontalRule', 'PasteText', 'PasteFromWord', 'SplitQuote', 'RemoveQuote', | |
'-', '-', 'Find', 'Replace', 'TextColor', | |
'BGColor', 'RemoveFormat', '-', 'ShowBlocks', 'Source', 'SpecialChar', | |
'-', 'Maximize' | |
], | |
[ 'Format', 'Font', 'FontSize' ] | |
]; | |
@ToolbarWithoutImage = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', | |
'-', 'NumberedList', 'BulletedList', 'Table', '-', 'Outdent', | |
'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', | |
'-', 'Link', 'Unlink', 'Undo', 'Redo', 'SelectAll' | |
], | |
'/', | |
[ | |
'HorizontalRule', 'PasteText', 'PasteFromWord', 'SplitQuote', 'RemoveQuote', '-', | |
'-', 'Find', 'Replace', 'TextColor', 'BGColor', | |
'RemoveFormat', '-', 'ShowBlocks', 'Source', 'SpecialChar', '-', | |
'Maximize' | |
], | |
[ 'Format', 'Font', 'FontSize' ] | |
]; | |
} | |
else { | |
@Toolbar = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', '-', 'NumberedList', | |
'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', | |
'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'Link', 'Unlink', | |
'-', 'Image', 'HorizontalRule', '-', 'Undo', 'Redo', | |
'-', 'Find' | |
], | |
'/', | |
[ | |
'Format', 'Font', 'FontSize', '-', 'TextColor', 'BGColor', | |
'RemoveFormat', '-', 'Source', 'SpecialChar', 'SplitQuote', 'RemoveQuote', | |
'-', 'Maximize' | |
] | |
]; | |
@ToolbarWithoutImage = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', | |
'-', 'NumberedList', 'BulletedList', '-', | |
'Outdent', 'Indent', '-', 'JustifyLeft', | |
'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', | |
'Link', 'Unlink', '-', 'HorizontalRule', | |
'-', 'Undo', 'Redo', '-', | |
'Find' | |
], | |
'/', | |
[ | |
'Format', 'Font', 'FontSize', '-', 'TextColor', 'BGColor', | |
'RemoveFormat', '-', 'Source', 'SpecialChar', 'SplitQuote', 'RemoveQuote', | |
'-', 'Maximize' | |
] | |
]; | |
} | |
# set data with AddJSData() | |
$Self->AddJSData( | |
Key => 'RichText', | |
Value => { | |
Height => $ScreenRichTextHeight, | |
Width => $ScreenRichTextWidth, | |
TextDir => $TextDir, | |
EditingAreaCSS => $EditingAreaCSS, | |
Lang => { | |
SplitQuote => $LanguageObject->Translate('Split Quote'), | |
RemoveQuote => $LanguageObject->Translate('Remove Quote'), | |
}, | |
Toolbar => $Toolbar[0], | |
ToolbarWithoutImage => $ToolbarWithoutImage[0], | |
PictureUploadAction => $PictureUploadAction, | |
Type => $RichTextType, | |
}, | |
); | |
return 1; | |
} | |
=head2 CustomerSetRichTextParameters() | |
set properties for customer rich text editor and send them to JS via AddJSData() | |
$LayoutObject->CustomerSetRichTextParameters( | |
Data => \%Param, | |
); | |
=cut | |
sub Kernel::Output::HTML::Layout::CustomerSetRichTextParameters { | |
my ( $Self, %Param ) = @_; | |
$Param{Data} ||= {}; | |
# get and check param Data | |
if ( ref $Param{Data} ne 'HASH' ) { | |
$Kernel::OM->Get('Kernel::System::Log')->Log( | |
Priority => 'error', | |
Message => "Need HashRef in Param Data! Got: '" . ref( $Param{Data} ) . "'!", | |
); | |
$Self->FatalError(); | |
} | |
# get needed objects | |
my $LanguageObject = $Kernel::OM->Get('Kernel::Language'); | |
my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); | |
my $ScreenRichTextHeight = $ConfigObject->Get("Frontend::RichTextHeight"); | |
my $ScreenRichTextWidth = $ConfigObject->Get("Frontend::RichTextWidth"); | |
my $TextDir = $Self->{TextDirection} || ''; | |
my $PictureUploadAction = $Param{Data}->{RichTextPictureUploadAction} || ''; | |
my $EditingAreaCSS = 'body { ' . $ConfigObject->Get("Frontend::RichText::DefaultCSS") . ' }'; | |
# decide if we need to use the enhanced mode (with tables) | |
my @Toolbar; | |
my @ToolbarWithoutImage; | |
if ( $ConfigObject->Get("Frontend::RichText::EnhancedMode::Customer") == '1' ) { | |
@Toolbar = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', | |
'-', 'NumberedList', 'BulletedList', 'Table', '-', 'Outdent', | |
'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', | |
'-', 'Link', 'Unlink', 'Undo', 'Redo', 'SelectAll' | |
], | |
'/', | |
[ | |
'Image', 'HorizontalRule', 'PasteText', 'PasteFromWord', 'SplitQuote', 'RemoveQuote', | |
'-', '-', 'Find', 'Replace', 'TextColor', | |
'BGColor', 'RemoveFormat', '-', 'ShowBlocks', 'Source', 'SpecialChar', | |
'-', 'Maximize' | |
], | |
[ 'Format', 'Font', 'FontSize' ] | |
]; | |
@ToolbarWithoutImage = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', | |
'-', 'NumberedList', 'BulletedList', 'Table', '-', 'Outdent', | |
'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', | |
'-', 'Link', 'Unlink', 'Undo', 'Redo', 'SelectAll' | |
], | |
'/', | |
[ | |
'HorizontalRule', 'PasteText', 'PasteFromWord', 'SplitQuote', 'RemoveQuote', '-', | |
'-', 'Find', 'Replace', 'TextColor', 'BGColor', | |
'RemoveFormat', '-', 'ShowBlocks', 'Source', 'SpecialChar', '-', | |
'Maximize' | |
], | |
[ 'Format', 'Font', 'FontSize' ] | |
]; | |
} | |
else { | |
@Toolbar = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', '-', 'NumberedList', | |
'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', | |
'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'Link', 'Unlink', | |
'-', 'Image', 'HorizontalRule', '-', 'Undo', 'Redo', | |
'-', 'Find' | |
], | |
'/', | |
[ | |
'Format', 'Font', 'FontSize', '-', 'TextColor', 'BGColor', | |
'RemoveFormat', '-', 'Source', 'SpecialChar', 'SplitQuote', 'RemoveQuote', | |
'-', 'Maximize' | |
] | |
]; | |
@ToolbarWithoutImage = [ | |
[ | |
'Bold', 'Italic', 'Underline', 'Strike', | |
'-', 'NumberedList', 'BulletedList', '-', | |
'Outdent', 'Indent', '-', 'JustifyLeft', | |
'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', | |
'Link', 'Unlink', '-', 'HorizontalRule', | |
'-', 'Undo', 'Redo', '-', | |
'Find' | |
], | |
'/', | |
[ | |
'Format', 'Font', 'FontSize', '-', 'TextColor', 'BGColor', | |
'RemoveFormat', '-', 'Source', 'SpecialChar', 'SplitQuote', 'RemoveQuote', | |
'-', 'Maximize' | |
] | |
]; | |
} | |
# set data with AddJSData() | |
$Self->AddJSData( | |
Key => 'RichText', | |
Value => { | |
Height => $ScreenRichTextHeight, | |
Width => $ScreenRichTextWidth, | |
TextDir => $TextDir, | |
EditingAreaCSS => $EditingAreaCSS, | |
Lang => { | |
SplitQuote => $LanguageObject->Translate('Split Quote'), | |
}, | |
Toolbar => $Toolbar[0], | |
ToolbarWithoutImage => $ToolbarWithoutImage[0], | |
PictureUploadAction => $PictureUploadAction, | |
}, | |
); | |
return 1; | |
} | |
1; | |
=head1 TERMS AND CONDITIONS | |
This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
the enclosed file COPYING for license information (AGPL). If you | |
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>. | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment