summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-06 00:10:35 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-04-06 00:10:35 (GMT)
commit3761de04f01d450953df21a5e832279b2ce89eb0 (patch)
tree675bb36ac5d8db0faa85065f73ec27527f11af31
parentd785250b91e47275de7a2a79851bafd0ed9231cc (diff)
downloadblogengine-3761de04f01d450953df21a5e832279b2ce89eb0.zip
blogengine-3761de04f01d450953df21a5e832279b2ce89eb0.tar.gz
blogengine-3761de04f01d450953df21a5e832279b2ce89eb0.tar.bz2
Handle smileys and favicon.
-rwxr-xr-xdaml2html.pl72
1 files changed, 66 insertions, 6 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 857c3da..94dabd5 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -428,6 +428,12 @@ sub daml_handler {
my $optref = shift;
print STDERR "warning: daml handler doesn't handle arguments\n" if @_;
die "daml element can only be root element" unless $$optref{is_root};
+ if ( defined(my $attr = $node->getAttributeNS("", "uri-to-top")) ) {
+ $uri_to_top = $attr;
+ }
+ if ( defined(my $attr = $node->getAttributeNS("", "file.name")) ) {
+ $file_name = $attr;
+ }
die "\$html_node already defined: what magic is this?" if defined($html_node);
$html_node = $doc->createElementNS(XHTML_NS, "html");
my $lang;
@@ -452,6 +458,11 @@ sub daml_handler {
create_meta_element_helper(undef, "http-equiv",
"Content-Language", $lang)) if $lang;
$head_node->appendChild($doc->createTextNode("\n"));
+ my $link = $doc->createElementNS(XHTML_NS, "link");
+ $link->setAttributeNS("", "rel", "Shortcut Icon");
+ $link->setAttributeNS("", "href", ($uri_to_top//"")."favicon.ico");
+ $head_node->appendChild($link);
+ $head_node->appendChild($doc->createTextNode("\n"));
my @child_nodes = $node->childNodes;
my @to_process;
foreach my $child ( @child_nodes ) {
@@ -476,12 +487,6 @@ sub daml_handler {
"style", \$style_content];
push @todo_stack, [\&create_style_or_script_node, $head_node, {special=>1},
"script", \$script_content];
- if ( defined(my $attr = $node->getAttributeNS("", "uri-to-top")) ) {
- $uri_to_top = $attr;
- }
- if ( defined(my $attr = $node->getAttributeNS("", "file.name")) ) {
- $file_name = $attr;
- }
}
sub body_handler {
@@ -717,6 +722,50 @@ sub email_despammed_handler {
unshift @todo_stack, @to_process;
}
+sub smiley_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: smiley handler doesn't handle arguments\n" if @_;
+ my ($emotion) = $node->localName =~ /^smiley-([a-z0-9\-]*)$/s
+ or die "this is impossible";
+ my %alt_text = ( "smile" => ":-)", "wink" => ";-)", "surprised" => ":-o",
+ "sad" => ":-(", "cool" => "8-)", "biggrin" => ":-D",
+ "confused" => ":-S", "crazy" => "%-)", "neutral" => ":-|",
+ "twisted" => "8->", "cry" => "¦-(" );
+ my %en_name = ( "smile" => "Smile", "wink" => "Wink",
+ "surprised" => "Surprised", "sad" => "Sad",
+ "cool" => "Cool", "biggrin" => "Big grin",
+ "confused" => "Confused", "crazy" => "Crazy",
+ "neutral" => "Non-grin", "twisted" => "Twisted",
+ "cry" => "Crying" );
+ my %fr_name = ( "smile" => "Sourire", "wink" => "Clin d'œil",
+ "surprised" => "Surpris", "sad" => "Triste",
+ "cool" => "Cool", "biggrin" => "Grand sourire",
+ "confused" => "Troublé", "crazy" => "Fou",
+ "neutral" => "Sans sourire", "twisted" => "Tordu",
+ "cry" => "Pleure" );
+ die "this is impossible"
+ unless ( defined($alt_text{$emotion}) && defined($en_name{$emotion})
+ && defined($fr_name{$emotion}) );
+ my $lang = get_node_lang_rec $node;
+ my $img = $doc->createElementNS(XHTML_NS, "img");
+ if ( defined(my $explicit_lang = get_node_lang_norec $node) ) {
+ set_node_lang_norec $img, $explicit_lang;
+ }
+ $img->setAttributeNS("", "src", ($uri_to_top//"")
+ ."images/smileys/${emotion}.png");
+ $img->setAttributeNS("", "class", "smiley");
+ $img->setAttributeNS("", "width", "15");
+ $img->setAttributeNS("", "height", "15");
+ $img->setAttributeNS("", "alt", $alt_text{$emotion});
+ if ( defined($lang) && $lang eq "en" ) {
+ $img->setAttributeNS("", "title", $en_name{$emotion});
+ } elsif ( defined($lang) && $lang eq "fr" ) {
+ $img->setAttributeNS("", "title", $fr_name{$emotion});
+ }
+ $node->replaceNode($img);
+}
+
my %daml_handler = (
"daml" => \&daml_handler,
"body" => \&body_handler,
@@ -729,6 +778,17 @@ my %daml_handler = (
"email-despammed" => \&email_despammed_handler,
"email-at" => \&email_at_handler,
"email-dot" => \&email_dot_handler,
+ "smiley-smile" => \&smiley_handler,
+ "smiley-wink" => \&smiley_handler,
+ "smiley-surprised" => \&smiley_handler,
+ "smiley-sad" => \&smiley_handler,
+ "smiley-cool" => \&smiley_handler,
+ "smiley-biggrin" => \&smiley_handler,
+ "smiley-confused" => \&smiley_handler,
+ "smiley-crazy" => \&smiley_handler,
+ "smiley-neutral" => \&smiley_handler,
+ "smiley-twisted" => \&smiley_handler,
+ "smiley-cry" => \&smiley_handler,
);
TODO_LOOP: