replace xml::simple with xml::libxml

git-svn-id: http://yolanda.mister-muffin.de/svn@319 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-04-27 00:42:15 +00:00
parent bdfef043e0
commit dfd08fd2dd
8 changed files with 473 additions and 320 deletions

View file

@ -86,12 +86,5 @@ if($query->param('id'))
}
else
{
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
print output_page();
print $query->redirect("index.pl?error=error_202c");
}

View file

@ -26,17 +26,18 @@ sub get_page_array
#get parameters
my (@userinfo) = @_;
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
if (!$page->{'locale'})
{
$page->{'locale'} = "en_us";
}
my $root = XML::LibXML::Element->new( "page" );
$page->{'username'} = $userinfo->{'username'};
$page->{'xmlns:dc'} = $config->{"xml_namespace_dc"};
$page->{'xmlns:cc'} = $config->{"xml_namespace_cc"};
$page->{'xmlns:rdf'} = $config->{"xml_namespace_rdf"};
my ($locale) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
$root->setAttribute( "locale", $locale ? $locale : "en_us" );
$root->setAttribute( "username", $userinfo->{'username'} );
$root->setNamespace("http://www.w3.org/1999/xhtml", "xhtml", 0);
$root->setNamespace("http://web.resource.org/cc/", "cc", 0);
$root->setNamespace("http://purl.org/dc/elements/1.1/", "dc", 0);
$root->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
return $root;
}
# index.pl (display custom search)
@ -46,6 +47,8 @@ sub fill_results
{
my ($dbquery, @args) = @_;
my $results = XML::LibXML::Element->new( "results" );
#prepare query
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
@ -72,10 +75,10 @@ sub fill_results
#execute it
$sth->execute(@args) or die $dbquery;
$page->{'results'}->{'lastpage'} = $lastpage;
$page->{'results'}->{'currentpage'} = $currentpage;
$page->{'results'}->{'resultcount'} = $resultcount eq '0E0' ? 0 : $resultcount;
$page->{'results'}->{'pagesize'} = $pagesize;
$results->setAttribute('lastpage', $lastpage);
$results->setAttribute('currentpage', $currentpage);
$results->setAttribute('resultcount', $resultcount eq '0E0' ? 0 : $resultcount);
$results->setAttribute('pagesize', $pagesize);
#get every returned value
while (my ($id, $title, $description, $publisher, $timestamp, $creator,
@ -83,40 +86,92 @@ sub fill_results
$license, $filesize, $duration, $width, $height, $fps, $viewcount,
$downloadcount) = $sth->fetchrow_array())
{
#before code cleanup, this was a really obfuscated array/hash creation
push @{ $page->{'results'}->{'result'} },
{
'thumbnail' => $config->{"url_root"}."/video-stills/thumbnails/$id",
'preview' => $config->{"url_root"}."/video-stills/previews/$id",
'duration' => $duration,
'viewcount' => $viewcount,
'rdf:RDF' =>
{
'cc:Work' =>
{
'rdf:about' => $config->{"url_root"}."/download/$id/",
'dc:title' => [$title],
'dc:creator' => [$creator],
'dc:subject' => [$subject],
'dc:description' => [$description],
'dc:publisher' => [$publisher],
'dc:date' => [$timestamp],
'dc:identifier' => [$config->{"url_root"}."/video/".urlencode($title)."/$id/"],
'dc:source' => [$source],
'dc:language' => [$language],
'dc:coverage' => [$coverage],
'dc:rights' => [$rights]
},
'cc:License' =>
{
'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
}
}
};
my $result = XML::LibXML::Element->new( "result" );
$result->setAttribute( "thumbnail", $config->{"url_root"}."/video-stills/thumbnails/$id" );
$result->setAttribute( "preview", $config->{"url_root"}."/video-stills/previews/$id" );
$result->setAttribute( "duration", $duration );
$result->setAttribute( "viewcount", $viewcount );
my $rdf = XML::LibXML::Element->new( "RDF" );
$rdf->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
my $work = XML::LibXML::Element->new( "Work" );
$work->setNamespace( "http://web.resource.org/cc/", "cc");
$work->setNamespace( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
$work->setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about", $config->{"url_root"}."/download/$id/" );
$node = XML::LibXML::Element->new( "coverage" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($coverage);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "creator" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($creator);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "date" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($date);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "description" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($description);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "identifier" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($config->{"url_root"}."/video/".urlencode($title)."/$id/");
$work->appendChild($node);
$node = XML::LibXML::Element->new( "language" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($language);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "publisher" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($publisher);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "rights" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($rights);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "source" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($source);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "subject" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($subjcet);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "title" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($title);
$work->appendChild($node);
my $license = XML::LibXML::Element->new( "License" );
$license->setNamespace("http://web.resource.org/cc/", "cc");
$license->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
$license->setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about", "http://creativecommons.org/licenses/GPL/2.0/" );
$rdf->appendChild($work);
$rdf->appendChild($license);
$result->appendChild($rdf);
$results->appendChild($result);
}
#finish query
$sth->finish() or die $dbh->errstr;
return $results;
}
sub get_sqlquery
@ -226,6 +281,7 @@ sub urlencode
sub output_page
{
my $doc = shift;
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
@ -233,68 +289,45 @@ sub output_page
my $param_xslt = $query->param('xslt');
$param_xslt =~ s/[^\w]//gi;
# "null" is a debuggin option, make it so that this doesn't show up in the final product
if($param_xslt eq "null")
if( -f "$root/xsl/$param_xslt.xsl")
{
return $session->header(
-type=>'application/xml',
-charset=>'UTF-8',
),
XMLout(
$page,
KeyAttr => {},
RootName => 'page'
);
$xsltpath = "$root/xsl/$param_xslt.xsl"
}
else
{
if( -f "$root/xsl/$param_xslt.xsl")
{
$xsltpath = "$root/xsl/$param_xslt.xsl"
}
else
{
$xsltpath = "$root/xsl/xhtml.xsl";
}
$xsltpath = "$root/xsl/xhtml.xsl";
}
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
#TODO: preload xslt stylesheet
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
$output = $stylesheet->transform(
$parser->parse_string(
XMLout(
$page,
KeyAttr => {},
RootName => 'page'
)
)
);
$output = $stylesheet->transform($doc);
if($param_xslt eq "xspf")
{
return $session->header(
-type=>$stylesheet->media_type,
-charset=>$stylesheet->output_encoding,
-attachment=>$query->param('query').".xspf",
),
$output->toString;
#$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62)
}
elsif($param_xslt eq "pr0n")
{
return $session->header(
-status=>'402 Payment required',
-cost=>'$9001.00', # OVER NEIN THOUSAND
)
}
else
{
return $session->header(
-type=>$stylesheet->media_type,
-charset=>$stylesheet->output_encoding,
"x-pingback"=>$config->{"url_root"}."/pingback.pl"
),
$output->toString;
#$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62)
}
if($param_xslt eq "xspf")
{
return $session->header(
-type=>$stylesheet->media_type,
-charset=>$stylesheet->output_encoding,
-attachment=>$query->param('query').".xspf",
),
$output->toString;
#$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62)
}
elsif($param_xslt eq "pr0n")
{
return $session->header(
-status=>'402 Payment required',
-cost=>'$9001.00', # OVER NEIN THOUSAND
)
}
else
{
return $session->header(
-type=>$stylesheet->media_type,
-charset=>$stylesheet->output_encoding,
"x-pingback"=>$config->{"url_root"}."/pingback.pl"
),
print $output->toString;
#$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62)
}
}

View file

@ -7,29 +7,38 @@ $session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
$page->{frontpage} = [''];
my $root = get_page_array(@userinfo);
$root->appendChild(XML::LibXML::Element->new( "frontpage" ));
if($query->param('information'))
{
$page->{'message'}->{'type'} = "information";
$page->{'message'}->{'text'} = $query->param('information');
$page->{'message'}->{'value'} = $query->param('value');
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "information");
$message->setAttribute("text", $query->param('information'));
$message->setAttribute("value",$query->param('value'));
$root->appendChild($message);
}
elsif($query->param('error'))
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = $query->param('error');
$page->{'message'}->{'value'} = $query->param('value');
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", $query->param('error'));
$message->setAttribute("value",$query->param('value'));
$root->appendChild($message);
}
elsif($query->param('warning'))
{
$page->{'message'}->{'type'} = "warning";
$page->{'message'}->{'text'} = $query->param('warning');
$page->{'message'}->{'value'} = $query->param('value');
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "warning");
$message->setAttribute("text", $query->param('warning'));
$message->setAttribute("value",$query->param('value'));
$root->appendChild($message);
}
my $tagcloud = XML::LibXML::Element->new( "tagcloud" );
#prepare query
my $sth = $dbh->prepare(qq{select text, count from tagcloud }) or die $dbh->errstr;
@ -40,20 +49,25 @@ $sth->execute() or die $dbh->errstr;
#get every returned value
while (my ($text, $count) = $sth->fetchrow_array())
{
#push the new value to the $page->tagcloud array
push @{ $page->{tagcloud}->{tag} }, { text => [$text =~ / / ? "\"$text\"" : $text], count => [$count] };
my $tag = XML::LibXML::Element->new( "tag" );
$tag->appendTextChild("text", $text);
$tag->appendTextChild("count", $count);
$tagcloud->appendChild($tag);
}
#finish query
$sth->finish() or die $dbh->errstr;
$root->appendChild($tagcloud);
#TODO: make this configureable
@querystrings = ("* orderby:timestamp sort:descending", "*", "*");
foreach $strquery (@querystrings)
{
#new results block
push @{$page->{'results'} }, { "query" => $strquery };
my $results = XML::LibXML::Element->new( "results" );
$results->setAttribute( "query", $strquery );
#get query string and args
my ($dbquery, @args) = get_sqlquery($strquery);
@ -71,36 +85,90 @@ foreach $strquery (@querystrings)
$license, $filesize, $duration, $width, $height, $fps, $viewcount,
$downloadcount) = $sth->fetchrow_array())
{
push @{$page->{'results'}[$#{$page->{'results'} }]->{'result'}},
{
'thumbnail' => $config->{"url_root"}."/video-stills/thumbnails/$id",
'preview' => $config->{"url_root"}."/video-stills/previews/$id",
'duration' => $duration,
'viewcount' => $viewcount,
'rdf:RDF' =>
{
'cc:Work' =>
{
'rdf:about' => $config->{"url_root"}."/download/$id/",
'dc:title' => [$title],
'dc:creator' => [$creator],
'dc:subject' => [$subject],
'dc:description' => [$description],
'dc:publisher' => [$publisher],
'dc:date' => [$timestamp],
'dc:identifier' => [$config->{"url_root"}."/video/".urlencode($title)."/$id/"],
'dc:source' => [$source],
'dc:language' => [$language],
'dc:coverage' => [$coverage],
'dc:rights' => [$rights]
},
'cc:License' =>
{
'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
}
}
};
my $result = XML::LibXML::Element->new( "result" );
$result->setAttribute( "thumbnail", $config->{"url_root"}."/video-stills/thumbnails/$id" );
$result->setAttribute( "preview", $config->{"url_root"}."/video-stills/previews/$id" );
$result->setAttribute( "duration", $duration );
$result->setAttribute( "viewcount", $viewcount );
my $rdf = XML::LibXML::Element->new( "RDF" );
$rdf->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
my $work = XML::LibXML::Element->new( "Work" );
$work->setNamespace( "http://web.resource.org/cc/", "cc");
$work->setNamespace( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
$work->setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about", $config->{"url_root"}."/download/$id/" );
$node = XML::LibXML::Element->new( "coverage" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($coverage);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "creator" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($creator);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "date" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($date);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "description" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($description);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "identifier" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($config->{"url_root"}."/video/".urlencode($title)."/$id/");
$work->appendChild($node);
$node = XML::LibXML::Element->new( "language" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($language);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "publisher" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($publisher);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "rights" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($rights);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "source" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($source);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "subject" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($subjcet);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "title" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($title);
$work->appendChild($node);
my $license = XML::LibXML::Element->new( "License" );
$license->setNamespace("http://web.resource.org/cc/", "cc");
$license->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
$license->setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about", "http://creativecommons.org/licenses/GPL/2.0/" );
$rdf->appendChild($work);
$rdf->appendChild($license);
$result->appendChild($rdf);
$results->appendChild($result);
}
$root->appendChild($results);
}
print output_page();
$doc->setDocumentElement($root);
output_page($doc);

View file

@ -7,7 +7,9 @@ $session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
if($query->param('action') eq "logout")
{
@ -20,10 +22,7 @@ if($query->param('action') eq "logout")
#check if user is logged in
elsif($userinfo->{'username'})
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_already_logged_in";
print output_page();
print $query->redirect("/index.pl?error=error_already_logged_in");
}
#if password is empty and username begins with http:// then it's an openid login
elsif($query->param('pass') eq '' and $query->param('user')=~m/^http:\/\//)
@ -36,32 +35,21 @@ elsif($query->param('pass') eq '' and $query->param('user')=~m/^http:\/\//)
consumer_secret => $session->id, #is this save? don't know...
required_root => $config->{"url_root"} );
#is an openid passed?
if($query->param('user'))
#claim identity
$claimed = $con->claimed_identity($query->param('user'));
if(!defined($claimed))
{
#claim identity
$claimed = $con->claimed_identity($query->param('user'));
if(!defined($claimed))
{
print $query->redirect("/index.pl?error=error_openid_".$con->errcode);
}
else
{
#try to set the check_url
$check_url = $claimed->check_url(
return_to => $config->{"url_root"}."login.pl?action=openid", #on success return to this address
trust_root => $config->{"url_root"}); #this is the string the user will be asked to trust
#redirect to openid server to check claim
print $query->redirect($check_url);
}
print $query->redirect("/index.pl?error=error_openid_".$con->errcode);
}
else
{
#if not, print login form
$page->{'loginform'} = [''];
#try to set the check_url
$check_url = $claimed->check_url(
return_to => $config->{"url_root"}."login.pl?action=openid", #on success return to this address
trust_root => $config->{"url_root"}); #this is the string the user will be asked to trust
print output_page();
#redirect to openid server to check claim
print $query->redirect($check_url);
}
}
#we return from an identity check
@ -132,17 +120,10 @@ elsif($query->param('pass') ne '' and $query->param('user')!~m/^http:\/\// and $
}
else
{
#if not, print error
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_username_password_do_not_match";
print output_page();
print $query->redirect("index.pl?error=error_username_password_do_not_match");
}
}
else
{
#if not, print login form
$page->{'loginform'} = [''];
print output_page();
print $query->redirect("index.pl");
}

View file

@ -7,15 +7,21 @@ $session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
#check if user is logged in
if($username)
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_already_registered";
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_already_registered");
$root->appendChild($message);
print output_page();
$doc->setDocumentElement($root);
output_page($doc);
}
#if username and password are passed put them into the database
elsif($query->param('user') and $query->param('pass') and $query->param('pass_repeat'))
@ -30,11 +36,16 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re
#if something was returned the selected username already exists
if($sth->fetchrow_array())
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_username_already_registered";
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
print output_page();
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_username_already_registered");
$root->appendChild($message);
$doc->setDocumentElement($root);
output_page($doc);
}
else
{
@ -47,40 +58,62 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re
}
else
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_passwords_do_not_match";
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
print output_page();
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_passwords_do_not_match");
$root->appendChild($message);
$doc->setDocumentElement($root);
output_page($doc);
}
}
elsif(not $query->param('user') and ($query->param('pass') or $query->param('pass_repeat')))
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_insert_username";
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
print output_page();
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_insert_username");
$root->appendChild($message);
$doc->setDocumentElement($root);
output_page($doc);
}
elsif(not $query->param('pass') and ($query->param('user') or $query->param('pass_repeat')))
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_insert_password";
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
print output_page();
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_insert_password");
$root->appendChild($message);
$doc->setDocumentElement($root);
output_page($doc);
}
elsif(not $query->param('pass_repeat') and ($query->param('user') or $query->param('pass')))
{
$page->{'registerform'} = [''];
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_repeat_password";
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
print output_page();
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_repeat_password");
$root->appendChild($message);
$doc->setDocumentElement($root);
output_page($doc);
}
else
{
$page->{'registerform'} = [''];
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
print output_page();
$doc->setDocumentElement($root);
output_page($doc);
}

View file

@ -7,30 +7,35 @@ $session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
#check if query is set
if($query->param('query'))
{
$page->{'results'}->{'query'} = $query->param('query');
my ($dbquery, @args) = get_sqlquery($query->param('query'));
if($dbquery)
{
fill_results($dbquery, @args);
$root->appendChild(fill_results($dbquery, @args));
$root->setAttribute('query', $query->param('query'));
if(@{$page->{'results'}->{'result'}} == 0)
$doc->setDocumentElement($root);
my @results = $doc->findnodes( "//results/result" );
if($#results == -1)
{
print $query->redirect("index.pl?warning=warning_no_results");
}
elsif((@{$page->{'results'}->{'result'}} == 1) and (not $query->param('page') or $query->param('page') == 1))
elsif(($#results == 0) and (not $query->param('page') or $query->param('page') == 1))
{
print $query->redirect($page->{'results'}->{'result'}[0]->{'rdf:RDF'}->{'cc:Work'}->{'dc:identifier'}[0]);
print $query->redirect(@{$doc->findnodes( "//results/result/rdf:RDF/cc:Work/dc:identifier/text()" )}[0]->data);
}
else
{
print output_page();
output_page($doc);
}
}
else

View file

@ -5,7 +5,11 @@ CGI::Session->name($config->{"page_cookie_name"});
$query = new CGI;
$session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
my @userinfo = get_userinfo_from_sid($session->id);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
if($userinfo->{'username'})
{
@ -13,23 +17,32 @@ if($userinfo->{'username'})
{
$dbh->do(qq{update users set pagesize = ? where id = ?}, undef, $query->param('pagesize'), $userinfo->{'id'} ) or die $dbh->errstr;
$page->{'message'}->{'type'} = "information";
$page->{'message'}->{'text'} = "information_settings_changed";
@userinfo = get_userinfo_from_sid($session->id);
$root = get_page_array(@userinfo);
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "information");
$message->setAttribute("text", "information_settings_changed");
$root->appendChild($message);
}
}
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
if($userinfo->{'username'})
{
$page->{'settings'}->{'pagesize'} = $userinfo->{'pagesize'};
my $settings = XML::LibXML::Element->new( "settings" );
$settings->setAttribute("pagesize", $userinfo->{'pagesize'});
$root->appendChild($settings);
}
else
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_202c");
$root->appendChild($message);
}
print output_page();
$doc->setDocumentElement($root);
output_page($doc);

View file

@ -7,7 +7,9 @@ $session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
@page = get_page_array(@userinfo);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
#check if id or title is passed
if($query->url_param('id'))
@ -52,11 +54,11 @@ if($query->url_param('id'))
{
if($query->param('embed') eq "video")
{
$page->{'embed'} = "video";
$root->setAttribute( "embed", "video" );
}
elsif($query->param('embed') eq "preview")
{
$page->{'embed'} = "preview";
$root->setAttribute( "embed", "preview" );
}
#if there was a single result, display the video
@ -74,8 +76,10 @@ if($query->url_param('id'))
if($query->param('comment'))
{
#output infobox
$page->{'message'}->{'type'} = "information";
$page->{'message'}->{'text'} = "information_comment_created";
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "information");
$message->setAttribute("text", "information_comment_created");
$root->appendChild($message);
#add to database
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef,
@ -148,94 +152,117 @@ if($query->url_param('id'))
}
}
#before code cleanup, this was a really obfuscated array/hash creation
push @{ $page->{'video'} },
{
'thumbnail' => $config->{"url_root"}."/video-stills/thumbnails/$id",
'preview' => $config->{"url_root"}."/video-stills/previews/$id",
'filesize' => $filesize,
'duration' => $duration,
'width' => $width,
'height' => $height,
'fps' => $fps,
'viewcount' => $viewcount,
'downloadcount' => $downloadcount,
'rdf:RDF' =>
{
'cc:Work' =>
{
'rdf:about' => $config->{"url_root"}."/download/$id/",
'dc:title' => [$title],
'dc:creator' => [$creator],
'dc:subject' => [$subject],
'dc:description' => [$description],
'dc:publisher' => [$publisher],
'dc:date' => [$timestamp],
'dc:identifier' => [$config->{"url_root"}."/video/".urlencode($title)."/$id/"],
'dc:source' => [$source],
'dc:language' => [$language],
'dc:coverage' => [$coverage],
'dc:rights' => [$rights]
},
'cc:License' =>
{
'rdf:about' => $license,
# ↓↓ dummy code because josch is too lazy for DOIN IT RITE ↓↓
'cc:permits' =>
{
'rdf:resource' => "http://web.resource.org/cc/Reproduction"
},
'cc:permits' =>
{
'rdf:resource' => "http://web.resource.org/cc/Distribution"
},
'cc:permits' =>
{
'rdf:resource' => "http://web.resource.org/cc/DerivativeWorks"
},
'cc:requires' =>
{
'rdf:resource' => "http://web.resource.org/cc/Notice"
},
'cc:requires' =>
{
'rdf:resource' => "http://web.resource.org/cc/ShareAlike"
},
'cc:prohibits' =>
{
'rdf:resource' => "http://web.resource.org/cc/CommercialUse"
},
'cc:prohibits' =>
{
'rdf:resource' => "http://web.resource.org/cc/DerivativeWorks"
}
# ↑↑ dummy code because josch is too lazy for DOIN IT RITE ↑↑
# sadly, i dunno how to add multiple tags with the same name
}
}
};
my $video = XML::LibXML::Element->new( "video" );
$video->setAttribute('thumbnail', $config->{"url_root"}."/video-stills/thumbnails/$id");
$video->setAttribute('preview', $config->{"url_root"}."/video-stills/previews/$id");
$video->setAttribute('filesize', $filesize);
$video->setAttribute('duration', $duration);
$video->setAttribute('width', $width);
$video->setAttribute('height', $height);
$video->setAttribute('fps', $fps);
$video->setAttribute('viewcount', $viewcount);
$video->setAttribute('downloadcount', $downloadcount);
my $rdf = XML::LibXML::Element->new( "RDF" );
$rdf->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
my $work = XML::LibXML::Element->new( "Work" );
$work->setNamespace( "http://web.resource.org/cc/", "cc");
$work->setNamespace( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
$work->setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about", $config->{"url_root"}."/download/$id/" );
$node = XML::LibXML::Element->new( "coverage" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($coverage);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "creator" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($creator);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "date" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($date);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "description" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($description);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "identifier" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($config->{"url_root"}."/video/".urlencode($title)."/$id/");
$work->appendChild($node);
$node = XML::LibXML::Element->new( "language" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($language);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "publisher" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($publisher);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "rights" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($rights);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "source" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($source);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "subject" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($subjcet);
$work->appendChild($node);
$node = XML::LibXML::Element->new( "title" );
$node->setNamespace( "http://purl.org/dc/elements/1.1/", "dc" );
$node->appendText($title);
$work->appendChild($node);
my $license = XML::LibXML::Element->new( "License" );
$license->setNamespace("http://web.resource.org/cc/", "cc");
$license->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
$license->setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about", "http://creativecommons.org/licenses/GPL/2.0/" );
$rdf->appendChild($work);
$rdf->appendChild($license);
$video->appendChild($rdf);
$root->appendChild($video);
#get comments
my $comments = XML::LibXML::Element->new( "comments" );
$sth = $dbh->prepare(qq{select comments.id, comments.text, users.username, from_unixtime( comments.timestamp )
from comments, users where
comments.videoid=? and users.id=comments.userid}) or die $dbh->errstr;
$sth->execute($id) or die $dbh->errstr;
while (my ($commentid, $text, $username, $timestamp) = $sth->fetchrow_array())
{
push @{ $page->{'comments'}->{'comment'} }, {
'text' => [$text],
'username' => $username,
'timestamp' => $timestamp,
'id' => $commentid
};
my $comment = XML::LibXML::Element->new( "comment" );
$comment->setAttribute('username', $username);
$comment->setAttribute('timestamp', $timestamp);
$comment->setAttribute('id', $commentid);
$comment->appendTextChild("text", $text);
$comments->appendChild($comment);
}
print output_page();
$root->appendChild($comments);
$doc->setDocumentElement($root);
output_page($doc);
}
}
else
{
$page->{'message'}->{'type'} = "error";
$page->{'message'}->{'text'} = "error_202c";
print output_page();
print $query->redirect("index.pl?error=error_202c");
}