Added my modules to source - FletcherPenney

This commit is contained in:
Alex Schroeder
2005-04-05 21:18:57 +00:00
parent e1367b7ae1
commit aee5a4eafb
5 changed files with 561 additions and 0 deletions

66
modules/antispam.pl Executable file
View File

@@ -0,0 +1,66 @@
# Copyright (C) 2004 Fletcher T. Penney <fletcher@freeshell.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 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 .= '<p>$Id: antispam.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $</p>';
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 "<a href=\"mailto:" . $email . "\">$chunk</a>";
}
if (m/\G($EmailRegExp)/igc) {
$email=$1;
if ($DoMaskEmail) {
$masked="";
@decimal = unpack('C*', $email);
foreach $i (@decimal) {
$masked.="&#".$i.";";
}
$email = $masked;
}
if ($CreateMailtoLinks) {
$email = "<a href=\"mailto:" . $email . "\">$email</a>";
}
return $email;
}
return undef;
}

189
modules/clustermap.pl Executable file
View File

@@ -0,0 +1,189 @@
# Copyright (C) 2004 Fletcher T. Penney <fletcher@freeshell.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 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 .= '<p>$Id: clustermap.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $</p>';
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]*\&lt;\s*clustermap\s*\&gt;\s*)$/mgc) {
Dirty($1);
my $oldpos = pos;
$oldstr = $_;
CreateClusterMap();
print "</p>"; # Needed to clean up, but could cause problems
# if <clustermap isn't put into a new paragraph
PrintClusterMap();
pos = $oldpos;
$oldstr =~ s/.*?\&lt;\s*clustermap\s*\&gt;//s;
# $oldstr =~ s/.*\&lt;\s*clustermap\s*\&gt;//s;
$_ = $oldstr;
return '';
}
return undef;
}
sub DoClusterMap {
# Get list of all clusters
# For each cluster, get list of all pages in that cluster
# Create map, using body of cluster pages, followed by titles of pages
# within that cluster
print GetHeader('',$ClusterMapPage,'');
CreateClusterMap();
if ($ClusterMapTOC) {
my $TOCCount = 0;
print '<div class="toc"><h2>Contents</h2><ol>';
foreach my $cluster ( sort keys %ClusterMap) {
print "<li><a href=\"#toc$TOCCount\">$cluster</a></li>";
$TOCCount++;
}
print '</ol></div>';
$PrintTOCAnchor = 1;
}
print '<div class="content">';
PrintClusterMap();
print '</div>';
PrintFooter();
}
sub DoUnclustered {
print GetHeader('','Pages without a Cluster','');
print '<div class="content">';
CreateClusterMap();
PrintUnclusteredMap();
print '</div>';
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("<a id=\"toc$TOCCount\"></a>" . GetPageOrEditLink($cluster, $cluster));
$TOCCount++;
} else {
print $q->h1(GetPageOrEditLink($cluster, $cluster));
}
PrintWikiToHTML($Page{text}, 0);
print "<ul>";
foreach my $page (sort keys %{$ClusterMap{$cluster}}) {
my $title = $page;
$title =~ s/_/ /g;
print "<li>" . ScriptLink($page, $title, 'local') . "</li>";
}
print "</ul>";
}
}
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 "<ul>";
foreach $page (sort keys %{$ClusterMap{$cluster}}) {
my $title = $page;
$title =~ s/_/ /g;
print "<li>" . ScriptLink($page, $title, 'local') . "</li>";
}
print "</ul>";
}
OldDoRc(@options);
}
sub PrintUnclusteredMap {
print "<ul>";
foreach $page (sort keys %Unclustered) {
my $title = $page;
$title =~ s/_/ /g;
print "<li>" . ScriptLink($page, $title, 'local') . "</li>";
}
print "</ul>";
}
sub ClusterMapAdminRule {
($id, $menuref, *restref) = @_;
push(@$menuref, ScriptLink('action=clustermap', T('Clustermap')));
push(@$menuref, ScriptLink('action=unclustered', T('Pages without a Cluster')));
}

36
modules/htmllinks.pl Executable file
View File

@@ -0,0 +1,36 @@
# Copyright (C) 2004 Fletcher T. Penney <fletcher@freeshell.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 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 .= '<p>$Id: htmllinks.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $</p>';
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;
}

51
modules/logbannedcontent.pl Executable file
View File

@@ -0,0 +1,51 @@
# Copyright (C) 2004 Fletcher T. Penney <fletcher@freeshell.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 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 .= '<p>$Id: logbannedcontent.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $</p>';
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;
}

219
modules/slideshow.pl Executable file
View File

@@ -0,0 +1,219 @@
# Copyright (C) 2004 Fletcher T. Penney <fletcher@freeshell.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 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 .= '<p>$Id: slideshow.pl,v 1.1 2005/04/05 21:18:57 fletcherpenney Exp $</p>';
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;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
EOT
$SlideShowTheme = "i18n" unless defined $SlideShowTheme;
$SlideShowConfiguration =
qq!<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
<link rel="stylesheet" href="$SlideShowDataFolder/$SlideShowTheme/slides.css" type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="$SlideShowDataFolder/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="$SlideShowDataFolder/default/print.css" type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="$SlideShowDataFolder/default/opera.css" type="text/css" media="projection" id="operaFix" />
<script src="$SlideShowDataFolder/default/slides.js" type="text/javascript"></script>!;
%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 .= '
<body><div class="layout"><div id="controls"></div><div id="currentSlide"></div>';
$html .= GetSlideHeader($id) . GetSlideFooter($id) . '</div>'
. '<div class="presentation">';
return $html;
}
sub GetSlideShowMeta {
my ($id) = @_;
my $html;
foreach my $MetaKey (keys %SlideShowMeta) {
next if $MetaKey =~ /^(footer[12])$/;
$html .= qq!<meta name="$MetaKey" content="$SlideShowMeta{$MetaKey}" />\n!;
}
return $html;
}
sub GetSlideHeader {
my ($id) = @_;
my $html = '<div id="header">';
$html .= '</div>';
return $html;
}
sub GetSlideFooter {
my ($id) = @_;
my $html = '<div id="footer">';
$html .= qq!<h1>$SlideShowMeta{footer1}</h1><h2>$SlideShowMeta{footer2}</h2>!;
$html .= '</div>';
return $html;
}
sub GetSlideShowFooter{
my ($id) = @_;
my $html = '</div></body></html>';
if ($InSlide) {
$html = '</div>' . $html;
}
return $html;
}
sub SlideShowRule {
# Don't put slide div's in HtmlEnvironment so they don't get closed
if (m/\G(\s*\n)*\&lt;slide[ \t]+([^\n]*?)([ \t]*class\=([^\n]*?))?\&gt;/icg) {
my $CloseDiv = "";
my $class = "slide";
$CloseDiv .= "</div>" if ($InSlide);
$CloseDiv .= "</div>" if ($InHandout);
$InSlide = 1;
$InHandout = 0;
$class = $4 if ($4 ne "");
if ($SlideShowBegun) {
return CloseHtmlEnvironments() . $CloseDiv . qq!<div class="$class">! . AddHtmlEnvironment('h1','') . $2 . CloseHtmlEnvironment();
} else {
$SlideShowBegun = 1;
return GetSlideShowHtmlHeader() . $CloseDiv . qq!<div class="slide">! . AddHtmlEnvironment('h1','') . $2 . CloseHtmlEnvironment(); }
}
if (m/\G(\s*\n)*\&lt;slidelink\s*(.*?)\=(.*?)\&gt;[\s\t\n]*/icg) {
return qq!<a href="#slide$SlideShowIndex{$2}">$3</a>!;
}
if (m/\G(\s*\n)*\&lt;handout([^\n]*)([ \t]*class\=([^\n]*?))?\&gt;/icg) {
$InHandout = 1;
my $class = "handout";
$class = $4 if ($4 ne "");
return CloseHtmlEnvironments() . qq!<div class="$class">!;
}
if (m/\G(\s*\n)*\&lt;image\s*(.*?)\=(.*?)\&gt;[\s\t\n]*/icg) {
return OpenHtmlEnvironment('div',1,'imagebox') . qq!<img src="$3" alt="$2">!;
}
if (m/\G(\s*\n)*\&lt;inc[ \t]*image\s*(.*?)\=(.*?)\&gt;[\s\t\n]*/icg) {
return OpenHtmlEnvironment('div',1,'imagebox') . qq!<img src="$3" alt="$2" class="incremental">!;
}
if (m/\G(\s*\n)*\&lt;meta\s*(.*?)\=(.*?)\&gt;[\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 =~ /\<slide[ \t]+([^\n]*)\>/isg ) {
$SlideShowIndex{$1}=$SlideCounter;
$SlideCounter++;
}
}