| 1 | Index: Utils.pm |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- Utils.pm (revision 756) |
|---|
| 4 | +++ Utils.pm (working copy) |
|---|
| 5 | @@ -2,12 +2,14 @@ |
|---|
| 6 | |
|---|
| 7 | use strict; |
|---|
| 8 | use vars qw( $VERSION ); |
|---|
| 9 | -$VERSION = '0.09'; |
|---|
| 10 | +$VERSION = '0.08'; |
|---|
| 11 | |
|---|
| 12 | use Carp qw( croak ); |
|---|
| 13 | +use Flickr::API; |
|---|
| 14 | use CGI::Wiki; |
|---|
| 15 | use CGI::Wiki::Formatter::UseMod; |
|---|
| 16 | use CGI::Wiki::Plugin::RSS::Reader; |
|---|
| 17 | +use CGI::Wiki::Plugin::ListLinks; |
|---|
| 18 | use URI::Escape; |
|---|
| 19 | |
|---|
| 20 | =head1 NAME |
|---|
| 21 | @@ -111,11 +113,53 @@ |
|---|
| 22 | |
|---|
| 23 | # Make formatter. |
|---|
| 24 | my $script_name = $config->script_name; |
|---|
| 25 | - my $search_url = $config->script_url . "search.cgi"; |
|---|
| 26 | + my $search_url = $config->script_url . "supersearch.cgi"; |
|---|
| 27 | |
|---|
| 28 | my %macros = ( |
|---|
| 29 | '@SEARCHBOX' => |
|---|
| 30 | qq(<form action="$search_url" method="get"><input type="text" size="20" name="search"><input type="submit" name="Go" value="Search"></form>), |
|---|
| 31 | + qr/\@MAP_LINK\s+\[\[(Category|Locale)\s+([^\]|]+)\|?([^\]]+)?\]\]/ => |
|---|
| 32 | + sub { |
|---|
| 33 | + # We may be being called by CGI::Wiki::Plugin::Diff, |
|---|
| 34 | + # which doesn't know it has to pass us $wiki - and |
|---|
| 35 | + # we don't use it anyway. |
|---|
| 36 | + if ( UNIVERSAL::isa( $_[0], "CGI::Wiki" ) ) { |
|---|
| 37 | + shift; # just throw it away |
|---|
| 38 | + } |
|---|
| 39 | + my $link_title = $_[2] || "View map of pages in $_[0] $_[1]"; |
|---|
| 40 | + return qq(<a href="$script_name?action=index;index_type=) . uri_escape(lc($_[0])) . qq(;index_value=) . uri_escape($_[1]) . qq(;format=map">$link_title</a>); |
|---|
| 41 | + }, |
|---|
| 42 | + qr/\@INCLUDE_NODE\s+\[\[([^\]|]+)\]\]/ => |
|---|
| 43 | + sub { |
|---|
| 44 | + my ($wiki, $node) = @_; |
|---|
| 45 | + if ( UNIVERSAL::isa( $_[0], "CGI::Wiki" ) ) { |
|---|
| 46 | + shift; # just throw it away |
|---|
| 47 | + } |
|---|
| 48 | + my %node_data = $wiki->retrieve_node( $node ); |
|---|
| 49 | + return $node_data{content}; |
|---|
| 50 | + }, |
|---|
| 51 | + |
|---|
| 52 | + qr/\@PREFIX_LIST\s+\[\[([^&]*)\]\]/ => |
|---|
| 53 | + sub { |
|---|
| 54 | + my ($wiki, $prefix) = @_; |
|---|
| 55 | + if ( UNIVERSAL::isa( $_[0], "CGI::Wiki" ) ) { |
|---|
| 56 | + shift; # just throw it away |
|---|
| 57 | + } |
|---|
| 58 | + |
|---|
| 59 | + my $list = CGI::Wiki::Plugin::ListLinks->new; |
|---|
| 60 | + $wiki->register_plugin( plugin => $list ); |
|---|
| 61 | + my @list = $list->backlinks_by_prefix( prefix=>"Image:" ); |
|---|
| 62 | + my $listHtml = ""; |
|---|
| 63 | + foreach my $i (@list) { |
|---|
| 64 | + $listHtml .= "* " |
|---|
| 65 | + . $wiki->formatter->format_link( |
|---|
| 66 | + wiki => $wiki, |
|---|
| 67 | + link => $i, |
|---|
| 68 | + ) |
|---|
| 69 | + . "\n"; |
|---|
| 70 | + } |
|---|
| 71 | + return $listHtml; |
|---|
| 72 | + }, |
|---|
| 73 | qr/\@INDEX_LINK\s+\[\[(Category|Locale)\s+([^\]|]+)\|?([^\]]+)?\]\]/ => |
|---|
| 74 | sub { |
|---|
| 75 | # We may be being called by CGI::Wiki::Plugin::Diff, |
|---|
| 76 | @@ -127,6 +171,23 @@ |
|---|
| 77 | my $link_title = $_[2] || "View all pages in $_[0] $_[1]"; |
|---|
| 78 | return qq(<a href="$script_name?action=index;index_type=) . uri_escape(lc($_[0])) . qq(;index_value=) . uri_escape($_[1]) . qq(">$link_title</a>); |
|---|
| 79 | }, |
|---|
| 80 | + qr/\[\[Image:(\d+)(?:\|(s|m|l))?(?:\|(.*))?\]\]/i => |
|---|
| 81 | + sub { |
|---|
| 82 | + my ($wiki, $id, $size, $style) = @_; |
|---|
| 83 | + $size = $size || "s"; |
|---|
| 84 | + |
|---|
| 85 | + my $api = new Flickr::API({'key' => $config->flickr_key, |
|---|
| 86 | + 'secret' => $config->flickr_secret}); |
|---|
| 87 | + my $response = $api->execute_method('flickr.photos.getInfo', { |
|---|
| 88 | + 'photo_id' => $id |
|---|
| 89 | + }); |
|---|
| 90 | + my $data = $response->content(); |
|---|
| 91 | + $data =~ m/<photo id="(.*?)" secret="(.*?)" server="(.*?)"/; |
|---|
| 92 | + my ($id, $secret, $server) = ($1, $2, $3); |
|---|
| 93 | + $data =~ m/<owner.*nsid="(.*?)".*username="(.*?)"/; |
|---|
| 94 | + my $owner = $2 || $1; |
|---|
| 95 | + return qq(<a href='http://www.flickr.com/photos/$owner/$id/'><img src='http://static.flickr.com/$server/${id}_${secret}_$size.jpg' style='$style' /></a>); |
|---|
| 96 | + }, |
|---|
| 97 | qr/\@INDEX_LIST\s+\[\[(Category|Locale)\s+([^\]]+)]]/ => |
|---|
| 98 | sub { |
|---|
| 99 | my ($wiki, $type, $value) = @_; |
|---|
| 100 | @@ -200,11 +261,11 @@ |
|---|
| 101 | implicit_links => 0, |
|---|
| 102 | allowed_tags => [qw(a p b strong i em pre small img table td |
|---|
| 103 | tr th br hr ul li center blockquote kbd |
|---|
| 104 | - div code strike sub sup font)], |
|---|
| 105 | + div code strike sub sup font span)], |
|---|
| 106 | macros => \%macros, |
|---|
| 107 | pass_wiki_to_macros => 1, |
|---|
| 108 | node_prefix => "$script_name?", |
|---|
| 109 | - edit_prefix => "$script_name?action=edit&id=", |
|---|
| 110 | + edit_prefix => "$script_name?action=edit&id=", |
|---|
| 111 | munge_urls => 1, |
|---|
| 112 | ); |
|---|
| 113 | |
|---|