From 293e1c0e47d91ca791051531ed54eaae7937e057 Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Tue, 4 Nov 2008 15:58:04 +0000 Subject: [PATCH] Google sitemaps index added to WebGUI --- docs/upgrades/upgrade_7.6.1-7.6.2.pl | 22 ++++++ lib/WebGUI/Content/SiteIndex.pm | 104 +++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 lib/WebGUI/Content/SiteIndex.pm diff --git a/docs/upgrades/upgrade_7.6.1-7.6.2.pl b/docs/upgrades/upgrade_7.6.1-7.6.2.pl index c0fa36e5a..6319114fb 100644 --- a/docs/upgrades/upgrade_7.6.1-7.6.2.pl +++ b/docs/upgrades/upgrade_7.6.1-7.6.2.pl @@ -39,6 +39,7 @@ addProfileExtrasField($session); addWorkflowToDataform( $session ); installDataTableAsset( $session ); installAjaxI18N( $session ); +installSiteIndex( $session ); finish($session); # this line required #---------------------------------------------------------------------------- @@ -85,6 +86,27 @@ sub installAjaxI18N { print "DONE!\n" unless $quiet; } +#---------------------------------------------------------------------------- +# installSiteIndex +# Install the content handler by adding it to the config file +sub installSiteIndex { + my $session = shift; + print "\tInstalling the SiteIndex content handler... " unless $quiet; + + my $oldHandlers = $session->config->get( "contentHandlers" ); + my @newHandlers; + for my $handler ( @{ $oldHandlers } ) { + if ( $handler eq "WebGUI::Content::Asset" ) { + push @newHandlers, "WebGUI::Content::SiteIndex"; + } + push @newHandlers, $handler; + } + $session->config->set( "contentHandlers", \@newHandlers ); + + print "DONE!\n" unless $quiet; +} + + #---------------------------------------------------------------------------- sub upgradeToYui26 { my $session = shift; diff --git a/lib/WebGUI/Content/SiteIndex.pm b/lib/WebGUI/Content/SiteIndex.pm new file mode 100644 index 000000000..cef377f4f --- /dev/null +++ b/lib/WebGUI/Content/SiteIndex.pm @@ -0,0 +1,104 @@ +package WebGUI::Content::SiteIndex; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::Asset; +use XML::Simple; + +=head1 NAME + +Package WebGUI::Content::SiteIndex + +=head1 DESCRIPTION + +A content handler that displays a google site index making it easier and faster +for search engines to index a website. + +=head1 SYNOPSIS + + use WebGUI::Content::SiteIndex; + my $output = WebGUI::Content::SiteIndex::handler($session); + +=head1 SUBROUTINES + +These subroutines are available from this package: + +=cut + +#------------------------------------------------------------------- + +=head2 handler ( session ) + +The content handler for this package. + +=cut + +sub handler { + my $session = shift; + + my $p = $session->url->page(); + unless ($p =~ m/siteindex\.xml/i) { + return undef; + } + + my $pages = WebGUI::Asset->getRoot($session)->getLineage(["self","descendants"],{ + returnObjects => 1, + includeOnlyClasses => ["WebGUI::Asset::Wobject::Layout"], + whereClause => "assetData.groupIdView = 7", + limit => 20000 + }); + + + my $url = []; + foreach my $page (@{$pages}) { + push(@{$url},{ + loc => $session->url->getSiteURL().formatXML($page->getUrl), + lastmod => $session->datetime->epochToSet($page->get("revisionDate")), + }); + } + + my $xmlStructure = { url => $url }; + my $xml = + '' + .'' + . XMLout( $xmlStructure, + NoAttr => 1, + KeepRoot => 1, + KeyAttr => ["url"], + ) + .''; + + + $session->http->setMimeType('text/xml'); + + return $xml; +} + +#------------------------------------------------------------------- +sub formatXML { + my $content = shift; + $content =~ s/&/&/g; + $content =~ s/\/>/g; + $content =~ s/'/'/g; + $content =~ s/"/"/g; + + return $content; +} + + +1; +