AxKit-XSP-Wiki
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/AxKit/XSP/Wiki.pm view on Meta::CPAN
my $quote = $1;
$term =~ s/^$quote//;
$term .= $space;
if ($query =~ /\G(.*?)\.?$quote\s*/gc) {
$term .= $1;
$search{phrase}{$term}++;
warn "Search phrase: $term\n";
}
}
else {
$search{required}{$term}++;
warn "Search normal: $term\n";
}
}
# turn into arrayrefs
foreach ( qw( normal required excluded phrase ) )
{
if ( $search{$_} )
{
$search{$_} = [ keys %{ $search{$_} } ]
}
else
{
$search{$_} = [];
}
}
return %search;
}
sub save_page {
my ($dbpath, $dbname, $page, $contents, $texttype, $ip, $user) = @_;
my $db = _mkdb($dbpath, $dbname);
_save_page($db, $page, $contents, $texttype, $ip, $user);
}
sub _save_page {
my ($db, $page, $contents, $texttype, $ip, $user) = @_;
# NB fix hard coded formatterid
my $last_modified = time;
my @history = $db->selectrow_array('SELECT content FROM History WHERE name = ? ORDER BY modified DESC', {}, $page);
local $db->{AutoCommit} = 0;
$db->do(<<'EOT', {}, $page, $texttype, $contents, $last_modified, $ip, $user);
INSERT OR REPLACE INTO Page ( name, formatterid, content, last_modified, ip_address, username )
VALUES ( ?, ?, ?, ?, ?, ? )
EOT
$db->do(<<'EOT', {}, $page, $texttype, $contents, $last_modified, $ip, $user);
INSERT INTO History ( name, formatterid, content, modified, ip_address, username )
VALUES ( ?, ?, ?, ?, ?, ? )
EOT
$db->commit;
_index_page($db, $page);
if ($EmailAlerts) {
# create diff using Text::Diff
my $prev = @history ? $history[0] : '';
my $diff = diff(\$prev, \$contents, { STYLE => 'Unified' });
my $host = $EmailHost || 'localhost';
my $smtp = Net::SMTP->new($host, Timeout => 10);
$smtp->mail('axkitwiki') || die "Wiki email alerts: MAIL FROM:<axkitwiki> failed";
$smtp->to($EmailAlerts) || die "Wiki email alerts: RCPT TO:<$EmailAlerts> failed";
$smtp->data() || die "Wiki email alerts: DATA failed";
my $date = strftime('%a, %d %b %Y %H:%M:%S %Z', localtime);
my $changed_by = $user ? "$user @ $ip" : "someone at IP $ip";
$smtp->datasend(<<"EOT");
To: $EmailAlerts
From: "AxKit Wiki" <axkitwiki>
Subject: New Wiki Content at $page
Date: $date
Wiki content at $page Changed by $changed_by :
$diff
EOT
$smtp->dataend();
$smtp->quit();
}
}
sub _index_page {
my ($db, $page) = @_;
my $sth = $db->prepare(<<'EOT');
SELECT Page.id, Page.content, Formatter.module
FROM Page, Formatter
WHERE Page.formatterid = Formatter.id
AND Page.name = ?
EOT
$sth->execute($page);
my $output = '';
while ( my $row = $sth->fetch ) {
my $handler = AxKit::XSP::Wiki::Indexer->new(DB => $db, PageId => $row->[0]);
# create the parser
my $parser = $row->[2]->new(Handler => $handler);
eval {
$parser->parse_string($row->[1]);
};
if ($@) {
warn("Indexing failed");
}
last;
}
}
sub show_history {
my ($db, $page) = @_;
my $sth = $page ? $db->prepare('SELECT * FROM History WHERE name = ? ORDER BY modified DESC LIMIT 50') :
$db->prepare('SELECT * FROM History ORDER BY modified DESC LIMIT 50');
$sth->execute($page);
my $hist = '<history>';
my %h;
my $cols = $sth->{NAME_lc};
while (my $row = $sth->fetch) {
@h{@$cols} = @$row;
$hist .= '<entry>';
$hist .= '<page>' . xml_escape($h{name}) . '</page>';
$hist .= '<id>' . xml_escape($h{id}) . '</id>';
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.037 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )