added sort: and orderby: to our query language, replaced sucky mime type for download, removed check for upload failure every pageload, global default and max-pagesize, added xspf download filename, added pagesize to rss query, redirect to frontpage after empty query, output value for messageboxes on index page, redirect to main page when zero results or when no query was given

git-svn-id: http://yolanda.mister-muffin.de/svn@218 7eef14d0-6ed0-489d-bf55-20463b2d70db
main
josch 17 years ago
parent 751ed83d13
commit 1c7d1d82aa

@ -50,7 +50,7 @@ if($query->param('id'))
#video is being downloaded - update downloadcount
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
print $query->header(-type=>'application/x-download',
print $query->header(-type=>'application/ogg',
-attachment=>$title.".ogv");
}

@ -30,22 +30,6 @@ sub get_page_array
if($userinfo->{'username'})
{
$page->{'locale'} = $userinfo->{'locale'};
#prepare query
my $sth = $dbh->prepare(qq{select id, title, status from uploaded where userid = ? and status != 0}) or die $dbh->errstr;
#execute it
$sth->execute($userinfo->{'id'}) or die $dbh->errstr;
while(my ($id, $title, $status) = $sth->fetchrow_array())
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
#TODO: delete from uploaded where id = $id
}
#finish query
$sth->finish() or die $dbh->errstr;
}
#else get the locale from the http server variable
else
@ -71,7 +55,11 @@ sub fill_results
#execute it
$resultcount = $sth->execute(@_) or die $dbh->errstr;
$pagesize = $query->param('pagesize') or $pagesize = $userinfo->{'pagesize'} or $pagesize = 5;
#set pagesize by query or usersettings or default
$pagesize = $query->param('pagesize') or $pagesize = $userinfo->{'pagesize'} or $pagesize = $defaultpagesize;
#if pagesize is more than maxpagesize reduce to maxpagesize
$pagesize = $pagesize > $maxpagesize ? $maxpagesize : $pagesize;
#rediculous but funny round up, will fail with 100000000000000 results per page
#on 0.0000000000001% of all queries - this is a risk we can handle
@ -160,7 +148,7 @@ sub output_page
#let the xslt param choose other stylesheets or default to xhtml.xsl
my $param_xslt = $query->param('xslt');
$param_xslt =~ s/[^a-z]//gi;
$param_xslt =~ s/[^\w]//gi;
if( -f "$root/xsl/$param_xslt.xsl")
{
@ -187,6 +175,7 @@ sub output_page
)
);
#send everything including http headers to the user - if xslt chosen is xspf set download filename
return $session->header(
-type=>'text/xml',
-charset=>'UTF-8'

@ -25,5 +25,7 @@ $stylesheet = "/style/default.css";
$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#";
$defaultpagesize = 20;
$maxpagesize = 500;
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
1;

@ -13,15 +13,21 @@ $page->{frontpage} = [''];
if($query->param('information'))
{
$page->{'message'}->{'type'} = "information";
$page->{'message'}->{'text'} = $query->param('information');
$page->{'message'}->{'value'} = $query->param('value');
}
elsif($query->param('error'))
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = $query->param('error');
$page->{'message'}->{'value'} = $query->param('value');
}
elsif($query->param('warning'))
{
$page->{'message'}->{'type'} = "warning";
$page->{'message'}->{'text'} = $query->param('warning');
$page->{'message'}->{'value'} = $query->param('value');
}

@ -64,9 +64,10 @@
<string id="information_comment_created">Your comment has been submitted.</string>
<string id="information_registered">Your account has been created.</string>
<string id="information_uploaded">Your file has been uploaded.</string>
<string id="information_no_results">There are no results satisfying your query.</string>
<!-- warnings -->
<string id="warning_no_results">There are no results satisfying your query.</string>
<string id="warning_no_query">You passed no query string.</string>
<!-- results page-->
<string id="results_heading_1">results</string>
@ -122,7 +123,7 @@
<string id="instruction_file">Specify the file you want to upload.</string>
<string id="instruction_title">State the title of the video.</string>
<string id="instruction_creator">Specify the creator of the video.</string>
<string id="instruction_subject">State some keywords, separated by commas.</string>
<string id="instruction_subject">State some keywords, separated by spaces.</string>
<string id="instruction_description">Describe the video in natural language.</string>
<string id="instruction_source">Specify the source, preferably by URL.</string>
<string id="instruction_language">State the language of the video.</string>

@ -10,10 +10,8 @@ $session = new CGI::Session;
@page = get_page_array(@userinfo);
#check if query is set
if($query->param('query') or $query->param('orderby'))
if($query->param('query'))
{
#TODO: clean up scriptname, argument, value only being there because of
#TODO: account.pl also calling fill_results() which will be changed
$page->{'search'} = [''];
$page->{'results'}->{'query'} = $query->param('query');
@ -22,7 +20,9 @@ if($query->param('query') or $query->param('orderby'))
$strquery = $query->param('query');
(@tags) = $strquery =~ /tag:(\w+)/gi;
($username) = $strquery =~ /user:(\w+)/i;
$strquery =~ s/(tag|title|user):\w+//gi;
($orderby) = $strquery =~ /orderby:(\w+)/i;
($sort) = $strquery =~ /sort:(\w+)/i;
$strquery =~ s/(tag|user|orderby|sort):\w+//gi;
$strquery =~ s/^\s*(.*?)\s*$/$1/;
#build mysql query
@ -55,29 +55,29 @@ if($query->param('query') or $query->param('orderby'))
push @args, "$username";
}
if($query->param('orderby'))
if($orderby)
{
if($query->param('orderby') eq 'filesize')
if($orderby eq 'filesize')
{
$dbquery .= " order by v.filesize";
}
elsif($query->param('orderby') eq 'duration')
elsif($orderby eq 'duration')
{
$dbquery .= " order by v.duration";
}
elsif($query->param('orderby') eq 'viewcount')
elsif($orderby eq 'viewcount')
{
$dbquery .= " order by v.viewcount";
}
elsif($query->param('orderby') eq 'downloadcount')
elsif($orderby eq 'downloadcount')
{
$dbquery .= " order by v.downloadcount";
}
elsif($query->param('orderby') eq 'timestamp')
elsif($orderby eq 'timestamp')
{
$dbquery .= " order by v.timestamp";
}
elsif($query->param('orderby') eq 'relevance' and $query->param('query'))
elsif($orderby eq 'relevance' and $strquery)
{
$dbquery .= " order by relevance";
}
@ -86,22 +86,28 @@ if($query->param('query') or $query->param('orderby'))
$dbquery .= " order by v.id";
}
if($query->param('sort') eq "asc")
if($sort eq "ascending")
{
$dbquery .= " asc"
$dbquery .= " asc";
}
else
elsif($sort eq "descending")
{
$dbquery .= " desc"
$dbquery .= " desc";
}
}
fill_results(@args);
if(@{$page->{'results'}->{'result'}} == 0)
{
print $query->redirect("index.pl?warning=warning_no_results");
}
else
{
print output_page();
}
}
else
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
print $query->redirect("index.pl?warning=warning_no_query");
}
print output_page();

@ -17,13 +17,13 @@
<string id="page_source-code">http://yolanda.mister-muffin.de/trac/browser/trunk</string>
<string id="page_register">/register.pl</string>
<string id="page_report_bug">http://yolanda.mister-muffin.de/trac/newticket</string>
<string id="page_results">search.pl?query=</string>
<string id="page_results">/search.pl?query=</string>
<string id="page_root">http://localhost/</string>
<string id="page_upload">/upload.pl</string>
<string id="page_uploader">uploader.pl</string>
<string id="page_query_latestadditions">search.pl?query=&amp;orderby=timestamp&amp;sort=desc</string>
<string id="page_query_mostdownloads">search.pl?query=&amp;orderby=downloadcount&amp;sort=desc</string>
<string id="page_query_mostviews">search.pl?query=&amp;orderby=viewcount&amp;sort=desc</string>
<string id="page_uploader">/uploader.pl</string>
<string id="page_query_latestadditions">/search.pl?query=orderby:timestamp%20sort:descending</string>
<string id="page_query_mostdownloads">/search.pl?query=orderby:downloadcount%20sort:descending</string>
<string id="page_query_mostviews">/search.pl?query=orderby:viewcount%20sort:descending</string>
</strings>

@ -79,12 +79,15 @@
<link rel="alternate" type="application/rss+xml">
<xsl:attribute name="title">
<xsl:value-of select="//results/@value" />
<xsl:value-of select="//results/@query" />
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="$site_strings[@id='page_root']" />
<xsl:value-of select="$site_strings[@id='page_results']" />
<xsl:value-of select="//results/@query" />&#38;xslt=rss
<xsl:value-of select="//results/@query" />
&amp;pagesize=<xsl:value-of select="//results/@pagesize" />
&amp;page=<xsl:value-of select="//results/@page" />
&#38;xslt=rss
</xsl:attribute>
</link>

Loading…
Cancel
Save