require "functions.pl"; #initialize session data CGI::Session->name($config->{"page_cookie_name"}); $query = new CGI; $session = new CGI::Session; @userinfo = get_userinfo_from_sid($session->id); @page = get_page_array(@userinfo); #check if id or title is passed if($query->url_param('id')) { $dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ), v.creator, v.subject, v.source, v.language, v.coverage, v.rights, v.license, filesize, duration, width, height, fps, viewcount, downloadcount from videos as v, users as u where v.id = ? and u.id=v.userid"; @args = ($query->url_param('id')); $sth = $dbh->prepare($dbquery); $rowcount = $sth->execute(@args) or die $dbh->errstr; #if there are still no results if($rowcount == 0) { #check if maybe the video has not yet been converted $dbquery = "select id from uploaded where id = ?"; $sth = $dbh->prepare($dbquery); $rowcount = $sth->execute($query->url_param('id')) or die $dbh->errstr; #if id is found if($rowcount == 1) { $sth = $dbh->prepare("select sum(duration) from uploaded where id < ?"); $sth->execute($query->url_param('id')) or die $dbh->errstr; ($length) = $sth->fetchrow_array(); $h = int($length/3600); $m = int($length/60-$h*60); $s = int($length-$m*60-$h*3600); print $query->redirect("/index.pl?information=information_video_not_yet_available&value=".$h."h ".$m."m ".$s."s"); } else { # there is nothing we can do now - this video doesn't exist... print $query->redirect("/index.pl?error=error_no_video"); # this is a typical 404 situation, why is there no 404 ? } } elsif($rowcount == 1) { if($query->param('embed') eq "video") { $page->{'embed'} = "video"; } elsif($query->param('embed') eq "preview") { $page->{'embed'} = "preview"; } #if there was a single result, display the video my ($id, $title, $description, $publisher, $timestamp, $creator, $subject, $source, $language, $coverage, $rights, $license, $filesize, $duration, $width, $height, $fps, $viewcount, $downloadcount) = $sth->fetchrow_array(); #finish query $sth->finish() or die $dbh->errstr; #if user is logged in if($userinfo->{'username'}) { #check if a comment is about to be created if($query->param('comment')) { #output infobox $page->{'message'}->{'type'} = "information"; $page->{'message'}->{'text'} = "information_comment_created"; #add to database $dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef, $userinfo->{'id'}, $id, $query->param('comment')) or die $dbh->errstr; #send pingbacks to every url in the comment my (@matches) = $query->param('comment') =~ /(http:\/\/\S+)/gi; foreach $match (@matches) { #ask for http header only - if pingbacks are implemented right, then we wont need the full site my $request = HTTP::Request->new(HEAD => $match); my $ua = LWP::UserAgent->new; my $response = $ua->request($request); if ($response->is_success) { my $pingbackurl = $response->header("x-pingback"); #if there was no x-pingback header, fetch the website and search for link element if (!$pingbackurl) { $request = HTTP::Request->new(GET => $match); $response = $ua->request($request); if ($response->is_success) { ($pingbackurl) = $response->content =~ //; } } #if requests were successful, send the pingbacks if ($pingbackurl) { #TODO: expand xml entities < > & " in $pingbackurl #contruct the xml-rpc request my $xmlpost = (); $xmlpost->{"methodName"} = ["pingback.ping"]; push @{$xmlpost->{'params'}->{'param'} }, { "value" => { "string" => [$config->{"url_root"}."/video/".urlencode($title)."/$id/"] } }; push @{$xmlpost->{'params'}->{'param'} }, { "value" => { "string" => [$match] } }; #post a xml-rpc request $request = HTTP::Request->new(POST => $pingbackurl); $request->header('Content-Type' => "application/xml"); $request->content(XMLout( $xmlpost, XMLDecl => 1, KeyAttr => {}, RootName => 'methodCall' )); $ua = LWP::UserAgent->new; $response = $ua->request($request); #TODO: maybe do something on success? } } } } } #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 } } }; #get 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 }; } print output_page(); } } else { $page->{'message'}->{'type'} = "error"; $page->{'message'}->{'text'} = "error_202c"; print output_page(); }