enabled xhtml comments

git-svn-id: http://yolanda.mister-muffin.de/svn@321 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-04-27 10:39:21 +00:00
parent 8d9a158957
commit 6c172e1057
8 changed files with 145 additions and 123 deletions

View file

@ -26,18 +26,18 @@ sub get_page_array
#get parameters
my (@userinfo) = @_;
my $root = XML::LibXML::Element->new( "page" );
my $page = XML::LibXML::Element->new( "page" );
my ($locale) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
$root->setAttribute( "locale", $locale ? $locale : "en_us" );
$page->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);
$page->setAttribute( "username", $userinfo->{'username'} );
$page->setNamespace("http://www.w3.org/1999/xhtml", "xhtml", 0);
$page->setNamespace("http://web.resource.org/cc/", "cc", 0);
$page->setNamespace("http://purl.org/dc/elements/1.1/", "dc", 0);
$page->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0);
return $root;
return $page;
}
# index.pl (display custom search)

View file

@ -9,9 +9,9 @@ $session = new CGI::Session;
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
my $page = get_page_array(@userinfo);
$root->appendChild(XML::LibXML::Element->new( "frontpage" ));
$page->appendChild(XML::LibXML::Element->new( "frontpage" ));
if($query->param('information'))
{
@ -19,7 +19,7 @@ if($query->param('information'))
$message->setAttribute("type", "information");
$message->setAttribute("text", $query->param('information'));
$message->setAttribute("value",$query->param('value'));
$root->appendChild($message);
$page->appendChild($message);
}
elsif($query->param('error'))
{
@ -27,7 +27,7 @@ elsif($query->param('error'))
$message->setAttribute("type", "error");
$message->setAttribute("text", $query->param('error'));
$message->setAttribute("value",$query->param('value'));
$root->appendChild($message);
$page->appendChild($message);
}
elsif($query->param('warning'))
{
@ -35,7 +35,7 @@ elsif($query->param('warning'))
$message->setAttribute("type", "warning");
$message->setAttribute("text", $query->param('warning'));
$message->setAttribute("value",$query->param('value'));
$root->appendChild($message);
$page->appendChild($message);
}
my $tagcloud = XML::LibXML::Element->new( "tagcloud" );
@ -58,7 +58,7 @@ while (my ($text, $count) = $sth->fetchrow_array())
#finish query
$sth->finish() or die $dbh->errstr;
$root->appendChild($tagcloud);
$page->appendChild($tagcloud);
foreach $strquery ($config->{"search_frontpage_one_query"}, $config->{"search_frontpage_two_query"}, $config->{"search_frontpage_three_query"})
{
@ -163,9 +163,9 @@ foreach $strquery ($config->{"search_frontpage_one_query"}, $config->{"search_fr
$results->appendChild($result);
}
$root->appendChild($results);
$page->appendChild($results);
}
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);

View file

@ -7,9 +7,7 @@ $session = new CGI::Session;
@userinfo = get_userinfo_from_sid($session->id);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
#TODO: use $query->http("HTTP_REFERER"); to redirect to the site last visited
if($query->param('action') eq "logout")
{

View file

@ -9,7 +9,7 @@ $session = new CGI::Session;
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
my $page = get_page_array(@userinfo);
#check if user is logged in
if($username)
@ -17,9 +17,9 @@ if($username)
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_already_registered");
$root->appendChild($message);
$page->appendChild($message);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}
@ -36,14 +36,14 @@ 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())
{
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_username_already_registered");
$root->appendChild($message);
$page->appendChild($message);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}
@ -58,62 +58,62 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re
}
else
{
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_passwords_do_not_match");
$root->appendChild($message);
$page->appendChild($message);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}
}
elsif(not $query->param('user') and ($query->param('pass') or $query->param('pass_repeat')))
{
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_insert_username");
$root->appendChild($message);
$page->appendChild($message);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}
elsif(not $query->param('pass') and ($query->param('user') or $query->param('pass_repeat')))
{
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_insert_password");
$root->appendChild($message);
$page->appendChild($message);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}
elsif(not $query->param('pass_repeat') and ($query->param('user') or $query->param('pass')))
{
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_repeat_password");
$root->appendChild($message);
$page->appendChild($message);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}
else
{
$root->appendChild(XML::LibXML::Element->new( "registerform" ));
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}

View file

@ -9,7 +9,7 @@ $session = new CGI::Session;
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
my $page = get_page_array(@userinfo);
#check if query is set
if($query->param('query'))
@ -18,10 +18,10 @@ if($query->param('query'))
if($dbquery)
{
$root->appendChild(fill_results($dbquery, @args));
$root->setAttribute('query', $query->param('query'));
$page->appendChild(fill_results($dbquery, @args));
$page->setAttribute('query', $query->param('query'));
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
my @results = $doc->findnodes( "//results/result" );

View file

@ -9,7 +9,7 @@ my @userinfo = get_userinfo_from_sid($session->id);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
my $page = get_page_array(@userinfo);
if($userinfo->{'username'})
{
@ -19,12 +19,12 @@ if($userinfo->{'username'})
@userinfo = get_userinfo_from_sid($session->id);
$root = get_page_array(@userinfo);
$page = get_page_array(@userinfo);
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "information");
$message->setAttribute("text", "information_settings_changed");
$root->appendChild($message);
$page->appendChild($message);
}
}
@ -33,16 +33,16 @@ if($userinfo->{'username'})
{
my $settings = XML::LibXML::Element->new( "settings" );
$settings->setAttribute("pagesize", $userinfo->{'pagesize'});
$root->appendChild($settings);
$page->appendChild($settings);
}
else
{
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "error");
$message->setAttribute("text", "error_202c");
$root->appendChild($message);
$page->appendChild($message);
}
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);

View file

@ -9,7 +9,7 @@ $session = new CGI::Session;
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $root = get_page_array(@userinfo);
my $page = get_page_array(@userinfo);
#check if id or title is passed
if($query->url_param('id'))
@ -54,11 +54,11 @@ if($query->url_param('id'))
{
if($query->param('embed') eq "video")
{
$root->setAttribute( "embed", "video" );
$page->setAttribute( "embed", "video" );
}
elsif($query->param('embed') eq "preview")
{
$root->setAttribute( "embed", "preview" );
$page->setAttribute( "embed", "preview" );
}
#if there was a single result, display the video
@ -75,78 +75,97 @@ if($query->url_param('id'))
#check if a comment is about to be created
if($query->param('comment'))
{
#output infobox
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,
$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)
my $dtd = XML::LibXML::Dtd->new(0, "$root/site/comment.dtd");
$dom = XML::LibXML->new;
$dom->clean_namespaces(1);
eval { $doc = $dom->parse_string("<comment>".$query->param('comment')."</comment>") };
if ($@)
{
#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)
die $@;
}
else
{
eval { $doc->validate($dtd) };
if ($@)
{
my $pingbackurl = $response->header("x-pingback");
die $@;
}
else
{
#output infobox
my $message = XML::LibXML::Element->new( "message" );
$message->setAttribute("type", "information");
$message->setAttribute("text", "information_comment_created");
$page->appendChild($message);
#if there was no x-pingback header, fetch the website and search for link element
if (!$pingbackurl)
#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') =~ /<a[^>]+href="(http:\/\/\S+)"[^>]*>.+?<\/a>/gi;
foreach $match (@matches)
{
$request = HTTP::Request->new(GET => $match);
$response = $ua->request($request);
#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)
{
($pingbackurl) = $response->content =~ /<link rel="pingback" href="([^"]+)" ?\/?>/;
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 =~ /<link rel="pingback" href="([^"]+)" ?\/?>/;
}
}
#if requests were successful, send the pingbacks
if ($pingbackurl)
{
#TODO: expand xml entities &lt; &gt; &amp; &quot; 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?
}
}
}
#if requests were successful, send the pingbacks
if ($pingbackurl)
{
#TODO: expand xml entities &lt; &gt; &amp; &quot; 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?
}
}
}
}
@ -236,7 +255,7 @@ if($query->url_param('id'))
$video->appendChild($rdf);
$root->appendChild($video);
$page->appendChild($video);
#get comments
my $comments = XML::LibXML::Element->new( "comments" );
@ -247,17 +266,22 @@ if($query->url_param('id'))
$sth->execute($id) or die $dbh->errstr;
while (my ($commentid, $text, $username, $timestamp) = $sth->fetchrow_array())
{
my $comment = XML::LibXML::Element->new( "comment" );
my $dom = XML::LibXML->new;
my $doc = $dom->parse_string("<comment>".$text."</comment>");
my $comment = $doc->documentElement();
foreach $node ($comment->getElementsByTagName("*"))
{
$node->setNamespace("http://www.w3.org/1999/xhtml", "xhtml");
}
$comment->setAttribute('username', $username);
$comment->setAttribute('timestamp', $timestamp);
$comment->setAttribute('id', $commentid);
$comment->appendTextChild("text", $text);
$comments->appendChild($comment);
}
$root->appendChild($comments);
$page->appendChild($comments);
$doc->setDocumentElement($root);
$doc->setDocumentElement($page);
output_page($doc);
}

View file

@ -90,10 +90,10 @@
<!--
comment system is broken (similar to the german online petition system)
if a video ever gets OVER NEIN THOUSAND comments, the shit hits the fan
-->
<xsl:call-template name="commentform"/>
<xsl:call-template name="comments"/>
-->
</xsl:template>
@ -109,7 +109,7 @@
<xsl:value-of select="@username" />
</a>:
<br />
<xsl:value-of select="." />
<xsl:copy-of select="." />
</div>
</xsl:for-each>
</div>