Skip to content

Commit

Permalink
Item12759:Item11587: modernized code and icon set
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@17300 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Feb 27, 2014
1 parent ac8b29a commit 76ba63d
Show file tree
Hide file tree
Showing 91 changed files with 401 additions and 136 deletions.
247 changes: 188 additions & 59 deletions SmiliesPlugin/data/System/SmiliesPlugin.txt

Large diffs are not rendered by default.

181 changes: 125 additions & 56 deletions SmiliesPlugin/lib/Foswiki/Plugins/SmiliesPlugin.pm
Expand Up @@ -9,99 +9,168 @@ use warnings;

use Foswiki::Func ();

use vars qw(
%smiliesUrls %smiliesEmotions
$smiliesPubUrl $allPattern $smiliesFormat );
our %cache = ();
our $current;

our $VERSION = '1.200';
$VERSION = eval $VERSION;
our $VERSION = '2.00';
our $RELEASE = '05 Oct 2012';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Render smilies like :-) as icons';

sub initPlugin {
my ( $topic, $web, $user, $installWeb ) = @_;

# Get plugin preferences
$smiliesFormat = Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_FORMAT')
|| '<img src=\'$url\' alt=\'$tooltip\' title=\'$tooltip\' border=\'0\' />';
Foswiki::Func::registerTagHandler( 'SMILIES', \&_renderSmilies );

$topic = Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_TOPIC')
|| "$installWeb.SmiliesPlugin";
my $web = $Foswiki::cfg{SystemWebName};
my $topic = Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_TOPIC')
|| "SmiliesPlugin";

$web = $installWeb;
if ( $topic =~ /(.+)\.(.+)/ ) {
$web = $1;
$topic = $2;
_loadSmilies( $web, $topic );

return 1;
}

sub preRenderingHandler {

if ( $_[0] =~
s/(\s|^)$cache{$current}{pattern}(?=\s|$)/_renderSmily($1,$2)/geo )
{
_addToZone();
}
}

sub _addToZone {
Foswiki::Func::addToZone( "head", "SMILIESPLUGIN",
"<style>.smily { height:1.5em; max-height:19px; vertical-align:text-bottom; }</style>"
);
}

$allPattern = "(";
foreach (
split( /\n/, Foswiki::Func::readTopicText( $web, $topic, undef, 1 ) ) )
sub _loadSmilies {
my ( $web, $topic, $force ) = @_;

( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic );

$current = "$web.$topic";
return if !$force && defined $cache{$current};

$cache{$current} = ();

$cache{$current}{format} =
Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_FORMAT')
|| '<img class=\'smily\' src=\'$url\' alt=\'$tooltip\' title=\'$tooltip\' />';

$cache{$current}{pattern} = "(";
my $state = 0;
foreach my $line ( split( /\n/, Foswiki::Func::readTopic( $web, $topic ) ) )
{

# smilie url emotion
if (
m/^\s*\|\s*<nop>(?:\&nbsp\;)?([^\s|]+)\s*\|\s*%ATTACHURL%\/([^\s]+)\s*\|\s*"([^"|]+)"\s*\|\s*$/o
)
{
$allPattern .= "\Q$1\E|";
$smiliesUrls{$1} = $2;
$smiliesEmotions{$1} = $3;
# | smily | image | description |
if ( $line =~ /^\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*$/ ) {

my $alternatives = $1;
my $image = $2;
my $desc = $3;

if ( $alternatives =~ /^\*/ ) {
$state = 1;
next;
}

$image =~ s/%ATTACHURL(PATH)?%//g;
$desc =~ s/"//g;

next unless $alternatives && $image;

foreach my $key ( split( /\s+/, $alternatives ) ) {
$key =~ s/<nop>|\&nbsp;//g;
$cache{$current}{pattern} .= "\Q$key\E|";
$cache{$current}{image}{$key} = $image;
$cache{$current}{desc}{$key} = $desc;
$cache{$current}{alts}{$key} = $alternatives;
}
}
else {
last if $state == 1;
}
}
$allPattern =~ s/\|$//o;
$allPattern .= ")";
$smiliesPubUrl = Foswiki::Func::getPubUrlPath() . "/$web/$topic";

# Initialization OK
return 1;
#$cache{$current}{pattern} =~ s/\|$//o;
$cache{$current}{pattern} .= ")";
$cache{$current}{pubUrl} = Foswiki::Func::getPubUrlPath() . "/$web/$topic";

}

sub commonTagsHandler {
sub _renderSmily {
my ( $pre, $smily ) = @_;

# my ( $text, $topic, $web ) = @_;
$_[0] =~ s/%SMILIES%/_allSmiliesTable()/geo;
return $pre unless $smily;
return $pre . _formatSmily( $cache{$current}{format}, $smily );
}

sub preRenderingHandler {
sub _formatSmily {
my ( $format, $smily ) = @_;

my $text = $format;

# my ( $text, \%removed ) = @_;
$text =~ s/\$key/<nop>$smily/g;
$text =~ s/\$alternatives/$cache{$current}{alts}{$smily}/g;
$text =~ s/\$emoticon/$smily/g;
$text =~ s/\$tooltip/$cache{$current}{desc}{$smily}/g;
$text =~
s/\$url/$cache{$current}{pubUrl}\/$cache{$current}{image}{$smily}/g;

$_[0] =~ s/(\s|^)$allPattern(?=\s|$)/_renderSmily($1,$2)/geo;
return $text;
}

sub _renderSmily {
my ( $thePre, $theSmily ) = @_;
sub _renderSmilies {
my ( $session, $params ) = @_;

return $thePre unless $theSmily;
my $smily = $params->{_DEFAULT};
my $header = $params->{header};
my $format = $params->{format};
my $footer = $params->{footer} || '';
my $separator = $params->{separator} || '$n';

my $text = $thePre . $smiliesFormat;
$text =~ s/\$emoticon/$theSmily/go;
$text =~ s/\$tooltip/$smiliesEmotions{$theSmily}/go;
$text =~ s/\$url/$smiliesPubUrl\/$smiliesUrls{$theSmily}/go;
$header =
'| *%MAKETEXT{"Notation"}%* | *%MAKETEXT{"Image"}%* | *%MAKETEXT{"Description"}%* |$n'
unless defined $header;

return $text;
}
$format = '| $alternatives | $emoticon | $tooltip |' unless defined $format;

sub _allSmiliesTable {
my $text = "| *What to Type* | *Graphic That Will Appear* | *Emotion* |\n";
my @smilies = ();
if ( defined $smily ) {
push @smilies, $smily;
}
else {
@smilies =
sort {
lc( $cache{$current}{image}{$a} ) cmp
lc( $cache{$current}{image}{$b} )
}
keys %{ $cache{$current}{alts} };
}

foreach my $k (
sort { $smiliesEmotions{$b} cmp $smiliesEmotions{$a} }
keys %smiliesEmotions
)
{
$text .= "| <nop>$k | $k | " . $smiliesEmotions{$k} . " |\n";
my @result = ();
my %seen = ();
foreach my $smily (@smilies) {
next if $seen{ $cache{$current}{alts}{$smily} };
push @result, _formatSmily( $format, $smily );
$seen{ $cache{$current}{alts}{$smily} } = 1;
}
return $text;

return '' unless @result;

_addToZone();

return Foswiki::Func::decodeFormatTokens(
$header . join( $separator, @result ) . $footer );
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2014 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
109 changes: 88 additions & 21 deletions SmiliesPlugin/lib/Foswiki/Plugins/SmiliesPlugin/MANIFEST
@@ -1,23 +1,90 @@
!noci
data/System/SmiliesPlugin.txt 0644
lib/Foswiki/Plugins/SmiliesPlugin.pm 0444
pub/System/SmiliesPlugin/biggrin.gif 0644
pub/System/SmiliesPlugin/confused.gif 0644
pub/System/SmiliesPlugin/cool.gif 0644
pub/System/SmiliesPlugin/devil.gif 0644
pub/System/SmiliesPlugin/devilwink.gif 0644
pub/System/SmiliesPlugin/eek.gif 0644
pub/System/SmiliesPlugin/frown.gif 0644
pub/System/SmiliesPlugin/indifferent.gif 0644
pub/System/SmiliesPlugin/mad.gif 0644
pub/System/SmiliesPlugin/redface.gif 0644
pub/System/SmiliesPlugin/rolleyes.gif 0644
pub/System/SmiliesPlugin/smile.gif 0644
pub/System/SmiliesPlugin/tongue.gif 0644
pub/System/SmiliesPlugin/wink.gif 0644
pub/System/SmiliesPlugin/sealed.gif 0644
pub/System/SmiliesPlugin/thumbs.gif 0644
pub/System/SmiliesPlugin/yes.gif 0644
pub/System/SmiliesPlugin/no.gif 0644
pub/System/SmiliesPlugin/love.gif 0644
pub/System/SmiliesPlugin/skull.gif 0644
pub/System/SmiliesPlugin/emoticon-0184-tmi.gif
pub/System/SmiliesPlugin/emoticon-0136-giggle.gif
pub/System/SmiliesPlugin/emoticon-0153-brokenheart.gif
pub/System/SmiliesPlugin/emoticon-0105-wink.gif
pub/System/SmiliesPlugin/emoticon-0131-angel.gif
pub/System/SmiliesPlugin/emoticon-0159-music.gif
pub/System/SmiliesPlugin/emoticon-0139-bow.gif
pub/System/SmiliesPlugin/emoticon-0166-cake.gif
pub/System/SmiliesPlugin/emoticon-0141-whew.gif
pub/System/SmiliesPlugin/emoticon-0161-phone.gif
pub/System/SmiliesPlugin/emoticon-0168-drink.gif
pub/System/SmiliesPlugin/emoticon-0160-movie.gif
pub/System/SmiliesPlugin/emoticon-0167-beer.gif
pub/System/SmiliesPlugin/emoticon-0147-emo.gif
pub/System/SmiliesPlugin/emoticon-0100-smile.gif
pub/System/SmiliesPlugin/emoticon-0107-sweating.gif
pub/System/SmiliesPlugin/emoticon-0169-dance.gif
pub/System/SmiliesPlugin/emoticon-0143-smirk.gif
pub/System/SmiliesPlugin/emoticon-0157-sun.gif
pub/System/SmiliesPlugin/emoticon-0171-star.gif
pub/System/SmiliesPlugin/emoticon-0180-bug.gif
pub/System/SmiliesPlugin/emoticon-0132-envy.gif
pub/System/SmiliesPlugin/emoticon-0164-cash.gif
pub/System/SmiliesPlugin/emoticon-0183-swear.gif
pub/System/SmiliesPlugin/emoticon-0162-coffee.gif
pub/System/SmiliesPlugin/emoticon-0185-heidy.gif
pub/System/SmiliesPlugin/emoticon-0134-bear.gif
pub/System/SmiliesPlugin/emoticon-0142-happy.gif
pub/System/SmiliesPlugin/emoticon-0135-makeup.gif
pub/System/SmiliesPlugin/emoticon-0110-tongueout.gif
pub/System/SmiliesPlugin/emoticon-0188-tauri.gif
pub/System/SmiliesPlugin/emoticon-0129-call.gif
pub/System/SmiliesPlugin/emoticon-0113-sleepy.gif
pub/System/SmiliesPlugin/emoticon-0108-speechless.gif
pub/System/SmiliesPlugin/emoticon-0137-clapping.gif
pub/System/SmiliesPlugin/emoticon-0155-flower.gif
pub/System/SmiliesPlugin/emoticon-0179-headbang.gif
pub/System/SmiliesPlugin/emoticon-0177-toivo.gif
pub/System/SmiliesPlugin/emoticon-0172-mooning.gif
pub/System/SmiliesPlugin/emoticon-0175-drunk.gif
pub/System/SmiliesPlugin/emoticon-0181-fubar.gif
pub/System/SmiliesPlugin/emoticon-0152-heart.gif
pub/System/SmiliesPlugin/emoticon-0133-wait.gif
pub/System/SmiliesPlugin/emoticon-0146-punch.gif
pub/System/SmiliesPlugin/emoticon-0125-mmm.gif
pub/System/SmiliesPlugin/emoticon-0145-shake.gif
pub/System/SmiliesPlugin/emoticon-0140-rofl.gif
pub/System/SmiliesPlugin/emoticon-0102-bigsmile.gif
pub/System/SmiliesPlugin/emoticon-0112-wondering.gif
pub/System/SmiliesPlugin/emoticon-0123-party.gif
pub/System/SmiliesPlugin/emoticon-0174-bandit.gif
pub/System/SmiliesPlugin/emoticon-0189-priidu.gif
pub/System/SmiliesPlugin/emoticon-0109-kiss.gif
pub/System/SmiliesPlugin/emoticon-0116-evilgrin.gif
pub/System/SmiliesPlugin/emoticon-0151-skype.gif
pub/System/SmiliesPlugin/emoticon-0148-yes.gif
pub/System/SmiliesPlugin/emoticon-0187-malthe.gif
pub/System/SmiliesPlugin/emoticon-0176-smoke.gif
pub/System/SmiliesPlugin/emoticon-0173-middlefinger.gif
pub/System/SmiliesPlugin/emoticon-0156-rain.gif
pub/System/SmiliesPlugin/emoticon-0163-pizza.gif
pub/System/SmiliesPlugin/emoticon-0158-time.gif
pub/System/SmiliesPlugin/emoticon-0178-rock.gif
pub/System/SmiliesPlugin/emoticon-0121-angry.gif
pub/System/SmiliesPlugin/emoticon-0138-thinking.gif
pub/System/SmiliesPlugin/emoticon-0101-sadsmile.gif
pub/System/SmiliesPlugin/emoticon-0165-muscle.gif
pub/System/SmiliesPlugin/emoticon-0124-worried.gif
pub/System/SmiliesPlugin/emoticon-0118-yawn.gif
pub/System/SmiliesPlugin/emoticon-0149-no.gif
pub/System/SmiliesPlugin/emoticon-0150-handshake.gif
pub/System/SmiliesPlugin/emoticon-0106-crying.gif
pub/System/SmiliesPlugin/emoticon-0115-inlove.gif
pub/System/SmiliesPlugin/emoticon-0144-nod.gif
pub/System/SmiliesPlugin/emoticon-0154-mail.gif
pub/System/SmiliesPlugin/emoticon-0126-nerd.gif
pub/System/SmiliesPlugin/emoticon-0182-poolparty.gif
pub/System/SmiliesPlugin/emoticon-0114-dull.gif
pub/System/SmiliesPlugin/emoticon-0130-devil.gif
pub/System/SmiliesPlugin/emoticon-0119-puke.gif
pub/System/SmiliesPlugin/emoticon-0103-cool.gif
pub/System/SmiliesPlugin/emoticon-0117-talking.gif
pub/System/SmiliesPlugin/emoticon-0170-ninja.gif
pub/System/SmiliesPlugin/emoticon-0128-hi.gif
pub/System/SmiliesPlugin/emoticon-0120-doh.gif
pub/System/SmiliesPlugin/emoticon-0111-blush.gif
pub/System/SmiliesPlugin/emoticon-0122-itwasntme.gif
pub/System/SmiliesPlugin/emoticon-0127-lipssealed.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 76ba63d

Please sign in to comment.