added account.pl with video list capabilities, inserted edit button for own videos in result list

git-svn-id: http://yolanda.mister-muffin.de/svn@145 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2007-10-27 11:59:23 +00:00
parent 72a781f1fc
commit 30c136a1d8
5 changed files with 211 additions and 27 deletions

154
trunk/account.pl Normal file
View file

@ -0,0 +1,154 @@
#!/usr/bin/perl
require "include.pl";
require "functions.pl";
#initialize session data
CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
$username = get_username_from_sid($session->id);
%page = ();
$page->{'username'} = $username;
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
if($username)
{
if($query->param('show') eq 'settings')
{
#results per page
#language
#cortado or plugin
}
elsif($query->param('show') eq 'uploads')
{
$page->{'results'}->{'scriptname'} = 'account.pl';
$page->{'results'}->{'argument'} = 'show';
$page->{'results'}->{'value'} = 'uploads';
$page->{'results'}->{'orderby'} = $query->param('orderby');
$page->{'results'}->{'sort'} = $query->param('sort');
#connect to db
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
#build mysql query
$dbquery = "(select v.id, v.title, u.username, from_unixtime( v.timestamp ) as timestamp, v.duration, v.viewcount
from videos as v, users as u where v.userid = u.id and u.sid = ?)
union
(select v.id, v.title, u.username, from_unixtime( v.timestamp ) as timestamp, 0, 0
from uploaded as v, users as u where v.userid = u.id and u.sid = ?)";
if($query->param('orderby'))
{
if($query->param('orderby') eq 'filesize')
{
$dbquery .= " order by filesize";
}
elsif($query->param('orderby') eq 'duration')
{
$dbquery .= " order by duration";
}
elsif($query->param('orderby') eq 'viewcount')
{
$dbquery .= " order by viewcount";
}
elsif($query->param('orderby') eq 'timestamp')
{
$dbquery .= " order by timestamp";
}
else
{
$dbquery .= " order by id";
}
if($query->param('sort') eq "asc")
{
$dbquery .= " asc"
}
else
{
$dbquery .= " desc"
}
}
#prepare query
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
#execute it
$resultcount = $sth->execute($session->id, $session->id) or die $dbh->errstr;
$rowsperpage = 2;
#rediculous but funny round up, will fail with 1000000000000000 results per page
#on 0.00000000000001% of all queries - this is a risk we can handle
$lastpage = int($resultcount/$rowsperpage+0.999999999999999);
$currentpage = $query->param('page') or $currentpage = 1;
$dbquery .= " limit ".($currentpage-1)*$rowsperpage.", ".$rowsperpage;
#prepare query
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
#execute it
$sth->execute($session->id, $session->id) or die $dbquery;
$page->{'results'}->{'lastpage'} = $lastpage;
$page->{'results'}->{'currentpage'} = $currentpage;
$page->{'results'}->{'resultcount'} = $resultcount;
#get every returned value
while (my ($id, $title, $publisher, $timestamp, $duration, $viewcount) = $sth->fetchrow_array())
{
#before code cleanup, this was a really obfuscated array/hash creation
push @{ $page->{'results'}->{'result'} },
{
'thumbnail' => $duration == 0 ? "/images/tango/video-x-generic.png" : "/video-stills/$id",
'duration' => $duration,
'viewcount' => $viewcount,
'edit' => $username eq $publisher ? "true" : "false",
'rdf:RDF' =>
{
'cc:Work' =>
{
'dc:title' => [$title],
'dc:date' => [$timestamp],
'dc:identifier' => ["$domain/video/$title/$id" . ($duration == 0 ? "/edit=true" : "") ],
'dc:publisher' => [$publisher]
},
'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;
}
else
{
$page->{'account'} = [''];
}
}
else
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
}
#print xml http header along with session cookie
print $session->header(-type=>'text/xml', -charset=>'UTF-8');
#print xml
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page', AttrIndent => '1');

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -6,10 +6,11 @@ CGI::Session->name($session_name);
$query = new CGI;
$session = new CGI::Session;
$username = get_username_from_sid($session->id);
%page = ();
#if a username is associated with session id, username is nonempty
$page->{'username'} = get_username_from_sid($session->id);
$page->{'username'} = $username;
$page->{'locale'} = $locale;
$page->{'stylesheet'} = $stylesheet;
$page->{'xmlns:dc'} = $xmlns_dc;
@ -19,9 +20,11 @@ $page->{'xmlns:rdf'} = $xmlns_rdf;
#check if query is set
if($query->param('query') or $query->param('orderby'))
{
$page->{results}->{query} = $query->param('query');
$page->{results}->{orderby} = $query->param('orderby');
$page->{results}->{sort} = $query->param('sort');
$page->{'results'}->{'scriptname'} = 'search.pl';
$page->{'results'}->{'argument'} = 'query';
$page->{'results'}->{'value'} = $query->param('query');
$page->{'results'}->{'orderby'} = $query->param('orderby');
$page->{'results'}->{'sort'} = $query->param('sort');
#connect to db
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
@ -88,7 +91,7 @@ if($query->param('query') or $query->param('orderby'))
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
#execute it
$resultcount = $sth->execute(@args) or die $dbquery;
$resultcount = $sth->execute(@args) or die $dbh->errstr;
$rowsperpage = 2;
@ -111,7 +114,7 @@ if($query->param('query') or $query->param('orderby'))
$page->{'results'}->{'resultcount'} = $resultcount;
#get every returned value
while (my ($id, $title, $creator, $description, $username, $timestamp, $duration, $viewcount, $relevance) = $sth->fetchrow_array())
while (my ($id, $title, $creator, $description, $publisher, $timestamp, $duration, $viewcount, $relevance) = $sth->fetchrow_array())
{
#before code cleanup, this was a really obfuscated array/hash creation
push @{ $page->{'results'}->{'result'} },
@ -119,6 +122,7 @@ if($query->param('query') or $query->param('orderby'))
'thumbnail' => "./video-stills/$id",
'duration' => $duration,
'viewcount' => $viewcount,
'edit' => $username eq $publisher ? "true" : "false",
'rdf:RDF' =>
{
'cc:Work' =>
@ -128,7 +132,7 @@ if($query->param('query') or $query->param('orderby'))
'dc:creator' => [$creator],
'dc:date' => [$timestamp],
'dc:identifier' => ["$domain/video/$title/$id"],
'dc:publisher' => [$username]
'dc:publisher' => [$publisher]
},
'cc:License' =>
{

View file

@ -16,8 +16,12 @@ $page->{'xmlns:dc'} = $xmlns_dc;
$page->{'xmlns:cc'} = $xmlns_cc;
$page->{'xmlns:rdf'} = $xmlns_rdf;
if($query->url_param('edit') eq 'true' and $query->url_param('id'))
{
$page->{'message'}->{'type'} = "information";
}
#check if id or title is passed
if($query->url_param('title') or $query->url_param('id'))
elsif($query->url_param('title') or $query->url_param('id'))
{
#connect to db
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;

View file

@ -290,13 +290,13 @@
<xsl:otherwise>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=1')" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=1')" />
</xsl:attribute>
&lt;&lt;
</a>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage - 1)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage - 1)" />
</xsl:attribute>
&lt;
</a>
@ -305,7 +305,7 @@
<xsl:if test="@currentpage > 2">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage - 2)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage - 2)" />
</xsl:attribute>
<xsl:value-of select="@currentpage - 2" />
</a>
@ -313,7 +313,7 @@
<xsl:if test="@currentpage > 1">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage - 1)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage - 1)" />
</xsl:attribute>
<xsl:value-of select="@currentpage - 1" />
</a>
@ -323,7 +323,7 @@
<xsl:if test="$temp > 0">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage + 1)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage + 1)" />
</xsl:attribute>
<xsl:value-of select="@currentpage + 1" />
</a>
@ -331,7 +331,7 @@
<xsl:if test="$temp > 1">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage + 2)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage + 2)" />
</xsl:attribute>
<xsl:value-of select="@currentpage + 2" />
</a>
@ -343,13 +343,13 @@
<xsl:otherwise>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage + 1)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @currentpage + 1)" />
</xsl:attribute>
&gt;
</a>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($site_strings[@id='page_results'], @query, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @lastpage)" />
<xsl:value-of select="concat(@scriptname, '?', @argument, '=', @value, '&amp;orderby=', @orderby, '&amp;sort=', @sort, '&amp;page=', @lastpage)" />
</xsl:attribute>
&gt;&gt;
</a>
@ -484,7 +484,8 @@
<xsl:value-of select="rdf:RDF/cc:Work/dc:identifier" />
</xsl:attribute>
<xsl:value-of select="rdf:RDF/cc:Work/dc:title" />
</a></h2>
</a>
</h2>
<table class="videometadata">
<tr>
<td class="leftcell">
@ -506,6 +507,21 @@
</td>
</tr>
</table>
<xsl:if test="@edit='true'">
<a>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="@duration=0">
<xsl:value-of select="rdf:RDF/cc:Work/dc:identifier" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(rdf:RDF/cc:Work/dc:identifier, '/edit=true')" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<img src="/images/tango/accessories-text-editor.png" style="border:0;vertical-align:bottom;" />edit
</a>
</xsl:if>
</td>
</tr>
</xsl:for-each>
@ -514,11 +530,17 @@
<xsl:call-template name="pagination"/>
<div>
<form method="get" action="search.pl">
<form method="get">
<xsl:attribute name="action">
<xsl:value-of select="@scriptname" />
</xsl:attribute>
<fieldset>
<input type="hidden" name="query">
<input type="hidden">
<xsl:attribute name="name">
<xsl:value-of select="@argument" />
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="@query" />
<xsl:value-of select="@value" />
</xsl:attribute>
</input>
order by: