App-Phoebe
view release on metacpan or search on metacpan
lib/App/Phoebe.pm view on Meta::CPAN
next if $seen{$name . "\x1c"};
$stream->write("<entry>\n");
$stream->write(encode_utf8 "<title>" . quote_html($name) . " (file)</title>\n");
my $link = to_url($stream, $host, $space, "file/$id", $scheme);
$stream->write("<link href=\"$link\"/>\n");
$stream->write("<id>$link</id>\n");
$seen{$name . "\x1c"} = 1;
}
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime($ts); # 2003-12-13T18:30:02Z
$ts = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
$stream->write("<updated>$ts</updated>\n");
$feed_ts = $ts if $ts gt $feed_ts;
$stream->write("<author><name>$code</name></author>\n");
$stream->write("</entry>\n");
}
$stream->write("<updated>$feed_ts</updated>\n");
$stream->write("</feed>\n");
}
sub serve_blog_atom {
my $stream = shift;
my $host = shift;
my $space = shift;
$log->info("Serving Gemini Blog Atom");
success($stream, "application/atom+xml");
blog_atom($stream, $host, $space, 'gemini');
lib/App/Phoebe.pm view on Meta::CPAN
# hard coded: 10 pages blog ATOM, no pagination
for my $id (@blog[0 .. min($#blog, 9)]) {
$stream->write("<entry>\n");
$stream->write(encode_utf8 "<title>" . quote_html($id) . "</title>\n");
my $link = to_url($stream, $host, $space, "page/$id", $scheme);
$stream->write("<link href=\"$link\"/>\n");
$stream->write("<id>$link</id>\n");
$stream->write(encode_utf8 "<content type=\"text\">" . quote_html(text($stream, $host, $space, $id)) . "</content>\n");
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime($changes->{$id}); # 2003-12-13T18:30:02Z
my $ts = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
$stream->write("<updated>$ts</updated>\n");
$feed_ts = $ts if $ts gt $feed_ts;
$stream->write("</entry>\n");
}
$stream->write("<updated>$feed_ts</updated>\n");
$stream->write("</feed>\n");
}
sub serve_raw {
my $stream = shift;
my $host = shift;
my $space = shift;
my $id = shift;
my $revision = shift;
$log->info("Serving raw $id");
lib/App/Phoebe/Oddmuse.pm view on Meta::CPAN
my $data = parse_data($entry);
$stream->write("<channel>\n");
$stream->write(encode_utf8 "<title>" . quote_html($data->{title}) . "</title>\n");
$stream->write(encode_utf8 "<description>" . quote_html($data->{description}) . "</description>\n");
$stream->write("<link>$scheme://$host:$port/</link>\n");
$stream->write("<atom:link rel=\"self\" type=\"application/rss+xml\" href=\"$scheme://$host:$port/do/rss\" />\n");
$stream->write("<generator>Phoebe + Config</generator>\n");
$stream->write("<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n");
my $dir = $oddmuse_wiki_dirs{$host};
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(modified("$dir/pageidx"));
$stream->write("<updated>"
. sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec)
. "</updated>\n");
while (@entries) {
$data = parse_data(shift(@entries));
$stream->write("<item>\n");
# namespaces
my $ns;
my $title = $data->{title};
if ($title =~ /:/) {
($ns, $title) = split(/:/, $title);
}
my $id = free_to_normal($title);
lib/App/Phoebe/Oddmuse.pm view on Meta::CPAN
my $action = shift;
my $port = port($stream);
$log->info("Serving Gemini Atom");
success($stream, "application/atom+xml");
$stream->write(qq{<?xml version="1.0" encoding="UTF-8"?>\n});
$stream->write("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n");
$stream->write("<link href=\"gemini:/$host:$port/\"/>\n");
$stream->write("<link rel=\"self\" type=\"application/atom+xml\" href=\"gemini://$host:$port/do/atom\"/>\n");
$stream->write("<id>gemini:/$host:$port/do/atom</id>\n");
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(modified("$oddmuse_wiki_dirs{$host}/pageidx"));
$stream->write("<updated>"
. sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec)
. "</updated>\n");
$stream->write("<generator uri=\"gemini://$host:$port/\" version=\"1.0\">Phoebe + Config</generator>\n");
# now get the data and print the entries
my $url = "$oddmuse_wikis{$host}?action=$action;raw=1;full=1";
if ($space) {
$url .= ";ns=$space";
}
my $page = oddmuse_get_raw($stream, $url) // return;
my @entries = split(/\n\n+/, $page);
my $data = parse_data(shift @entries);
$stream->write(encode_utf8 "<title>" . quote_html($data->{title}) . "</title>\n");
lib/App/Phoebe/Oddmuse.pm view on Meta::CPAN
$data = parse_data(shift @entries);
$stream->write("<entry>\n");
my $name = $data->{title};
my $id = free_to_normal($name);
$stream->write(encode_utf8 "<title>$name</title>\n");
my $link = "gemini://$host:$port/page/" . uri_escape_utf8($id);
$stream->write("<link href=\"$link\"/>\n");
$stream->write("<id>$link</id>\n");
my $summary = quote_html(oddmuse_gemini_text($stream, $host, $space, $data->{description}, $id));
$stream->write(encode_utf8 "<content type=\"text\">$summary</content>\n") if $summary;
$stream->write("<updated>$data->{'last-modified'}</updated>\n");
$stream->write("</entry>\n");
};
$stream->write("</feed>\n");
}
sub oddmuse_comment {
my $stream = shift;
my $host = shift;
my $space = shift;
my $id = shift;
lib/App/Phoebe/Oddmuse.pm view on Meta::CPAN
push(@tokens, @{$server->{wiki_token}}) unless @tokens;
if (not $fingerprints{$fingerprint}) {
if (not $token) {
result($stream, "10", "Token required to edit this wiki");
} elsif (not grep { $token eq $_ } @tokens) {
result($stream, "59", "Wrong token");
} else {
result($stream, "10", "Short comment");
$fingerprints{$fingerprint} = $now;
}
# Save new or updated fingerprint timestamp.
write_text($file, join("\n", map { "$_ $fingerprints{$_}" } keys %fingerprints));
# Return undefined so that the user needs to react to the message above.
return;
}
# Fingerprint found!
$fingerprints{$fingerprint} = $now;
# Save new or updated fingerprint timestamp.
write_text($file, join("\n", map { "$_ $fingerprints{$_}" } keys %fingerprints));
# User wants to provide no name: use "" so that we have a defined name.
return ($stream->handle->peer_certificate('cn') || "");
}
t/Oddmuse.t view on Meta::CPAN
}
die "$!: giving up after ${total}s\n" unless $ok;
# Test Oddmuse, and create the Test page in the main namespace (with the text
# "Alex"), in the "Travels" namespace (with the text "Berta"), and in a Mëtal
# namespace (with the text "Chloë"), and the page "Link" that links to it.
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Test&text=Fnord")->result;
is($res->code, 302, "Oddmuse save page");
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Test&text=Alex")->result;
is($res->code, 302, "Oddmuse updated page");
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Link&text=[M%C3%ABtal:Test Mëtal Link]")->result;
is($res->code, 302, "Oddmuse updated page");
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Test&text=Check%20out%20[[Bet]].&ns=Travels")->result;
is($res->code, 302, "Oddmuse save page in namespace");
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Test&text=Bert&ns=Travels")->result;
is($res->code, 302, "Oddmuse save page in namespace");
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Test&text=Berta&ns=Travels")->result;
is($res->code, 302, "Oddmuse updated page in namespace");
$res = $ua->get("http://localhost:$oddmuse_port/wiki?title=Test&text=Chlo%C3%AB&ns=M%C3%ABtal")->result;
is($res->code, 302, "Oddmuse updated page in namespace with umlauts");
$res = $ua->get("http://localhost:$oddmuse_port/wiki/raw/Test")->result;
is($res->code, 200, "Oddmuse read page");
is($res->body, "Alex\n", "Oddmuse page content");
$res = $ua->get("http://localhost:$oddmuse_port/wiki/Travels/raw/Test")->result;
is($res->code, 200, "Oddmuse read page from namespace");
is($res->body, "Berta\n", "Oddmuse page content from namespace");
$res = $ua->get("http://localhost:$oddmuse_port/wiki/M%C3%ABtal/raw/Test")->result;
is($res->code, 200, "Oddmuse read page from umlaut namespace");
is($res->body, encode_utf8("Chloë\n"), "Oddmuse umlaut page content from umlaut namespace");
t/oddmuse-wiki.pl view on Meta::CPAN
$rss .= "<title>$name</title>\n";
my $link = ScriptUrl(GetParam('all', $cluster)
? GetPageParameters('browse', $id, $revision, $cluster, $last)
: UrlEncode($id));
$rss .= "<link>$link</link>\n<guid>$link</guid>\n";
$rss .= "<description>" . QuoteHtml($summary) . "</description>\n" if $summary;
$rss .= "<pubDate>" . $date . "</pubDate>\n";
$rss .= "<comments>" . ScriptUrl($CommentsPrefix . UrlEncode($id))
. "</comments>\n" if $CommentsPattern and $id !~ /$CommentsPattern/;
$rss .= "<dc:contributor>" . $username . "</dc:contributor>\n" if $username;
$rss .= "<wiki:status>" . (1 == $revision ? 'new' : 'updated') . "</wiki:status>\n";
$rss .= "<wiki:importance>" . ($minor ? 'minor' : 'major') . "</wiki:importance>\n";
$rss .= "<wiki:version>" . $revision . "</wiki:version>\n";
$rss .= "<wiki:history>" . ScriptUrl("action=history;id=" . UrlEncode($id))
. "</wiki:history>\n";
$rss .= "<wiki:diff>" . ScriptUrl("action=browse;diff=1;id=" . UrlEncode($id))
. "</wiki:diff>\n" if $UseDiff and GetParam('diffrclink', 1);
return $rss . "</item>\n";
}
sub DoRss {
t/oddmuse-wiki.pl view on Meta::CPAN
my $author = GetAuthorLink($entry{username});
$author ||= $entry{generator};
my $id = $entry{title};
my ($class, $resolved, $title, $exists) = ResolveId($id);
my $text = NormalToFree($id);
my $result = $q->span({-class=>'result'}, ScriptLink(UrlEncode($resolved), $text, $class, undef, $title));
my $description = $entry{description};
$description = $q->br() . $description if $description;
my $info = $entry{size};
$info .= ' - ' if $info;
$info .= T('last updated') . ' ' . $entry{'last-modified'} if $entry{'last-modified'};
$info .= ' ' . T('by') . ' ' . $author if $author;
$info = $q->br() . $q->span({-class=>'info'}, $info) if $info;
print $q->p($result, $description, $info);
}
}
sub SearchHighlight {
my ($data, $regex) = @_;
$data =~ s/($regex)/<strong>$1<\/strong>/gi unless GetParam('raw');
return $data;
( run in 0.292 second using v1.01-cache-2.11-cpan-05444aca049 )