tagcloud-1.4.orig/0000755000000000000000000000000011321333733011004 5ustar tagcloud-1.4.orig/bin/0000755000000000000000000000000011320660552011555 5ustar tagcloud-1.4.orig/bin/tagcloud0000500000000000000000000002066711272203367013307 0ustar #!/usr/bin/perl -w use strict; # OS X hack - tell CGI where to write uploaded temp files. Otherwise, # the uploaded file seems to get lost... BEGIN {$ENV{TMPDIR} = '/var/tmp';} use FindBin; use lib "$FindBin::Bin/lib"; use HTML::TagCloud; use HTML::Entities; use Getopt::Long; # Parse the notes file, locating tags at the end of entries and # building up two data structures. # # Both of these structures collect "notes," references in %lines and # the actual scalar in @all_notes, which contains a note ready for # display in our HTML output. First, these notes have had HTML # elements encoded to simplify processing and make it harder to do # nasty things to the user's browser. Then the tags at the end of the # lines have been turned into links, same as are used in the tag # cloud, to enhance navigation. # # %lines # foo => [ # "note ref (tagged with foo)", # "another note ref (tagged with foo)", # ... # ] # # @all_notes - arrary of the set of all notes refered to in %lines - # in other words, every note found. Used in searching. our $filename; # Name of the parsed notes file our $cloud; our %lines; our @all_notes; # Parse notes file or files. Argument list is either a single file # handle from a CGI upload, in which case it's a ref, or else a list # of filenames provided via the command line --files option, in which # case I need to open them and parse them. sub parse_notes_file { # Reset on new file %lines = (); @all_notes = (); # URL used in constructing tag-links my $url = '?tag='; my $fh; foreach my $element (@_) { if (ref $element) { $fh = $element; } else { open ($fh, $element) or die "Can't open $element: $!\n"; } local $/ = "\n\n"; # Double-newline separates input records while (<$fh>) { # Need a copy of the "note" to work on and refer to, and we need # it with HTML chars like <, >, etc, escaped to "<", ">", # etc. my $this_line = HTML::Entities::encode($_); # Pop words off the end of the note, processing them as tags as # long as they start with "@". Keep a list of these tags so that # we can wrap them in href's when we're done picking them out. my @tags; # tags found at the end of this note foreach my $tag ( reverse split ) { last unless $tag =~ s/^\@//; # Not a tag, bail push @tags, $tag; push (@{$lines{$tag}}, \$this_line); } foreach my $tag (@tags) { # Greedy match in $1 insures that $2 will be the last instance # of $tag in the note - in other words, the one on the end with # the "@" prefix. And we know that each $tag was parsed off the # end of this note, insuring this works. $this_line =~ s|(.*)\b($tag)\b|$1$2|s; } push @all_notes, $this_line; } } # Build tag cloud $cloud = HTML::TagCloud->new(levels => 24); foreach my $tag (keys %lines) { $cloud->add($tag, $url.$tag, scalar @{$lines{$tag}}); } } # Dirt-simple web server - displays the tag cloud, and the set of all # notes that match a given tag, if provided. Also accepts requests to # search the notes, showing highlighted results. { package MyWebServer; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); sub handle_request { my $self = shift; my $cgi = shift; return if !ref $cgi; # If you were given a file of notes to parse, then do so my $fh = $cgi->upload('upload'); &main::parse_notes_file($fh) if $fh; # Print out the headers, html, the tag cloud, and the search form. $main::filename = $cgi->param('upload') if $cgi->param('upload');; my $title = 'Tag Cloud' . ($main::filename ? " for $main::filename" : ''); print "HTTP/1.0 200 OK\r\n", $cgi->header, $cgi->start_html($title); # Only print the tag cloud, search box, and results if you've parsed a file if (scalar @all_notes) { print $main::cloud->html_and_css(); print $cgi->start_form(), "

Search all notes for: ", $cgi->textfield('search_string'), $cgi->submit(-value => 'Search'), $cgi->end_form(), "
(search is case-insensitive)

"; print "


"; # Now do something interesting with your params, if any. my $tag = $cgi->param('tag'); my $search_string = $cgi->param('search_string'); if ($search_string) { # Display search results my $output; # Perform same HTML encoding on the search string that we did on # the notes, so that searching for things like "<" will work. $search_string = HTML::Entities::encode($search_string); print $cgi->h1("Notes that match \"$search_string\""); # A little ugly: We're going to grep thru @all_notes looking for # a match - but we need to strip the HTML markup (which we've # added to turn tags into links) out of the notes before checking # for a match, so that you don't match inside the HTML markup # while searching. Also, you need to use a temp var, because # otherwise grep will modify $_. Finally, use \Q (quotemeta) - # we don't want full patterns here, too much risk foreach (grep {my $t; ($t=$_) =~ s/<.*?>//g; $t =~ /\Q$search_string/i} @main::all_notes) { # We want to highlight the match in yellow, but not change the # saved copy of the note - so we work on a copy, $output. # # Regex to (roughly) match an HTML tag: <.*?> # # This s/// matches either an entire tag, or our search # string. The replacement bit is executed (/e): if $2 (our # search string) has matched, wrap it in yellow. # Otherwise, $1 (a tag) is what matched, and it gets # replaced with itself. # # The /e is used instead of just saying "$1$2" (with $2 wrapped # in yellow) because that produces endless warnings about use # of undefined values - because only one of the two alternates # is ever defined in the replacement bit. ($output = $_) =~ s{(<.*?>)|($search_string)} { $2 ? "$2" : $1}eig; print $output, "

"; } } elsif ($tag) { # Display notes that match "$tag" print $cgi->h1("Notes tagged with \"$tag\""); foreach my $ref (@{$main::lines{$tag}}) { print $$ref, "

"; } } } # Always print out your upload field at the end of the page print $cgi->hr(), $cgi->start_multipart_form(), "

Create tag cloud from file: ", $cgi->filefield(-name => 'upload', -size => 60), $cgi->br(), $cgi->br(), $cgi->submit(-label => 'Load File'), "

", $cgi->end_form(); print $cgi->end_html; } } # End of web server class # Parse your command line options sub Usage { "$0 [--port N] [--files filename [filename...]]\n"; } my $port; my @files; die Usage() unless GetOptions("files=s{,}" => \@files, "port=s" => \$port); $port ||= 8080; # If you got file names on your command line, start with them. if (scalar @files) { parse_notes_file(@files); $filename = join ", ", @files; } # Start an instance of MyWebServer on port $port, only bind to localhost my $pid = MyWebServer->new($port); $pid->host('localhost'); # Spawn a web browser, pointing to us. Wait a sec for the server to get running. if (not fork()) { sleep 2; # Try a couple of different ways to open a broswer pointed at us if ($^O =~ /darwin/) { # OS X system "open http://localhost:$port"; } elsif ($^O =~ /linux/) { my $res = system "gnome-open http://localhost:$port"; # $res is -1 if gnome-open not found, 256 on error, 0 on success. # In any case, guess you're running under kde and try again. if ($res) { system "kde-open http://localhost:$port"; } } exit; } eval { $pid->run(); }; if ($@) { die "Something else is already listening to port $port, pick another port to use\n" if $@ =~ /Address already in use/; die $@; } # Copyright (c) 2008, Dan McDonald. All Rights Reserved. # This program is free software. It may be used, redistributed # and/or modified under the terms of the Perl Artistic License # (see http://www.perl.com/perl/misc/Artistic.html) # Version: $Revision: 1.4 $ # # Changelog: # # $Log: tagcloud.pl,v $ # Revision 1.4 2009/10/29 03:05:53 dan # Switched to Getopt::Long. Added --files option, changed # parse_notes_file() to take either a filehandle or a list of files to # parse. # # Revision 1.3 2009/10/21 15:23:23 dan # Made port configurable, added command line switch processing, trap # bind error and die with meaningful message. # # Revision 1.2 2009/10/21 01:58:28 dan # Added "open" code for gnome and kde desktop environments, in addition # to OS X. # # Revision 1.1 2009/10/21 01:37:21 dan # Initial revision # tagcloud-1.4.orig/Makefile.PL0000644000000000000000000000043011321333733012753 0ustar use ExtUtils::MakeMaker; WriteMakefile( NAME => "Perl::Tagcloud", ( $] >= 5.005 ? ( ABSTRACT => 'visualize notes as a tagcloud', AUTHOR => 'Dan McDonald ' ) : () ), EXE_FILES => ['bin/tagcloud'], dist => { COMPRESS => 'gzip', SUFFIX => 'gz' }, ); tagcloud-1.4.orig/COPYING0000644000000000000000000001460111320662006012036 0ustar ARTISTIC LICENSE http://www.perl.com/language/misc/Artistic.html Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a. place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b. use the modified Package only within your corporation or organization. c. rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d. make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a. distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b. accompany the distribution with the machine-readable source of the Package with your modifications. c. give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d. make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. tagcloud-1.4.orig/docs/0000755000000000000000000000000011320652477011744 5ustar tagcloud-1.4.orig/docs/tagcloud.10000644000000000000000000000166011320650336013623 0ustar .TH tagcloud 1 .SH NAME tagcloud - visualize notes as a tagcloud .SH SYNOPSIS tagcloud [ .B \-p | .B \-f ] .SH DESCRIPTION .I tagcloud allows you to visualize tagged notes as a cloud. Tagcloud will start a simple web server and display a webpage where you can choose which textfile to create a tagcloud from. If you wish to create a cloud from more than one textfile, you will have to use the -f option on the command line. .P You can click on tags to retrieve the notes, as well as search the fulltext of all the notes. Each tag will have to be indicated by an "@" prefix in the textfile. For example: "Rock Paper Scissor Lizard Spock @tbbt". .SH OPTIONS .TP .B -p Set the port you want the web server to run on. Default is 8080. .TP .B -f List the textfiles you want to visualize in the tagcloud. .SH AUTHOR This manual page was written by Runa Sandvik , for the Debian GNU/Linux system (but may be used by others).