# Copyright (C) 2005, 2006 Alex Schroeder # # 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 . use strict; use v5.10; AddModuleDescription('aggregate.pl', 'Front Page Extension'); our ($q, $bol, %Action, %Page, $OpenPageName, $UseDiff, $UsePathInfo, $RssStyleSheet, $RssLicense, $RssRights, $RssImageUrl, $CommentsPrefix, $SiteName, $ScriptName, $HomePage, $SiteDescription, @MyRules, $LastUpdate, $InterWikiMoniker); push(@MyRules, \&AggregateRule); sub AggregateRule { if ($bol && m/\G(<aggregate\s+((("[^\"&]+",?\s*)+)|(sort\s+)?search\s+(.+?))>)/cg) { Clean(CloseHtmlEnvironments()); Dirty($1); my ($oldpos, $old_, $str, $sort, $search) = ((pos), $_, $3, $5, $6); my $master = $OpenPageName; local ($OpenPageName, %Page); print $q->start_div({class=>"aggregate journal"}); my @pages = (); @pages = $str =~ m/"([^\"&]+)"/g if $str; @pages = SearchTitleAndBody($search) if $search; if ($sort) { if (defined &PageSort) { @pages = sort PageSort @pages; } else { @pages = sort(@pages); } } foreach my $id (@pages) { next if $id eq $master; my $title = $id; local $OpenPageName = FreeToNormal($id); my $page = GetPageContent($OpenPageName); my $size = length($page); my $i = index($page, "\n="); my $j = index($page, "\n----"); $page = substr($page, 0, $i) if $i >= 0; $page = substr($page, 0, $j) if $j >= 0; $page =~ s/^=.*\n//; # if it starts with a header print $q->start_div({class=>"page"}), $q->h2(GetPageLink($OpenPageName, $title)); ApplyRules(QuoteHtml($page), 1, 0, undef, 'p'); print $q->p(GetPageLink($OpenPageName, T('Learn more...'))) if length($page) < $size; print $q->end_div(); } print $q->end_div(); Clean(AddHtmlEnvironment('p')); ($_, pos) = ($old_, $oldpos); # restore \G (assignment order matters!) return ''; } return; } $Action{aggregate} = \&DoAggregate; sub DoAggregate { print GetHttpHeader('application/xml'); my $frontpage = GetParam('id', $HomePage); my $title = $frontpage; $title =~ s/_/ /g; my $source = GetPageContent($frontpage); my $url = QuoteHtml($ScriptName); my $diffPrefix = $url . QuoteHtml("?action=browse;diff=1;id="); my $historyPrefix = $url . QuoteHtml("?action=history;id="); my $date = TimeToRFC822($LastUpdate); my $rss = qq{}; if ($RssStyleSheet =~ /\.(xslt?|xml)$/) { $rss .= qq{}; } elsif ($RssStyleSheet) { $rss .= qq{}; } $rss .= qq{ http://blogs.law.harvard.edu/tech/rss }; $rss .= "" . QuoteHtml("$SiteName: $title") . "\n"; $rss .= "" . $url . ($UsePathInfo ? "/" : "?") . UrlEncode($frontpage) . "\n"; $rss .= "" . QuoteHtml($SiteDescription) . "\n"; $rss .= "" . $date. "\n"; $rss .= "" . $date . "\n"; $rss .= "Oddmuse\n"; $rss .= "" . $RssRights . "\n" if $RssRights; if (ref $RssLicense eq 'ARRAY') { $rss .= join('', map {"$_\n"} @$RssLicense); } elsif ($RssLicense) { $rss .= "" . $RssLicense . "\n"; } $rss .= "" . $InterWikiMoniker . "\n" if $InterWikiMoniker; if ($RssImageUrl) { $rss .= "\n"; $rss .= "" . $RssImageUrl . "\n"; $rss .= "" . QuoteHtml($SiteName) . "\n"; $rss .= "" . $url . "\n"; $rss .= "\n"; } while ($source =~ m//g) { my ($str, $sort, $search) = ($1, $5, $6); my @pages = (); @pages = $str =~ m/"([^\"&]+)"/g if $str; @pages = SearchTitleAndBody($search) if $search; if ($sort) { if (defined &PageSort) { @pages = sort PageSort @pages; } else { @pages = sort(@pages); } } foreach my $id (@pages) { my $data = ParseData(ReadFileOrDie(GetPageFile(FreeToNormal($id)))); my $page = $data->{text}; my $size = length($page); my $i = index($page, "\n="); my $j = index($page, "\n----"); $page = substr($page, 0, $i) if $i >= 0; $page = substr($page, 0, $j) if $j >= 0; $page =~ s/^=.*\n//; # if it starts with a header my $name = $id; $name =~ s/_/ /g; my $date = TimeToRFC822($data->{ts}); my $host = $data->{host}; my $username = $data->{username}; $username = QuoteHtml($username); $username = $host unless $username; my $minor = $data->{minor}; my $revision = $data->{revision}; my $cluster = GetCluster($page); my $description = ToString(sub { ApplyRules(QuoteHtml($page), 1, 0, undef, 'p') }); $description .= $q->p(GetPageLink($id, T('Learn more...'))) if length($page) < $size; $rss .= "\n\n"; $rss .= "" . QuoteHtml($name) . "\n"; $rss .= "" . $url . (GetParam("all", 0) ? "?" . GetPageParameters("browse", $id, $revision, $cluster) : ($UsePathInfo ? "/" : "?") . UrlEncode($id)) . "\n"; $rss .= "" . QuoteHtml($description) . "\n"; $rss .= "" . $date . "\n"; $rss .= "" . $url . ($UsePathInfo ? "/" : "?") . $CommentsPrefix . UrlEncode($id) . "\n" if $CommentsPrefix and $id !~ /^$CommentsPrefix/; $rss .= "" . $username . "\n"; $rss .= "" . (1 == $revision ? "new" : "updated") . "\n"; $rss .= "" . ($minor ? "minor" : "major") . "\n"; $rss .= "" . $revision . "\n"; $rss .= "" . $historyPrefix . UrlEncode($id) . "\n"; $rss .= "" . $diffPrefix . UrlEncode($id) . "\n" if $UseDiff and GetParam("diffrclink", 1); $rss .= "\n"; } $rss .= "\n\n"; } print $rss; }