gmnifaq

faq engine for gemini with full text search
git clone https://git.clttr.info/gmnifaq.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 7e2f5958e9055dfcf7ceedf8a583584bb8ca52c8
parent fae1610eb1c7a29f29244578926a97477471e5b7
Author: René Wagner <rwagner@rw-net.de>
Date:   Wed, 25 Nov 2020 12:04:27 +0100

tabify

Diffstat:
Mfaqs.pl | 10+++++-----
Mindex.pl | 12++++++------
Mlib/gmnifaq.pm | 14+++++++-------
Msearch.pl | 6+++---
Mtags.pl | 7++++---
5 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/faqs.pl b/faqs.pl @@ -9,15 +9,15 @@ use URI::Escape; use lib 'lib/'; use gmnifaq; -config(); - # enable UTF-8 mode for everything use utf8; binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; +config(); + if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') { - write_response('CGI_ERROR', 'CGI execution error', undef); + write_response('CGI_ERROR', 'CGI execution error', undef); } my @body = (); @@ -52,8 +52,8 @@ sub faqs my @return; my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr; - my @rows = $dbh->selectall_array(sql()); - $dbh->disconnect(); + my @rows = $dbh->selectall_array(sql()); + $dbh->disconnect(); if ( !scalar @rows ) { push @return, 'No faqs found!'; diff --git a/index.pl b/index.pl @@ -8,15 +8,15 @@ use DBI; use lib 'lib/'; use gmnifaq; -config(); - # enable UTF-8 mode for everything use utf8; binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; +config(); + if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') { - write_response('CGI_ERROR', 'CGI execution error', undef); + write_response('CGI_ERROR', 'CGI execution error', undef); } my @body = (); @@ -37,9 +37,9 @@ sub header { my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr; - my $tagcount = $dbh->selectrow_array("SELECT count(id) from tags"); - my $faqcount = $dbh->selectrow_array("SELECT count(id) from questions"); - $dbh->disconnect(); + my $tagcount = $dbh->selectrow_array("SELECT count(id) from tags"); + my $faqcount = $dbh->selectrow_array("SELECT count(id) from questions"); + $dbh->disconnect(); return ('# '. $CONF{'name'}, '', $CONF{'intro'}, '', sprintf('We are currently serving %d FAQs categorized with %d tags!', $faqcount, $tagcount), ''); } diff --git a/lib/gmnifaq.pm b/lib/gmnifaq.pm @@ -56,16 +56,16 @@ sub footer sub write_response { - my ($returncode, $meta, @content) = @_; - + my ($returncode, $meta, @content) = @_; + if (!defined($RC{$returncode})) { die "Unknown response code!"; } - printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta); - foreach (@content) { - print("$_\r\n"); - } + printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta); + foreach (@content) { + print("$_\r\n"); + } - exit; + exit; } 1; diff --git a/search.pl b/search.pl @@ -17,7 +17,7 @@ binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') { - write_response('CGI_ERROR', 'CGI execution error', undef); + write_response('CGI_ERROR', 'CGI execution error', undef); } my $query = lc(uri_unescape($ENV{'QUERY_STRING'})); @@ -41,8 +41,8 @@ sub search my @result = (); my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr; - my @matchingtags = $dbh->selectall_array("SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id WHERE name LIKE '%$term%' GROUP BY t_id"); - my @matchingfaqs = $dbh->selectall_array("SELECT * FROM questions WHERE question LIKE '%$term%' OR answer LIKE '%$term%'"); + my @matchingtags = $dbh->selectall_array("SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id WHERE name LIKE '%$term%' GROUP BY t_id"); + my @matchingfaqs = $dbh->selectall_array("SELECT * FROM questions WHERE question LIKE '%$term%' OR answer LIKE '%$term%'"); $dbh->disconnect(); if ( scalar(@matchingtags)) { diff --git a/tags.pl b/tags.pl @@ -5,6 +5,7 @@ use strict; use DBI; +use URI::Escape; use lib 'lib/'; use gmnifaq; @@ -16,7 +17,7 @@ binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') { - write_response('CGI_ERROR', 'CGI execution error', undef); + write_response('CGI_ERROR', 'CGI execution error', undef); } my @body = (); @@ -33,8 +34,8 @@ sub tags my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr; my @result; - my @rows = $dbh->selectall_array('SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id GROUP BY t_id'); - $dbh->disconnect(); + my @rows = $dbh->selectall_array('SELECT id, name, count(t_id) FROM tags LEFT JOIN tags_questions ON tags_questions.t_id = tags.id GROUP BY t_id'); + $dbh->disconnect(); if ( !scalar @rows ) { push @result, 'No tags found!';