From aee5a4eafba1e7bc2a45eb1f04a00c6fbdbd5dd4 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Tue, 5 Apr 2005 21:18:57 +0000 Subject: [PATCH] Added my modules to source - FletcherPenney --- modules/antispam.pl | 66 +++++++++++ modules/clustermap.pl | 189 +++++++++++++++++++++++++++++++ modules/htmllinks.pl | 36 ++++++ modules/logbannedcontent.pl | 51 +++++++++ modules/slideshow.pl | 219 ++++++++++++++++++++++++++++++++++++ 5 files changed, 561 insertions(+) create mode 100755 modules/antispam.pl create mode 100755 modules/clustermap.pl create mode 100755 modules/htmllinks.pl create mode 100755 modules/logbannedcontent.pl create mode 100755 modules/slideshow.pl diff --git a/modules/antispam.pl b/modules/antispam.pl new file mode 100755 index 00000000..b9c11d60 --- /dev/null +++ b/modules/antispam.pl @@ -0,0 +1,66 @@ +# Copyright (C) 2004 Fletcher T. Penney +# +# 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 2 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, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: antispam.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $

'; + +use vars qw($DoMaskEmail $CreateMailtoLinks); + +$DoMaskEmail = 1; # Mask all email, not just those in []'s +$CreateMailtoLinks = 1; # Create mailto's for all addresses + +$EmailRegExp = '[\w\.\-]+@([\w\-]+\.)+[\w]+'; + + +push(@MyRules, \&MaskEmailRule); + +sub MaskEmailRule { + # Allow [email@foo.bar Email Me] links + if (m/\G\[($EmailRegExp(\s\w+)*\s*)\]/igc) { + $chunk = $1; + $chunk =~ s/($EmailRegExp)//i; + $email = $1; + $chunk =~ s/^\s*//; + $chunk =~ s/\s*$//; + + $masked=""; + @decimal = unpack('C*', $email); + foreach $i (@decimal) { + $masked.="&#".$i.";"; + } + $email = $masked; + $chunk = $email if $chunk eq ""; + return "$chunk"; + } + + if (m/\G($EmailRegExp)/igc) { + $email=$1; + if ($DoMaskEmail) { + $masked=""; + @decimal = unpack('C*', $email); + foreach $i (@decimal) { + $masked.="&#".$i.";"; + } + $email = $masked; + } + if ($CreateMailtoLinks) { + $email = "$email"; + } + return $email; + } + return undef; +} diff --git a/modules/clustermap.pl b/modules/clustermap.pl new file mode 100755 index 00000000..50de969d --- /dev/null +++ b/modules/clustermap.pl @@ -0,0 +1,189 @@ +# Copyright (C) 2004 Fletcher T. Penney +# +# 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 2 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, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: clustermap.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $

'; + +use vars qw($ClusterMapPage $ClusterMapTOC); + +$ClusterMapPage = "ClusterMap" unless defined $ClusterMapPage; + +$ClusterMapTOC = 1 unless defined $ClusterMapTOC; +$PrintTOCAnchor = 0; + +%ClusterMap = (); + +*OldDoRc = *DoRc; +*DoRc = *ClusterMapDoRc; + +push(@MyAdminCode, \&ClusterMapAdminRule); + +$Action{clustermap} = \&DoClusterMap; + +$Action{unclustered} = \&DoUnclustered; + +push(@MyRules, \&ClusterMapRule); + +sub ClusterMapRule { + if (/\G^([\n\r]*\<\s*clustermap\s*\>\s*)$/mgc) { + Dirty($1); + my $oldpos = pos; + $oldstr = $_; + CreateClusterMap(); + print "

"; # Needed to clean up, but could cause problems + # if

Contents

    '; + foreach my $cluster ( sort keys %ClusterMap) { + print "
  1. $cluster
  2. "; + $TOCCount++; + } + print '
'; + $PrintTOCAnchor = 1; + } + print '
'; + PrintClusterMap(); + + print '
'; + PrintFooter(); +} + +sub DoUnclustered { + + print GetHeader('','Pages without a Cluster',''); + print '
'; + + CreateClusterMap(); + PrintUnclusteredMap(); + + print '
'; + PrintFooter(); +} + +sub PrintClusterMap { + my $TOCCount = 0; + foreach my $cluster (sort keys %ClusterMap) { + local %Page; + local $OpenPageName=''; + + OpenPage($cluster); + + if ( GetCluster($Page{text}) eq $cluster ) { + # Don't display the page name twice if the cluster page is also + # a member of the cluster + $Page{text} =~ s/^\[*$cluster\]*\n//s; + } + + if ($PrintTOCAnchor) { + print $q->h1("" . GetPageOrEditLink($cluster, $cluster)); + $TOCCount++; + + } else { + print $q->h1(GetPageOrEditLink($cluster, $cluster)); + } + PrintWikiToHTML($Page{text}, 0); + + print "
    "; + foreach my $page (sort keys %{$ClusterMap{$cluster}}) { + my $title = $page; + $title =~ s/_/ /g; + print "
  • " . ScriptLink($page, $title, 'local') . "
  • "; + } + print "
"; + } +} + +sub CreateClusterMap { + my @pages = AllPagesList(); + + local %Page; + local $OpenPageName=''; + + foreach my $page ( @pages) { + OpenPage($page); + my $cluster = GetCluster($Page{text}); + + if ($cluster ne "") { + if ( ($cluster ne $page) + && ($cluster ne $DeletedPage)) { + $ClusterMap{$cluster}{$page} = 1; + } + } else { + $Unclustered{$page} = 1; + } + } +} + +sub ClusterMapDoRc { + my ( @options ) = @_; + my $page = ""; + my $cluster = GetParam(rcclusteronly); + + if ($cluster ne "") { + CreateClusterMap(); + print "Pages in this cluster:"; + print "
    "; + foreach $page (sort keys %{$ClusterMap{$cluster}}) { + my $title = $page; + $title =~ s/_/ /g; + print "
  • " . ScriptLink($page, $title, 'local') . "
  • "; + } + print "
"; + } + + OldDoRc(@options); +} + +sub PrintUnclusteredMap { + print "
    "; + foreach $page (sort keys %Unclustered) { + my $title = $page; + $title =~ s/_/ /g; + print "
  • " . ScriptLink($page, $title, 'local') . "
  • "; + } + print "
"; + +} + +sub ClusterMapAdminRule { + ($id, $menuref, *restref) = @_; + + push(@$menuref, ScriptLink('action=clustermap', T('Clustermap'))); + push(@$menuref, ScriptLink('action=unclustered', T('Pages without a Cluster'))); +} \ No newline at end of file diff --git a/modules/htmllinks.pl b/modules/htmllinks.pl new file mode 100755 index 00000000..9f4bc84e --- /dev/null +++ b/modules/htmllinks.pl @@ -0,0 +1,36 @@ +# Copyright (C) 2004 Fletcher T. Penney +# +# 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 2 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, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: htmllinks.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $

'; + +use vars qw($HtmlLinks); + +$HtmlLinks = 0; # Mask all email, not just those in []'s + +push(@MyRules, \&HtmlLinksRule); + +$RuleOrder{\&HtmlLinksRule} = 105; + +sub HtmlLinksRule { + if (-f GetLockedPageFile($OpenPageName)) { + $HtmlLinks = 1; + } else { + $HtmlLinks = 0; + } + return undef; +} \ No newline at end of file diff --git a/modules/logbannedcontent.pl b/modules/logbannedcontent.pl new file mode 100755 index 00000000..0727d7eb --- /dev/null +++ b/modules/logbannedcontent.pl @@ -0,0 +1,51 @@ +# Copyright (C) 2004 Fletcher T. Penney +# +# 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 2 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, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: logbannedcontent.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $

'; + +use vars qw($BannedFile); + +$BannedFile = "$DataDir/spammer.log" unless defined $BannedFile; + +*OldBannedContent = *BannedContent; +*BannedContent = *LogBannedContent; + +sub LogBannedContent { + my $str = shift; + *BannedContent = *OldBannedContent; + my $rule = BannedContent($str); + if ($rule) { + my $visitor = $ENV{'REMOTE_ADDR'}; + + # Create timestamp + ($sec, $min, $hr, $mday, $mon, $year, $wday, $yday, $isdst) =localtime(time); + $year=$year+1900; + $mon += 1; + + # Fix for 0's + $mon = sprintf("%02d", $mon); + $day = sprintf("%02d", $day); + $sec = sprintf("%02d", $sec); + $min = sprintf("%02d", $min); + $hr = sprintf("%02d", $hr); + + AppendStringToFile($BannedFile, "$year/$mon/$mday\t$hr:$min:$sec\t$visitor: $OpenPageName - $rule\n"); + } + + return $rule; +} \ No newline at end of file diff --git a/modules/slideshow.pl b/modules/slideshow.pl new file mode 100755 index 00000000..a5570117 --- /dev/null +++ b/modules/slideshow.pl @@ -0,0 +1,219 @@ +# Copyright (C) 2004 Fletcher T. Penney +# +# 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 2 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, write to the +# Free Software Foundation, Inc. +# 59 Temple Place, Suite 330 +# Boston, MA 02111-1307 USA + +$ModulesDescription .= '

$Id: slideshow.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $

'; + +use vars qw($SlideShowDataFolder $SlideShowTheme $SlideShowHeader %SlideShowMeta); + +my $InSlide = 0; +my $SlideShowBegun = 0; +my %SlideShowIndex; +my $SlideCounter = 0; + +$SlideShowDataFolder = "/s5/v11b3"; + +$SlideShowHeader = <<'EOT' unless defined $SlideShowHeader; + + + +EOT + +$SlideShowTheme = "i18n" unless defined $SlideShowTheme; + +$SlideShowConfiguration = +qq! + + + + + + + +!; + +%SlideShowMeta = ( generator => "S5", + version => "S5 1.1b2", + presdate => "", + author => "", + company => "", + authafill => "", +) unless defined %SlideShowMeta; + +my $SlideShowTitle; + +$Action{slideshow} = \&DoSlideShow; + +sub DoSlideShow { + my $id = shift; + print GetSlideShowHeader($id, Ts('Slideshow:%s', $id)); + + IndexSlideShow($id); + + push(@MyRules, \&SlideShowRule); + *OldPrintWikiToHTML = *PrintWikiToHTML; + *PrintWikiToHTML = *PrintSlideWikiToHTML; + $IgnoreForTOC = 1; + + OpenPage($id); + PrintPageHtml(); + print GetSlideShowFooter($id); +} + + +sub GetSlideShowHeader { + my ($id, $title, $oldId, $nocache, $status) = @_; + $title =~ s/_/ /g; + $SlideShowTitle = $title; + my $result = GetHttpHeader('text/html', $nocache ? $Now : 0, $status); +# $result .= GetHtmlHeader($title, $id); +# $result .= GetSlideShowHtmlHeader($title, $id); + $result .= $SlideShowHeader; + return $result; +} + +sub GetSlideShowHtmlHeader { + my ($title, $id) = @_; + + $html = $q->head($q->title($q->escapeHTML($SlideShowTitle)) . "\n" . GetSlideShowMeta($id) . $SlideShowConfiguration); + $html .= ' +
'; + $html .= GetSlideHeader($id) . GetSlideFooter($id) . '
' + . '
'; + return $html; +} + +sub GetSlideShowMeta { + my ($id) = @_; + my $html; + + foreach my $MetaKey (keys %SlideShowMeta) { + next if $MetaKey =~ /^(footer[12])$/; + $html .= qq!\n!; + } + return $html; +} + +sub GetSlideHeader { + my ($id) = @_; + my $html = ''; + return $html; +} + +sub GetSlideFooter { + my ($id) = @_; + my $html = ''; + return $html; +} + +sub GetSlideShowFooter{ + my ($id) = @_; + my $html = '
'; + + if ($InSlide) { + $html = '' . $html; + } + return $html; +} + + +sub SlideShowRule { +# Don't put slide div's in HtmlEnvironment so they don't get closed + if (m/\G(\s*\n)*\<slide[ \t]+([^\n]*?)([ \t]*class\=([^\n]*?))?\>/icg) { + my $CloseDiv = ""; + my $class = "slide"; + + $CloseDiv .= "" if ($InSlide); + $CloseDiv .= "" if ($InHandout); + $InSlide = 1; + $InHandout = 0; + $class = $4 if ($4 ne ""); + + if ($SlideShowBegun) { + return CloseHtmlEnvironments() . $CloseDiv . qq!
! . AddHtmlEnvironment('h1','') . $2 . CloseHtmlEnvironment(); + } else { + $SlideShowBegun = 1; + return GetSlideShowHtmlHeader() . $CloseDiv . qq!
! . AddHtmlEnvironment('h1','') . $2 . CloseHtmlEnvironment(); } + } + + if (m/\G(\s*\n)*\<slidelink\s*(.*?)\=(.*?)\>[\s\t\n]*/icg) { + return qq!$3!; + } + + if (m/\G(\s*\n)*\<handout([^\n]*)([ \t]*class\=([^\n]*?))?\>/icg) { + $InHandout = 1; + my $class = "handout"; + $class = $4 if ($4 ne ""); + + return CloseHtmlEnvironments() . qq!
!; + } + + if (m/\G(\s*\n)*\<image\s*(.*?)\=(.*?)\>[\s\t\n]*/icg) { + return OpenHtmlEnvironment('div',1,'imagebox') . qq!$2!; + } + + if (m/\G(\s*\n)*\<inc[ \t]*image\s*(.*?)\=(.*?)\>[\s\t\n]*/icg) { + return OpenHtmlEnvironment('div',1,'imagebox') . qq!$2!; + } + + if (m/\G(\s*\n)*\<meta\s*(.*?)\=(.*?)\>[\s\t\n]*/icg) { + $SlideShowMeta{$2}=$3; + return ""; + } + + if ( m/\G(\s*\n)*(inc\*+)[ \t]/cg + or InElement('li') && m/\G(\s*\n)+(inc\*+)[ \t]/cg) { + return CloseHtmlEnvironmentUntil('li') . OpenHtmlEnvironment('ul',length($2)-3, 'incremental') + . AddHtmlEnvironment('li'); + } + return undef; +} + + +sub PrintSlideWikiToHTML { + my ($pageText, $savecache, $revision, $islocked) = @_; + $FootnoteNumber = 0; + $pageText =~ s/$FS//g; # Remove separators (paranoia) + $pageText = QuoteHtml($pageText); + my ($blocks, $flags) = ApplyRules($pageText, 1, $savecache, $revision); # p is start tag! + # local links, anchors if cache ok + if ($savecache and not $revision) { + $Page{blocks} = $blocks; + $Page{flags} = $flags; + if ($islocked or RequestLockDir('main')) { # not fatal! + SavePage(); + ReleaseLock() unless $islocked; + } + } +} + +sub IndexSlideShow { + my ($id) = @_; + + my $page = GetPageContent($id); + + while ($page =~ /\/isg ) { + $SlideShowIndex{$1}=$SlideCounter; + $SlideCounter++; + } +}