Google sitemaps index added to WebGUI
This commit is contained in:
parent
83bb3c1904
commit
293e1c0e47
2 changed files with 126 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ addProfileExtrasField($session);
|
||||||
addWorkflowToDataform( $session );
|
addWorkflowToDataform( $session );
|
||||||
installDataTableAsset( $session );
|
installDataTableAsset( $session );
|
||||||
installAjaxI18N( $session );
|
installAjaxI18N( $session );
|
||||||
|
installSiteIndex( $session );
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -85,6 +86,27 @@ sub installAjaxI18N {
|
||||||
print "DONE!\n" unless $quiet;
|
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 {
|
sub upgradeToYui26 {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
|
|
|
||||||
104
lib/WebGUI/Content/SiteIndex.pm
Normal file
104
lib/WebGUI/Content/SiteIndex.pm
Normal file
|
|
@ -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 =
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>'
|
||||||
|
.'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
|
||||||
|
. XMLout( $xmlStructure,
|
||||||
|
NoAttr => 1,
|
||||||
|
KeepRoot => 1,
|
||||||
|
KeyAttr => ["url"],
|
||||||
|
)
|
||||||
|
.'</urlset>';
|
||||||
|
|
||||||
|
|
||||||
|
$session->http->setMimeType('text/xml');
|
||||||
|
|
||||||
|
return $xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
sub formatXML {
|
||||||
|
my $content = shift;
|
||||||
|
$content =~ s/&/&/g;
|
||||||
|
$content =~ s/\</</g;
|
||||||
|
$content =~ s/\>/>/g;
|
||||||
|
$content =~ s/'/'/g;
|
||||||
|
$content =~ s/"/"/g;
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue