implemented basic searching

git-svn-id: http://yolanda.mister-muffin.de/svn@23 7eef14d0-6ed0-489d-bf55-20463b2d70db
main
josch 17 years ago
parent ffdea24ee5
commit 253d28ffea

@ -9,5 +9,5 @@ eg.: insert into tagcloud values ('web tv', 68);
create table users (id int auto_increment not null, username varchar(255) not null, password char(41) not null, primary key (id));
create table videos (id int auto_increment not null, title varchar(255) not null, userid varchar(255) not null, hash char(64) not null, status int not null, primary key (id));
create table videos (id int auto_increment not null, title varchar(255) not null, caption text, userid varchar(255) not null, hash char(64) not null, status int not null, primary key (id), fulltext (title, caption));

@ -2,7 +2,8 @@ use CGI qw(:standard);
use CGI::Session;
use DBI;
use XML::Simple qw(:strict);
use Digest::SHA qw(sha256_hex);
use Digest::SHA;
#use Digest::SHA qw(sha256_hex);
#set global variables
$database = 'gnutube';

@ -0,0 +1,57 @@
require "/var/www/perl/include.pl";
require "/var/www/perl/functions.pl";
#initialize session data
CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
#check if query is set
if($query->param('query')) {
my $search_query = $query->param('query');
$page = XMLin('/var/www/perl/search.xml', ForceArray => 1, KeyAttr => {} );
#if a username is associated with session id, username is nonempty
$page->{username} = get_username_from_sid($session->id);
$page->{results}->{query} = $query->param('query');
#connect to db
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
#prepare query
my $sth = $dbh->prepare(qq{select title, caption from videos where match(title, caption) against('$search_query') }) or die $dbh->errstr;
#execute it
$sth->execute() or die $dbh->errstr;
#get every returned value
while (my ($title, $caption) = $sth->fetchrow_array())
{
#really ofuscated array/hash creation
push @{ $page->{'results'}->{'result'} }, { 'thumbnail' => ['./video-stills/225x150/4chan_city_mashup.png'],
'rdf:RDF' => { 'cc:Work' => { 'rdf:about' => './videos/1050x700/4chan_city_mashup.ogg',
'dc:title' => [$title]
},
'cc:License' => { 'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
}
}
};
}
#finish query
$sth->finish() or die $dbh->errstr;
#close db
$dbh->disconnect() or die $dbh->errstr;
#print xml http header along with session cookie
print $session->header(-type=>'text/xml');
#print xml
print XMLout($page, KeyAttr => {}, XMLDecl => '<?xml version="1.0" encoding="ISO-8859-1" ?><?xml-stylesheet type="text/xsl" href="./xsl/xhtml.xsl" ?>', RootName => 'page');
} else {
print $session->header();
print "no query passed";
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="./xsl/xhtml.xsl" ?>
<page
locale="en-US"
stylesheet="./style/gnutube.css"
username="pedobear@myopenid.net"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<searchbar />
</page>

@ -23,14 +23,16 @@ if($userid) {
#save POST data in local variables
my $title = $query->param("title");
my $caption = $query->param("caption");
#video status:
# 0 - fresh upload - needs conversion
# 1 - successfully converted
# 2 - error: was not a valid video/format
# 3 - error: video is a duplicate
# 0 - new entry - nothing done yet
# 1 - successfully uploaded
# 2 - successfully converted
# 3 - error: was not a valid video/format
# 4 - error: video is a duplicate
#do query
$dbh->do(qq{insert into videos (title, userid, status) values ('$title', '$userid', 0)}) or die $dbh->errstr;
$dbh->do(qq{insert into videos (title, caption, userid, status) values ('$title', '$caption', '$userid', 0)}) or die $dbh->errstr;
#prepare query
my $sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;

@ -20,7 +20,7 @@
<xsl:variable name="site_strings" select="document('../site/gnutube.xml')//strings" />
<xsl:variable name="locale_strings" select="document(concat('../locale/',/page/@locale,'.xml'))//strings" />
<xsl:variable name="resultspage">results.pl?query=</xsl:variable>
<xsl:variable name="resultspage">search.pl?query=</xsl:variable>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">

Loading…
Cancel
Save