123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- # Copyright (C) 2004, 2005, 2006, 2009 Alex Schroeder <alex@gnu.org>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- use strict;
- use v5.10;
- AddModuleDescription('portrait-support.pl', 'Portraits Support Extension');
- our ($q, $bol, $Now, @MyMacros, @MyRules, $FreeLinkPattern, $UrlPattern, $FS);
- push(@MyMacros, sub{ s/\[new::\]/"[new:" . GetParam('username', T('Anonymous'))
- . ':' . TimeToText($Now) . "]"/eg });
- push(@MyMacros, sub{ s/\[new:$FreeLinkPattern\]/"[new:$1:" . TimeToText($Now) . "]"/eg });
- push(@MyRules, \&PortraitSupportRule);
- our ($PortraitSupportColorDiv, $PortraitSupportColor);
- $PortraitSupportColor = 0;
- $PortraitSupportColorDiv = 0;
- my %Portrait = ();
- sub PortraitSupportRule {
- if ($bol) {
- if (m/\G(\s*\n)*----+[ \t]*\n?/cg) {
- $PortraitSupportColor = 0;
- my $html = CloseHtmlEnvironments() . ($PortraitSupportColorDiv ? '</div>' : '')
- . $q->hr() . AddHtmlEnvironment('p');
- $PortraitSupportColorDiv = 0;
- return $html;
- } elsif ($bol && m/\Gportrait:$UrlPattern/cg) {
- return $q->img({-src=>$1, -alt=>T("Portrait"), -class=>'portrait'});
- } elsif ($bol && m/\G(:*)\[new(.*)\]/cg) {
- my $portrait = '';
- my $depth = length($1);
- my ($ignore, $name, $time) = split(/:/, $2, 3);
- if ($name) {
- if (not $Portrait{$name}) {
- my $oldpos = pos;
- if (GetPageContent($name) =~ m/portrait:$UrlPattern/) {
- $Portrait{$name} =
- $q->div({-class=>"portrait"},
- $q->p(ScriptLink($name, $q->img({-src=>$1, -alt=>'new: ' . $time,
- -class=>'portrait'}),
- 'newauthor', '', $FS),
- $q->br(),
- GetPageLink($name)));
- }
- }
- $portrait = $Portrait{$name};
- $portrait =~ s/$FS/$time/;
- }
- my $html = CloseHtmlEnvironments()
- . ($PortraitSupportColorDiv ? '</div>' : '');
- $PortraitSupportColor = !$PortraitSupportColor;
- $html .= '<div class="color '
- . ($PortraitSupportColor ? 'one' : 'two')
- . ' level' . $depth
- . '">' . $portrait . AddHtmlEnvironment('p');
- $PortraitSupportColorDiv = 1;
- return $html;
- }
- }
- return;
- }
- *OldPortraitSupportApplyRules = \&ApplyRules;
- *ApplyRules = \&NewPortraitSupportApplyRules;
- sub NewPortraitSupportApplyRules {
- my ($blocks, $flags) = OldPortraitSupportApplyRules(@_);
- if ($PortraitSupportColorDiv) {
- print '</div>';
- $blocks .= $FS . '</div>';
- $flags .= $FS . 0;
- $PortraitSupportColorDiv = 0;
- }
- return ($blocks, $flags);
- }
|