| 1 | # PurpleWiki::Search::IrcLogger.pm | ||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||
| 3 | # | ||
| 4 | # $Id: IrcLogger.pm 352 2004-05-08 22:00:33Z cdent $ | ||
| 5 | # | ||
| 6 | # A Search Module for irclogger (see | ||
| 7 | # http://collab.blueoxen.net/forums/tools-yak/2003-12/msg00003.html | ||
| 8 | # ) | ||
| 9 | # | ||
| 10 | # A sublcass of the Arts module as they use the same file format. | ||
| 11 | # | ||
| 12 | # FIXME: Change the Arts module to WikiText and make both Arts and | ||
| 13 | # IrcLogger subclasses of that. | ||
| 14 | # | ||
| 15 | # Copyright (c) Blue Oxen Associates 2002-2004. All rights reserved. | ||
| 16 | # | ||
| 17 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||
| 18 | # | ||
| 19 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||
| 20 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||
| 21 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||
| 22 | # The Original WikiWikiWeb (c) Ward Cunningham | ||
| 23 | # | ||
| 24 | # PurpleWiki is free software; you can redistribute it and/or modify | ||
| 25 | # it under the terms of the GNU General Public License as published by | ||
| 26 | # the Free Software Foundation; either version 2 of the License, or | ||
| 27 | # (at your option) any later version. | ||
| 28 | # | ||
| 29 | # This program is distributed in the hope that it will be useful, | ||
| 30 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 31 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 32 | # GNU General Public License for more details. | ||
| 33 | # | ||
| 34 | # You should have received a copy of the GNU General Public License | ||
| 35 | # along with this program; if not, write to the | ||
| 36 | # Free Software Foundation, Inc. | ||
| 37 | # 59 Temple Place, Suite 330 | ||
| 38 | # Boston, MA 02111-1307 USA | ||
| 39 | # | ||
| 40 | |||
| 41 | package PurpleWiki::Search::IrcLogger; | ||
| 42 | |||
| 43 | use strict; | ||
| 44 | use base 'PurpleWiki::Search::Arts'; | ||
| 45 | use PurpleWiki::Search::Result; | ||
| 46 | use AppConfig; | ||
| 47 | |||
| 48 | our $VERSION; | ||
| 49 | $VERSION = sprintf("%d", q$Id: IrcLogger.pm 352 2004-05-08 22:00:33Z cdent $ =~ /\s(\d+)\s/); | ||
| 50 | |||
| 51 | # AppConfig values from the irclogger config file | ||
| 52 | my @CONFIG = qw(channel wikiconfig url logfile); | ||
| 53 | |||
| 54 | # The regular expression used for matching filenames | ||
| 55 | my $FILE_MATCH = 'irclog\.\d+\.wiki'; | ||
| 56 | |||
| 57 | sub _initRepository { | ||
| 58 | my $self = shift; | ||
| 59 | |||
| 60 | # open the logger config files and get the relevant info | ||
| 61 | # and translate it to arts style | ||
| 62 | my %config; | ||
| 63 | |||
| 64 | foreach my $configFile (@{$self->config()->IrcLogConfig()}) { | ||
| 65 | my $configRef = $self->_initConfig($configFile); | ||
| 66 | |||
| 67 | my $channel = $configRef->channel(); | ||
| 68 | $config{$channel}{purpleConfig} = $configRef->wikiconfig(); | ||
| 69 | |||
| 70 | my $url = $configRef->url(); | ||
| 71 | $url =~ s/\/[^\/]+$//; | ||
| 72 | $config{$channel}{urlprefix} = $url; | ||
| 73 | |||
| 74 | my $files = $configRef->logfile(); | ||
| 75 | $files =~ s/\/[^\/]+$//; | ||
| 76 | $config{$channel}{repository} = $files; | ||
| 77 | } | ||
| 78 | |||
| 79 | # collect information on the repository locations | ||
| 80 | my %repositories; | ||
| 81 | |||
| 82 | foreach my $repository (keys(%config)) { | ||
| 83 | if ($config{$repository}{purpleConfig} = | ||
| 84 | $self->{config}->DataDir()) { | ||
| 85 | $repositories{$repository} = $config{$repository}{repository}; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | # FIXME: its redundant to have both of these but I wanted easy | ||
| 90 | # access | ||
| 91 | $self->{repositoryConfig} = \%config; | ||
| 92 | $self->{repositories} = \%repositories; | ||
| 93 | |||
| 94 | return $self; | ||
| 95 | } | ||
| 96 | |||
| 97 | # initialize the irclogger config | ||
| 98 | # taken from irclogger itself | ||
| 99 | sub _initConfig { | ||
| 100 | my $self = shift; | ||
| 101 | my $file = shift; | ||
| 102 | |||
| 103 | $self->{fileMatch} = $FILE_MATCH; | ||
| 104 | |||
| 105 | my $config; | ||
| 106 | |||
| 107 | $config = AppConfig->new({ | ||
| 108 | CREATE => 1, | ||
| 109 | GLOBAL => { | ||
| 110 | EXPAND => AppConfig::EXPAND_VAR, | ||
| 111 | }, | ||
| 112 | }); | ||
| 113 | |||
| 114 | foreach my $var (@CONFIG) { | ||
| 115 | $config->define($var, { | ||
| 116 | ARGCOUNT => AppConfig::ARGCOUNT_ONE, | ||
| 117 | }); | ||
| 118 | } | ||
| 119 | |||
| 120 | $config->file($file) || die "unable to parse config file: $file"; | ||
| 121 | |||
| 122 | return $config; | ||
| 123 | } | ||
| 124 | |||
| 125 | 1; | ||
| 126 | |||
| 127 | __END__ |