public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-projects commit in forums/scripts: sitemap.pl
@ 2009-07-30 11:36 Dean Stephens (desultory)
  0 siblings, 0 replies; 3+ messages in thread
From: Dean Stephens (desultory) @ 2009-07-30 11:36 UTC (permalink / raw
  To: gentoo-commits

desultory    09/07/30 11:36:56

  Added:                sitemap.pl
  Log:
  Basic sitemap script.

Revision  Changes    Path
1.1                  forums/scripts/sitemap.pl

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/forums/scripts/sitemap.pl?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/forums/scripts/sitemap.pl?rev=1.1&content-type=text/plain

Index: sitemap.pl
===================================================================
#!/usr/bin/perl

# -----------------------------------------------------------------------------
#
# sitemap.pl
#
# date        : 2009-07-30
# author      : Dean Stephens <desultory@gentoo.org>
# version     : 0.1
# license     : GPL2
# description : This script generates a basic site map consisting of links to 
# -----------------------------------------------------------------------------
#
# 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.
#
# -----------------------------------------------------------------------------

use strict;
use warnings;
use DBI;

my $connectString = "DBI:mysql:;mysql_read_default_file=~/.my.cnf;mysql_read_default_group=forum_ro";
my $dbh = DBI->connect( $connectString, '', '', { RaiseError => 1, AutoCommit => 0 } ) || die 'Failed to connect to the DB.';

sub query( $ ) {
	my $sth = $dbh->prepare( shift );
	my $return = $dbh->selectall_arrayref($sth);

	$sth->finish;

	return $return;
}

sub page_header($){
	my $title = shift;

	return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
	"\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<header><title>$title</title></header>\n".
	"<body><h1>$title</h1>\n<ul>\n";
}

sub page_footer($){
	my $info = shift;

	return "</ul>\n$info\n</body></html>\n";
}

my $sitemap = "index.html";
my $suffix = "new";

my $sitenameQuery = 'SELECT config_value FROM phpbb_config WHERE config_name = "sitename";';
my $sitename = query($sitenameQuery)->[0][0]; #phpbb_config.sitename
my $pagesizeQuery = 'SELECT config_value FROM phpbb_config WHERE config_name = "posts_per_page";';
my $posts_per_page = query($pagesizeQuery)->[0][0]; #phpbb_config.posts_per_page
my $dustbinQuery = 'SELECT config_value FROM phpbb_config WHERE config_name = "dustbin_forum_id";';
my $dustbin = query($dustbinQuery)->[0][0]; #phpbb_config.dustbin_forum_id
my $forumsQuery = 'SELECT forum_id,forum_name,forum_desc,cat_id,forum_order,parent_id FROM phpbb_forums WHERE auth_view=0 AND auth_read=0 AND forum_id != "'. $dustbin .'" ORDER BY cat_id, forum_order;';
my $forums = query($forumsQuery); # public,readable,viewable forums, aside from dustbin, it's an arayref.

open( SITEMAP, '>', "$sitemap.$suffix" );

print SITEMAP page_header( "${sitename} site map" );

foreach my $forum (@$forums){
	my $forumId = $forum->[0];
	my $forumName = $forum->[1];
	my $topicsQuery = 'SELECT topic_id,topic_title,topic_replies FROM phpbb_topics WHERE forum_id = '.$forumId.' ORDER BY topic_time DESC;';
	my $topics = query( $topicsQuery );

	my $sectionIndex = $forumId.'.html';
	my $newSectionIndex = "${sectionIndex}.$suffix";

	open( SECTIONMAP, '>', "$newSectionIndex" );

	print SECTIONMAP page_header( 'Index of '.$forumName );

	foreach my $topic (@$topics){
		my $topicId = $topic->[0];
		my $topicTitle = $topic->[1];
		my $topicReplies = $topic->[2];

		my $offset = 0;
		my $page = 1;

		do{
			print SECTIONMAP '<li><a href="../viewtopic-t-'.$topicId.'-start-'.$offset.'.html">"'.$topicTitle.'" Page:'.$page."</a></li>\n";

			$offset += $posts_per_page;
			$page++;
		}while( $offset < $topicReplies );
	}

	print SECTIONMAP page_footer( 'Generated at'.scalar(localtime).', "'.$forumName.'" contained '.scalar(@{$topics}).' topics.' );

	close(SECTIONMAP);

	rename( $newSectionIndex, $sectionIndex ) or die "Could not rename $newSectionIndex to $sectionIndex\n";

	print SITEMAP "<li><a href=\"./$forumId.html\">\"$forumName\"</a></li>\n";
}


print SITEMAP page_footer( 'Generated at'.scalar(localtime) );

close(SITEMAP);

$dbh->disconnect;

rename( "$sitemap.$suffix", "$sitemap" );






^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gentoo-commits] gentoo-projects commit in forums/scripts: sitemap.pl
@ 2009-07-30 23:07 Dean Stephens (desultory)
  0 siblings, 0 replies; 3+ messages in thread
From: Dean Stephens (desultory) @ 2009-07-30 23:07 UTC (permalink / raw
  To: gentoo-commits

desultory    09/07/30 23:07:07

  Modified:             sitemap.pl
  Log:
  Error handling fixes.

Revision  Changes    Path
1.2                  forums/scripts/sitemap.pl

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/forums/scripts/sitemap.pl?rev=1.2&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/forums/scripts/sitemap.pl?rev=1.2&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/forums/scripts/sitemap.pl?r1=1.1&r2=1.2

Index: sitemap.pl
===================================================================
RCS file: /var/cvsroot/gentoo-projects/forums/scripts/sitemap.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sitemap.pl	30 Jul 2009 11:36:56 -0000	1.1
+++ sitemap.pl	30 Jul 2009 23:07:07 -0000	1.2
@@ -60,7 +60,7 @@
 my $forumsQuery = 'SELECT forum_id,forum_name,forum_desc,cat_id,forum_order,parent_id FROM phpbb_forums WHERE auth_view=0 AND auth_read=0 AND forum_id != "'. $dustbin .'" ORDER BY cat_id, forum_order;';
 my $forums = query($forumsQuery); # public,readable,viewable forums, aside from dustbin, it's an arayref.
 
-open( SITEMAP, '>', "$sitemap.$suffix" );
+open( SITEMAP, '>', "$sitemap.$suffix" ) or die "Can't open $sitemap.$suffix : $!\n";
 
 print SITEMAP page_header( "${sitename} site map" );
 
@@ -73,7 +73,7 @@
 	my $sectionIndex = $forumId.'.html';
 	my $newSectionIndex = "${sectionIndex}.$suffix";
 
-	open( SECTIONMAP, '>', "$newSectionIndex" );
+	open( SECTIONMAP, '>', "$newSectionIndex" ) or die "Can't open $sitemap.$suffix : $!\n";
 
 	print SECTIONMAP page_header( 'Index of '.$forumName );
 
@@ -109,4 +109,4 @@
 
 $dbh->disconnect;
 
-rename( "$sitemap.$suffix", "$sitemap" );
+rename( "$sitemap.$suffix", "$sitemap" ) or die "Could not rename $sitemap.$suffix to $sitemap\n";






^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gentoo-commits] gentoo-projects commit in forums/scripts: sitemap.pl
@ 2010-07-23  6:42 Dean Stephens (desultory)
  0 siblings, 0 replies; 3+ messages in thread
From: Dean Stephens (desultory) @ 2010-07-23  6:42 UTC (permalink / raw
  To: gentoo-commits

desultory    10/07/23 06:42:32

  Modified:             sitemap.pl
  Log:
  Tweaks by robbat2 to trigger sitemap cloning, in place since 2009-08-12

Revision  Changes    Path
1.3                  forums/scripts/sitemap.pl

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/forums/scripts/sitemap.pl?rev=1.3&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/forums/scripts/sitemap.pl?rev=1.3&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/forums/scripts/sitemap.pl?r1=1.2&r2=1.3

Index: sitemap.pl
===================================================================
RCS file: /var/cvsroot/gentoo-projects/forums/scripts/sitemap.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sitemap.pl	30 Jul 2009 23:07:07 -0000	1.2
+++ sitemap.pl	23 Jul 2010 06:42:32 -0000	1.3
@@ -50,6 +50,7 @@
 
 my $sitemap = "index.html";
 my $suffix = "new";
+my $marker = '.marker';
 
 my $sitenameQuery = 'SELECT config_value FROM phpbb_config WHERE config_name = "sitename";';
 my $sitename = query($sitenameQuery)->[0][0]; #phpbb_config.sitename
@@ -110,3 +111,8 @@
 $dbh->disconnect;
 
 rename( "$sitemap.$suffix", "$sitemap" ) or die "Could not rename $sitemap.$suffix to $sitemap\n";
+
+# Touch the marker to say we are DONE
+open( MARKER, '>', $marker ) or die "Failed to open marker $marker\n";
+printf MARKER "%d\n", time;
+close(MARKER);






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-23  6:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-30 11:36 [gentoo-commits] gentoo-projects commit in forums/scripts: sitemap.pl Dean Stephens (desultory)
  -- strict thread matches above, loose matches on Subject: below --
2009-07-30 23:07 Dean Stephens (desultory)
2010-07-23  6:42 Dean Stephens (desultory)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox