tagging: Allow using titles in for related stories.
[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
60 url whenever they are used in a story.  You can insert "<!-- noautolink -->"
61 in a story to prevent any changes
62
63 You can set your own location for the autolinks data file, but by default it
64 lives in your data directory.
65
66 =head1 BUGS
67
68 None known; please send bug reports and feedback to the Blosxom
69 development mailing list <blosxom-devel@lists.sourceforge.net>.
70
71 =head1 AUTHOR
72
73 Fletcher T. Penney - http://fletcher.freeshell.org
74
75 This plugin is now maintained by the Blosxom Sourceforge Team,
76 <blosxom-devel@lists.sourceforge.net>.
77
78 =head1 LICENSE
79
80 This source is submitted to the public domain.  Feel free to use and modify
81 it.  If you like, a comment in your modified source attributing credit to
82 myself and Gregory Bair for his original work would be appreciated.
83
84 THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.  USE AT
85 YOUR OWN RISK!
86