Add Fletcher Penney plugins to general.
[matthijs/upstream/blosxom-plugins.git] / general / autolink
1 # Bloxsom Plugin:AutoLink
2 # Author: Fletcher T. Penney
3 # Version: 0.3
4 # modelled after dictionary by Gregory Bair
5
6 package autolink;
7
8 # --- Configurable variables ----
9
10 # Where is the definition page
11 $link_file = "$blosxom::datadir/autolinks";
12
13
14 # -------------------------------
15
16 $ignore = 0;
17
18 sub start {
19         open (LINKS, $link_file);
20         @linkslist = <LINKS>;
21         close LINKS;
22         1;
23 }
24
25 sub story {
26         my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
27
28         if ($$story_ref =~ m/<!-- noautolink -->/gi || $$body_ref =~ m/<!-- noautolink -->/gi) {
29                 $ignore = 1;
30         }
31
32         if ($ignore == 0) {
33                 foreach $i (@linkslist) {
34                         if ($i =~ /(.*?)=(.*)/) {
35                                 $word = $1;
36                                 $link = $2;
37
38 # By default, autolinks now changes only the first occurence of a given term
39 # If you want to change all occurences, 
40 # change the end of the following line to '\/a>/ig'
41                                 $$body_ref =~ s/(?<=\s)($word)(?=([\s\,\!\;]|\.\s|\:\s|[\(\)]\s))/<a href="$link">$1<\/a>/i;
42                         }
43                 }
44         }
45         1;
46 }
47
48 1;
49
50
51 __END__
52
53 =head1 NAME
54
55 Blosxom Plug-in: autolink
56
57 =head1 DESCRIPTION
58
59 Allows you to create a list of keywords that are automatically converted to a url whenever they are used in a story.  You can insert "<!-- noautolink -->" in a story to prevent any changes
60
61 You can set your own location for the autolinks data file, but by default it lives in your data directory.
62
63 =head1 AUTHOR
64
65 Fletcher T. Penney - http://fletcher.freeshell.org
66
67
68 =head1 LICENSE
69
70 This source is submitted to the public domain.  Feel free to use and modify it.  If you like, a comment in your modified source attributing credit to myself and Gregory Bair for his original work would be appreciated.
71
72 THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.  USE AT YOUR OWN RISK!